From 132fe6f98ce6762312805699c88bce9a88833a70 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Thu, 23 Apr 2015 11:50:22 +0200 Subject: [PATCH] Disable registration/event submission without sign in with ichain --- app/controllers/application_controller.rb | 4 +++- app/models/ability.rb | 13 +++++++------ config/environments/development.rb | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fca129ac..df6bedff 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -44,7 +44,9 @@ class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |exception| Rails.logger.debug "Access denied on #{exception.action} #{exception.subject.inspect}" - redirect_to root_path, alert: exception.message + message = exception.message + message << ' Maybe you need to sign in?' if !current_user + redirect_to root_path, alert: message end rescue_from IChainRecordNotFound do diff --git a/app/models/ability.rb b/app/models/ability.rb index 4a1abe99..0f89057e 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -49,12 +49,13 @@ class Ability # can view Commercials of confirmed Events can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id) can :show, User - can [:show, :create], Registration do |registration| - registration.new_record? - end - - can [:show, :create], Event do |event| - event.new_record? + unless CONFIG['authentication']['ichain']['enabled'] + can [:show, :create], Registration do |registration| + registration.new_record? + end + can [:show, :create], Event do |event| + event.new_record? + end end end diff --git a/config/environments/development.rb b/config/environments/development.rb index c66c56f0..8167887f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -85,4 +85,12 @@ Osem::Application.configure do } ) + + config.after_initialize do + Devise.setup do |devise_config| + # Enable ichain test mode + devise_config.ichain_test_mode = true + end + end + end