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,
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// 修改广告
|
||||
func Modify(ctx context.Context, in *pb.AdsItem) (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
|
||||
}
|
||||
@@ -26,6 +26,13 @@ func Modify(ctx context.Context, in *pb.AdsItem) (reply *pb.IdentityStatusReply,
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 只能修改当前登录者所属店铺的广告
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
data := models.MallAds{
|
||||
Title: in.Title,
|
||||
PosKey: in.PosKey,
|
||||
@@ -35,11 +42,15 @@ func Modify(ctx context.Context, in *pb.AdsItem) (reply *pb.IdentityStatusReply,
|
||||
Std_IICUDS: types.Std_IICUDS{Status: int8(in.GetStatus())},
|
||||
}
|
||||
|
||||
err = impl.DBService.Select("title", "pos_key", "content", "type", "to_url").Where("id=?", in.GetId()).Updates(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
tx := impl.DBService.Select("title", "pos_key", "content", "type", "to_url").
|
||||
Where("id=?", in.GetId()).Where("store_identity = ?", storeIdentity).Updates(&data)
|
||||
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