Skip to content
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

fix: removing extra #member on assignIdentities service call #286

Merged
merged 3 commits into from
Apr 22, 2024
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
4 changes: 4 additions & 0 deletions internal/authorization/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ func (c GroupConverter) Map(r *http.Request) []Permission {
// edit permission on group {id} and view permissions on identity {i_id}
return []Permission{
{Relation: CAN_EDIT, ResourceID: fmt.Sprintf("%s:%s", c.TypeName(), group_id)},
// TODO @shipperizer this checks for an identity being present, even though the relation
// is between a user type and the group
// we need to work and sync users and identities or drop the check below as this would
// be missing 100% of the times
{Relation: CAN_VIEW, ResourceID: fmt.Sprintf("%s:%s", IDENTITY_TYPE, identity_id)},
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/groups/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (s *Service) AssignIdentities(ctx context.Context, ID string, identities ..

for _, identity := range identities {
// TODO @shipperizer swap user for identity if/when model changes
ids = append(ids, *ofga.NewTuple(fmt.Sprintf("user:%s", identity), MEMBER_RELATION, s.buildGroupMember(ctx, ID)))
ids = append(ids, *ofga.NewTuple(fmt.Sprintf("user:%s", identity), MEMBER_RELATION, fmt.Sprintf("group:%s", ID)))
}

err := s.ofga.WriteTuples(ctx, ids...)
Expand All @@ -376,7 +376,7 @@ func (s *Service) RemoveIdentities(ctx context.Context, ID string, identities ..

for _, identity := range identities {
// TODO @shipperizer swap user for identity if/when model changes
ids = append(ids, *ofga.NewTuple(fmt.Sprintf("user:%s", identity), MEMBER_RELATION, s.buildGroupMember(ctx, ID)))
ids = append(ids, *ofga.NewTuple(fmt.Sprintf("user:%s", identity), MEMBER_RELATION, fmt.Sprintf("group:%s", ID)))
}

err := s.ofga.DeleteTuples(ctx, ids...)
Expand Down
4 changes: 2 additions & 2 deletions pkg/groups/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func TestServiceAssignIdentities(t *testing.T) {
ids := make([]ofga.Tuple, 0)

for _, i := range test.input.identities {
ids = append(ids, *ofga.NewTuple(fmt.Sprintf("user:%s", i), MEMBER_RELATION, fmt.Sprintf("group:%s#%s", test.input.group, MEMBER_RELATION)))
ids = append(ids, *ofga.NewTuple(fmt.Sprintf("user:%s", i), MEMBER_RELATION, fmt.Sprintf("group:%s", test.input.group)))
}

if !reflect.DeepEqual(ids, tuples) {
Expand Down Expand Up @@ -615,7 +615,7 @@ func TestServiceRemoveIdentities(t *testing.T) {
ids := make([]ofga.Tuple, 0)

for _, i := range test.input.identities {
ids = append(ids, *ofga.NewTuple(fmt.Sprintf("user:%s", i), MEMBER_RELATION, fmt.Sprintf("group:%s#%s", test.input.group, MEMBER_RELATION)))
ids = append(ids, *ofga.NewTuple(fmt.Sprintf("user:%s", i), MEMBER_RELATION, fmt.Sprintf("group:%s", test.input.group)))
}

if !reflect.DeepEqual(ids, tuples) {
Expand Down
Loading