Skip to content

Commit

Permalink
Improving the removal of users
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Aug 10, 2024
1 parent 0e1d156 commit 8fcec55
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions user/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ func (s *Store) removeRoleUser(ctx context.Context, ru RoleUser) error {
return nil
}

// removeRoleUser removes all links between role.Role and a User
func (s *Store) removeRoleUsers(ctx context.Context, u User) error {
// removeUserForRoles removes all links between role.Role and a User
func (s *Store) removeUserForRoles(ctx context.Context, u User) error {
_, err := s.db.NamedExecContext(ctx, `DELETE FROM people.role_members WHERE user_id = :user_id`, u)
if err != nil {
return fmt.Errorf("failed to remove roleUsers: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@ func (s *Store) RemoveRoleUser(ctx context.Context, ru RoleUser) error {
return s.removeRoleUser(ctx, ru)
}

func (s *Store) RemoveRoleUsers(ctx context.Context, u User) error {
return s.removeRoleUsers(ctx, u)
// RemoveUserForRoles removes links between a User and Roles
func (s *Store) RemoveUserForRoles(ctx context.Context, u User) error {
return s.removeUserForRoles(ctx, u)
}

// GetPermissionsForRole returns all permissions for role
Expand Down
2 changes: 1 addition & 1 deletion views/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func (v *Views) UserDeleteFunc(c echo.Context) error {
return fmt.Errorf("failed to get user for deleteUser: %w", err)
}

err = v.user.RemoveRoleUsers(c.Request().Context(), user1)
err = v.user.RemoveUserForRoles(c.Request().Context(), user1)
if err != nil {
return fmt.Errorf("failed to delete roleUsers for deleteUser: %w", err)
}
Expand Down

0 comments on commit 8fcec55

Please sign in to comment.