Skip to content

Commit

Permalink
bugfix. Fix merged permission error
Browse files Browse the repository at this point in the history
  • Loading branch information
cho4036 committed Apr 24, 2024
1 parent e0ed7cb commit 74ea85c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
7 changes: 1 addition & 6 deletions internal/delivery/http/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,8 @@ func (u UserHandler) GetPermissionsByAccountId(w http.ResponseWriter, r *http.Re
return
}

var roles []*model.Role
for _, role := range user.Roles {
roles = append(roles, &role)
}

var permissionSets []*model.PermissionSet
for _, role := range roles {
for _, role := range user.Roles {
permissionSet, err := u.permissionUsecase.GetPermissionSetByRoleId(r.Context(), role.ID)
if err != nil {
ErrorJSON(w, r, httpErrors.NewInternalServerError(err, "", ""))
Expand Down
2 changes: 1 addition & 1 deletion internal/model/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewAdminPermissionSet() *PermissionSet {
}

func GetEdgePermission(root *Permission, edgePermissions []*Permission, f *func(permission Permission) bool) []*Permission {
if root.Children == nil {
if root.Children == nil || len(root.Children) == 0 {
return append(edgePermissions, root)
}

Expand Down
14 changes: 7 additions & 7 deletions internal/usecase/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,18 @@ func (p PermissionUsecase) MergePermissionWithOrOperator(ctx context.Context, pe
continue
}

out.Dashboard = p.mergePermission(out.Dashboard, ps.Dashboard)
out.Stack = p.mergePermission(out.Stack, ps.Stack)
out.Policy = p.mergePermission(out.Policy, ps.Policy)
out.ProjectManagement = p.mergePermission(out.ProjectManagement, ps.ProjectManagement)
out.Notification = p.mergePermission(out.Notification, ps.Notification)
out.Configuration = p.mergePermission(out.Configuration, ps.Configuration)
out.Dashboard = p.mergePermission(ctx, out.Dashboard, ps.Dashboard)
out.Stack = p.mergePermission(ctx, out.Stack, ps.Stack)
out.Policy = p.mergePermission(ctx, out.Policy, ps.Policy)
out.ProjectManagement = p.mergePermission(ctx, out.ProjectManagement, ps.ProjectManagement)
out.Notification = p.mergePermission(ctx, out.Notification, ps.Notification)
out.Configuration = p.mergePermission(ctx, out.Configuration, ps.Configuration)
}

return out
}

func (p PermissionUsecase) mergePermission(mergedPermission, permission *model.Permission) *model.Permission {
func (p PermissionUsecase) mergePermission(ctx context.Context, mergedPermission, permission *model.Permission) *model.Permission {
var mergedEdgePermissions []*model.Permission
mergedEdgePermissions = model.GetEdgePermission(mergedPermission, mergedEdgePermissions, nil)

Expand Down

0 comments on commit 74ea85c

Please sign in to comment.