Skip to content

Commit

Permalink
Merge pull request #71 from mlibrary/collection-class-soft-delete
Browse files Browse the repository at this point in the history
GrantRepo#for_collection_class inst,group soft delete support
  • Loading branch information
malakai97 authored Feb 21, 2024
2 parents 7f6d33d + 54cfe5c commit d7e335f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
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
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

0 comments on commit d7e335f

Please sign in to comment.