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

MG-2216 - Rename delete policy function #2218

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

nyagamunene
Copy link
Contributor

@nyagamunene nyagamunene commented May 6, 2024

What type of PR is this?

This is a feature that renames the DeletePolicy gRPC function to DeletePolicyFilter policy with relationship filter.

What does this do?

It rename gRPC, gRPC request & SpiceDB function DeletePolicy to DeletePolicyFilter

Which issue(s) does this PR fix/relate to?

Have you included tests for your changes?

Yes.

Did you document any new/modified feature?

No.

Notes

@nyagamunene nyagamunene self-assigned this May 6, 2024
@nyagamunene nyagamunene force-pushed the MG-2216-RenameDeletePolicygRPCSpiceDBfunction branch 2 times, most recently from 2848916 to 158f23d Compare May 7, 2024 15:56
@nyagamunene nyagamunene marked this pull request as ready for review May 8, 2024 10:28
@dborovcanin dborovcanin force-pushed the MG-2216-RenameDeletePolicygRPCSpiceDBfunction branch from 72da806 to 7bc5809 Compare May 13, 2024 09:57
@nyagamunene nyagamunene changed the title MG-2216-RenameDeletePolicygRPCSpiceDBfunction MG-2216-RenameDeletePolicyFunction May 13, 2024
@nyagamunene nyagamunene changed the title MG-2216-RenameDeletePolicyFunction MG-2216-Rename Delete Policy Function May 14, 2024
@nyagamunene nyagamunene changed the title MG-2216-Rename Delete Policy Function MG-2216-Rename delete policy function May 14, 2024
@dborovcanin dborovcanin force-pushed the MG-2216-RenameDeletePolicygRPCSpiceDBfunction branch from 7bc5809 to edf248a Compare May 15, 2024 12:27
auth/api/logging.go Show resolved Hide resolved
auth/api/metrics.go Show resolved Hide resolved
@@ -1394,7 +1394,7 @@ func TestDeletePolicies(t *testing.T) {
}

for _, tc := range cases {
repocall := prepo.On("DeletePolicies", mock.Anything, mock.Anything).Return(tc.err)
repocall := prepo.On("DeletePolicies", context.Background(), mock.Anything).Return(tc.err)
err := svc.DeletePolicies(context.Background(), tc.pr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyagamunene ,Why we are changing from mock.Anything to context.Background()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When calling page, err := svc.ListAllObjects(context.Background(), tc.pr) context.Background is passed to the repo call. This is a mistake that was not noted during the mock test

auth/policies.go Show resolved Hide resolved
auth/policies.go Show resolved Hide resolved
auth/api/logging.go Show resolved Hide resolved
deletePolicyReq *magistrala.DeletePolicyReq
deletePolicyRes *magistrala.DeletePolicyRes
deletePolicyReq *magistrala.DeletePolicyFilterReq
deletePolicyRes *magistrala.DeletePolicyFilterRes
err error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err error
deletePolicyFilterReq *magistrala.DeletePolicyFilterReq
deletePolicyFilterRes *magistrala.DeletePolicyFilterRes

@@ -1050,7 +1050,7 @@ func TestUpdateClientRole(t *testing.T) {
desc: "update client role to user role with failed to delete policy",
identifyResponse: &magistrala.IdentityRes{UserId: client.ID},
authorizeResponse: &magistrala.AuthorizeRes{Authorized: true},
deletePolicyResponse: &magistrala.DeletePolicyRes{Deleted: false},
deletePolicyResponse: &magistrala.DeletePolicyFilterRes{Deleted: false},
updateRoleResponse: mgclients.Client{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updateRoleResponse: mgclients.Client{},
deletePolicyFilterResponse: &magistrala.DeletePolicyFilterRes{Deleted: false},

@@ -1059,7 +1059,7 @@ func TestUpdateClientRole(t *testing.T) {
desc: "update client role to user role with failed to delete policy with error",
identifyResponse: &magistrala.IdentityRes{UserId: client.ID},
authorizeResponse: &magistrala.AuthorizeRes{Authorized: true},
deletePolicyResponse: &magistrala.DeletePolicyRes{Deleted: false},
deletePolicyResponse: &magistrala.DeletePolicyFilterRes{Deleted: false},
updateRoleResponse: mgclients.Client{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updateRoleResponse: mgclients.Client{},
deletePolicyFilterResponse: &magistrala.DeletePolicyFilterRes{Deleted: false},

@@ -1071,7 +1071,7 @@ func TestUpdateClientRole(t *testing.T) {
identifyResponse: &magistrala.IdentityRes{UserId: client.ID},
authorizeResponse: &magistrala.AuthorizeRes{Authorized: true},
addPolicyResponse: &magistrala.AddPolicyRes{Added: true},
deletePolicyResponse: &magistrala.DeletePolicyRes{Deleted: true},
deletePolicyResponse: &magistrala.DeletePolicyFilterRes{Deleted: true},
updateRoleResponse: mgclients.Client{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updateRoleResponse: mgclients.Client{},
deletePolicyFilterResponse: &magistrala.DeletePolicyFilterRes{Deleted: true},

@@ -1083,7 +1083,7 @@ func TestUpdateClientRole(t *testing.T) {
identifyResponse: &magistrala.IdentityRes{UserId: client.ID},
authorizeResponse: &magistrala.AuthorizeRes{Authorized: true},
addPolicyResponse: &magistrala.AddPolicyRes{Added: true},
deletePolicyResponse: &magistrala.DeletePolicyRes{Deleted: false},
deletePolicyResponse: &magistrala.DeletePolicyFilterRes{Deleted: false},
updateRoleResponse: mgclients.Client{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updateRoleResponse: mgclients.Client{},
deletePolicyFilterResponse: &magistrala.DeletePolicyFilterRes{Deleted: false},

auth.proto Outdated
Comment on lines 118 to 120
message DeletePoliciesReq {
repeated DeletePolicyReq deletePoliciesReq = 1;
repeated DeletePolicyFilterReq deletePoliciesReq = 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets have seperate message for DeletePoliciesReq, DeletePolicyReq is different from DeletePolicyFilterReq
In DeletePolicies all fields are required , but in DeletePolicyFilter not all the fields are required.
DeletePolicyFilter filters the relation and then delete.

Suggested change
message DeletePoliciesReq {
repeated DeletePolicyReq deletePoliciesReq = 1;
repeated DeletePolicyFilterReq deletePoliciesReq = 1;
}
message DeletePolicyReq {
string domain = 1;
string subject_type = 2;
string subject_relation = 3;
string subject_kind = 4;
string subject = 5;
string relation = 6;
string permission = 7;
string object = 8;
string object_kind = 9;
string object_type = 10;
}
message DeletePoliciesReq {
repeated DeletePolicyReq DeletePolicyReq = 1;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I clarification on this is needed. Should I create a a separate DeletePolicyFilterRes and DeletePolicyFilterReq to be used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@nyagamunene nyagamunene force-pushed the MG-2216-RenameDeletePolicygRPCSpiceDBfunction branch from edf248a to 271320b Compare May 20, 2024 22:02
@nyagamunene nyagamunene changed the title MG-2216-Rename delete policy function MG-2216 - Rename delete policy function May 21, 2024
auth.proto Outdated Show resolved Hide resolved
@nyagamunene nyagamunene force-pushed the MG-2216-RenameDeletePolicygRPCSpiceDBfunction branch from c15818b to f0e8c67 Compare May 23, 2024 10:09
@nyagamunene nyagamunene force-pushed the MG-2216-RenameDeletePolicygRPCSpiceDBfunction branch from f0e8c67 to 39482cf Compare May 23, 2024 10:11
rodneyosodo
rodneyosodo previously approved these changes May 23, 2024
Copy link
Member

@rodneyosodo rodneyosodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

WashingtonKK
WashingtonKK previously approved these changes May 23, 2024
Copy link
Contributor

@WashingtonKK WashingtonKK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyagamunene I will approve this, however upon testing I found out that UnshareThing does not check whether the provided userID is actually a user in the platform. Additionally, unshare thing with a correct thing ID and a random user ID passes successfully, and it can be done multiple times successfully.

Please test this on your end and create an issue for it so that we do not forget it.

JeffMboya
JeffMboya previously approved these changes May 23, 2024
auth/policies.go Outdated Show resolved Hide resolved
auth.proto Outdated
@@ -116,10 +116,10 @@ message DeletePolicyReq {
}

message DeletePoliciesReq {
repeated DeletePolicyReq deletePoliciesReq = 1;
repeated DeletePolicyFilterReq deletePoliciesReq = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
repeated DeletePolicyFilterReq deletePoliciesReq = 1;
message DeletePolicyFilterReq {
string domain = 1;
string subject_type = 2;
string subject_relation = 3;
string subject_kind = 4;
string subject = 5;
string relation = 6;
string permission = 7;
string object = 8;
string object_kind = 9;
string object_type = 10;
}
message DeletePolicyFilterRes { bool deleted = 1; }
message DeletePoliciesReq {
repeated DeletePolicyReq deletePoliciesReq = 1;
}
message DeletePolicyReq {
string domain = 1;
string subject_type = 2;
string subject_relation = 3;
string subject_kind = 4;
string subject = 5;
string relation = 6;
string permission = 7;
string object = 8;
string object_kind = 9;
string object_type = 10;
}

Signed-off-by: nyagamunene <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Rename DeletePolicy gRPC & SpiceDB function to DeletePolicyFilter and
5 participants