From 598606547ee15444e55a64e3665660da263d481c Mon Sep 17 00:00:00 2001 From: Aditya Chatterjee Date: Tue, 1 Mar 2016 18:58:41 +0530 Subject: [PATCH] Flash uniformity done in a bunch of files --- app/controllers/application_controller.rb | 8 ++++---- app/controllers/commercials_controller.rb | 8 ++++---- .../conference_registrations_controller.rb | 16 +++++++-------- app/controllers/proposal_controller.rb | 20 ++++++++----------- app/controllers/registrations_controller.rb | 1 + app/controllers/subscriptions_controller.rb | 14 ++++++------- .../ticket_purchases_controller.rb | 2 ++ app/controllers/tickets_controller.rb | 2 ++ app/controllers/users_controller.rb | 5 +++-- 9 files changed, 37 insertions(+), 39 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a0d87498..64f8299f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,8 @@ class ApplicationController < ActionController::Base before_filter :get_conferences before_filter :store_location helper_method :date_string + add_flash_types :error + add_flash_types :alert # Ensure every controller authorizes resource or skips authorization (skip_authorization_check) check_authorization unless: :devise_controller? @@ -52,16 +54,14 @@ class ApplicationController < ActionController::Base rescue_from IChainRecordNotFound do Rails.logger.debug('IChain Record was not Unique!') sign_out(current_user) - flash[:error] = 'Your E-Mail adress is already registered at OSEM. Please contact the admin if you want to attach your openSUSE Account to OSEM!' - redirect_to root_path + redirect_to root_path(@ user), error: "Your E-Mail adress is already registered at OSEM. Please contact the admin if you want to attach your openSUSE Account to OSEM!" end rescue_from UserDisabled do Rails.logger.debug('User is disabled!') sign_out(current_user) mail = User.admin.first ? User.admin.first.email : 'the admin!' - flash[:error] = "This User is disabled. Please contact #{mail}!" - redirect_to User.ichain_logout_url + redirect_to User.ichain_logout_url(@ user), error: "This User is disabled. Please contact #{mail}!" end def not_found diff --git a/app/controllers/commercials_controller.rb b/app/controllers/commercials_controller.rb index c36feedc..c0256de7 100644 --- a/app/controllers/commercials_controller.rb +++ b/app/controllers/commercials_controller.rb @@ -2,6 +2,8 @@ class CommercialsController < ApplicationController load_resource :conference, find_by: :short_title before_action :set_event load_and_authorize_resource through: :event + add_flash_types :error + add_flash_types :alert def create @commercial = @event.commercials.build(commercial_params) @@ -11,8 +13,7 @@ class CommercialsController < ApplicationController redirect_to edit_conference_program_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'), notice: 'Commercial was successfully created.' else - flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." - redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content') + redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'), error: "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." end end @@ -21,8 +22,7 @@ class CommercialsController < ApplicationController redirect_to edit_conference_program_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'), notice: 'Commercial was successfully updated.' else - flash[:error] = "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." - redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content') + redirect_to edit_conference_proposal_path(conference_id: @conference.short_title, id: @event.id, anchor: 'commercials-content'), error: "An error prohibited this Commercial from being saved: #{@commercial.errors.full_messages.join('. ')}." end end diff --git a/app/controllers/conference_registrations_controller.rb b/app/controllers/conference_registrations_controller.rb index c9d7d216..926cac2a 100644 --- a/app/controllers/conference_registrations_controller.rb +++ b/app/controllers/conference_registrations_controller.rb @@ -3,6 +3,8 @@ class ConferenceRegistrationsController < ApplicationController load_resource :conference, find_by: :short_title authorize_resource :conference_registrations, class: Registration before_action :set_registration, only: [:edit, :update, :destroy, :show] + add_flash_types :error + add_flash_types :alert def new # Redirect to registration edit when user is already registered @@ -60,16 +62,14 @@ class ConferenceRegistrationsController < ApplicationController sign_in(@registration.user) end - flash[:notice] = 'You are now registered and will be receiving E-Mail notifications.' if @conference.tickets.any? && !current_user.supports?(@conference) - redirect_to conference_tickets_path(@conference.short_title) + redirect_to conference_tickets_path(@conference.short_title), notice: 'You are now registered and will be receiving E-Mail notifications.' else - redirect_to conference_conference_registrations_path(@conference.short_title) + redirect_to conference_conference_registrations_path(@conference.short_title), notice: 'You are now registered and will be receiving E-Mail notifications.' end else - flash[:error] = "Could not create your registration for #{@conference.title}: "\ + render :new, error: "Could not create your registration for #{@conference.title}: "\ "#{@registration.errors.full_messages.join('. ')}." - render :new end end @@ -78,9 +78,8 @@ class ConferenceRegistrationsController < ApplicationController redirect_to conference_conference_registrations_path(@conference.short_title), notice: 'Registration was successfully updated.' else - flash[:error] = "Could not update your registration for #{@conference.title}: "\ + render :edit, error: "Could not update your registration for #{@conference.title}: "\ "#{@registration.errors.full_messages.join('. ')}." - render :edit end end @@ -100,8 +99,7 @@ class ConferenceRegistrationsController < ApplicationController def set_registration @registration = Registration.find_by(conference: @conference, user: current_user) if !@registration - flash[:alert] = "Can't find a registration for #{@conference.title} for you. Please register." - redirect_to new_conference_conference_registrations_path(@conference.short_title) + redirect_to new_conference_conference_registrations_path(@conference.short_title), alert: "Can't find a registration for #{@conference.title} for you. Please register." end end diff --git a/app/controllers/proposal_controller.rb b/app/controllers/proposal_controller.rb index 95042af5..e56f5ce8 100644 --- a/app/controllers/proposal_controller.rb +++ b/app/controllers/proposal_controller.rb @@ -3,6 +3,8 @@ class ProposalController < ApplicationController load_resource :conference, find_by: :short_title load_resource :program, through: :conference, singleton: true load_and_authorize_resource :event, parent: false, through: :program + add_flash_types :error + add_flash_types :alert def index @events = current_user.proposals(@conference) @@ -31,8 +33,7 @@ class ProposalController < ApplicationController if @user.save sign_in(@user) else - flash[:error] = "Could not save user: #{@user.errors.full_messages.join(', ')}" - render action: 'new' + render action: 'new', error: "Could not save user: #{@user.errors.full_messages.join(', ')}" return end end @@ -48,15 +49,13 @@ class ProposalController < ApplicationController event_role: 'speaker') unless @event.save - flash[:error] = "Could not submit proposal: #{@event.errors.full_messages.join(', ')}" - render action: 'new' + render action: 'new', error: "Could not submit proposal: #{@event.errors.full_messages.join(', ')}" return end ahoy.track 'Event submission', title: 'New submission' - flash[:notice] = 'Proposal was successfully submitted.' - redirect_to conference_program_proposal_index_path(@conference.short_title) + redirect_to conference_program_proposal_index_path(@conference.short_title), notice: 'Proposal was successfully submitted.' end def update @@ -64,8 +63,7 @@ class ProposalController < ApplicationController @url = conference_program_proposal_path(@conference.short_title, params[:id]) if !@event.update(event_params) - flash[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}" - render action: 'new' + render action: 'new', error: "Could not update proposal: #{@event.errors.full_messages.join(', ')}" return end @@ -101,8 +99,7 @@ class ProposalController < ApplicationController end if !@event.save - flash[:error] = "Could not confirm proposal: #{@event.errors.full_messages.join(', ')}" - render action: 'new' + render action: 'new', error: "Could not confirm proposal: #{@event.errors.full_messages.join(', ')}" return end @@ -128,8 +125,7 @@ class ProposalController < ApplicationController end if !@event.save - flash[:error] = "Could not re-submit proposal: #{@event.errors.full_messages.join(', ')}" - render action: 'new' + render action: 'new', error: "Could not re-submit proposal: #{@event.errors.full_messages.join(', ')}" return end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 62292bf0..474fa2ec 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -1,5 +1,6 @@ class RegistrationsController < Devise::RegistrationsController before_action :configure_permitted_parameters, if: :devise_controller? + def edit @openids = Openid.where(user_id: current_user.id).order(:provider) diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 6d5b7cdf..71821ba5 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -2,26 +2,24 @@ class SubscriptionsController < ApplicationController before_filter :authenticate_user! load_resource :conference, find_by: :short_title load_and_authorize_resource only: [:create, :destroy], through: :conference + add_flash_types :error + add_flash_types :alert def create @subscription = current_user.subscriptions.build(conference_id: @conference.id) if @subscription.save! - flash[:notice] = "You have been subscribed to receive email notifications for #{@conference.short_title}." - redirect_to root_path + redirect_to root_path, notice: "You have been subscribed to receive email notifications for #{@conference.short_title}." else - flash[:error] = subscription.errors.full_messages.to_sentence - redirect_to root_path + redirect_to root_path, error: subscription.errors.full_messages.to_sentence end end def destroy @subscription = current_user.subscriptions.find_by(conference_id: @conference.id) if @subscription.destroy - flash[:notice] = "You have been unsubscribed and now you will not be receiving email notifications for #{@conference.short_title}." - redirect_to root_path + redirect_to root_path, notice: "You have been unsubscribed and now you will not be receiving email notifications for #{@conference.short_title}." else - flash[:error] = @subscription.errors.full_messages.to_sentence - redirect_to root_path + redirect_to root_path, error: @subscription.errors.full_messages.to_sentence end end end diff --git a/app/controllers/ticket_purchases_controller.rb b/app/controllers/ticket_purchases_controller.rb index 395f09ce..947a9fe0 100644 --- a/app/controllers/ticket_purchases_controller.rb +++ b/app/controllers/ticket_purchases_controller.rb @@ -2,6 +2,8 @@ class TicketPurchasesController < ApplicationController before_filter :authenticate_user! load_resource :conference, find_by: :short_title authorize_resource :conference_registrations, class: Registration + add_flash_types :error + add_flash_types :alert def create message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0]) diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 55c73fc0..6cf917c1 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -4,6 +4,8 @@ class TicketsController < ApplicationController load_resource :ticket, through: :conference authorize_resource :conference_registrations, class: Registration before_filter :check_load_resource, only: :index + add_flash_types :error + add_flash_types :alert def index; end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a453c83f..291a6cfa 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,7 @@ class UsersController < ApplicationController load_and_authorize_resource + add_flash_types :error + add_flash_types :alert # GET /users/1 def show @@ -15,8 +17,7 @@ class UsersController < ApplicationController if @user.update(user_params) redirect_to @user, notice: 'User was successfully updated.' else - flash[:error] = "An error prohibited your Profile from being saved: #{@user.errors.full_messages.join('. ')}." - render :edit + render :edit, error: "An error prohibited your Profile from being saved: #{@user.errors.full_messages.join('. ')}." end end