feat: 统一账户角色展示并优化资源页面
This commit is contained in:
@@ -12,18 +12,33 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// gasAdminRoleCode 是气站管理后台当前唯一允许登录的角色编码。
|
||||
const gasAdminRoleCode = "admin"
|
||||
|
||||
// newGasAccount 构造平台创建的气站账户,并固定为气站管理员角色。
|
||||
func newGasAccount(gasBasicID uint64, request accountRequest, passwordHash string) models.GasAccount {
|
||||
return models.GasAccount{
|
||||
Entity: common.NewEntity(common.StatusEnable),
|
||||
GasBasicID: gasBasicID,
|
||||
Username: request.Username,
|
||||
DisplayName: request.DisplayName,
|
||||
PasswordHash: passwordHash,
|
||||
RoleCode: gasAdminRoleCode,
|
||||
}
|
||||
}
|
||||
|
||||
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"`
|
||||
RoleCode string `json:"role_code" binding:"max=64"` // 兼容旧客户端,服务端固定使用 admin。
|
||||
GasBasicIdentity string `json:"gas_basic_identity"`
|
||||
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"`
|
||||
RoleCode string `json:"role_code" binding:"max=64"` // 兼容旧客户端,更新时不采纳。
|
||||
GasBasicIdentity string `json:"gas_basic_identity"`
|
||||
DeliveryBasicIdentity string `json:"delivery_basic_identity"`
|
||||
}
|
||||
@@ -63,7 +78,7 @@ func CreateGasAccount(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
account := models.GasAccount{Entity: common.NewEntity(common.StatusEnable), GasBasicID: gasBasicID, Username: request.Username, DisplayName: request.DisplayName, PasswordHash: hash, RoleCode: request.RoleCode}
|
||||
account := newGasAccount(gasBasicID, request, hash)
|
||||
if err := impl.DBService.Create(&account).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
@@ -82,7 +97,7 @@ func UpdateGasAccount(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
common.UpdateAllowedByIdentity(ctx, &models.GasAccount{}, gin.H{"gas_basic_id": gasBasicID, "display_name": request.DisplayName, "role_code": request.RoleCode}, []string{"gas_basic_id", "display_name", "role_code"})
|
||||
common.UpdateAllowedByIdentity(ctx, &models.GasAccount{}, gin.H{"gas_basic_id": gasBasicID, "display_name": request.DisplayName}, []string{"gas_basic_id", "display_name"})
|
||||
}
|
||||
|
||||
func splitOwnerIdentities(value string) []string {
|
||||
|
||||
Reference in New Issue
Block a user