application_controller.rb
3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# his is the application's main controller. Features defined here are
# available in all controllers.
class ApplicationController < ActionController::Base
include ApplicationHelper
layout :get_layout
def get_layout
theme_option(:layout) || 'application'
end
filter_parameter_logging :password
def log_processing
super
return unless ENV['RAILS_ENV'] == 'production'
if logger && logger.info?
logger.info(" HTTP Referer: #{request.referer}")
logger.info(" User Agent: #{request.user_agent}")
logger.info(" Accept-Language: #{request.headers['HTTP_ACCEPT_LANGUAGE']}")
end
end
helper :document
helper :language
def boxes_editor?
false
end
protected :boxes_editor?
def self.no_design_blocks
@no_design_blocks = true
end
def self.uses_design_blocks?
!@no_design_blocks
end
def uses_design_blocks?
!@no_design_blocks && self.class.uses_design_blocks?
end
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
include PermissionCheck
before_filter :set_locale
def set_locale
FastGettext.available_locales = Noosfero.available_locales
FastGettext.default_locale = Noosfero.default_locale
FastGettext.set_locale(params[:lang] || session[:lang] || Noosfero.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en')
if params[:lang]
session[:lang] = params[:lang]
end
end
include NeedsProfile
before_filter :detect_stuff_by_domain
before_filter :init_noosfero_plugins
attr_reader :environment
before_filter :load_terminology
# declares that the given <tt>actions</tt> cannot be accessed by other HTTP
# method besides POST.
def self.post_only(actions, redirect = { :action => 'index'})
verify :method => :post, :only => actions, :redirect_to => redirect
end
helper_method :current_person, :current_person
protected
def user
current_user.person if logged_in?
end
alias :current_person :user
# TODO: move this logic somewhere else (Domain class?)
def detect_stuff_by_domain
@domain = Domain.find_by_name(request.host)
if @domain.nil?
@environment = Environment.default
else
@environment = @domain.environment
@profile = @domain.profile
end
end
def init_noosfero_plugins
@plugins = Noosfero::Plugin::Manager.new(self)
end
def load_terminology
# cache terminology for performance
@@terminology_cache ||= {}
@@terminology_cache[environment.id] ||= environment.terminology
Noosfero.terminology = @@terminology_cache[environment.id]
end
def render_not_found(path = nil)
@no_design_blocks = true
@path ||= request.path
render :template => 'shared/not_found.rhtml', :status => 404, :layout => get_layout
end
alias :render_404 :render_not_found
def render_access_denied(message = nil, title = nil)
@no_design_blocks = true
@message = message
@title = title
render :template => 'shared/access_denied.rhtml', :status => 403
end
def load_category
unless params[:category_path].blank?
path = params[:category_path].join('/')
@category = environment.categories.find_by_path(path)
if @category.nil?
render_not_found(path)
end
end
end
end