Skip to content

fix: allow user to create group policy if they have update permission #376

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

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
Disabled State = "disabled"

MemberPermission = schema.MembershipPermission
AdminPermission = schema.DeletePermission
)

type Repository interface {
Expand Down
20 changes: 14 additions & 6 deletions pkg/server/interceptors/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"

"github.com/raystack/frontier/core/group"

"github.com/raystack/frontier/pkg/server/health"

"github.com/raystack/frontier/internal/api/v1beta1"
Expand Down Expand Up @@ -418,10 +420,13 @@ var authorizationValidationMap = map[string]func(ctx context.Context, handler *v
return err
}

if ns == schema.OrganizationNamespace {
return handler.IsAuthorized(ctx, schema.OrganizationNamespace, id, schema.PolicyManagePermission)
switch ns {
case schema.OrganizationNamespace, schema.ProjectNamespace:
return handler.IsAuthorized(ctx, ns, id, schema.PolicyManagePermission)
case schema.GroupNamespace:
return handler.IsAuthorized(ctx, ns, id, group.AdminPermission)
}
return handler.IsAuthorized(ctx, schema.ProjectNamespace, id, schema.PolicyManagePermission)
return handler.IsAuthorized(ctx, ns, id, schema.DeletePermission)
},
"/raystack.frontier.v1beta1.FrontierService/GetPolicy": func(ctx context.Context, handler *v1beta1.Handler, req any) error {
return nil
Expand All @@ -440,10 +445,13 @@ var authorizationValidationMap = map[string]func(ctx context.Context, handler *v
return err
}

if ns == schema.OrganizationNamespace {
return handler.IsAuthorized(ctx, schema.OrganizationNamespace, id, schema.PolicyManagePermission)
switch ns {
case schema.OrganizationNamespace, schema.ProjectNamespace:
return handler.IsAuthorized(ctx, ns, id, schema.PolicyManagePermission)
case schema.GroupNamespace:
return handler.IsAuthorized(ctx, ns, id, group.AdminPermission)
}
return handler.IsAuthorized(ctx, schema.ProjectNamespace, id, schema.PolicyManagePermission)
return handler.IsAuthorized(ctx, ns, id, schema.DeletePermission)
},

// relations
Expand Down