From dc1a6a43635e47782d988870d8570e987b92cb2b Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Fri, 7 Jun 2024 16:13:28 +0200 Subject: [PATCH] Drop Organization abilities --- app/models/ability.rb | 2 -- app/models/admin_ability.rb | 21 +++------------------ spec/ability/ability_spec.rb | 4 +--- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 77746620..913c97ff 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -17,7 +17,6 @@ class Ability # Abilities for not signed in users (guests) def not_signed_in - can [:index, :conferences, :code_of_conduct], Organization can [:index], Conference can [:show], Conference do |conference| conference.splashpage&.public == true @@ -86,7 +85,6 @@ class Ability end end - can :index, Organization can :index, Ticket can :manage, TicketPurchase, user_id: user.id can [:new, :create], Payment, user_id: user.id diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 6100455c..67bf6cfe 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -30,7 +30,6 @@ class AdminAbility conference.registration_open? && !conference.registration_limit_exceeded? || conference.program.speakers.confirmed.include?(user) end - can [:index, :admins], Organization can :index, Ticket can :manage, TicketPurchase, user_id: user.id can [:new, :create], Payment, user_id: user.id @@ -81,7 +80,6 @@ class AdminAbility # Abilities for signed in users with roles def signed_in_with_roles(user) - signed_in_with_organization_admin_role(user) if user.has_cached_role? :organization_admin, :any signed_in_with_organizer_role(user) if user.has_cached_role? :organizer, :any signed_in_with_cfp_role(user) if user.has_cached_role? :cfp, :any signed_in_with_info_desk_role(user) if user.has_cached_role? :info_desk, :any @@ -90,22 +88,9 @@ class AdminAbility common_abilities_for_roles(user) end - def signed_in_with_organization_admin_role(user) - org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id) - conf_ids_for_organization_admin = Conference.where(organization_id: org_ids_for_organization_admin).pluck(:id) - - can [:read, :update, :destroy, :assign_org_admins, :unassign_org_admins, :admins], Organization, id: org_ids_for_organization_admin - can :new, Conference - can :manage, Conference, organization_id: org_ids_for_organization_admin - can [:index, :show], Role - - signed_in_with_organizer_role(user, conf_ids_for_organization_admin) - end - - def signed_in_with_organizer_role(user, conf_ids_for_organization_admin = []) - # ids of all the conferences for which the user has the 'organizer' role and - # conferences that belong to organizations for which user is 'organization_admin' - conf_ids = conf_ids_for_organization_admin.concat(Conference.with_role(:organizer, user).pluck(:id)).uniq + def signed_in_with_organizer_role(user) + # ids of all the conferences for which the user has the 'organizer' role + conf_ids = Conference.with_role(:organizer, user).pluck(:id) # ids of all the tracks that belong to the programs of the above conferences track_ids = Track.joins(:program).where('programs.conference_id IN (?)', conf_ids).pluck(:id) diff --git a/spec/ability/ability_spec.rb b/spec/ability/ability_spec.rb index d119f9c5..0f3438ac 100644 --- a/spec/ability/ability_spec.rb +++ b/spec/ability/ability_spec.rb @@ -11,8 +11,7 @@ describe 'User' do subject(:ability){ Ability.new(user) } let(:user){ nil } - let!(:organization) { create(:organization) } - let!(:my_conference) { create(:full_conference, organization: organization) } + let!(:my_conference) { create(:full_conference) } let(:my_room) { create(:room, venue: my_conference.venue) } @@ -36,7 +35,6 @@ describe 'User' do # Test abilities for not signed in users context 'when user is not signed in' do - it{ should be_able_to(:index, Organization)} it{ should be_able_to(:index, Conference)} it{ should be_able_to(:show, conference_public)}