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

GrantRepo#for_collection_class inst,group soft delete support #71

Merged
merged 2 commits into from
Feb 21, 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
10 changes: 7 additions & 3 deletions lauth/app/repositories/grant_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def for_collection_class(username:, client_ip:, collection_class:)
.where(grants[:dlpsDeleted].is("f"))
.join(collections.name.dataset, uniqueIdentifier: :coll, dlpsDeleted: "f")
.left_join(users.name.dataset, userid: grants[:userid], dlpsDeleted: "f")
.left_join(institution_memberships.name.dataset, inst: grants[:inst])
.left_join(group_memberships.name.dataset, user_grp: grants[:user_grp])
.left_join(institutions.name.dataset, uniqueIdentifier: grants[:inst], dlpsDeleted: "f")
.left_join(institution_memberships.name.dataset, inst: grants[:inst], dlpsDeleted: "f")
.left_join(groups.name.dataset, uniqueIdentifier: grants[:user_grp], dlpsDeleted: "f")
.left_join(group_memberships.name.dataset, user_grp: grants[:user_grp], dlpsDeleted: "f")
.left_join(Sequel.as(smallest_network, :smallest), inst: grants[:inst])
.where(collections[:dlpsClass] => collection_class)
.where(
Expand All @@ -27,10 +29,12 @@ def for_collection_class(username:, client_ip:, collection_class:)
{users[:userid] => username}
),
Sequel.&(
Sequel.~(institutions[:uniqueIdentifier] => nil),
Sequel.~(institution_memberships[:userid] => nil),
{institution_memberships[:userid] => username}
),
Sequel.&(
Sequel.~(groups[:uniqueIdentifier] => nil),
Sequel.~(group_memberships[:userid] => nil),
{group_memberships[:userid] => username}
),
Expand Down Expand Up @@ -93,7 +97,7 @@ def for(username:, uri:, client_ip: nil)

def smallest_network_for_ip(client_ip)
ip = client_ip ? IPAddr.new(client_ip).to_i : nil
smallest_network = networks
networks
.dataset
.where(dlpsDeleted: "f")
.where { dlpsAddressStart <= ip }
Expand Down
Copy link
Collaborator

@gkostin1966 gkostin1966 Feb 21, 2024

Choose a reason for hiding this comment

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

The flow of the spec is to state the positive “it” then start soft deleting resources. Therefore I would expect to see ….
it "#for_collection_class finds grants" do
expect(repo.for_collection_class(
username: "lauth-group-member",
client_ip: "10.99.3.4",
collection_class: "someclass"
)).to FIND THE GRANT
end
as the second “it” block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense. added.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subject(:grants) { repo.for(username: "lauth-group-member", uri: "/restricted-by-username/") }

let(:repo) { Lauth::Repositories::GrantRepo.new }
let(:collection) { Factory[:collection, :restricted_by_username] }
let(:collection) { Factory[:collection, :restricted_by_username, dlpsClass: "someclass"] }
let(:group) { Factory[:group] }
let(:member) { Factory[:user, userid: "lauth-group-member"] }
let(:membership) { Factory[:group_membership, user: member, group: group] }
Expand All @@ -21,6 +21,14 @@
expect(grants.map(&:uniqueIdentifier)).to contain_exactly grant.uniqueIdentifier
end

it "#for_collection_class finds the grant" do
expect(repo.for_collection_class(
username: "lauth-group-member",
client_ip: "10.99.3.4",
collection_class: "someclass"
).map(&:uniqueIdentifier)).to contain_exactly grant.uniqueIdentifier
end

context "when collection is soft deleted" do
let(:collection) { Factory[:collection, :restricted_by_username, :soft_deleted] }

Expand All @@ -43,6 +51,14 @@
it "finds no grants" do
expect(grants).to be_empty
end

it "#for_collection_class finds no grants" do
expect(repo.for_collection_class(
username: "lauth-group-member",
client_ip: "10.99.3.4",
collection_class: "someclass"
)).to be_empty
end
end

context "when member is soft deleted" do
Expand All @@ -59,6 +75,14 @@
it "finds no grants" do
expect(grants).to be_empty
end

it "#for_collection_class finds no grants" do
expect(repo.for_collection_class(
username: "lauth-group-member",
client_ip: "10.99.3.4",
collection_class: "someclass"
)).to be_empty
end
end

context "when grant is soft deleted" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subject(:grants) { repo.for(username: "lauth-inst-member", uri: "/restricted-by-username/") }

let(:repo) { Lauth::Repositories::GrantRepo.new }
let(:collection) { Factory[:collection, :restricted_by_username] }
let(:collection) { Factory[:collection, :restricted_by_username, dlpsClass: "someclass"] }
let(:institution) { Factory[:institution] }
let(:member) { Factory[:user, userid: "lauth-inst-member"] }
let(:membership) { Factory[:institution_membership, user: member, institution: institution] }
Expand All @@ -21,6 +21,14 @@
expect(grants.map(&:uniqueIdentifier)).to contain_exactly(grant.uniqueIdentifier)
end

it "#for_collection_class finds the grant" do
expect(repo.for_collection_class(
username: "lauth-inst-member",
client_ip: "10.99.3.4",
collection_class: "someclass"
).map(&:uniqueIdentifier)).to contain_exactly grant.uniqueIdentifier
end

context "when collection is soft deleted" do
let(:collection) { Factory[:collection, :restricted_by_username, :soft_deleted] }

Expand All @@ -43,6 +51,14 @@
it "finds no grants" do
expect(grants).to be_empty
end

it "#for_collection_class finds no grants" do
expect(repo.for_collection_class(
username: "lauth-inst-member",
client_ip: "10.99.3.4",
collection_class: "someclass"
)).to be_empty
end
end

context "when member is soft deleted" do
Expand All @@ -59,6 +75,14 @@
it "finds no grants" do
expect(grants).to be_empty
end

it "#for_collection_class finds no grants" do
expect(repo.for_collection_class(
username: "lauth-inst-member",
client_ip: "10.2.3.4",
collection_class: "someclass"
)).to be_empty
end
end

context "when grant is soft deleted" do
Expand Down