Skip to content

Commit 7476c69

Browse files
committed
feat: replace an existing policy
- 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]>
1 parent 0898f4e commit 7476c69

17 files changed

+5120
-3889
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TAG := $(shell git rev-list --tags --max-count=1)
44
VERSION := $(shell git describe --tags ${TAG})
55
.PHONY: build check fmt lint test test-race vet test-cover-html help install proto ui
66
.DEFAULT_GOAL := build
7-
PROTON_COMMIT := "eb24a09e48f7f746b07006daae47f9434ef70ec4"
7+
PROTON_COMMIT := "4c0454a0e55cd15750d3e007d5cc06ca6e186b6e"
88

99
ui:
1010
@echo " > generating ui build"

core/audit/audit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const (
6767

6868
PolicyCreatedEvent EventName = "app.policy.created"
6969
PolicyDeletedEvent EventName = "app.policy.deleted"
70+
PolicyReplaceEvent EventName = "app.policy.replaced"
7071

7172
OrgCreatedEvent EventName = "app.organization.created"
7273
OrgUpdatedEvent EventName = "app.organization.updated"

core/policy/service.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package policy
22

33
import (
44
"context"
5+
"errors"
56

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

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

78+
func (s Service) Replace(ctx context.Context, existingID string, pol Policy) (Policy, error) {
79+
if err := s.Delete(ctx, existingID); err != nil && !errors.Is(err, ErrNotExist) {
80+
return Policy{}, err
81+
}
82+
pol.ID = existingID
83+
return s.Create(ctx, pol)
84+
}
85+
7786
// AssignRole Note: ideally this should be in a single transaction
7887
// read more about how user defined roles work in spicedb https://authzed.com/blog/user-defined-roles
7988
func (s Service) AssignRole(ctx context.Context, pol Policy) error {

0 commit comments

Comments
 (0)