rework users page, add role assignment

This commit is contained in:
Stella Rouzi 2014-07-20 19:40:16 +03:00
parent 9998e00ae3
commit 80d48ed7d8
13 changed files with 118 additions and 72 deletions

View file

@ -21,7 +21,30 @@ class Ability
user ||= User.new # guest user (not logged in)
# Abilities per role
# Check roles of user, using rolify. Role name is *case sensitive*
# user.is_organizer? or user.has_role? :organizer
# user.is_cfp_of? Conference or user.has_role? :cfp, Conference
# user.is_info_desk_of? Conference
# user.is_volunteer_coordinator_of? Conference
# user.is_attendee_of? Conference
# The following is wrong because a user will only have 'cfp' role for a specific conference
# user.is_cfp? # This is always false
# Ids of all the conferences for which the user has an 'organizer' role
conf_ids_for_organizer =
Conference.with_role(:organizer, user).pluck(:id) unless user.new_record?
# Ids of the venues of the conference for which (conferences) the user has an 'organizer' role
conf_ids_for_organizer_venue =
Conference.with_role(:organizer, user).pluck(:venue_id) unless user.new_record?
# Ids of all the conferences for which the user has a 'cfp' role
conf_ids_for_cfp =
Conference.with_role(:cfp, user).pluck(:id) unless user.new_record?
# Ids of all the conferences for which the user has an 'info_desk' role
conf_ids_for_info_desk =
Conference.with_role(:info_desk, user).pluck(:id) unless user.new_record?
# Ids of all the conferences for which the user has a 'volunteer_coordinator' role
conf_ids_for_volunteer_coordinator =
Conference.with_role(:volunteer_coordinator, user).pluck(:id) unless user.new_record?
# Abilities for signed in users
unless user.new_record?
@ -30,7 +53,7 @@ class Ability
can :manage, Conference, id: Conference.with_role(:organizer, user).map(&:id)
# Conference Registration
can :manage, :conference_registration
can :manage, Registration
# Proposals
# Users can edit their own proposals
@ -59,30 +82,13 @@ class Ability
can :show, Event # if confirmed...?
can :index, :schedule # show?
# Check roles of user, using rolify. Role name is *case sensitive*
# user.is_organizer? or user.has_role? :organizer
# user.is_cfp_of? Conference or user.has_role? :cfp, Conference
# user.is_info_desk_of? Conference
# user.is_volunteer_coordinator_of? Conference
# user.is_attendee_of? Conference
# The following is wrong because a user will only have 'cfp' role for a specific conference
# user.is_cfp? # This is always false
# Ids of all the conferences for which the user has an 'organizer' role
conf_ids_for_organizer =
Conference.with_role(:organizer, user).pluck(:id) unless user.new_record?
# Ids of the venues of the conference for which (conferences) the user has an 'organizer' role
conf_ids_for_organizer_venue =
Conference.with_role(:organizer, user).pluck(:venue_id) unless user.new_record?
# Ids of all the conferences for which the user has a 'cfp' role
conf_ids_for_cfp =
Conference.with_role(:cfp, user).pluck(:id) unless user.new_record?
# Ids of all the conferences for which the user has an 'info_desk' role
conf_ids_for_info_desk =
Conference.with_role(:info_desk, user).pluck(:id) unless user.new_record?
# Ids of all the conferences for which the user has a 'volunteer_coordinator' role
conf_ids_for_volunteer_coordinator =
Conference.with_role(:volunteer_coordinator, user).pluck(:id) unless user.new_record?
## Authorization for admins
if user.is_admin # is_admin is an attribute of User
can :create, Conference
can :index, Conference # this will allow the Conference to appear in the menu
can :view, Conference # for /admin/conference overview
can :manage, User # to make other users admins
end
## Authorization for ORGANIZER
# If a user is organizer of a conference, they can manage everything related to this conference
@ -116,13 +122,6 @@ class Ability
# can :manage, Role, resource_id: conf_ids_for_organizer
end
if user.is_admin # is_admin is an attribute of User
can :create, Conference
can :index, Conference # this will allow the Conference to appear in the menu
can :view, Conference # for /admin/conference overview
can :manage, User # to make other users admins
end
## Authorization for CfP
# A user can manage events of the conference, for which conference the user has a 'cfp' role
if user.has_role? :cfp, :any

View file

@ -4,4 +4,6 @@ class Role < ActiveRecord::Base
belongs_to :resource, polymorphic: true
scopify
LABELS = ['Participant', 'Attendee', 'Volunteer', 'Speaker', 'Sponsor', 'Press', 'Organizer', 'CfP', 'Info Desk', 'Volunteers Coordinator']
end