mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(keystone): enable user (#20455)
This commit is contained in:
@@ -388,16 +388,18 @@ func init() {
|
||||
})
|
||||
|
||||
type ProjectAddUserGroupOptions struct {
|
||||
Project string `help:"ID or name of project to add users/groups" positional:"true" optional:"false"`
|
||||
User []string `help:"ID of user to add"`
|
||||
Group []string `help:"ID of group to add"`
|
||||
Role []string `help:"ID of role to add"`
|
||||
Project string `help:"ID or name of project to add users/groups" positional:"true" optional:"false"`
|
||||
User []string `help:"ID of user to add"`
|
||||
Group []string `help:"ID of group to add"`
|
||||
Role []string `help:"ID of role to add"`
|
||||
EnableAllUsers bool
|
||||
}
|
||||
R(&ProjectAddUserGroupOptions{}, "project-add-user-group", "Batch add users/groups to project", func(s *mcclient.ClientSession, args *ProjectAddUserGroupOptions) error {
|
||||
input := api.SProjectAddUserGroupInput{}
|
||||
input.Users = args.User
|
||||
input.Groups = args.Group
|
||||
input.Roles = args.Role
|
||||
input.EnableAllUsers = args.EnableAllUsers
|
||||
err := input.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -413,15 +413,32 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type UserGroupsOptions struct {
|
||||
USER string `help:"User ID or Name"`
|
||||
Gids []string `help:"group ID or Name"`
|
||||
Action string `default:"join" choices:"join|leave"`
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
R(&UserGroupsOptions{}, "user-join-groups", "Add a user to groups", func(s *mcclient.ClientSession, args *UserGroupsOptions) error {
|
||||
_, err := modules.UsersV3.DoJoinGroups(s, args.USER, jsonutils.Marshal(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
type UserJoinProjectOptions struct {
|
||||
User string `help:"User Id or name" optional:"false" positional:"true"`
|
||||
Project []string `help:"Projects to join" nargs:"+"`
|
||||
Role []string `help:"User join project with roles" nargs:"+"`
|
||||
Enabled bool
|
||||
}
|
||||
R(&UserJoinProjectOptions{}, "user-join-project", "User join projects with roles", func(s *mcclient.ClientSession, args *UserJoinProjectOptions) error {
|
||||
input := api.SJoinProjectsInput{}
|
||||
input.Projects = args.Project
|
||||
input.Roles = args.Role
|
||||
input.Enabled = args.Enabled
|
||||
result, err := modules.UsersV3.PerformAction(s, args.User, "join", jsonutils.Marshal(input))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -232,6 +232,8 @@ type EndpointListInput struct {
|
||||
type SJoinProjectsInput struct {
|
||||
Projects []string `json:"projects"`
|
||||
Roles []string `json:"roles"`
|
||||
// 启用用户, 仅用户禁用时生效
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
func (input SJoinProjectsInput) Validate() error {
|
||||
@@ -269,9 +271,10 @@ func (input SLeaveProjectsInput) Validate() error {
|
||||
}
|
||||
|
||||
type SProjectAddUserGroupInput struct {
|
||||
Users []string
|
||||
Groups []string
|
||||
Roles []string
|
||||
Users []string
|
||||
Groups []string
|
||||
Roles []string
|
||||
EnableAllUsers bool
|
||||
}
|
||||
|
||||
func (input SProjectAddUserGroupInput) Validate() error {
|
||||
|
||||
@@ -735,6 +735,12 @@ func (project *SProject) PerformJoin(
|
||||
}
|
||||
}
|
||||
|
||||
if input.EnableAllUsers {
|
||||
for i := range users {
|
||||
db.EnabledPerformEnable(users[i], ctx, userCred, true)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1233,6 +1233,9 @@ func (user *SUser) PerformJoin(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "joinProjects")
|
||||
}
|
||||
if input.Enabled {
|
||||
db.EnabledPerformEnable(user, ctx, userCred, true)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,13 @@ func (this *UserManagerV3) DoJoinGroups(s *mcclient.ClientSession, uid string, p
|
||||
return nil, httperrors.NewInputParameterError("unsupported action %s", action)
|
||||
}
|
||||
|
||||
if enabled, _ := params.Bool("enabled"); enabled && action == "join" {
|
||||
_, err := this.PerformAction(s, uid, "enable", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
errs := make([]error, 0)
|
||||
for _, gid := range gids {
|
||||
_gid, _ := gid.GetString()
|
||||
|
||||
Reference in New Issue
Block a user