fix(platform): constrain delivery account role
This commit is contained in:
@@ -12,17 +12,30 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// deliveryAdminRoleCode 是配送点管理后台当前唯一允许的登录角色编码。
|
||||
const deliveryAdminRoleCode = "admin"
|
||||
|
||||
// newDeliveryAccount 构造平台创建的配送点登录账号,并固定其权限身份。
|
||||
func newDeliveryAccount(deliveryBasicID uint64, request accountRequest, passwordHash string) models.DeliveryAccount {
|
||||
return models.DeliveryAccount{
|
||||
Entity: common.NewEntity(common.StatusEnable),
|
||||
DeliveryBasicID: deliveryBasicID,
|
||||
Username: request.Username,
|
||||
DisplayName: request.DisplayName,
|
||||
PasswordHash: passwordHash,
|
||||
RoleCode: deliveryAdminRoleCode,
|
||||
}
|
||||
}
|
||||
|
||||
type accountRequest struct {
|
||||
Username string `json:"username" binding:"required,max=64"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
DisplayName string `json:"display_name" binding:"max=64"`
|
||||
RoleCode string `json:"role_code" binding:"max=64"`
|
||||
DeliveryBasicIdentity string `json:"delivery_basic_identity"`
|
||||
}
|
||||
|
||||
type accountUpdateRequest struct {
|
||||
DisplayName string `json:"display_name" binding:"max=64"`
|
||||
RoleCode string `json:"role_code" binding:"max=64"`
|
||||
DeliveryBasicIdentity string `json:"delivery_basic_identity"`
|
||||
}
|
||||
|
||||
@@ -64,7 +77,7 @@ func CreateDeliveryAccount(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
account := models.DeliveryAccount{Entity: common.NewEntity(common.StatusEnable), DeliveryBasicID: deliveryBasicID, Username: request.Username, DisplayName: request.DisplayName, PasswordHash: hash, RoleCode: request.RoleCode}
|
||||
account := newDeliveryAccount(deliveryBasicID, request, hash)
|
||||
if err := impl.DBService.Create(&account).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
@@ -83,5 +96,5 @@ func UpdateDeliveryAccount(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
common.UpdateAllowedByIdentity(ctx, &models.DeliveryAccount{}, gin.H{"delivery_basic_id": deliveryBasicID, "display_name": request.DisplayName, "role_code": request.RoleCode}, []string{"delivery_basic_id", "display_name", "role_code"})
|
||||
common.UpdateAllowedByIdentity(ctx, &models.DeliveryAccount{}, gin.H{"delivery_basic_id": deliveryBasicID, "display_name": request.DisplayName}, []string{"delivery_basic_id", "display_name"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user