From 75fb68c4d1eb647a268890c080da2dc3875c0e77 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 29 Jan 2013 16:44:47 +0100 Subject: Get rid of @current_user. The use of current_user is better. --- app/controllers/application_controller.rb | 12 ++++++------ app/controllers/call_forwards_controller.rb | 4 ++-- app/controllers/gui_functions_controller.rb | 2 +- app/controllers/softkeys_controller.rb | 2 +- app/controllers/tenants_controller.rb | 8 ++++---- app/views/phone_numbers/_form_core.html.haml | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) (limited to 'app') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e4165f3..2d49890 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -106,7 +106,7 @@ class ApplicationController < ActionController::Base end rescue_from CanCan::AccessDenied do |exception| - if @current_user + if current_user redirect_to root_url, :alert => 'Access denied! Please ask your admin to grant you the necessary rights.' else if Tenant.count == 0 && User.count == 0 @@ -121,13 +121,13 @@ class ApplicationController < ActionController::Base private - def current_user - begin - @current_user ||= User.find(session[:user_id]) if session[:user_id] - rescue ActiveRecord::RecordNotFound + def current_user + if session[:user_id] && User.where(:id => session[:user_id]).any? + return User.where(:id => session[:user_id]).first + else session[:user_id] = nil + return nil end - @current_user end def go_to_setup_if_new_installation diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb index 001ed60..b1ced87 100644 --- a/app/controllers/call_forwards_controller.rb +++ b/app/controllers/call_forwards_controller.rb @@ -28,7 +28,7 @@ class CallForwardsController < ApplicationController @available_call_forward_cases = [] CallForwardCase.all.each do |available_call_forward_case| - if GuiFunction.display?("call_forward_case_#{available_call_forward_case.value}_field_in_call_forward_form", @current_user) + if GuiFunction.display?("call_forward_case_#{available_call_forward_case.value}_field_in_call_forward_form", current_user) @available_call_forward_cases << available_call_forward_case end end @@ -112,7 +112,7 @@ class CallForwardsController < ApplicationController voice_mail_destination, ] - if GuiFunction.display?('huntgroup_in_destination_field_in_call_forward_form', @current_user) + if GuiFunction.display?('huntgroup_in_destination_field_in_call_forward_form', current_user) HuntGroup.all.each do |hunt_group| hunt_group_destination = CallForwardingDestination.new() hunt_group_destination.id = "#{hunt_group.id}:HuntGroup" diff --git a/app/controllers/gui_functions_controller.rb b/app/controllers/gui_functions_controller.rb index 0cb7898..4b57322 100644 --- a/app/controllers/gui_functions_controller.rb +++ b/app/controllers/gui_functions_controller.rb @@ -58,7 +58,7 @@ class GuiFunctionsController < ApplicationController private def load_user_groups - @user_groups = Tenant.find(@current_user.current_tenant).user_groups.order(:position) + @user_groups = Tenant.find(current_user.current_tenant).user_groups.order(:position) end def spread_breadcrumbs diff --git a/app/controllers/softkeys_controller.rb b/app/controllers/softkeys_controller.rb index d2a2bb9..8f363cd 100644 --- a/app/controllers/softkeys_controller.rb +++ b/app/controllers/softkeys_controller.rb @@ -61,7 +61,7 @@ class SoftkeysController < ApplicationController @softkey_functions = [] SoftkeyFunction.accessible_by(current_ability, :read).each do |softkey_function| - if GuiFunction.display?("softkey_function_#{softkey_function.name.downcase}_field_in_softkey_form", @current_user) + if GuiFunction.display?("softkey_function_#{softkey_function.name.downcase}_field_in_softkey_form", current_user) @softkey_functions << softkey_function end end diff --git a/app/controllers/tenants_controller.rb b/app/controllers/tenants_controller.rb index 37874b2..f30246b 100644 --- a/app/controllers/tenants_controller.rb +++ b/app/controllers/tenants_controller.rb @@ -27,17 +27,17 @@ class TenantsController < ApplicationController if @tenant.save # Become a member of this tenant. # - @tenant.tenant_memberships.create(:user_id => @current_user.id) + @tenant.tenant_memberships.create(:user_id => current_user.id) # Groups # admin_group = @tenant.user_groups.create(:name => t('gemeinschaft_setups.initial_setup.admin_group_name')) - admin_group.users << @current_user + admin_group.users << current_user user_group = @tenant.user_groups.create(:name => t('gemeinschaft_setups.initial_setup.user_group_name')) - user_group.users << @current_user + user_group.users << current_user - @current_user.update_attributes!(:current_tenant_id => @tenant.id) + current_user.update_attributes!(:current_tenant_id => @tenant.id) # Generate the internal_extensions # diff --git a/app/views/phone_numbers/_form_core.html.haml b/app/views/phone_numbers/_form_core.html.haml index a1ce1f3..a0a69db 100644 --- a/app/views/phone_numbers/_form_core.html.haml +++ b/app/views/phone_numbers/_form_core.html.haml @@ -4,7 +4,7 @@ = f.input :name, :collection => ['Office', 'Home', 'Mobile', 'Fax'], :include_blank => false, :label => t('phone_numbers.form.name.label'), :hint => conditional_hint('phone_numbers.form.name.hint') = f.input :number, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :autofocus => true - else - - if @callthrough || @hunt_group_member || @access_authorization || @current_user.current_tenant.array_of_available_internal_extensions_and_dids.count == 0 || @current_user.current_tenant.array_of_available_internal_extensions_and_dids.count > 250 + - if @callthrough || @hunt_group_member || @access_authorization || current_user.current_tenant.array_of_available_internal_extensions_and_dids.count == 0 || current_user.current_tenant.array_of_available_internal_extensions_and_dids.count > 250 = f.input :number, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :autofocus => true - else - = f.input :number, :collection => @current_user.current_tenant.array_of_available_internal_extensions_and_dids, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :include_blank => false, :autofocus => true + = f.input :number, :collection => current_user.current_tenant.array_of_available_internal_extensions_and_dids, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :include_blank => false, :autofocus => true -- cgit v1.2.3 From bf3af8f8a444365f3040da2928837986409fa016 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 29 Jan 2013 18:43:06 +0100 Subject: Single Sign On via a ENV['USER_NAME'] mechanism. --- app/controllers/application_controller.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2d49890..2aadf19 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -122,11 +122,21 @@ class ApplicationController < ActionController::Base private def current_user - if session[:user_id] && User.where(:id => session[:user_id]).any? - return User.where(:id => session[:user_id]).first + if session[:user_id] || GsParameter.get('SingleSignOnEnvUserNameKey').blank? + if session[:user_id] && User.where(:id => session[:user_id]).any? + return User.where(:id => session[:user_id]).first + else + session[:user_id] = nil + return nil + end else - session[:user_id] = nil - return nil + if User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).any? + auth_user = User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).first + session[:user_id] = auth_user.id + return auth_user + else + return nil + end end end -- cgit v1.2.3 From 5d84248cf177635a19f033f53abbca87ac5c87bc Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 29 Jan 2013 18:55:07 +0100 Subject: Fixed hidden-phone bug. --- .../shared/_index_view_edit_destroy_part.html.haml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/views/shared/_index_view_edit_destroy_part.html.haml b/app/views/shared/_index_view_edit_destroy_part.html.haml index 6bb1e7b..d396460 100644 --- a/app/views/shared/_index_view_edit_destroy_part.html.haml +++ b/app/views/shared/_index_view_edit_destroy_part.html.haml @@ -4,17 +4,20 @@ - if can? :show, child %a.btn.btn-small.btn-success{:href => method( :"#{parent.class.name.underscore}_#{child.class.name.underscore}_path" ).(parent, child) } %i.icon-info-sign.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.show") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.show") - if can? :edit, child %a.btn.btn-small.btn-warning{:href => method( :"edit_#{parent.class.name.underscore}_#{child.class.name.underscore}_path" ).(parent, child) } %i.icon-edit.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.edit") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.edit") - if can? :destroy, child %a.btn.btn-small.btn-danger{"data-confirm" => t("#{child.class.name.underscore.pluralize}.index.actions.confirm_destroy"), "data-method" => "delete", :href => method( :"#{parent.class.name.underscore}_#{child.class.name.underscore}_path" ).(parent, child), :rel => "nofollow"} %i.icon-remove.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.destroy") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.destroy") - elsif !(defined? child).nil? %td @@ -22,15 +25,18 @@ - if can? :show, child %a.btn.btn-small.btn-success{:href => method( :"#{child.class.name.underscore}_path" ).(child) } %i.icon-info-sign.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.show") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.show") - if can? :edit, child %a.btn.btn-small.btn-warning{:href => method( :"edit_#{child.class.name.underscore}_path" ).(child) } %i.icon-edit.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.edit") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.edit") - if can? :destroy, child %a.btn.btn-small.btn-danger{"data-confirm" => t("#{child.class.name.underscore.pluralize}.index.actions.confirm_destroy"), "data-method" => "delete", :href => method( :"#{child.class.name.underscore}_path" ).(child), :rel => "nofollow"} %i.icon-trash.icon-white - =t("#{child.class.name.underscore.pluralize}.index.actions.destroy") + %span.hidden-phone + =t("#{child.class.name.underscore.pluralize}.index.actions.destroy") \ No newline at end of file -- cgit v1.2.3