Implement track requests and add the track organizer role

About track requests:
Create migration that adds the fields submitter_id, state, and
cfp_active to Tracks
Add validations and the self_organized? method to the Track model
Create a new TracksController outide of the admin namespace
Create the relevant views for index, show, new and edit
Modify the admin views for tracks to include extra info for
self-organized tracks

About track organizers:
Create the role when a self-organized track is created
Define track organizer abilities
Modify the roles views and controller to handle the new role

The route for Roles#edit needs to have higher priority than the nested
routes for track roles, otherwise, the word edit in the url is matched
as a track with short_name edit
This commit is contained in:
AEtherC0r3 2017-06-08 12:25:33 +03:00 committed by Stella Rouzi
parent 98fc1137e1
commit 68fc750e9f
26 changed files with 766 additions and 27 deletions

View file

@ -70,6 +70,11 @@ class AdminAbility
cannot :destroy, Venue do |venue|
venue.conference.program.events.where.not(room_id: nil).any?
end
# Prevent requests for tracks from being destroyed
cannot :destroy, Track do |track|
track.self_organized?
end
end
# Abilities for signed in users with roles
@ -79,6 +84,7 @@ class AdminAbility
signed_in_with_cfp_role(user) if user.has_role? :cfp, :any
signed_in_with_info_desk_role(user) if user.has_role? :info_desk, :any
signed_in_with_volunteers_coordinator_role(user) if user.has_role? :volunteers_coordinator, :any
signed_in_with_track_organizer_role(user) if user.has_role? :track_organizer, :any
common_abilities_for_roles(user)
end
@ -100,6 +106,9 @@ class AdminAbility
# 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
# 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)
can :manage, Resource, conference_id: conf_ids
can [:read, :update, :destroy], Conference, id: conf_ids
can :manage, Splashpage, conference_id: conf_ids
@ -140,11 +149,12 @@ class AdminAbility
# Abilities for Role (Conference resource)
can [:index, :show], Role do |role|
role.resource_type == 'Conference'
role.resource_type == 'Conference' || role.resource_type == 'Track'
end
can [:edit, :update, :toggle_user], Role do |role|
role.resource_type == 'Conference' && (conf_ids.include? role.resource_id)
role.resource_type == 'Conference' && (conf_ids.include? role.resource_id) ||
role.resource_type == 'Track' && (track_ids.include? role.resource_id)
end
can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version|
@ -178,7 +188,7 @@ class AdminAbility
# Abilities for Role (Conference resource)
can [:index, :show], Role do |role|
role.resource_type == 'Conference'
role.resource_type == 'Conference' || role.resource_type == 'Track'
end
# Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
@ -211,7 +221,7 @@ class AdminAbility
# Abilities for Role (Conference resource)
can [:index, :show], Role do |role|
role.resource_type == 'Conference'
role.resource_type == 'Conference' || role.resource_type == 'Track'
end
# Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
@ -234,7 +244,7 @@ class AdminAbility
# Abilities for Role (Conference resource)
can [:index, :show], Role do |role|
role.resource_type == 'Conference'
role.resource_type == 'Conference' || role.resource_type == 'Track'
end
# Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
@ -243,4 +253,34 @@ class AdminAbility
(Conference.with_role(:volunteers_coordinator, user).pluck(:id).include? role.resource_id)
end
end
def signed_in_with_track_organizer_role(user)
# ids of all the conferences for which the user has the 'track organizer' role
conf_ids_for_track_organizer = Track.with_role(:track_organizer, user).joins(:program).pluck(:conference_id)
# ids of all the tracks for which the user has the 'track_organizer' role
track_ids_for_track_organizer = Track.with_role(:track_organizer, user).pluck(:id)
can :show, Conference do |conf|
conf_ids_for_track_organizer.include?(conf.id)
end
# Show Program in the admin sidebar
can :show, Program, conference_id: conf_ids_for_track_organizer
# Show Tracks in the admin sidebar
can :update, Track do |track|
track.new_record? && conf_ids_for_track_organizer.include?(track.program.conference_id)
end
can :manage, Track, id: track_ids_for_track_organizer
# Show Roles in the admin sidebar and allow authorization of the index action
can [:index, :show], Role do |role|
role.resource_type == 'Conference' || role.resource_type == 'Track'
end
can :toggle_user, Role do |role|
role.resource_type == 'Track' && track_ids_for_track_organizer.include?(role.resource_id)
end
end
end