fix: close platform access re-review findings
This commit is contained in:
@@ -22,6 +22,9 @@ func GetPlatformRole(ctx *gin.Context) { getByIdentity[models.PlatformRole](ctx)
|
||||
|
||||
// CreatePlatformRole 创建非内置平台角色。
|
||||
func CreatePlatformRole(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var request models.PlatformRole
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil || request.RoleCode == "" || request.Name == "" || request.RoleCode == "root" {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
@@ -41,6 +44,9 @@ func CreatePlatformRole(ctx *gin.Context) {
|
||||
|
||||
// UpdatePlatformRole 更新非内置平台角色。
|
||||
func UpdatePlatformRole(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var request struct {
|
||||
Name string `json:"name" binding:"required,max=64"`
|
||||
DataScope string `json:"data_scope" binding:"required,max=32"`
|
||||
@@ -111,6 +117,9 @@ func GetPlatformMenu(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func CreatePlatformMenu(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var request platformMenuRequest
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
@@ -130,6 +139,9 @@ func CreatePlatformMenu(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func UpdatePlatformMenu(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var request platformMenuRequest
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
@@ -143,12 +155,29 @@ func UpdatePlatformMenu(ctx *gin.Context) {
|
||||
updateAllowedByIdentity(ctx, &models.PlatformMenu{}, gin.H{"parent_id": parentID, "name": request.Name, "icon": request.Icon, "path": request.Path, "sort_no": request.SortNo}, []string{"parent_id", "name", "icon", "path", "sort_no"})
|
||||
}
|
||||
|
||||
func UpdatePlatformMenuStatus(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
UpdateRecordStatus(ctx, &models.PlatformMenu{})
|
||||
}
|
||||
|
||||
func ArchivePlatformMenu(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
ArchiveRecord(ctx, &models.PlatformMenu{})
|
||||
}
|
||||
|
||||
type platformRoleMenusRequest struct {
|
||||
MenuIdentities []string `json:"menu_identities" binding:"required"`
|
||||
MenuIdentities []string `json:"menu_identities"`
|
||||
}
|
||||
|
||||
// ReplacePlatformRoleMenus replaces every menu assignment for a role atomically.
|
||||
func ReplacePlatformRoleMenus(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var request platformRoleMenusRequest
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
@@ -198,6 +227,9 @@ func ReplacePlatformRoleMenus(ctx *gin.Context) {
|
||||
|
||||
// ListPlatformRoleMenuIdentities returns the current assignment for the role editor.
|
||||
func ListPlatformRoleMenuIdentities(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var role models.PlatformRole
|
||||
if err := impl.DBService.Where("identity = ?", ctx.Param("identity")).First(&role).Error; err != nil {
|
||||
respondRecordError(ctx, err)
|
||||
@@ -217,6 +249,9 @@ func ListPlatformRoleMenuIdentities(ctx *gin.Context) {
|
||||
|
||||
// UpdatePlatformRoleStatus 更新非内置平台角色状态,系统角色始终受保护。
|
||||
func UpdatePlatformRoleStatus(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var request struct {
|
||||
Status string `json:"status" binding:"required,max=32"`
|
||||
}
|
||||
@@ -238,6 +273,9 @@ func UpdatePlatformRoleStatus(ctx *gin.Context) {
|
||||
|
||||
// ArchivePlatformRole 归档非内置平台角色,系统角色始终受保护。
|
||||
func ArchivePlatformRole(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var role models.PlatformRole
|
||||
if err := impl.DBService.Where("identity = ?", ctx.Param("identity")).First(&role).Error; err != nil {
|
||||
respondRecordError(ctx, err)
|
||||
@@ -279,9 +317,11 @@ func ListPlatfromAccount(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
views := make([]gin.H, 0, len(list))
|
||||
views := make([]map[string]any, 0, len(list))
|
||||
for _, item := range list {
|
||||
views = append(views, gin.H{"identity": item.Identity, "username": item.Username, "display_name": item.DisplayName, "avatar": item.Avatar, "phone_masked": maskPhone(item.Phone), "platform_role_code": item.PlatformRoleCode, "status": item.Status})
|
||||
view := platformAccountView(item)
|
||||
protectPreciseLocation(ctx, &models.PlatfromAccount{}, view)
|
||||
views = append(views, view)
|
||||
}
|
||||
infra.Response.Success(ctx, gin.H{"total": total, "list": views})
|
||||
}
|
||||
@@ -295,18 +335,12 @@ type platfromAccountRequest struct {
|
||||
Phone string `json:"phone" binding:"max=32"`
|
||||
}
|
||||
|
||||
type platfromAccountView struct {
|
||||
Identity string `json:"identity"`
|
||||
Username string `json:"username"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Avatar string `json:"avatar"`
|
||||
PhoneMasked string `json:"phone_masked"`
|
||||
PlatformRoleCode string `json:"platform_role_code"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func platformAccountView(account models.PlatfromAccount) platfromAccountView {
|
||||
return platfromAccountView{Identity: account.Identity, Username: account.Username, DisplayName: account.DisplayName, Avatar: account.Avatar, PhoneMasked: maskPhone(account.Phone), PlatformRoleCode: account.PlatformRoleCode, Status: account.Status}
|
||||
func platformAccountView(account models.PlatfromAccount) map[string]any {
|
||||
return map[string]any{
|
||||
"identity": account.Identity, "username": account.Username,
|
||||
"display_name": account.DisplayName, "avatar": account.Avatar, "phone": account.Phone,
|
||||
"platform_role_code": account.PlatformRoleCode, "status": account.Status,
|
||||
}
|
||||
}
|
||||
|
||||
func GetPlatfromAccount(ctx *gin.Context) {
|
||||
@@ -315,10 +349,14 @@ func GetPlatfromAccount(ctx *gin.Context) {
|
||||
respondRecordError(ctx, err)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(ctx, platformAccountView(account))
|
||||
view := platformAccountView(account)
|
||||
infra.Response.Success(ctx, protectPreciseLocation(ctx, &models.PlatfromAccount{}, view))
|
||||
}
|
||||
|
||||
func CreatePlatfromAccount(ctx *gin.Context) {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
var request platfromAccountRequest
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
@@ -338,7 +376,8 @@ func CreatePlatfromAccount(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(ctx, platformAccountView(account))
|
||||
view := platformAccountView(account)
|
||||
infra.Response.Success(ctx, protectPreciseLocation(ctx, &models.PlatfromAccount{}, view))
|
||||
}
|
||||
|
||||
func UpdatePlatfromAccount(ctx *gin.Context) {
|
||||
@@ -354,6 +393,9 @@ func UpdatePlatfromAccount(ctx *gin.Context) {
|
||||
}
|
||||
values := gin.H{"display_name": request.DisplayName, "avatar": request.Avatar, "phone": request.Phone}
|
||||
if request.PlatformRoleCode != nil {
|
||||
if !requirePlatformRoot(ctx) {
|
||||
return
|
||||
}
|
||||
if !isAssignablePlatformRole(*request.PlatformRoleCode) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user