changes from comments, fix commercials failing test

This commit is contained in:
Stella Rouzi 2014-08-13 22:46:41 +03:00
parent d794593e10
commit beb88b848d
15 changed files with 58 additions and 77 deletions

View file

@ -4,7 +4,7 @@ module Admin
load_and_authorize_resource :campaign, through: :conference
def index
authorize! :show, Campaign.new(conference_id: @conference.id)
authorize! :index, Campaign.new(conference_id: @conference.id)
@campaigns = @conference.campaigns
end

View file

@ -1,7 +1,7 @@
module Admin
class CommercialsController < ApplicationController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
load_and_authorize_resource through: :conference, except: [:new, :create]
def index
@commercials = @conference.commercials
@ -9,12 +9,14 @@ module Admin
def new
@commercial = @conference.commercials.build
authorize! :create, @commercial
end
def edit; end
def create
@commercial = @conference.commercials.build(commercial_params)
authorize! :create, @commercial
if @commercial.save
redirect_to admin_conference_commercials_path,

View file

@ -202,17 +202,14 @@ module Admin
@user = User.new
@roles = Role::ACTIONABLES + Role::LABELS
params[:user] ? (@selected = params[:user][:roles]) : (@selected = 'Organizer')
@selection = @selected.parameterize.underscore
params[:user] ? (@selection = params[:user][:roles].parameterize.underscore) : (@selection = 'organizer')
@role = Role.where(name: @selection, resource: @conference)
@role_users = get_users(@selection)
end
def add_user
user = User.find_by(email: params[:user][:email])
@selected = params[:role]
@selection = @selected.parameterize.underscore
@selection = params[:role].parameterize.underscore
@role_users = get_users(@selection)
user.add_role @selection.to_sym, @conference
@ -220,23 +217,22 @@ module Admin
end
def remove_user
@selected = params[:role]
@selection = @selected.parameterize.underscore
role = Role.where(name: @selection, resource: @conference).first
@selection = params[:role]
@role_users = get_users(@selection)
@user.revoke role.name.to_sym, @conference
@user.revoke @selection.to_sym, @conference
render 'roles', formats: [:js]
end
protected
def get_users(role)
def get_users(role_name)
@role_users = {}
get_role = Role.where(name: role, resource: @conference)
get_role.blank? ? @role_users[role] = get_role : @role_users[role] = get_role.first.users
role = Role.where(name: role_name, resource: @conference)
role.blank? ? @role_users[role_name] = role : @role_users[role_name] = role.first.users
# Initialize @role variable, so that view can show the role description
@role = Role.where(name: role_name, resource: @conference)
@role_users
end
end

View file

@ -12,18 +12,12 @@ module Admin
# PATCH/PUT /:conference/contact
def update
if @contact.update(contact_params)
redirect_to admin_conference_contact_path, notice: 'Contact details were successfully updated.'
redirect_to edit_admin_conference_contact_path, notice: 'Contact details were successfully updated.'
else
render :edit
end
end
# DELETE /:conference/contact
def destroy
@contact.destroy
redirect_to admin_conference_contacts_url, notice: 'Contact details were successfully destroyed.'
end
private
# Only allow a trusted parameter "white list" through.
def contact_params

View file

@ -4,7 +4,7 @@ module Admin
load_and_authorize_resource through: :conference, except: [:new, :create]
def index
authorize! :update, Question.new(conference_id: @conference.id)
authorize! :index, Question.new(conference_id: @conference.id)
@questions = Question.where(global: true).all | Question.where(conference_id: @conference.id)
@questions_conference = @conference.questions
@new_question = @conference.questions.new
@ -32,7 +32,7 @@ module Admin
# GET questions/1/edit
def edit
if @question.global == true && !(current_user.has_role? :organizer, @conference)
if @question.global
redirect_to(admin_conference_questions_path(conference_id: @conference.short_title), alert: "Sorry, you cannot edit global questions. Create a new one.")
end
end
@ -48,6 +48,7 @@ module Admin
# Update questions used for the conference
def update_conference
authorize! :update, Question.new(conference_id: @conference.id)
if @conference.update_attributes(params[:conference])
redirect_to(admin_conference_questions_path(conference_id: @conference.short_title), notice: "Questions for #{@conference.short_title} successfully updated.")
else
@ -59,7 +60,7 @@ module Admin
def destroy
if can? :destroy, @question
# Do not delete global questions
if @question.global == false
if !@question.global
# Delete question and its answers
begin
@ -67,7 +68,7 @@ module Admin
@question.destroy
@question.answers.each do |a|
a.delete
a.destroy
end
flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map {|a| a.title}.join ','}"
end

View file

@ -20,8 +20,11 @@ module Admin
end
def update
@user.update_attributes!(params[:user])
redirect_to admin_users_path, notice: "Updated #{@user.email}"
if @user.update_attributes(params[:user])
redirect_to admin_users_path, notice: "Updated #{@user.email}"
else
redirect_to admin_users_path, alert: "Could not update #{@user.name}. #{@user.errors.full_messages.join '. '}."
end
end
def edit; end

View file

@ -3,7 +3,7 @@ module Admin
load_and_authorize_resource :conference, find_by: :short_title
def index
if (current_user.has_role? :organizer, @conference) || (current_user.has_role? :volunteer_coordinator, @conference)
if can_manage_volunteers(@conference)
render :index
else
authorize! :index, :volunteer
@ -11,7 +11,7 @@ module Admin
end
def show
if (current_user.has_role? :organizer, @conference) || (current_user.has_role? :volunteer_coordinator, @conference)
if can_manage_volunteers(@conference)
if @conference.use_vpositions
@volunteers = @conference.registrations.joins(:vchoices).uniq
else
@ -23,12 +23,11 @@ module Admin
end
def update
if (current_user.has_role? :organizer, @conference) || (current_user.has_role? :volunteer_coordinator, @conference)
begin
@conference.update_attributes!(params[:conference])
if can_manage_volunteers(@conference)
if @conference.update_attributes(params[:conference])
redirect_to(admin_conference_volunteers_info_path(conference_id: params[:conference_id]), notice: "Volunteering options were successfully updated.")
rescue => e
redirect_to(admin_conference_volunteers_info_path(conference_id: params[:conference_id]), alert: "Volunteering options update failed: #{e.message}")
else
redirect_to(admin_conference_volunteers_info_path(conference_id: params[:conference_id]), alert: "Volunteering options update failed: #{@conference.errors.full_messages.join '. '}")
end
else
authorize! :index, :volunteer