work on authorization in controllers and refine ability.rb
This commit is contained in:
parent
2d3a1ef37e
commit
0684dbad19
5 changed files with 23 additions and 39 deletions
|
|
@ -1,9 +1,8 @@
|
||||||
module Admin
|
module Admin
|
||||||
class EventsController < ApplicationController
|
class EventsController < ApplicationController
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_resource :conference, find_by: :short_title
|
||||||
load_and_authorize_resource :event, through: :conference
|
load_and_authorize_resource :event, through: :conference
|
||||||
|
before_filter :authorize_conference
|
||||||
before_action :get_event, except: [:index, :create]
|
|
||||||
|
|
||||||
# FIXME: The timezome should only be applied on output, otherwise
|
# FIXME: The timezome should only be applied on output, otherwise
|
||||||
# you get lost in timezone conversions...
|
# you get lost in timezone conversions...
|
||||||
|
|
@ -14,7 +13,6 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@conference = Conference.find_by(short_title: params[:conference_id])
|
|
||||||
@events = @conference.events
|
@events = @conference.events
|
||||||
@tracks = @conference.tracks
|
@tracks = @conference.tracks
|
||||||
@machine_states = @events.state_machine.states.map
|
@machine_states = @events.state_machine.states.map
|
||||||
|
|
@ -170,15 +168,6 @@ module Admin
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_event
|
|
||||||
@event = @conference.events.find_by_id(params[:id])
|
|
||||||
if !@event
|
|
||||||
redirect_to(admin_conference_events_path(conference_id: @conference.short_title),
|
|
||||||
alert: 'Error! Could not find event!') && return
|
|
||||||
end
|
|
||||||
@event
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_state(transition, notice, mail = false, subject = false, send_mail = false)
|
def update_state(transition, notice, mail = false, subject = false, send_mail = false)
|
||||||
alert = @event.update_state(transition, mail, subject, send_mail, params[:send_mail].blank?)
|
alert = @event.update_state(transition, mail, subject, send_mail, params[:send_mail].blank?)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
module Admin
|
module Admin
|
||||||
class SpeakersController < ApplicationController
|
class SpeakersController < ApplicationController
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
load_and_authorize_resource :speaker, through: :conference
|
load_resource :event, through: :conference
|
||||||
|
|
||||||
respond_to :js, :html
|
respond_to :js, :html
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@event = @conference.events.find(params[:event_id])
|
|
||||||
@speaker = @event.event_users.where(event_role: 'speaker').first
|
@speaker = @event.event_users.where(event_role: 'speaker').first
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@event = @conference.events.find(params[:event_id])
|
|
||||||
@speaker = @event.event_users.where(event_role: 'speaker').first
|
@speaker = @event.event_users.where(event_role: 'speaker').first
|
||||||
@speaker.user_id = params[:speaker][:user_id]
|
@speaker.user_id = params[:speaker][:user_id]
|
||||||
@speaker.save
|
@speaker.save
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,15 @@ class ApplicationController < ActionController::Base
|
||||||
@conferences =Conference.all
|
@conferences =Conference.all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def authorize_conference
|
||||||
|
authorize! :update, @conference
|
||||||
|
end
|
||||||
|
|
||||||
def verify_user_admin
|
def verify_user_admin
|
||||||
if self.class.to_s.split('::').first == 'Admin' && verify_user
|
if self.class.to_s.split('::').first == 'Admin' && verify_user
|
||||||
unless (current_user.has_role? :organizer, :any) || (current_user.has_role? :cfp, :any) ||
|
unless (current_user.has_role? :organizer, :any) || (current_user.has_role? :cfp, :any) ||
|
||||||
(current_user.has_role? :info_desk, :any) ||
|
(current_user.has_role? :info_desk, :any) ||
|
||||||
(current_user.has_role? :volunteers_coordinator, :any)
|
(current_user.has_role? :volunteers_coordinator, :any) || (current_user.is_admin)
|
||||||
raise CanCan::AccessDenied.new('You are not authorized to access this area!')
|
raise CanCan::AccessDenied.new('You are not authorized to access this area!')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
class ConferenceRegistrationController < ApplicationController
|
class ConferenceRegistrationController < ApplicationController
|
||||||
before_filter :verify_user
|
before_filter :verify_user
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_resource :conference, find_by: :short_title
|
||||||
authorize_resource :conference_registration, class: Registration
|
load_and_authorize_resource :conference_registration, class: Registration
|
||||||
|
|
||||||
def register
|
def register
|
||||||
@workshops = @conference.events.where('require_registration = ? AND state LIKE ?',
|
@workshops = @conference.events.where('require_registration = ? AND state LIKE ?',
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,13 @@ class Ability
|
||||||
|
|
||||||
# Check roles of user, using rolify. Role name is *case sensitive*
|
# Check roles of user, using rolify. Role name is *case sensitive*
|
||||||
# user.is_organizer? or user.has_role? :organizer
|
# user.is_organizer? or user.has_role? :organizer
|
||||||
# user.is_cfp_of? Conference or user.has_role? :cfp, Conference
|
# We only assign roles per conference, so:
|
||||||
# user.is_info_desk_of? Conference
|
# user.is_cfp_of? Conference.find(1) or user.has_role? :cfp, @conference
|
||||||
# user.is_volunteer_coordinator_of? Conference
|
# user.is_info_desk_of? @conference
|
||||||
# user.is_attendee_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
|
# The following is wrong because a user will only have 'cfp' role for a specific conference
|
||||||
# user.is_cfp? # This is always false
|
# user.is_cfp? # Always FALSE
|
||||||
|
|
||||||
# Ids of all the conferences for which the user has an 'organizer' role
|
# Ids of all the conferences for which the user has an 'organizer' role
|
||||||
conf_ids_for_organizer =
|
conf_ids_for_organizer =
|
||||||
|
|
@ -48,31 +49,23 @@ class Ability
|
||||||
event_ids_for_user =
|
event_ids_for_user =
|
||||||
EventUser.where(user_id: user.id).pluck(:event_id)
|
EventUser.where(user_id: user.id).pluck(:event_id)
|
||||||
|
|
||||||
## Abilities for everyone, even guests (not logged in users)
|
## Abilities for everyone (incl. GUESTS - not logged in users)
|
||||||
can :show, Conference do |conference|
|
can :show, Conference, make_conference_public: true
|
||||||
conference.make_conference_public
|
|
||||||
end
|
|
||||||
|
|
||||||
can :show, Event do |event|
|
can :show, Event, state: 'confirmed'
|
||||||
event.state == 'confirmed'
|
|
||||||
end
|
|
||||||
|
|
||||||
can :index, :schedule # show?
|
can :index, :schedule
|
||||||
|
|
||||||
## Abilities for signed in users
|
## Abilities for signed in users
|
||||||
unless user.new_record?
|
unless user.new_record?
|
||||||
can :show, Conference do |conference|
|
|
||||||
conference.make_conference_public
|
|
||||||
end
|
|
||||||
|
|
||||||
# Conference Registration
|
# Conference Registration
|
||||||
can :manage, Registration
|
can [:register, :update, :unregister], Registration, user_id: user.id
|
||||||
|
|
||||||
# Proposals
|
# Proposals
|
||||||
# Users can edit their own proposals
|
# Users can edit their own proposals
|
||||||
# Organizer and CfP team can edit any proposal they want
|
# Organizer and CfP team can edit any proposal they want
|
||||||
# Can manage an event if the user is a speaker or a submitter of that event
|
# Can manage an event if the user is a speaker or a submitter of that event
|
||||||
# can [:index, :create], Event
|
|
||||||
can :create, Event
|
can :create, Event
|
||||||
can :manage, Event do |event|
|
can :manage, Event do |event|
|
||||||
event.event_users.where(:user_id => user.id).present?
|
event.event_users.where(:user_id => user.id).present?
|
||||||
|
|
@ -88,7 +81,7 @@ class Ability
|
||||||
if user.is_admin # is_admin is an attribute of User
|
if user.is_admin # is_admin is an attribute of User
|
||||||
can :create, Conference
|
can :create, Conference
|
||||||
can :index, Conference # this will allow the Conference to appear in the menu
|
can :index, Conference # this will allow the Conference to appear in the menu
|
||||||
can :view, Conference # for /admin/conference overview
|
can :show, Conference # for /admin/conference overview
|
||||||
can :manage, User # to make other users admins
|
can :manage, User # to make other users admins
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue