fix platform authorization and workflow integrity
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package gas
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/infra"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type accountRequest struct {
|
||||
@@ -25,8 +28,20 @@ type accountUpdateRequest struct {
|
||||
DeliveryBasicIdentity string `json:"delivery_basic_identity"`
|
||||
}
|
||||
|
||||
func ListGasAccount(ctx *gin.Context) { common.ListPage[models.GasAccount](ctx) }
|
||||
func GetGasAccount(ctx *gin.Context) { common.GetByIdentity[models.GasAccount](ctx) }
|
||||
func ListGasAccount(ctx *gin.Context) {
|
||||
identities := splitOwnerIdentities(ctx.Query("gas_basic_identities"))
|
||||
if len(identities) > 100 {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
common.ListPageFiltered[models.GasAccount](ctx, func(query *gorm.DB) *gorm.DB {
|
||||
if len(identities) == 0 {
|
||||
return query
|
||||
}
|
||||
return query.Where("gas_basic_id IN (SELECT id FROM gas_basic WHERE identity IN ? AND status <> ?)", identities, common.StatusArchived)
|
||||
})
|
||||
}
|
||||
func GetGasAccount(ctx *gin.Context) { common.GetByIdentity[models.GasAccount](ctx) }
|
||||
|
||||
func CreateGasAccount(ctx *gin.Context) {
|
||||
var request accountRequest
|
||||
@@ -65,3 +80,11 @@ func UpdateGasAccount(ctx *gin.Context) {
|
||||
}
|
||||
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"})
|
||||
}
|
||||
|
||||
func splitOwnerIdentities(value string) []string {
|
||||
parts := strings.Split(strings.TrimSpace(value), ",")
|
||||
if len(parts) == 1 && parts[0] == "" {
|
||||
return nil
|
||||
}
|
||||
return parts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user