base controller

Conflicts:
	app/controllers/admin/commercials_controller.rb
	app/controllers/admin/questions_controller.rb
	app/controllers/admin/users_controller.rb
This commit is contained in:
Stella Rouzi 2014-08-13 14:37:05 +03:00
parent 336d0e9d04
commit 17ebad413e
29 changed files with 48 additions and 31 deletions

View file

@ -0,0 +1,17 @@
module Admin
class BaseController < ApplicationController
before_filter :verify_user_admin
def verify_user_admin
if (current_user.nil?)
redirect_to new_user_session_path
return false
end
unless (current_user.has_role? :organizer, :any) || (current_user.has_role? :cfp, :any) ||
(current_user.has_role? :info_desk, :any) ||
(current_user.has_role? :volunteers_coordinator, :any) || current_user.is_admin
raise CanCan::AccessDenied.new('You are not authorized to access this area!')
end
end
end
end

View file

@ -1,5 +1,5 @@
module Admin module Admin
class CallforpapersController < ApplicationController class CallforpapersController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
# load_and_authorize_resource :cfp, class: 'CallForPapers', through: :conference # load_and_authorize_resource :cfp, class: 'CallForPapers', through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class CampaignsController < ApplicationController class CampaignsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :campaign, through: :conference load_and_authorize_resource :campaign, through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class CommercialsController < ApplicationController class CommercialsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, except: [:new, :create] load_and_authorize_resource through: :conference, except: [:new, :create]
@ -9,7 +9,7 @@ module Admin
def new def new
@commercial = @conference.commercials.build @commercial = @conference.commercials.build
authorize! :create, @commercial authorize! :create, @conference.commercials.new
end end
def edit; end def edit; end

View file

@ -1,5 +1,5 @@
module Admin module Admin
class ConferenceController < ApplicationController class ConferenceController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_resource :user, only: [:remove_user] load_resource :user, only: [:remove_user]

View file

@ -1,5 +1,5 @@
module Admin module Admin
class ContactsController < ApplicationController class ContactsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, singleton: true load_and_authorize_resource through: :conference, singleton: true

View file

@ -1,5 +1,5 @@
module Admin module Admin
class DietchoicesController < ApplicationController class DietchoicesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :dietary_choice, through: :conference load_and_authorize_resource :dietary_choice, through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class DifficultyLevelsController < ApplicationController class DifficultyLevelsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class EmailsController < ApplicationController class EmailsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource class: EmailSettings load_and_authorize_resource class: EmailSettings

View file

@ -1,5 +1,5 @@
module Admin module Admin
class EventTypesController < ApplicationController class EventTypesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource :event_type, through: :conference authorize_resource :event_type, through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class EventsController < ApplicationController class EventsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :event, through: :conference load_and_authorize_resource :event, through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class LodgingsController < ApplicationController class LodgingsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :venue, through: :conference, singleton: true load_and_authorize_resource :venue, through: :conference, singleton: true
authorize_resource :lodging, through: :venue authorize_resource :lodging, through: :venue

View file

@ -1,5 +1,5 @@
module Admin module Admin
class PhotosController < ApplicationController class PhotosController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference load_and_authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class QuestionsController < ApplicationController class QuestionsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, except: [:new, :create] load_and_authorize_resource through: :conference, except: [:new, :create]

View file

@ -1,5 +1,5 @@
module Admin module Admin
class RegistrationsController < ApplicationController class RegistrationsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference load_and_authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class RoomsController < ApplicationController class RoomsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class SchedulesController < ApplicationController class SchedulesController < Admin::BaseController
# By authorizing 'conference' resource, we can ensure there will be no unauthorized access to # By authorizing 'conference' resource, we can ensure there will be no unauthorized access to
# the schedule of a conference, which should not be accessed in the first place # the schedule of a conference, which should not be accessed in the first place
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title

View file

@ -1,5 +1,5 @@
module Admin module Admin
class SocialEventsController < ApplicationController class SocialEventsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource :social_event, through: :conference authorize_resource :social_event, through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class SpeakersController < ApplicationController class SpeakersController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :event load_and_authorize_resource :event

View file

@ -1,5 +1,5 @@
module Admin module Admin
class SponsorsController < ApplicationController class SponsorsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource :sponsor, through: :conference authorize_resource :sponsor, through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class SponsorshipLevelsController < ApplicationController class SponsorshipLevelsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class StatsController < ApplicationController class StatsController < Admin::BaseController
load_and_authorize_resource load_and_authorize_resource
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title

View file

@ -1,5 +1,5 @@
module Admin module Admin
class SupporterLevelsController < ApplicationController class SupporterLevelsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class SupportersController < ApplicationController class SupportersController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference load_and_authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class TargetsController < ApplicationController class TargetsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class TracksController < ApplicationController class TracksController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference authorize_resource through: :conference

View file

@ -1,5 +1,5 @@
module Admin module Admin
class UsersController < ApplicationController class UsersController < Admin::BaseController
load_and_authorize_resource load_and_authorize_resource
def new def new
@ -21,9 +21,9 @@ module Admin
def update def update
if @user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
redirect_to admin_users_path, notice: "Updated #{@user.email}" redirect_to admin_users_path, notice: "Updated #{@user.name} (#{@user.email})!"
else else
redirect_to admin_users_path, alert: "Could not update #{@user.name}. #{@user.errors.full_messages.join '. '}." redirect_to admin_users_path, alert: "Could not update #{@user.name} (#{@user.email}). #{@user.errors.full_messages.join('. ')}."
end end
end end

View file

@ -1,5 +1,5 @@
module Admin module Admin
class VenueController < ApplicationController class VenueController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :venue, through: :conference, singleton: true load_and_authorize_resource :venue, through: :conference, singleton: true

View file

@ -1,5 +1,5 @@
module Admin module Admin
class VolunteersController < ApplicationController class VolunteersController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
def index def index