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

Valkyrizes spec/abilities/ability_spec.rb. #6454

Merged
merged 2 commits into from
Nov 17, 2023
Merged
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
17 changes: 11 additions & 6 deletions spec/abilities/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@
it { is_expected.not_to be_able_to(:update, ContentBlock) }
it { is_expected.not_to be_able_to(:create, AdminSet) }
it { is_expected.to be_able_to(:read, ContentBlock) }
it { is_expected.to be_able_to(:read, GenericWork) }
it { is_expected.to be_able_to(:stats, GenericWork) }
it { is_expected.to be_able_to(:citation, GenericWork) }
unless Hyrax.config.disable_wings
it { is_expected.to be_able_to(:read, GenericWork) }
it { is_expected.to be_able_to(:stats, GenericWork) }
it { is_expected.to be_able_to(:citation, GenericWork) }
Comment on lines +102 to +104
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there equivalent checks that can be added for work resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That depends on Koppie setup. At the moment, there are no Work objects that come with an "empty" user ability inside Koppie.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#<Ability:0x00007fbcea58e388
 @aliased_actions={:read=>[:index, :show, :stats, :citation], :create=>[:new], :update=>[:edit, :versions, :file_manager]},
 @cache=#<Blacklight::AccessControls::PermissionsCache:0x00007fbceb1b8a78 @cache={}>,
 @current_user=
  #<User id: nil, email: "", created_at: nil, updated_at: nil, guest: false, facebook_handle: nil, twitter_handle: nil, googleplus_handle: nil, display_name: nil, address: nil, admin_area: nil, department: nil, title: nil, office: nil, chat_id: nil, website: nil, affiliation: nil, telephone: nil, avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil, linkedin_handle: nil, orcid: nil, arkivo_token: "bu1ijt6+hMzK64oMYtN5/4K/+IMZFikx", arkivo_subscription: nil, zotero_token: nil, zotero_userid: nil, preferred_locale: nil>,
 @options={},
 @rules=
  [#<CanCan::Rulecan [:edit, :update, :destroy], [String], [], {}>,
   #<CanCan::Rulecan [:edit, :update, :destroy], [ActiveFedora::Base], [], {}>,
   #<CanCan::Rulecan [:edit, :update, :destroy], [SolrDocument], [], {}>,
   #<CanCan::Rulecan [:read], [String], [], {}>,
   #<CanCan::Rulecan [:read], [SolrDocument], [], {}>,
   #<CanCan::Rulecan [:read], [ActiveFedora::Base], [], {}>,
   #<CanCan::Rulecan [:discover], [String], [], {}>,
   #<CanCan::Rulecan [:discover], [SolrDocument], [], {}>,
   #<CanCan::Rulecan [:discover], [ActiveFedora::Base], [], {}>,
   #<CanCan::Rulecan [:download], [String], [], {}>,
   #<CanCan::Rulecan [:download], [SolrDocument], [], {}>,
   #<CanCan::Rulecan [:edit, :update, :destroy], [Hyrax::Resource], [], {}>,
   #<CanCan::Rulecannot [:index], [Hydra::AccessControls::Embargo], [], {}>,
   #<CanCan::Rulecannot [:index], [Hydra::AccessControls::Lease], [], {}>,
   #<CanCan::Rulecan [:read], [Hyrax::Operation(id: integer, status: string, operation_type: string, job_class: string, job_id: string, type: string, message: text, user_id: integer, parent_id: integer, lft: integer, rgt: integer, depth: integer, children_count: integer, created_at: datetime, updated_at: datetime)], [], {:user_id=>nil}>,
   #<CanCan::Rulecan [:edit, :update, :toggle_trophy], [User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, created_at: datetime, updated_at: datetime, guest: boolean, facebook_handle: string, twitter_handle: string, googleplus_handle: string, display_name: string, address: string, admin_area: string, department: string, title: string, office: string, chat_id: string, website: string, affiliation: string, telephone: string, avatar_file_name: string, avatar_content_type: string, avatar_file_size: integer, avatar_updated_at: datetime, linkedin_handle: string, orcid: string, arkivo_token: string, arkivo_subscription: string, zotero_token: binary, zotero_userid: string, preferred_locale: string)], [], {:id=>nil}>,
   #<CanCan::Rulecan [:show], [User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, created_at: datetime, updated_at: datetime, guest: boolean, facebook_handle: string, twitter_handle: string, googleplus_handle: string, display_name: string, address: string, admin_area: string, department: string, title: string, office: string, chat_id: string, website: string, affiliation: string, telephone: string, avatar_file_name: string, avatar_content_type: string, avatar_file_size: integer, avatar_updated_at: datetime, linkedin_handle: string, orcid: string, arkivo_token: string, arkivo_subscription: string, zotero_token: binary, zotero_userid: string, preferred_locale: string)], [], {}>,
   #<CanCan::Rulecan [:read], [ContentBlock(id: integer, name: string, value: text, created_at: datetime, updated_at: datetime, external_key: string)], [], {}>,
   #<CanCan::Rulecan [:transfer], [String], [], {}>,
   #<CanCan::Rulecan [:accept], [ProxyDepositRequest(id: integer, work_id: string, sending_user_id: integer, receiving_user_id: integer, fulfillment_date: datetime, status: string, sender_comment: text, receiver_comment: text, created_at: datetime, updated_at: datetime)], [], {:receiving_user_id=>nil, :status=>"pending"}>,
   #<CanCan::Rulecan [:reject], [ProxyDepositRequest(id: integer, work_id: string, sending_user_id: integer, receiving_user_id: integer, fulfillment_date: datetime, status: string, sender_comment: text, receiver_comment: text, created_at: datetime, updated_at: datetime)], [], {:receiving_user_id=>nil, :status=>"pending"}>,
   #<CanCan::Rulecan [:destroy], [ProxyDepositRequest(id: integer, work_id: string, sending_user_id: integer, receiving_user_id: integer, fulfillment_date: datetime, status: string, sender_comment: text, receiver_comment: text, created_at: datetime, updated_at: datetime)], [], {:sending_user_id=>nil, :status=>"pending"}>,
   #<CanCan::Rulecan [:edit, :update, :destroy], [Hyrax::AdministrativeSet], [], {}>,
   #<CanCan::Rulecan [:deposit], [AdminSet], [], {}>,
   #<CanCan::Rulecan [:deposit], [Hyrax::AdministrativeSet], [], {}>,
   #<CanCan::Rulecan [:view_admin_show], [AdminSet], [], {}>,
   #<CanCan::Rulecan [:view_admin_show], [Hyrax::AdministrativeSet], [], {}>,
   #<CanCan::Rulecan [:read], [Hyrax::AdministrativeSet], [], {}>,
   #<CanCan::Rulecan [:review], [:submissions], [], {}>,
   #<CanCan::Rulecan [:edit, :update, :destroy], [Hyrax::PcdmCollection], [], {}>,
   #<CanCan::Rulecan [:deposit], [Hyrax::PcdmCollection], [], {}>,
   #<CanCan::Rulecan [:view_admin_show], [Hyrax::PcdmCollection], [], {}>,
   #<CanCan::Rulecan [:read], [Hyrax::PcdmCollection], [], {}>,
   #<CanCan::Rulecan [:edit, :update, :destroy], [CollectionResource], [], {}>,
   #<CanCan::Rulecan [:deposit], [CollectionResource], [], {}>,
   #<CanCan::Rulecan [:view_admin_show], [CollectionResource], [], {}>,
   #<CanCan::Rulecan [:read], [CollectionResource], [], {}>,
   #<CanCan::Rulecan [:deposit], [SolrDocument], [], {}>,
   #<CanCan::Rulecan [:deposit], [String], [], {}>,
   #<CanCan::Rulecan [:view_admin_show], [SolrDocument], [], {}>,
   #<CanCan::Rulecan [:create_collection_of_type], [Hyrax::CollectionType(id: integer, title: string, description: text, machine_id: string, nestable: boolean, discoverable: boolean, sharable: boolean, allow_multiple_membership: boolean, require_membership: boolean, assigns_workflow: boolean, assigns_visibility: boolean, share_applies_to_new_works: boolean, brandable: boolean, badge_color: string)], [], {}>,
   #<CanCan::Rulecan [:create, :edit, :update, :destroy], [Hyrax::PermissionTemplate(id: integer, source_id: string, visibility: string, created_at: datetime, updated_at: datetime, release_date: date, release_period: string)], [], {}>,
   #<CanCan::Rulecan [:create, :edit, :update, :destroy], [Hyrax::PermissionTemplateAccess(id: integer, permission_template_id: integer, agent_type: string, agent_id: string, access: string, created_at: datetime, updated_at: datetime)], [], {}>,
   #<CanCan::Rulecan [:edit, :update, :destroy], [SolrDocument], [], {}>,
   #<CanCan::Rulecan [:read], [SolrDocument], [], {}>,
   #<CanCan::Rulecan [:create, :destroy], [Trophy(id: integer, user_id: integer, work_id: string, created_at: datetime, updated_at: datetime)], [], {}>],
 @rules_index=
  {String=>[0, 3, 6, 9, 18, 38],
   ActiveFedora::Base=>[1, 5, 8],
   SolrDocument=>[2, 4, 7, 10, 37, 39, 43, 44],
   Hyrax::Resource=>[11],
   Hydra::AccessControls::Embargo=>[12],
   Hydra::AccessControls::Lease=>[13],
   Hyrax::Operation(id: integer, status: string, operation_type: string, job_class: string, job_id: string, type: string, message: text, user_id: integer, parent_id: integer, lft: integer, rgt: integer, depth: integer, children_count: integer, created_at: datetime, updated_at: datetime)=>
    [14],
   User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, created_at: datetime, updated_at: datetime, guest: boolean, facebook_handle: string, twitter_handle: string, googleplus_handle: string, display_name: string, address: string, admin_area: string, department: string, title: string, office: string, chat_id: string, website: string, affiliation: string, telephone: string, avatar_file_name: string, avatar_content_type: string, avatar_file_size: integer, avatar_updated_at: datetime, linkedin_handle: string, orcid: string, arkivo_token: string, arkivo_subscription: string, zotero_token: binary, zotero_userid: string, preferred_locale: string)=>
    [15, 16],
   ContentBlock(id: integer, name: string, value: text, created_at: datetime, updated_at: datetime, external_key: string)=>[17],
   ProxyDepositRequest(id: integer, work_id: string, sending_user_id: integer, receiving_user_id: integer, fulfillment_date: datetime, status: string, sender_comment: text, receiver_comment: text, created_at: datetime, updated_at: datetime)=>
    [19, 20, 21],
   Hyrax::AdministrativeSet=>[22, 24, 26, 27],
   AdminSet=>[23, 25],
   :submissions=>[28],
   Hyrax::PcdmCollection=>[29, 30, 31, 32],
   CollectionResource=>[33, 34, 35, 36],
   Hyrax::CollectionType(id: integer, title: string, description: text, machine_id: string, nestable: boolean, discoverable: boolean, sharable: boolean, allow_multiple_membership: boolean, require_membership: boolean, assigns_workflow: boolean, assigns_visibility: boolean, share_applies_to_new_works: boolean, brandable: boolean, badge_color: string)=>
    [40],
   Hyrax::PermissionTemplate(id: integer, source_id: string, visibility: string, created_at: datetime, updated_at: datetime, release_date: date, release_period: string)=>
    [41],
   Hyrax::PermissionTemplateAccess(id: integer, permission_template_id: integer, agent_type: string, agent_id: string, access: string, created_at: datetime, updated_at: datetime)=>
    [42],
   Trophy(id: integer, user_id: integer, work_id: string, created_at: datetime, updated_at: datetime)=>[45]},
 @user=
  #<User id: nil, email: "", created_at: nil, updated_at: nil, guest: false, facebook_handle: nil, twitter_handle: nil, googleplus_handle: nil, display_name: nil, address: nil, admin_area: nil, department: nil, title: nil, office: nil, chat_id: nil, website: nil, affiliation: nil, telephone: nil, avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil, linkedin_handle: nil, orcid: nil, arkivo_token: "bu1ijt6+hMzK64oMYtN5/4K/+IMZFikx", arkivo_subscription: nil, zotero_token: nil, zotero_userid: nil, preferred_locale: nil>,
 @user_groups=["public"]>

end
end

describe "a registered user" do
Expand Down Expand Up @@ -134,7 +136,7 @@
let(:permission_template) { build(:permission_template, source_id: admin_set.id) }
let(:permission_template_access) { build(:permission_template_access, permission_template: permission_template) }
let(:user) { create(:user) }
let(:admin_set) { create(:admin_set) }
let(:admin_set) { valkyrie_create(:hyrax_admin_set) }

RSpec.shared_examples 'A user with additional access' do
it { is_expected.to be_able_to(:edit, admin_set) }
Expand All @@ -154,7 +156,10 @@
end

describe 'via AdminSet-specific edit_users' do
let(:admin_set) { create(:admin_set, with_permission_template: true, edit_users: [user]) }
let(:admin_set) { valkyrie_create(:hyrax_admin_set, edit_users: [user.user_key]) }
let(:permission_template) do
create(:permission_template, source_id: admin_set.id)
end

it '#admin? is false' do
expect(ability).not_to be_admin
Expand All @@ -163,7 +168,7 @@
it 'A user who can manage an AdminSet' do
create(:permission_template_access,
:manage,
permission_template: admin_set.permission_template,
permission_template: permission_template,
agent_type: 'user',
agent_id: user.user_key)
is_expected.to be_able_to(:manage_any, AdminSet)
Expand Down