@@ -734,7 +734,6 @@ func TestService_RemoveOrganizationMember(t *testing.T) {
734734
735735 enabledOrg := organization.Organization {ID : orgID , Title : "Test Org" }
736736
737- orgObj := relation.Object {ID : orgID , Namespace : schema .OrganizationNamespace }
738737 grpObj := relation.Object {ID : groupID , Namespace : schema .GroupNamespace }
739738 userSub := relation.Subject {ID : userID , Namespace : schema .UserPrincipal }
740739
@@ -828,8 +827,6 @@ func TestService_RemoveOrganizationMember(t *testing.T) {
828827 }, nil )
829828 d .policySvc .EXPECT ().Delete (ctx , "org-p1" ).Return (nil )
830829 d .resSvc .EXPECT ().RemovePrincipalAccess (ctx , userID , schema .UserPrincipal , []string {}).Return (nil )
831- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (relation .ErrNotExist )
832- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (nil )
833830 d .auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
834831 },
835832 wantErr : nil ,
@@ -853,9 +850,6 @@ func TestService_RemoveOrganizationMember(t *testing.T) {
853850 d .policySvc .EXPECT ().Delete (ctx , "proj-p1" ).Return (nil )
854851 d .policySvc .EXPECT ().Delete (ctx , "grp-p1" ).Return (nil )
855852 d .resSvc .EXPECT ().RemovePrincipalAccess (ctx , userID , schema .UserPrincipal , []string {projectID }).Return (nil )
856- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (nil )
857- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (relation .ErrNotExist )
858- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : grpObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (nil )
859853 d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : grpObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (relation .ErrNotExist )
860854 d .auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
861855 },
@@ -878,8 +872,6 @@ func TestService_RemoveOrganizationMember(t *testing.T) {
878872 }, nil )
879873 d .policySvc .EXPECT ().Delete (ctx , "org-p1" ).Return (nil )
880874 d .resSvc .EXPECT ().RemovePrincipalAccess (ctx , userID , schema .UserPrincipal , []string {}).Return (nil )
881- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (relation .ErrNotExist )
882- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (nil )
883875 d .auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
884876 },
885877 wantErr : nil ,
@@ -901,23 +893,23 @@ func TestService_RemoveOrganizationMember(t *testing.T) {
901893 wantErrContain : "delete sub-resource policy" ,
902894 },
903895 {
904- name : "should return error if org relation removal fails after org policies deleted" ,
896+ name : "should return error if group relation removal fails after org policies deleted" ,
905897 setup : func (d testDeps ) {
906898 d .orgSvc .EXPECT ().Get (ctx , orgID ).Return (enabledOrg , nil )
907899 d .policySvc .EXPECT ().List (ctx , policy.Filter {OrgID : orgID , PrincipalID : userID , PrincipalType : schema .UserPrincipal }).Return ([]policy.Policy {{ID : "org-p1" , RoleID : viewerRoleID }}, nil )
908900 d .roleSvc .EXPECT ().Get (ctx , schema .RoleOrganizationOwner ).Return (role.Role {ID : ownerRoleID , Name : schema .RoleOrganizationOwner }, nil )
909901 d .projSvc .EXPECT ().List (ctx , project.Filter {OrgID : orgID }).Return ([]project.Project {}, nil )
910- d .grpSvc .EXPECT ().List (ctx , group.Filter {OrganizationID : orgID }).Return ([]group.Group {}, nil )
902+ d .grpSvc .EXPECT ().List (ctx , group.Filter {OrganizationID : orgID }).Return ([]group.Group {{ ID : groupID } }, nil )
911903 d .policySvc .EXPECT ().List (ctx , policy.Filter {PrincipalID : userID , PrincipalType : schema .UserPrincipal }).Return ([]policy.Policy {
912904 {ID : "org-p1" , ResourceType : schema .OrganizationNamespace , ResourceID : orgID , RoleID : viewerRoleID },
913905 }, nil )
914906 // org policy deleted first (viewer, plain Delete)
915907 d .policySvc .EXPECT ().Delete (ctx , "org-p1" ).Return (nil )
916908 d .resSvc .EXPECT ().RemovePrincipalAccess (ctx , userID , schema .UserPrincipal , []string {}).Return (nil )
917909 // then relation removal fails
918- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (errors .New ("spicedb down" ))
910+ d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : grpObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (errors .New ("spicedb down" ))
919911 },
920- wantErrContain : "remove org relations" ,
912+ wantErrContain : "relations" ,
921913 },
922914 {
923915 name : "should remove custom-resource access across every project in the org" ,
@@ -933,8 +925,6 @@ func TestService_RemoveOrganizationMember(t *testing.T) {
933925 }, nil )
934926 d .policySvc .EXPECT ().Delete (ctx , "org-p1" ).Return (nil )
935927 d .resSvc .EXPECT ().RemovePrincipalAccess (ctx , userID , schema .UserPrincipal , []string {projectID , secondProjectID }).Return (nil )
936- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (relation .ErrNotExist )
937- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (nil )
938928 d .auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
939929 },
940930 wantErr : nil ,
@@ -1018,8 +1008,6 @@ func TestService_ForceRemoveOrganizationMember(t *testing.T) {
10181008 ownerRoleID := uuid .New ().String ()
10191009
10201010 enabledOrg := organization.Organization {ID : orgID , Title : "Test Org" }
1021- orgObj := relation.Object {ID : orgID , Namespace : schema .OrganizationNamespace }
1022- userSub := relation.Subject {ID : userID , Namespace : schema .UserPrincipal }
10231011
10241012 type testDeps struct {
10251013 policySvc * mocks.PolicyService
@@ -1051,8 +1039,6 @@ func TestService_ForceRemoveOrganizationMember(t *testing.T) {
10511039 // plain delete, not DeleteWithMinRoleGuard
10521040 d .policySvc .EXPECT ().Delete (ctx , "org-p1" ).Return (nil )
10531041 d .resSvc .EXPECT ().RemovePrincipalAccess (ctx , userID , schema .UserPrincipal , []string {}).Return (nil )
1054- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (nil )
1055- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (relation .ErrNotExist )
10561042 d .auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
10571043 },
10581044 },
@@ -1065,8 +1051,6 @@ func TestService_ForceRemoveOrganizationMember(t *testing.T) {
10651051 d .grpSvc .EXPECT ().List (ctx , group.Filter {OrganizationID : orgID }).Return ([]group.Group {}, nil )
10661052 d .policySvc .EXPECT ().List (ctx , policy.Filter {PrincipalID : userID , PrincipalType : schema .UserPrincipal }).Return ([]policy.Policy {}, nil )
10671053 d .resSvc .EXPECT ().RemovePrincipalAccess (ctx , userID , schema .UserPrincipal , []string {}).Return (nil )
1068- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (relation .ErrNotExist )
1069- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (relation .ErrNotExist )
10701054 d .auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
10711055 },
10721056 },
@@ -1085,8 +1069,6 @@ func TestService_ForceRemoveOrganizationMember(t *testing.T) {
10851069 }, nil )
10861070 d .policySvc .EXPECT ().Delete (ctx , "org-p1" ).Return (nil )
10871071 d .resSvc .EXPECT ().RemovePrincipalAccess (ctx , userID , schema .UserPrincipal , []string {}).Return (nil )
1088- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (nil )
1089- d .relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (relation .ErrNotExist )
10901072 d .auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
10911073 },
10921074 },
@@ -1137,9 +1119,6 @@ func TestService_RemoveOrganizationMember_WithoutResourceService(t *testing.T) {
11371119 ownerRoleID := uuid .New ().String ()
11381120 viewerRoleID := uuid .New ().String ()
11391121
1140- orgObj := relation.Object {ID : orgID , Namespace : schema .OrganizationNamespace }
1141- userSub := relation.Subject {ID : userID , Namespace : schema .UserPrincipal }
1142-
11431122 policySvc := mocks .NewPolicyService (t )
11441123 relSvc := mocks .NewRelationService (t )
11451124 roleSvc := mocks .NewRoleService (t )
@@ -1157,8 +1136,6 @@ func TestService_RemoveOrganizationMember_WithoutResourceService(t *testing.T) {
11571136 {ID : "org-p1" , ResourceType : schema .OrganizationNamespace , ResourceID : orgID },
11581137 }, nil )
11591138 policySvc .EXPECT ().Delete (ctx , "org-p1" ).Return (nil )
1160- relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .OwnerRelationName }).Return (relation .ErrNotExist )
1161- relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : orgObj , Subject : userSub , RelationName : schema .MemberRelationName }).Return (nil )
11621139 auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
11631140
11641141 svc := membership .NewService (slog .New (slog .NewTextHandler (io .Discard , nil )), policySvc , relSvc , roleSvc , orgSvc , mocks .NewUserService (t ), projSvc , grpSvc , mocks .NewServiceuserService (t ), auditRepo )
@@ -2080,15 +2057,6 @@ func TestService_OnGroupCreated(t *testing.T) {
20802057 Subject : relation.Subject {ID : orgID , Namespace : schema .OrganizationNamespace },
20812058 RelationName : schema .OrganizationRelationName ,
20822059 }
2083- orgGroupMemberRelation := relation.Relation {
2084- Object : relation.Object {ID : orgID , Namespace : schema .OrganizationNamespace },
2085- Subject : relation.Subject {
2086- ID : groupID ,
2087- Namespace : schema .GroupNamespace ,
2088- SubRelationName : schema .MemberRelationName ,
2089- },
2090- RelationName : schema .MemberRelationName ,
2091- }
20922060 creatorMemberRelation := relation.Relation {
20932061 Object : relation.Object {ID : groupID , Namespace : schema .GroupNamespace },
20942062 Subject : relation.Subject {ID : creatorID , Namespace : schema .UserPrincipal },
@@ -2150,9 +2118,8 @@ func TestService_OnGroupCreated(t *testing.T) {
21502118 _ = mockRoleSvc
21512119 _ = mockUserSvc
21522120
2153- // rollback: delete the identity link plus any legacy org-member relation
2121+ // rollback: delete the identity link
21542122 mockRelSvc .EXPECT ().Delete (ctx , groupOrgRelation ).Return (nil )
2155- mockRelSvc .EXPECT ().Delete (ctx , orgGroupMemberRelation ).Return (relation .ErrNotExist )
21562123
21572124 svc := membership .NewService (slog .New (slog .NewTextHandler (io .Discard , nil )), mockPolicySvc , mockRelSvc , mockRoleSvc , mocks .NewOrgService (t ), mockUserSvc , mocks .NewProjectService (t ), mockGrpSvc , mocks .NewServiceuserService (t ), mocks .NewAuditRecordRepository (t ))
21582125
@@ -2232,7 +2199,7 @@ func TestService_RemoveGroupMember(t *testing.T) {
22322199 wantErr : membership .ErrLastGroupOwnerRole ,
22332200 },
22342201 {
2235- name : "should remove a member (non-owner) and delete both relations " ,
2202+ name : "should remove a member (non-owner) and delete the member relation " ,
22362203 setup : func (policySvc * mocks.PolicyService , relSvc * mocks.RelationService , roleSvc * mocks.RoleService , grpSvc * mocks.GroupService , userSvc * mocks.UserService , auditRepo * mocks.AuditRecordRepository ) {
22372204 grpSvc .EXPECT ().Get (ctx , groupID ).Return (grp , nil )
22382205 userSvc .EXPECT ().GetByID (ctx , userID ).Return (enabledUser , nil )
@@ -2242,7 +2209,6 @@ func TestService_RemoveGroupMember(t *testing.T) {
22422209 policySvc .EXPECT ().Delete (ctx , "p1" ).Return (nil )
22432210 obj := relation.Object {ID : groupID , Namespace : schema .GroupNamespace }
22442211 sub := relation.Subject {ID : userID , Namespace : schema .UserPrincipal }
2245- relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : obj , Subject : sub , RelationName : schema .OwnerRelationName }).Return (relation .ErrNotExist )
22462212 relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : obj , Subject : sub , RelationName : schema .MemberRelationName }).Return (nil )
22472213 auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
22482214 },
@@ -2259,7 +2225,6 @@ func TestService_RemoveGroupMember(t *testing.T) {
22592225 policySvc .EXPECT ().DeleteWithMinRoleGuard (ctx , "p1" , ownerRoleID ).Return (nil )
22602226 obj := relation.Object {ID : groupID , Namespace : schema .GroupNamespace }
22612227 sub := relation.Subject {ID : userID , Namespace : schema .UserPrincipal }
2262- relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : obj , Subject : sub , RelationName : schema .OwnerRelationName }).Return (nil )
22632228 relSvc .EXPECT ().Delete (ctx , relation.Relation {Object : obj , Subject : sub , RelationName : schema .MemberRelationName }).Return (relation .ErrNotExist )
22642229 auditRepo .EXPECT ().Create (ctx , mock .Anything ).Return (auditrecord.AuditRecord {}, nil )
22652230 },
@@ -2325,9 +2290,7 @@ func TestService_RemoveAllGroupMembers(t *testing.T) {
23252290 policySvc .EXPECT ().Delete (ctx , "p1" ).Return (nil )
23262291 policySvc .EXPECT ().Delete (ctx , "p2" ).Return (nil )
23272292 policySvc .EXPECT ().Delete (ctx , "p3" ).Return (nil )
2328- relSvc .EXPECT ().Delete (ctx , relFor (schema .OwnerRelationName , userA )).Return (relation .ErrNotExist )
23292293 relSvc .EXPECT ().Delete (ctx , relFor (schema .MemberRelationName , userA )).Return (nil )
2330- relSvc .EXPECT ().Delete (ctx , relFor (schema .OwnerRelationName , userB )).Return (nil )
23312294 relSvc .EXPECT ().Delete (ctx , relFor (schema .MemberRelationName , userB )).Return (relation .ErrNotExist )
23322295
23332296 svc := membership .NewService (slog .New (slog .NewTextHandler (io .Discard , nil )), policySvc , relSvc ,
@@ -2348,7 +2311,6 @@ func TestService_RemoveAllGroupMembers(t *testing.T) {
23482311 }, nil )
23492312 policySvc .EXPECT ().Delete (ctx , "p1" ).Return (errors .New ("db down" ))
23502313 policySvc .EXPECT ().Delete (ctx , "p2" ).Return (nil )
2351- relSvc .EXPECT ().Delete (ctx , relFor (schema .OwnerRelationName , userB )).Return (nil )
23522314 relSvc .EXPECT ().Delete (ctx , relFor (schema .MemberRelationName , userB )).Return (nil )
23532315
23542316 svc := membership .NewService (slog .New (slog .NewTextHandler (io .Discard , nil )), policySvc , relSvc ,
@@ -2382,21 +2344,12 @@ func TestService_OnGroupDeleted(t *testing.T) {
23822344 }).Return ([]policy.Policy {{ID : "principal-p1" }}, nil )
23832345 policySvc .EXPECT ().Delete (ctx , "principal-p1" ).Return (nil )
23842346
2385- // unlinkGroupFromOrg: both hierarchy relations
2347+ // unlinkGroupFromOrg: the identity link
23862348 relSvc .EXPECT ().Delete (ctx , relation.Relation {
23872349 Object : relation.Object {ID : groupID , Namespace : schema .GroupNamespace },
23882350 Subject : relation.Subject {ID : orgID , Namespace : schema .OrganizationNamespace },
23892351 RelationName : schema .OrganizationRelationName ,
23902352 }).Return (nil )
2391- relSvc .EXPECT ().Delete (ctx , relation.Relation {
2392- Object : relation.Object {ID : orgID , Namespace : schema .OrganizationNamespace },
2393- Subject : relation.Subject {
2394- ID : groupID ,
2395- Namespace : schema .GroupNamespace ,
2396- SubRelationName : schema .MemberRelationName ,
2397- },
2398- RelationName : schema .MemberRelationName ,
2399- }).Return (nil )
24002353
24012354 svc := membership .NewService (slog .New (slog .NewTextHandler (io .Discard , nil )), policySvc , relSvc ,
24022355 mocks .NewRoleService (t ), mocks .NewOrgService (t ), mocks .NewUserService (t ),
0 commit comments