Remove unnecessary ability from adminAbilities
CanCanCan can load @events and @event in EventsController by itself
This commit is contained in:
parent
c4eec6a3de
commit
a87c6e55f7
4 changed files with 4 additions and 19 deletions
|
|
@ -5,8 +5,6 @@ module Admin
|
||||||
load_and_authorize_resource :event, through: :program
|
load_and_authorize_resource :event, through: :program
|
||||||
load_and_authorize_resource :events_registration, only: :toggle_attendance
|
load_and_authorize_resource :events_registration, only: :toggle_attendance
|
||||||
|
|
||||||
before_action :get_event, except: [:index, :create, :new]
|
|
||||||
|
|
||||||
# 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...
|
||||||
# around_filter :set_timezone_for_this_request
|
# around_filter :set_timezone_for_this_request
|
||||||
|
|
@ -16,7 +14,6 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@events = @program.events
|
|
||||||
@tracks = @program.tracks.confirmed.cfp_active
|
@tracks = @program.tracks.confirmed.cfp_active
|
||||||
@difficulty_levels = @program.difficulty_levels
|
@difficulty_levels = @program.difficulty_levels
|
||||||
@event_types = @program.event_types
|
@event_types = @program.event_types
|
||||||
|
|
@ -187,16 +184,6 @@ module Admin
|
||||||
params.require(:comment).permit(:commentable, :body, :user_id)
|
params.require(:comment).permit(:commentable, :body, :user_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_event
|
|
||||||
@event = @conference.program.events.find(params[:id])
|
|
||||||
unless @event
|
|
||||||
redirect_to admin_conference_program_events_path(conference_id: @conference.short_title),
|
|
||||||
error: '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?)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@ module Admin
|
||||||
class ReportsController < Admin::BaseController
|
class ReportsController < Admin::BaseController
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
load_and_authorize_resource :program, through: :conference, singleton: true
|
load_and_authorize_resource :program, through: :conference, singleton: true
|
||||||
|
# For some reason this doesn't work, so a workaround is used
|
||||||
|
# load_and_authorize_resource :event, through: :program
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@events = @program.events
|
@events = Event.accessible_by(current_ability).where(program: @program)
|
||||||
@events_commercials = Commercial.where(commercialable_type: 'Event', commercialable_id: @events.pluck(:id))
|
@events_commercials = Commercial.where(commercialable_type: 'Event', commercialable_id: @events.pluck(:id))
|
||||||
@events_missing_commercial = @events.where.not(id: @events_commercials.pluck(:commercialable_id))
|
@events_missing_commercial = @events.where.not(id: @events_commercials.pluck(:commercialable_id))
|
||||||
@events_with_requirements = @events.where.not(description: ['', nil])
|
@events_with_requirements = @events.where.not(description: ['', nil])
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,6 @@ class AdminAbility
|
||||||
event.program.cfp_open? && event.new_record?
|
event.program.cfp_open? && event.new_record?
|
||||||
end
|
end
|
||||||
|
|
||||||
can [:update, :show, :index], Event do |event|
|
|
||||||
event.users.include?(user)
|
|
||||||
end
|
|
||||||
|
|
||||||
# can manage the commercials of their own events
|
# can manage the commercials of their own events
|
||||||
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
|
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ feature 'Has correct abilities' do
|
||||||
expect(current_path).to eq root_path
|
expect(current_path).to eq root_path
|
||||||
|
|
||||||
visit admin_conference_program_events_path(conference.short_title)
|
visit admin_conference_program_events_path(conference.short_title)
|
||||||
expect(current_path).to eq admin_conference_program_events_path(conference.short_title)
|
expect(current_path).to eq root_path
|
||||||
|
|
||||||
create(:event, program: conference.program)
|
create(:event, program: conference.program)
|
||||||
visit edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first)
|
visit edit_admin_conference_program_event_path(conference.short_title, conference.program.events.first)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue