@@ -62,19 +62,10 @@ func (svr *Server) CreateUser(ctx context.Context, req *apisecurity.User) *apise
6262 ownerID := utils .ParseOwnerID (ctx )
6363 req .Owner = utils .NewStringValue (ownerID )
6464
65- if checkErrResp := checkCreateUser (req ); checkErrResp != nil {
65+ if checkErrResp := checkCreateUser (ctx , req ); checkErrResp != nil {
6666 return checkErrResp
6767 }
6868
69- // 如果创建的目标账户类型是非子账户,则 ownerId 需要设置为 “”
70- if convertCreateUserRole (authcommon .ParseUserRole (ctx )) != authcommon .SubAccountUserRole {
71- // 如果创建的不是子帐户,需要判断是否来自内部的 InitMainUser 请求
72- if ! authcommon .IsInitMainUser (ctx ) {
73- log .Error ("[auth][user] can't create user which role is not sub-account" , utils .RequestID (ctx ))
74- return api .NewUserResponse (apimodel .Code_OperationRoleForbidden , req )
75- }
76- }
77-
7869 if ownerID != "" {
7970 owner , err := svr .storage .GetUser (ownerID )
8071 if err != nil {
@@ -579,7 +570,7 @@ func userRecordEntry(ctx context.Context, req *apisecurity.User, md *authcommon.
579570}
580571
581572// checkCreateUser 检查创建用户的请求
582- func checkCreateUser (req * apisecurity.User ) * apiservice.Response {
573+ func checkCreateUser (ctx context. Context , req * apisecurity.User ) * apiservice.Response {
583574 if req == nil {
584575 return api .NewUserResponse (apimodel .Code_EmptyRequest , req )
585576 }
@@ -592,8 +583,15 @@ func checkCreateUser(req *apisecurity.User) *apiservice.Response {
592583 return api .NewUserResponse (apimodel .Code_InvalidUserPassword , req )
593584 }
594585
595- if err := CheckOwner (req .Owner ); err != nil {
596- return api .NewUserResponse (apimodel .Code_InvalidUserOwners , req )
586+ if ! authcommon .IsInitMainUser (ctx ) {
587+ if err := CheckOwner (req .Owner ); err != nil {
588+ return api .NewUserResponse (apimodel .Code_InvalidUserOwners , req )
589+ }
590+ // 如果创建的目标账户类型是非子账户,则 ownerId 需要设置为 “”
591+ if convertCreateUserRole (authcommon .ParseUserRole (ctx )) != authcommon .SubAccountUserRole {
592+ log .Error ("[auth][user] can't create user which role is not sub-account" , utils .RequestID (ctx ))
593+ return api .NewUserResponse (apimodel .Code_OperationRoleForbidden , req )
594+ }
597595 }
598596 return nil
599597}
0 commit comments