Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Commit

Permalink
vrr: support revoking in NewRightsProcessor
Browse files Browse the repository at this point in the history
The previous implementation did not actually test revoking via the
nightly rake task. Examples being:

- Assuming in `initialize` that the attributes were based on a
  Hashie:Mash class or subclass, which Aeon::Request is, but is not what
was provided in `revoke_old` (was just a simple hash)
- The work_pid would never be found in `initialize` because
  `subLocation` would not exist in the request attributes supplied by
`revoke_old`
  • Loading branch information
mcritchlow authored and VivianChu committed Jul 1, 2019
1 parent 5b2ab0d commit 332676d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/processors/new_rights_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def self.process_new
def self.revoke_old
WorkAuthorization.where('updated_at < ?', 1.month.ago).each do |auth|
begin
params = { work_pid: auth.work_pid, email: auth.user.email, aeon_id: auth.aeon_id }
params = Hashie::Mash.new(work_pid: auth.work_pid,
email: auth.user.email,
aeon_id: auth.aeon_id)
request = Processors::NewRightsProcessor.new(params)
request.revoke
rescue => e
Expand All @@ -33,11 +35,15 @@ def self.revoke_old
end
end

# Initialize a rights processor for authorizing or revoking access
# @param request_attributes [Hashie:Mash] list of attributes for request
def initialize(request_attributes)
@request_attributes = request_attributes
@work_title = @request_attributes[:itemTitle]
@work_pid = if ['development'].include? Rails.env
DamsObject.last.pid
elsif @request_attributes.work_pid?
@request_attributes.work_pid
else
@request_attributes[:subLocation]
end
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/processors/new_rights_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
end
end

describe ".revoke_old" do
let!(:dams_object){ DamsObject.create(pid: 'revoke_pid', titleValue: 'test_title') }
let!(:user){ create_auth_link_user }
context "when there are work authorizations to expire" do
it "deletes them" do
allow_any_instance_of(described_class).to receive(:expire_request).with(anything)
Timecop.freeze(Date.today - 31) do
WorkAuthorization.create(work_pid: dams_object.pid, aeon_id: '1234567', user: user)
end
expect(WorkAuthorization.count).to be(1)
described_class.revoke_old
expect(WorkAuthorization.count).to be(0)
end
end
end

describe "authorize" do
let!(:dams_object){ DamsObject.create(pid: 'test_pid', titleValue: 'test_title') }
context "when credentials are valid" do
Expand Down

0 comments on commit 332676d

Please sign in to comment.