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

Update access and permissions rake task #2488

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
5 changes: 3 additions & 2 deletions lib/tasks/access_and_permissions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace :permissions do
message = "Organisation with ID: #{args[:org_content_id]} already has permission to access the document with ID: #{document.id}"
else
Edition.where(panopticon_id: document.id).each do |edition|
edition.owning_org_content_ids << args[:org_content_id]
edition.save!(validate: false)
owning_org_content_ids = edition.owning_org_content_ids
owning_org_content_ids << args[:org_content_id]
edition.set(owning_org_content_ids:)
end
document.save_as_task!("PermissionsAddition")
message = "Access permission for organisation ID: #{args[:org_content_id]}, successfully assigned to document with ID: #{document.id}"
Expand Down
17 changes: 17 additions & 0 deletions test/unit/tasks/access_and_permissions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ class AccessAndPermissionsTaskTest < ActiveSupport::TestCase
assert_equal(1, @edition1.owning_org_content_ids.count { |id| id == organisation_id })
end

test "add_organisation_access does not update 'updated_at' values" do
organisation_id = "test-org-id"
# For some reason, the "updated_at" value when reloaded is different from the one in the object returned by the
# factory, so we need to do a reload before storing a copy of the original value.
@edition1.reload
@artefact1.reload
original_edition_updated_at = @edition1.updated_at
original_artefact_updated_at = @artefact1.updated_at

@add_organisation_access_task.invoke(@artefact1.id, organisation_id)
@edition1.reload
@artefact1.reload

assert_equal(original_edition_updated_at, @edition1.updated_at)
assert_equal(original_artefact_updated_at, @artefact1.updated_at)
end

test "bulk_process_access_flags processes all rows in CSV" do
organisation_id = "test-org-id"

Expand Down
Loading