-
Notifications
You must be signed in to change notification settings - Fork 677
SMQ-2739 - Prevent removing of all users from Built in admin role #2835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -351,15 +351,40 @@ func (svc *service) RemoveEntityMembers(ctx context.Context, session authn.Sessi | |||||||||||
| return svc.ProvisionManageService.RemoveEntityMembers(ctx, session, entityID, members) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| func (svc *service) RoleRemoveMembers(ctx context.Context, session authn.Session, entityID, roleID string, members []string) (err error) { | ||||||||||||
| for _, member := range members { | ||||||||||||
| if err := svc.repo.DeleteInvitation(ctx, member, entityID); err != nil && err != repoerr.ErrNotFound { | ||||||||||||
| func (svc *service) RoleRemoveMembers(ctx context.Context, session authn.Session, entityID, roleID string, members []string) error { | ||||||||||||
| ro, err := svc.repo.RetrieveEntityRole(ctx, entityID, roleID) | ||||||||||||
| if err != nil { | ||||||||||||
| return errors.Wrap(svcerr.ErrViewEntity, err) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if _, err := svc.ProvisionManageService.BuiltInRoleActions(roles.BuiltInRoleName(ro.Name)); err == nil { | ||||||||||||
| membersPage, err := svc.repo.RoleListMembers(ctx, ro.ID, 0, 0) | ||||||||||||
| if err != nil { | ||||||||||||
| return errors.Wrap(svcerr.ErrViewEntity, err) | ||||||||||||
| } | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| if membersPage.Total <= uint64(len(members)) { | ||||||||||||
| return svcerr.ErrRetainOneMember | ||||||||||||
| } | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need for details , like how many members request and role name |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| for _, memberID := range members { | ||||||||||||
| if err := svc.repo.DeleteInvitation(ctx, memberID, entityID); err != nil && err != repoerr.ErrNotFound { | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can have repo call where we can delete All the Invitation at once something like svc.repo.DeleteUsersInvitation(ctx,entityID, memberIDs...)This requires new function invitations repo like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create ticket for this #2924 |
||||||||||||
| return err | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return svc.ProvisionManageService.RoleRemoveMembers(ctx, session, entityID, roleID, members) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| func (svc *service) RoleRemoveAllMembers(ctx context.Context, session authn.Session, entityID, roleID string) (err error) { | ||||||||||||
| return svcerr.ErrNotFound | ||||||||||||
| func (svc *service) RoleRemoveAllMembers(ctx context.Context, session authn.Session, entityID, roleID string) error { | ||||||||||||
| ro, err := svc.repo.RetrieveEntityRole(ctx, entityID, roleID) | ||||||||||||
| if err != nil { | ||||||||||||
| return errors.Wrap(svcerr.ErrViewEntity, err) | ||||||||||||
| } | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
|
||||||||||||
| if _, err := svc.ProvisionManageService.BuiltInRoleActions(roles.BuiltInRoleName(ro.Name)); err == nil { | ||||||||||||
| return svcerr.ErrRetainOneMember | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return svc.ProvisionManageService.RoleRemoveAllMembers(ctx, session, entityID, roleID) | ||||||||||||
| } | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.