Skip to content

Commit

Permalink
feat: replace an existing policy
Browse files Browse the repository at this point in the history
- ReplacePolicy will take an id of the existing policy
and replace it with the provided policy body.
- raystack/proton#318

Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma committed Nov 7, 2023
1 parent 0898f4e commit 7476c69
Show file tree
Hide file tree
Showing 17 changed files with 5,120 additions and 3,889 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TAG := $(shell git rev-list --tags --max-count=1)
VERSION := $(shell git describe --tags ${TAG})
.PHONY: build check fmt lint test test-race vet test-cover-html help install proto ui
.DEFAULT_GOAL := build
PROTON_COMMIT := "eb24a09e48f7f746b07006daae47f9434ef70ec4"
PROTON_COMMIT := "4c0454a0e55cd15750d3e007d5cc06ca6e186b6e"

ui:
@echo " > generating ui build"
Expand Down
1 change: 1 addition & 0 deletions core/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const (

PolicyCreatedEvent EventName = "app.policy.created"
PolicyDeletedEvent EventName = "app.policy.deleted"
PolicyReplaceEvent EventName = "app.policy.replaced"

OrgCreatedEvent EventName = "app.organization.created"
OrgUpdatedEvent EventName = "app.organization.updated"
Expand Down
9 changes: 9 additions & 0 deletions core/policy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package policy

import (
"context"
"errors"

"github.com/raystack/frontier/pkg/utils"

Expand Down Expand Up @@ -74,6 +75,14 @@ func (s Service) Delete(ctx context.Context, id string) error {
return s.repository.Delete(ctx, id)
}

func (s Service) Replace(ctx context.Context, existingID string, pol Policy) (Policy, error) {
if err := s.Delete(ctx, existingID); err != nil && !errors.Is(err, ErrNotExist) {
return Policy{}, err
}
pol.ID = existingID
return s.Create(ctx, pol)
}

// AssignRole Note: ideally this should be in a single transaction
// read more about how user defined roles work in spicedb https://authzed.com/blog/user-defined-roles
func (s Service) AssignRole(ctx context.Context, pol Policy) error {
Expand Down
Loading

0 comments on commit 7476c69

Please sign in to comment.