fix version 1
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
// 删除广告
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,22 @@ func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusR
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Delete(&models.MallAds{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
// 只能删除当前登录者所属店铺的广告
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("store_identity = ?", storeIdentity).Delete(&models.MallAds{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
Reference in New Issue
Block a user