Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/application_controller.rb

Overview

License

Ekylibre - Simple agricultural ERP Copyright (C) 2009 Brice Texier, Thibaud Merigon

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Direct Known Subclasses

BaseController

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_themeObject

Returns the value of attribute current_theme


36
37
38
# File 'app/controllers/application_controller.rb', line 36

def current_theme
  @current_theme
end

Class Method Details

.human_action_name(action, options = {}) ⇒ Object


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/application_controller.rb', line 50

def self.human_action_name(action, options = {})
  options = {} unless options.is_a?(Hash)
  root = 'actions.' + controller_path + '.'
  action = action.to_s
  options[:default] ||= []
  if action == 'create' && !options[:default].include?((root + 'new').to_sym)
    options[:default] << (root + 'new').to_sym
  elsif action == 'update' && !options[:default].include?((root + 'edit').to_sym)
    options[:default] << (root + 'edit').to_sym
  elsif action == 'update_many' && !options[:default].include?((root + 'edit_many').to_sym)
    options[:default] << (root + 'edit_many').to_sym
  end
  klass = superclass
  while klass != ApplicationController
    default = "actions.#{klass.controller_path}.#{action}".to_sym
    options[:default] << default unless options[:default].include?(default)
    klass = klass.superclass
  end
  ::I18n.translate(root + action, options)
end

Instance Method Details

#after_sign_in_path_for(resource) ⇒ Object


40
41
42
43
# File 'app/controllers/application_controller.rb', line 40

def (resource)
  Ekylibre::Hook.publish(:after_sign_in, resource)
  @new_after_sign_in_path || super
end

#authorized?(url_options = {}) ⇒ Boolean

Returns:

  • (Boolean)

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/application_controller.rb', line 76

def authorized?(url_options = {})
  return true if url_options == '#' || current_user.administrator?
  if url_options.is_a?(Hash)
    url_options[:controller] ||= controller_path
    url_options[:action] ||= action_name
  elsif url_options.is_a?(String) && url_options.match(/\#/)
    action = url_options.split('#')
    url_options = { controller: action[0].to_sym, action: action[1].to_sym }
  else
    raise ArgumentError, 'Invalid URL: ' + url_options.inspect
  end
  unless url_options[:controller] =~ /\/\w+/
    namespace = controller_path.gsub(/\/\w+$/, '')
    if namespace.present?
      url_options[:controller] = "/#{namespace}/#{url_options[:controller]}"
    end
  end
  if current_user
    return current_user.can_access?(url_options)
  # if url_options[:controller].blank? or url_options[:action].blank?
  #   raise ArgumentError, "Uncheckable URL: " + url_options.inspect
  # end
  # return current_user.authorization(url_options[:controller], url_options[:action], session[:rights]).nil?
  else
    true
  end
end

#human_action_nameObject


72
73
74
# File 'app/controllers/application_controller.rb', line 72

def human_action_name
  self.class.human_action_name(action_name.to_s, @title)
end

#session_controller?Boolean

Returns:

  • (Boolean)

46
47
48
# File 'app/controllers/application_controller.rb', line 46

def session_controller?
  controller_name == 'sessions' && action_name == 'create'
end