fix version 1
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
// 修改公告
|
||||
func Modify(ctx context.Context, in *pb.NoticeItem) (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
|
||||
}
|
||||
@@ -24,18 +24,29 @@ func Modify(ctx context.Context, in *pb.NoticeItem) (reply *pb.IdentityStatusRep
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
// 只能修改当前登录者所属店铺的公告
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
data := models.MallNotice{
|
||||
Title: in.Title,
|
||||
Author: in.Author,
|
||||
Content: in.Content,
|
||||
Std_IICUDS: types.Std_IICUDS{Status: int8(in.GetStatus())},
|
||||
}
|
||||
err = impl.DBService.Model(&models.MallNotice{}).Select("title", "author", "content").Where("identity = ?", in.Identity).Updates(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
tx := impl.DBService.Model(&models.MallNotice{}).Select("title", "author", "content").
|
||||
Where("identity = ?", in.Identity).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