Commit ebf468c613b5b2d4b75a96fdf47d482ffa7bb55a
Exists in
staging
and in
1 other branch
merge with master
Showing
154 changed files
with
1196 additions
and
1323 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 154 files displayed.
app/concerns/authenticated_system.rb
@@ -1,169 +0,0 @@ | @@ -1,169 +0,0 @@ | ||
1 | -module AuthenticatedSystem | ||
2 | - | ||
3 | - protected | ||
4 | - | ||
5 | - extend ActiveSupport::Concern | ||
6 | - | ||
7 | - included do | ||
8 | - if self < ActionController::Base | ||
9 | - around_filter :user_set_current | ||
10 | - before_filter :override_user | ||
11 | - before_filter :login_from_cookie | ||
12 | - end | ||
13 | - | ||
14 | - # Inclusion hook to make #current_user and #logged_in? | ||
15 | - # available as ActionView helper methods. | ||
16 | - helper_method :current_user, :logged_in? | ||
17 | - end | ||
18 | - | ||
19 | - # Returns true or false if the user is logged in. | ||
20 | - # Preloads @current_user with the user model if they're logged in. | ||
21 | - def logged_in? | ||
22 | - current_user != nil | ||
23 | - end | ||
24 | - | ||
25 | - # Accesses the current user from the session. | ||
26 | - def current_user user_id = session[:user] | ||
27 | - @current_user ||= begin | ||
28 | - user = User.find_by id: user_id if user_id | ||
29 | - user.session = session if user | ||
30 | - User.current = user | ||
31 | - user | ||
32 | - end | ||
33 | - end | ||
34 | - | ||
35 | - # Store the given user in the session. | ||
36 | - def current_user=(new_user) | ||
37 | - if new_user.nil? | ||
38 | - session.delete(:user) | ||
39 | - else | ||
40 | - session[:user] = new_user.id | ||
41 | - new_user.session = session | ||
42 | - new_user.register_login | ||
43 | - end | ||
44 | - @current_user = User.current = new_user | ||
45 | - end | ||
46 | - | ||
47 | - # See impl. from http://stackoverflow.com/a/2513456/670229 | ||
48 | - def user_set_current | ||
49 | - User.current = current_user | ||
50 | - yield | ||
51 | - ensure | ||
52 | - # to address the thread variable leak issues in Puma/Thin webserver | ||
53 | - User.current = nil | ||
54 | - end | ||
55 | - | ||
56 | - # Check if the user is authorized. | ||
57 | - # | ||
58 | - # Override this method in your controllers if you want to restrict access | ||
59 | - # to only a few actions or if you want to check if the user | ||
60 | - # has the correct rights. | ||
61 | - # | ||
62 | - # Example: | ||
63 | - # | ||
64 | - # # only allow nonbobs | ||
65 | - # def authorize? | ||
66 | - # current_user.login != "bob" | ||
67 | - # end | ||
68 | - def authorized? | ||
69 | - true | ||
70 | - end | ||
71 | - | ||
72 | - # Filter method to enforce a login requirement. | ||
73 | - # | ||
74 | - # To require logins for all actions, use this in your controllers: | ||
75 | - # | ||
76 | - # before_filter :login_required | ||
77 | - # | ||
78 | - # To require logins for specific actions, use this in your controllers: | ||
79 | - # | ||
80 | - # before_filter :login_required, :only => [ :edit, :update ] | ||
81 | - # | ||
82 | - # To skip this in a subclassed controller: | ||
83 | - # | ||
84 | - # skip_before_filter :login_required | ||
85 | - # | ||
86 | - def login_required | ||
87 | - username, passwd = get_auth_data | ||
88 | - if username && passwd | ||
89 | - self.current_user ||= User.authenticate(username, passwd) || nil | ||
90 | - end | ||
91 | - if logged_in? && authorized? | ||
92 | - true | ||
93 | - else | ||
94 | - if params[:require_login_popup] | ||
95 | - render :json => { :require_login_popup => true } | ||
96 | - else | ||
97 | - access_denied | ||
98 | - end | ||
99 | - end | ||
100 | - end | ||
101 | - | ||
102 | - # Redirect as appropriate when an access request fails. | ||
103 | - # | ||
104 | - # The default action is to redirect to the login screen. | ||
105 | - # | ||
106 | - # Override this method in your controllers if you want to have special | ||
107 | - # behavior in case the user is not authorized | ||
108 | - # to access the requested action. For example, a popup window might | ||
109 | - # simply close itself. | ||
110 | - def access_denied | ||
111 | - respond_to do |accepts| | ||
112 | - accepts.html do | ||
113 | - if request.xhr? | ||
114 | - render :text => _('Access denied'), :status => 401 | ||
115 | - else | ||
116 | - store_location | ||
117 | - redirect_to :controller => '/account', :action => 'login' | ||
118 | - end | ||
119 | - end | ||
120 | - accepts.xml do | ||
121 | - headers["Status"] = "Unauthorized" | ||
122 | - headers["WWW-Authenticate"] = %(Basic realm="Web Password") | ||
123 | - render :text => "Could't authenticate you", :status => '401 Unauthorized' | ||
124 | - end | ||
125 | - end | ||
126 | - false | ||
127 | - end | ||
128 | - | ||
129 | - # Store the URI of the current request in the session. | ||
130 | - # | ||
131 | - # We can return to this location by calling #redirect_back_or_default. | ||
132 | - def store_location(location = request.url) | ||
133 | - session[:return_to] = location | ||
134 | - end | ||
135 | - | ||
136 | - # Redirect to the URI stored by the most recent store_location call or | ||
137 | - # to the passed default. | ||
138 | - def redirect_back_or_default(default) | ||
139 | - if session[:return_to] | ||
140 | - redirect_to(session.delete(:return_to)) | ||
141 | - else | ||
142 | - redirect_to(default) | ||
143 | - end | ||
144 | - end | ||
145 | - | ||
146 | - def override_user | ||
147 | - return if params[:override_user].blank? | ||
148 | - return unless logged_in? and user.is_admin? environment | ||
149 | - @current_user = nil | ||
150 | - current_user params[:override_user] | ||
151 | - end | ||
152 | - | ||
153 | - # When called with before_filter :login_from_cookie will check for an :auth_token | ||
154 | - # cookie and log the user back in if apropriate | ||
155 | - def login_from_cookie | ||
156 | - return if cookies[:auth_token].blank? or logged_in? | ||
157 | - user = User.where(remember_token: cookies[:auth_token]).first | ||
158 | - self.current_user = user if user and user.remember_token? | ||
159 | - end | ||
160 | - | ||
161 | - private | ||
162 | - @@http_auth_headers = %w(X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION Authorization) | ||
163 | - # gets BASIC auth info | ||
164 | - def get_auth_data | ||
165 | - auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) } | ||
166 | - auth_data = request.env[auth_key].to_s.split unless auth_key.blank? | ||
167 | - return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil] | ||
168 | - end | ||
169 | -end |
app/controllers/application_controller.rb
@@ -19,6 +19,20 @@ class ApplicationController < ActionController::Base | @@ -19,6 +19,20 @@ class ApplicationController < ActionController::Base | ||
19 | before_filter :redirect_to_current_user | 19 | before_filter :redirect_to_current_user |
20 | 20 | ||
21 | before_filter :set_session_theme | 21 | before_filter :set_session_theme |
22 | + | ||
23 | + # FIXME: only include necessary methods | ||
24 | + include ApplicationHelper | ||
25 | + | ||
26 | + # concerns | ||
27 | + include PermissionCheck | ||
28 | + include CustomDesign | ||
29 | + include NeedsProfile | ||
30 | + | ||
31 | + # implementations | ||
32 | + include FindByContents | ||
33 | + include Noosfero::Plugin::HotSpot | ||
34 | + include SearchTermHelper | ||
35 | + | ||
22 | def set_session_theme | 36 | def set_session_theme |
23 | if params[:theme] | 37 | if params[:theme] |
24 | session[:theme] = environment.theme_ids.include?(params[:theme]) ? params[:theme] : nil | 38 | session[:theme] = environment.theme_ids.include?(params[:theme]) ? params[:theme] : nil |
@@ -53,7 +67,6 @@ class ApplicationController < ActionController::Base | @@ -53,7 +67,6 @@ class ApplicationController < ActionController::Base | ||
53 | end | 67 | end |
54 | end | 68 | end |
55 | 69 | ||
56 | - include ApplicationHelper | ||
57 | layout :get_layout | 70 | layout :get_layout |
58 | def get_layout | 71 | def get_layout |
59 | return false if request.format == :js or request.xhr? | 72 | return false if request.format == :js or request.xhr? |
@@ -79,9 +92,6 @@ class ApplicationController < ActionController::Base | @@ -79,9 +92,6 @@ class ApplicationController < ActionController::Base | ||
79 | helper :document | 92 | helper :document |
80 | helper :language | 93 | helper :language |
81 | 94 | ||
82 | - include DesignHelper | ||
83 | - include PermissionCheck | ||
84 | - | ||
85 | before_filter :set_locale | 95 | before_filter :set_locale |
86 | def set_locale | 96 | def set_locale |
87 | FastGettext.available_locales = environment.available_locales | 97 | FastGettext.available_locales = environment.available_locales |
@@ -94,8 +104,6 @@ class ApplicationController < ActionController::Base | @@ -94,8 +104,6 @@ class ApplicationController < ActionController::Base | ||
94 | end | 104 | end |
95 | end | 105 | end |
96 | 106 | ||
97 | - include NeedsProfile | ||
98 | - | ||
99 | attr_reader :environment | 107 | attr_reader :environment |
100 | 108 | ||
101 | # declares that the given <tt>actions</tt> cannot be accessed by other HTTP | 109 | # declares that the given <tt>actions</tt> cannot be accessed by other HTTP |
@@ -156,8 +164,6 @@ class ApplicationController < ActionController::Base | @@ -156,8 +164,6 @@ class ApplicationController < ActionController::Base | ||
156 | end | 164 | end |
157 | end | 165 | end |
158 | 166 | ||
159 | - include Noosfero::Plugin::HotSpot | ||
160 | - | ||
161 | # FIXME this filter just loads @plugins to children controllers and helpers | 167 | # FIXME this filter just loads @plugins to children controllers and helpers |
162 | def init_noosfero_plugins | 168 | def init_noosfero_plugins |
163 | plugins | 169 | plugins |
@@ -189,9 +195,6 @@ class ApplicationController < ActionController::Base | @@ -189,9 +195,6 @@ class ApplicationController < ActionController::Base | ||
189 | end | 195 | end |
190 | end | 196 | end |
191 | 197 | ||
192 | - include SearchTermHelper | ||
193 | - include FindByContents | ||
194 | - | ||
195 | def find_suggestions(query, context, asset, options={}) | 198 | def find_suggestions(query, context, asset, options={}) |
196 | plugins.dispatch_first(:find_suggestions, query, context, asset, options) | 199 | plugins.dispatch_first(:find_suggestions, query, context, asset, options) |
197 | end | 200 | end |
@@ -0,0 +1,169 @@ | @@ -0,0 +1,169 @@ | ||
1 | +module AuthenticatedSystem | ||
2 | + | ||
3 | + protected | ||
4 | + | ||
5 | + extend ActiveSupport::Concern | ||
6 | + | ||
7 | + included do | ||
8 | + if self < ActionController::Base | ||
9 | + around_filter :user_set_current | ||
10 | + before_filter :override_user | ||
11 | + before_filter :login_from_cookie | ||
12 | + end | ||
13 | + | ||
14 | + # Inclusion hook to make #current_user and #logged_in? | ||
15 | + # available as ActionView helper methods. | ||
16 | + helper_method :current_user, :logged_in? | ||
17 | + end | ||
18 | + | ||
19 | + # Returns true or false if the user is logged in. | ||
20 | + # Preloads @current_user with the user model if they're logged in. | ||
21 | + def logged_in? | ||
22 | + current_user != nil | ||
23 | + end | ||
24 | + | ||
25 | + # Accesses the current user from the session. | ||
26 | + def current_user user_id = session[:user] | ||
27 | + @current_user ||= begin | ||
28 | + user = User.find_by id: user_id if user_id | ||
29 | + user.session = session if user | ||
30 | + User.current = user | ||
31 | + user | ||
32 | + end | ||
33 | + end | ||
34 | + | ||
35 | + # Store the given user in the session. | ||
36 | + def current_user=(new_user) | ||
37 | + if new_user.nil? | ||
38 | + session.delete(:user) | ||
39 | + else | ||
40 | + session[:user] = new_user.id | ||
41 | + new_user.session = session | ||
42 | + new_user.register_login | ||
43 | + end | ||
44 | + @current_user = User.current = new_user | ||
45 | + end | ||
46 | + | ||
47 | + # See impl. from http://stackoverflow.com/a/2513456/670229 | ||
48 | + def user_set_current | ||
49 | + User.current = current_user | ||
50 | + yield | ||
51 | + ensure | ||
52 | + # to address the thread variable leak issues in Puma/Thin webserver | ||
53 | + User.current = nil | ||
54 | + end | ||
55 | + | ||
56 | + # Check if the user is authorized. | ||
57 | + # | ||
58 | + # Override this method in your controllers if you want to restrict access | ||
59 | + # to only a few actions or if you want to check if the user | ||
60 | + # has the correct rights. | ||
61 | + # | ||
62 | + # Example: | ||
63 | + # | ||
64 | + # # only allow nonbobs | ||
65 | + # def authorize? | ||
66 | + # current_user.login != "bob" | ||
67 | + # end | ||
68 | + def authorized? | ||
69 | + true | ||
70 | + end | ||
71 | + | ||
72 | + # Filter method to enforce a login requirement. | ||
73 | + # | ||
74 | + # To require logins for all actions, use this in your controllers: | ||
75 | + # | ||
76 | + # before_filter :login_required | ||
77 | + # | ||
78 | + # To require logins for specific actions, use this in your controllers: | ||
79 | + # | ||
80 | + # before_filter :login_required, :only => [ :edit, :update ] | ||
81 | + # | ||
82 | + # To skip this in a subclassed controller: | ||
83 | + # | ||
84 | + # skip_before_filter :login_required | ||
85 | + # | ||
86 | + def login_required | ||
87 | + username, passwd = get_auth_data | ||
88 | + if username && passwd | ||
89 | + self.current_user ||= User.authenticate(username, passwd) || nil | ||
90 | + end | ||
91 | + if logged_in? && authorized? | ||
92 | + true | ||
93 | + else | ||
94 | + if params[:require_login_popup] | ||
95 | + render :json => { :require_login_popup => true } | ||
96 | + else | ||
97 | + access_denied | ||
98 | + end | ||
99 | + end | ||
100 | + end | ||
101 | + | ||
102 | + # Redirect as appropriate when an access request fails. | ||
103 | + # | ||
104 | + # The default action is to redirect to the login screen. | ||
105 | + # | ||
106 | + # Override this method in your controllers if you want to have special | ||
107 | + # behavior in case the user is not authorized | ||
108 | + # to access the requested action. For example, a popup window might | ||
109 | + # simply close itself. | ||
110 | + def access_denied | ||
111 | + respond_to do |accepts| | ||
112 | + accepts.html do | ||
113 | + if request.xhr? | ||
114 | + render :text => _('Access denied'), :status => 401 | ||
115 | + else | ||
116 | + store_location | ||
117 | + redirect_to :controller => '/account', :action => 'login' | ||
118 | + end | ||
119 | + end | ||
120 | + accepts.xml do | ||
121 | + headers["Status"] = "Unauthorized" | ||
122 | + headers["WWW-Authenticate"] = %(Basic realm="Web Password") | ||
123 | + render :text => "Could't authenticate you", :status => '401 Unauthorized' | ||
124 | + end | ||
125 | + end | ||
126 | + false | ||
127 | + end | ||
128 | + | ||
129 | + # Store the URI of the current request in the session. | ||
130 | + # | ||
131 | + # We can return to this location by calling #redirect_back_or_default. | ||
132 | + def store_location(location = request.url) | ||
133 | + session[:return_to] = location | ||
134 | + end | ||
135 | + | ||
136 | + # Redirect to the URI stored by the most recent store_location call or | ||
137 | + # to the passed default. | ||
138 | + def redirect_back_or_default(default) | ||
139 | + if session[:return_to] | ||
140 | + redirect_to(session.delete(:return_to)) | ||
141 | + else | ||
142 | + redirect_to(default) | ||
143 | + end | ||
144 | + end | ||
145 | + | ||
146 | + def override_user | ||
147 | + return if params[:override_user].blank? | ||
148 | + return unless logged_in? and user.is_admin? environment | ||
149 | + @current_user = nil | ||
150 | + current_user params[:override_user] | ||
151 | + end | ||
152 | + | ||
153 | + # When called with before_filter :login_from_cookie will check for an :auth_token | ||
154 | + # cookie and log the user back in if apropriate | ||
155 | + def login_from_cookie | ||
156 | + return if cookies[:auth_token].blank? or logged_in? | ||
157 | + user = User.where(remember_token: cookies[:auth_token]).first | ||
158 | + self.current_user = user if user and user.remember_token? | ||
159 | + end | ||
160 | + | ||
161 | + private | ||
162 | + @@http_auth_headers = %w(X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION Authorization) | ||
163 | + # gets BASIC auth info | ||
164 | + def get_auth_data | ||
165 | + auth_key = @@http_auth_headers.detect { |h| request.env.has_key?(h) } | ||
166 | + auth_data = request.env[auth_key].to_s.split unless auth_key.blank? | ||
167 | + return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil] | ||
168 | + end | ||
169 | +end |
@@ -0,0 +1,50 @@ | @@ -0,0 +1,50 @@ | ||
1 | +module CustomDesign | ||
2 | + | ||
3 | + extend ActiveSupport::Concern | ||
4 | + | ||
5 | + included do | ||
6 | + extend ClassMethods | ||
7 | + include InstanceMethods | ||
8 | + before_filter :load_custom_design if self.respond_to? :before_filter | ||
9 | + end | ||
10 | + | ||
11 | + module ClassMethods | ||
12 | + | ||
13 | + def no_design_blocks | ||
14 | + @no_design_blocks = true | ||
15 | + end | ||
16 | + | ||
17 | + def use_custom_design options = {} | ||
18 | + @custom_design = options | ||
19 | + end | ||
20 | + | ||
21 | + def custom_design | ||
22 | + @custom_design ||= {} | ||
23 | + end | ||
24 | + | ||
25 | + def uses_design_blocks? | ||
26 | + !@no_design_blocks | ||
27 | + end | ||
28 | + | ||
29 | + end | ||
30 | + | ||
31 | + module InstanceMethods | ||
32 | + | ||
33 | + protected | ||
34 | + | ||
35 | + def uses_design_blocks? | ||
36 | + !@no_design_blocks && self.class.uses_design_blocks? | ||
37 | + end | ||
38 | + | ||
39 | + def load_custom_design | ||
40 | + # see also: LayoutHelper#body_classes | ||
41 | + @layout_template = self.class.custom_design[:layout_template] | ||
42 | + end | ||
43 | + | ||
44 | + def custom_design | ||
45 | + @custom_design || self.class.custom_design | ||
46 | + end | ||
47 | + | ||
48 | + end | ||
49 | + | ||
50 | +end |
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +module NeedsProfile | ||
2 | + | ||
3 | + module ClassMethods | ||
4 | + def needs_profile | ||
5 | + before_filter :load_profile | ||
6 | + end | ||
7 | + end | ||
8 | + | ||
9 | + def self.included(including) | ||
10 | + including.send(:extend, NeedsProfile::ClassMethods) | ||
11 | + end | ||
12 | + | ||
13 | + def boxes_holder | ||
14 | + profile || environment # prefers profile, but defaults to environment | ||
15 | + end | ||
16 | + | ||
17 | + def profile | ||
18 | + @profile | ||
19 | + end | ||
20 | + | ||
21 | + protected | ||
22 | + | ||
23 | + def load_profile | ||
24 | + if params[:profile] | ||
25 | + params[:profile].downcase! | ||
26 | + @profile ||= environment.profiles.where(identifier: params[:profile]).first | ||
27 | + end | ||
28 | + | ||
29 | + if @profile | ||
30 | + profile_hostname = @profile.hostname | ||
31 | + if profile_hostname && profile_hostname != request.host | ||
32 | + if params[:controller] == 'content_viewer' | ||
33 | + params[:profile] = nil | ||
34 | + else | ||
35 | + params.delete(:profile) | ||
36 | + end | ||
37 | + redirect_to(Noosfero.url_options.merge(params).merge(:host => profile_hostname)) | ||
38 | + end | ||
39 | + else | ||
40 | + render_not_found | ||
41 | + end | ||
42 | + end | ||
43 | + | ||
44 | +end |
app/helpers/design_helper.rb
@@ -1,50 +0,0 @@ | @@ -1,50 +0,0 @@ | ||
1 | -module DesignHelper | ||
2 | - | ||
3 | - extend ActiveSupport::Concern | ||
4 | - | ||
5 | - included do | ||
6 | - extend ClassMethods | ||
7 | - include InstanceMethods | ||
8 | - before_filter :load_custom_design if self.respond_to? :before_filter | ||
9 | - end | ||
10 | - | ||
11 | - module ClassMethods | ||
12 | - | ||
13 | - def no_design_blocks | ||
14 | - @no_design_blocks = true | ||
15 | - end | ||
16 | - | ||
17 | - def use_custom_design options = {} | ||
18 | - @custom_design = options | ||
19 | - end | ||
20 | - | ||
21 | - def custom_design | ||
22 | - @custom_design ||= {} | ||
23 | - end | ||
24 | - | ||
25 | - def uses_design_blocks? | ||
26 | - !@no_design_blocks | ||
27 | - end | ||
28 | - | ||
29 | - end | ||
30 | - | ||
31 | - module InstanceMethods | ||
32 | - | ||
33 | - protected | ||
34 | - | ||
35 | - def uses_design_blocks? | ||
36 | - !@no_design_blocks && self.class.uses_design_blocks? | ||
37 | - end | ||
38 | - | ||
39 | - def load_custom_design | ||
40 | - # see also: LayoutHelper#body_classes | ||
41 | - @layout_template = self.class.custom_design[:layout_template] | ||
42 | - end | ||
43 | - | ||
44 | - def custom_design | ||
45 | - @custom_design || self.class.custom_design | ||
46 | - end | ||
47 | - | ||
48 | - end | ||
49 | - | ||
50 | -end |
app/helpers/forms_helper.rb
@@ -128,14 +128,14 @@ module FormsHelper | @@ -128,14 +128,14 @@ module FormsHelper | ||
128 | counter += 1 | 128 | counter += 1 |
129 | row << item | 129 | row << item |
130 | if counter % per_row == 0 | 130 | if counter % per_row == 0 |
131 | - rows << content_tag('tr', row.join("\n")) | 131 | + rows << content_tag('tr', row.join("\n").html_safe) |
132 | counter = 0 | 132 | counter = 0 |
133 | row = [] | 133 | row = [] |
134 | end | 134 | end |
135 | end | 135 | end |
136 | - rows << content_tag('tr', row.join("\n")) | 136 | + rows << content_tag('tr', row.join("\n").html_safe) |
137 | 137 | ||
138 | - content_tag('table',rows.join("\n")) | 138 | + content_tag('table',rows.join("\n").html_safe) |
139 | end | 139 | end |
140 | 140 | ||
141 | def date_field(name, value, datepicker_options = {}, html_options = {}) | 141 | def date_field(name, value, datepicker_options = {}, html_options = {}) |
app/mailers/mailing.rb
@@ -2,7 +2,8 @@ require_dependency 'mailing_job' | @@ -2,7 +2,8 @@ require_dependency 'mailing_job' | ||
2 | 2 | ||
3 | class Mailing < ApplicationRecord | 3 | class Mailing < ApplicationRecord |
4 | 4 | ||
5 | - acts_as_having_settings :field => :data | 5 | + extend ActsAsHavingSettings::ClassMethods |
6 | + acts_as_having_settings field: :data | ||
6 | 7 | ||
7 | attr_accessible :subject, :body, :data | 8 | attr_accessible :subject, :body, :data |
8 | 9 |
app/models/article.rb
@@ -13,7 +13,9 @@ class Article < ApplicationRecord | @@ -13,7 +13,9 @@ class Article < ApplicationRecord | ||
13 | :image_builder, :show_to_followers, :archived, | 13 | :image_builder, :show_to_followers, :archived, |
14 | :author, :display_preview, :published_at, :person_followers | 14 | :author, :display_preview, :published_at, :person_followers |
15 | 15 | ||
16 | + extend ActsAsHavingImage::ClassMethods | ||
16 | acts_as_having_image | 17 | acts_as_having_image |
18 | + | ||
17 | include Noosfero::Plugin::HotSpot | 19 | include Noosfero::Plugin::HotSpot |
18 | 20 | ||
19 | SEARCHABLE_FIELDS = { | 21 | SEARCHABLE_FIELDS = { |
@@ -91,7 +93,8 @@ class Article < ApplicationRecord | @@ -91,7 +93,8 @@ class Article < ApplicationRecord | ||
91 | has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' | 93 | has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' |
92 | has_many :categories_including_virtual, :through => :article_categorizations_including_virtual, :source => :category | 94 | has_many :categories_including_virtual, :through => :article_categorizations_including_virtual, :source => :category |
93 | 95 | ||
94 | - acts_as_having_settings :field => :setting | 96 | + extend ActsAsHavingSettings::ClassMethods |
97 | + acts_as_having_settings field: :setting | ||
95 | 98 | ||
96 | settings_items :display_hits, :type => :boolean, :default => true | 99 | settings_items :display_hits, :type => :boolean, :default => true |
97 | settings_items :author_name, :type => :string, :default => "" | 100 | settings_items :author_name, :type => :string, :default => "" |
@@ -242,6 +245,7 @@ class Article < ApplicationRecord | @@ -242,6 +245,7 @@ class Article < ApplicationRecord | ||
242 | acts_as_taggable | 245 | acts_as_taggable |
243 | N_('Tag list') | 246 | N_('Tag list') |
244 | 247 | ||
248 | + extend ActsAsFilesystem::ActsMethods | ||
245 | acts_as_filesystem | 249 | acts_as_filesystem |
246 | 250 | ||
247 | acts_as_versioned | 251 | acts_as_versioned |
app/models/block.rb
@@ -17,6 +17,7 @@ class Block < ApplicationRecord | @@ -17,6 +17,7 @@ class Block < ApplicationRecord | ||
17 | belongs_to :mirror_block, :class_name => "Block" | 17 | belongs_to :mirror_block, :class_name => "Block" |
18 | has_many :observers, :class_name => "Block", :foreign_key => "mirror_block_id" | 18 | has_many :observers, :class_name => "Block", :foreign_key => "mirror_block_id" |
19 | 19 | ||
20 | + extend ActsAsHavingSettings::ClassMethods | ||
20 | acts_as_having_settings | 21 | acts_as_having_settings |
21 | 22 | ||
22 | scope :enabled, -> { where :enabled => true } | 23 | scope :enabled, -> { where :enabled => true } |
app/models/blog.rb
@@ -2,7 +2,9 @@ class Blog < Folder | @@ -2,7 +2,9 @@ class Blog < Folder | ||
2 | 2 | ||
3 | attr_accessible :visualization_format | 3 | attr_accessible :visualization_format |
4 | 4 | ||
5 | + extend ActsAsHavingPosts::ClassMethods | ||
5 | acts_as_having_posts | 6 | acts_as_having_posts |
7 | + | ||
6 | include PostsLimit | 8 | include PostsLimit |
7 | 9 | ||
8 | #FIXME This should be used until there is a migration to fix all blogs that | 10 | #FIXME This should be used until there is a migration to fix all blogs that |
app/models/category.rb
@@ -21,6 +21,7 @@ class Category < ApplicationRecord | @@ -21,6 +21,7 @@ class Category < ApplicationRecord | ||
21 | 21 | ||
22 | scope :on_level, -> parent { where :parent_id => parent } | 22 | scope :on_level, -> parent { where :parent_id => parent } |
23 | 23 | ||
24 | + extend ActsAsFilesystem::ActsMethods | ||
24 | acts_as_filesystem | 25 | acts_as_filesystem |
25 | 26 | ||
26 | has_many :article_categorizations | 27 | has_many :article_categorizations |
@@ -35,6 +36,7 @@ class Category < ApplicationRecord | @@ -35,6 +36,7 @@ class Category < ApplicationRecord | ||
35 | has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person' | 36 | has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person' |
36 | has_many :communities, :through => :profile_categorizations, :source => :profile, :class_name => 'Community' | 37 | has_many :communities, :through => :profile_categorizations, :source => :profile, :class_name => 'Community' |
37 | 38 | ||
39 | + extend ActsAsHavingImage::ClassMethods | ||
38 | acts_as_having_image | 40 | acts_as_having_image |
39 | 41 | ||
40 | before_save :normalize_display_color | 42 | before_save :normalize_display_color |
app/models/comment.rb
@@ -38,6 +38,7 @@ class Comment < ApplicationRecord | @@ -38,6 +38,7 @@ class Comment < ApplicationRecord | ||
38 | 38 | ||
39 | validate :article_archived? | 39 | validate :article_archived? |
40 | 40 | ||
41 | + extend ActsAsHavingSettings::ClassMethods | ||
41 | acts_as_having_settings | 42 | acts_as_having_settings |
42 | 43 | ||
43 | xss_terminate :only => [ :body, :title, :name ], :on => 'validation' | 44 | xss_terminate :only => [ :body, :title, :name ], :on => 'validation' |
@@ -0,0 +1,265 @@ | @@ -0,0 +1,265 @@ | ||
1 | +module ActsAsFilesystem | ||
2 | + | ||
3 | + module ActsMethods | ||
4 | + | ||
5 | + # Declares the ActiveRecord model to acts like a filesystem: objects are | ||
6 | + # arranged in a tree (liks acts_as_tree), and . The underlying table must | ||
7 | + # have the following fields: | ||
8 | + # | ||
9 | + # * name (+:string+) - the title of the object | ||
10 | + # * slug (+:string+)- the title turned in a URL-friendly string (downcased, | ||
11 | + # non-ascii chars transliterated into ascii, all sequences of | ||
12 | + # non-alphanumericd characters changed into dashed) | ||
13 | + # * path (+:text+)- stores the full path of the object (the full path of | ||
14 | + # the parent, a "/" and the slug of the object) | ||
15 | + # * children_count - a cache of the number of children elements. | ||
16 | + def acts_as_filesystem | ||
17 | + # a filesystem is a tree | ||
18 | + acts_as_tree :counter_cache => :children_count | ||
19 | + | ||
20 | + extend ClassMethods | ||
21 | + include InstanceMethods | ||
22 | + if self.has_path? | ||
23 | + after_update :update_children_path | ||
24 | + before_create :set_path | ||
25 | + include InstanceMethods::PathMethods | ||
26 | + end | ||
27 | + | ||
28 | + before_save :set_ancestry | ||
29 | + end | ||
30 | + | ||
31 | + end | ||
32 | + | ||
33 | + module ClassMethods | ||
34 | + | ||
35 | + def build_ancestry(parent_id = nil, ancestry = '') | ||
36 | + ActiveRecord::Base.transaction do | ||
37 | + self.base_class.where(parent_id: parent_id).each do |node| | ||
38 | + node.update_column :ancestry, ancestry | ||
39 | + | ||
40 | + build_ancestry node.id, (ancestry.empty? ? "#{node.formatted_ancestry_id}" : | ||
41 | + "#{ancestry}#{node.ancestry_sep}#{node.formatted_ancestry_id}") | ||
42 | + end | ||
43 | + end | ||
44 | + | ||
45 | + #raise "Couldn't reach and set ancestry on every record" if self.base_class.where('ancestry is null').count != 0 | ||
46 | + end | ||
47 | + | ||
48 | + def has_path? | ||
49 | + (['name', 'slug', 'path'] - self.column_names).blank? | ||
50 | + end | ||
51 | + | ||
52 | + end | ||
53 | + | ||
54 | + module InstanceMethods | ||
55 | + | ||
56 | + def ancestry_column | ||
57 | + 'ancestry' | ||
58 | + end | ||
59 | + def ancestry_sep | ||
60 | + '.' | ||
61 | + end | ||
62 | + def has_ancestry? | ||
63 | + self.class.column_names.include? self.ancestry_column | ||
64 | + end | ||
65 | + | ||
66 | + def formatted_ancestry_id | ||
67 | + "%010d" % self.id if self.id | ||
68 | + end | ||
69 | + | ||
70 | + def ancestry | ||
71 | + self[ancestry_column] | ||
72 | + end | ||
73 | + def ancestor_ids | ||
74 | + return nil if !has_ancestry? or ancestry.nil? | ||
75 | + @ancestor_ids ||= ancestry.split(ancestry_sep).map{ |id| id.to_i } | ||
76 | + end | ||
77 | + | ||
78 | + def ancestry=(value) | ||
79 | + self[ancestry_column] = value | ||
80 | + end | ||
81 | + def set_ancestry | ||
82 | + return unless self.has_ancestry? | ||
83 | + if self.ancestry.nil? or (new_record? or parent_id_changed?) or recalculate_path | ||
84 | + self.ancestry = self.hierarchy(true)[0...-1].map{ |p| p.formatted_ancestry_id }.join(ancestry_sep) | ||
85 | + end | ||
86 | + end | ||
87 | + | ||
88 | + def descendents_options | ||
89 | + ["#{self.ancestry_column} LIKE ?", "%#{self.formatted_ancestry_id}%"] | ||
90 | + end | ||
91 | + def descendents | ||
92 | + self.class.where descendents_options | ||
93 | + end | ||
94 | + | ||
95 | + # calculates the level of the record in the records hierarchy. Top-level | ||
96 | + # records have level 0; the children of the top-level records have | ||
97 | + # level 1; the children of records with level 1 have level 2, and so on. | ||
98 | + # | ||
99 | + # A level 0 | ||
100 | + # / \ | ||
101 | + # B C level 1 | ||
102 | + # / \ / \ | ||
103 | + # E F G H level 2 | ||
104 | + # ... | ||
105 | + def level | ||
106 | + self.hierarchy.size - 1 | ||
107 | + end | ||
108 | + | ||
109 | + # Is this record a top-level record? | ||
110 | + def top_level? | ||
111 | + self.parent.nil? | ||
112 | + end | ||
113 | + | ||
114 | + # Is this record a leaf in the hierarchy tree of records? | ||
115 | + # | ||
116 | + # Being a leaf means that this record has no subrecord. | ||
117 | + def leaf? | ||
118 | + self.children.empty? | ||
119 | + end | ||
120 | + | ||
121 | + def top_ancestor | ||
122 | + if has_ancestry? and !ancestry.blank? | ||
123 | + self.class.base_class.find_by id: self.top_ancestor_id | ||
124 | + else | ||
125 | + self.hierarchy.first | ||
126 | + end | ||
127 | + end | ||
128 | + def top_ancestor_id | ||
129 | + if has_ancestry? and !ancestry.nil? | ||
130 | + self.ancestor_ids.first | ||
131 | + else | ||
132 | + self.hierarchy.first.id | ||
133 | + end | ||
134 | + end | ||
135 | + | ||
136 | + # returns the full hierarchy from the top-level item to this one. For | ||
137 | + # example, if item1 has a children item2 and item2 has a children item3, | ||
138 | + # then item3's hierarchy would be [item1, item2, item3]. | ||
139 | + # | ||
140 | + # If +reload+ is passed as +true+, then the hierarchy is reload (usefull | ||
141 | + # when the ActiveRecord object was modified in some way, or just after | ||
142 | + # changing parent) | ||
143 | + def hierarchy(reload = false) | ||
144 | + @hierarchy = nil if reload or recalculate_path | ||
145 | + | ||
146 | + if @hierarchy.nil? | ||
147 | + @hierarchy = [] | ||
148 | + | ||
149 | + if !reload and !recalculate_path and ancestor_ids | ||
150 | + objects = self.class.base_class.where(id: ancestor_ids) | ||
151 | + ancestor_ids.each{ |id| @hierarchy << objects.find{ |t| t.id == id } } | ||
152 | + @hierarchy << self | ||
153 | + else | ||
154 | + item = self | ||
155 | + while item | ||
156 | + @hierarchy.unshift(item) | ||
157 | + item = item.parent | ||
158 | + end | ||
159 | + end | ||
160 | + end | ||
161 | + | ||
162 | + @hierarchy | ||
163 | + end | ||
164 | + | ||
165 | + def map_traversal(&block) | ||
166 | + result = [] | ||
167 | + current_level = [self] | ||
168 | + | ||
169 | + while !current_level.empty? | ||
170 | + result += current_level | ||
171 | + ids = current_level.select {|item| item.children_count > 0}.map(&:id) | ||
172 | + break if ids.empty? | ||
173 | + current_level = self.class.base_class.where(parent_id: ids) | ||
174 | + end | ||
175 | + block ||= (lambda { |x| x }) | ||
176 | + result.map(&block) | ||
177 | + end | ||
178 | + | ||
179 | + def all_children | ||
180 | + res = map_traversal | ||
181 | + res.shift | ||
182 | + res | ||
183 | + end | ||
184 | + | ||
185 | + ##### | ||
186 | + # Path methods | ||
187 | + # These methods are used when _path_, _name_ and _slug_ attributes exist | ||
188 | + # and should be calculated based on the tree | ||
189 | + ##### | ||
190 | + module PathMethods | ||
191 | + # used to know when to trigger batch renaming | ||
192 | + attr_accessor :recalculate_path | ||
193 | + | ||
194 | + # calculates the full path to this record using parent's path. | ||
195 | + def calculate_path | ||
196 | + self.hierarchy.map{ |obj| obj.slug }.join('/') | ||
197 | + end | ||
198 | + def set_path | ||
199 | + if self.path == self.slug && !self.top_level? | ||
200 | + self.path = self.calculate_path | ||
201 | + end | ||
202 | + end | ||
203 | + def explode_path | ||
204 | + path.split(/\//) | ||
205 | + end | ||
206 | + | ||
207 | + def update_children_path | ||
208 | + if self.recalculate_path | ||
209 | + self.children.each do |child| | ||
210 | + child.path = child.calculate_path | ||
211 | + child.recalculate_path = true | ||
212 | + child.save! | ||
213 | + end | ||
214 | + end | ||
215 | + self.recalculate_path = false | ||
216 | + end | ||
217 | + | ||
218 | + # calculates the full name of a record by accessing the name of all its | ||
219 | + # ancestors. | ||
220 | + # | ||
221 | + # If you have this record hierarchy: | ||
222 | + # Record "A" | ||
223 | + # Record "B" | ||
224 | + # Record "C" | ||
225 | + # | ||
226 | + # Then Record "C" will have "A/B/C" as its full name. | ||
227 | + def full_name(sep = '/') | ||
228 | + self.hierarchy.map {|item| item.name || '?' }.join(sep) | ||
229 | + end | ||
230 | + | ||
231 | + # gets the name without leading parents. Useful when dividing records | ||
232 | + # in top-level groups and full names must not include the top-level | ||
233 | + # record which is already a emphasized label | ||
234 | + def full_name_without_leading(count, sep = '/') | ||
235 | + parts = self.full_name(sep).split(sep) | ||
236 | + count.times { parts.shift } | ||
237 | + parts.join(sep) | ||
238 | + end | ||
239 | + | ||
240 | + def set_name(value) | ||
241 | + if self.name != value | ||
242 | + self.recalculate_path = true | ||
243 | + end | ||
244 | + self[:name] = value | ||
245 | + end | ||
246 | + | ||
247 | + # sets the name of the record. Also sets #slug accordingly. | ||
248 | + def name=(value) | ||
249 | + self.set_name(value) | ||
250 | + unless self.name.blank? | ||
251 | + self.slug = self.name.to_slug | ||
252 | + end | ||
253 | + end | ||
254 | + | ||
255 | + # sets the slug of the record. Also sets the path with the new slug value. | ||
256 | + def slug=(value) | ||
257 | + self[:slug] = value | ||
258 | + unless self.slug.blank? | ||
259 | + self.path = self.calculate_path | ||
260 | + end | ||
261 | + end | ||
262 | + end | ||
263 | + end | ||
264 | +end | ||
265 | + |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +module ActsAsHavingBoxes | ||
2 | + | ||
3 | + module ClassMethods | ||
4 | + def acts_as_having_boxes | ||
5 | + has_many :boxes, -> { order :position }, as: :owner, dependent: :destroy | ||
6 | + self.send(:include, ActsAsHavingBoxes) | ||
7 | + end | ||
8 | + end | ||
9 | + | ||
10 | + module BlockArray | ||
11 | + def find(id) | ||
12 | + select { |item| item.id == id.to_i }.first | ||
13 | + end | ||
14 | + end | ||
15 | + | ||
16 | + def blocks(reload = false) | ||
17 | + if (reload) | ||
18 | + @blocks = nil | ||
19 | + end | ||
20 | + if @blocks.nil? | ||
21 | + @blocks = boxes.includes(:blocks).inject([]) do |acc,obj| | ||
22 | + acc.concat(obj.blocks) | ||
23 | + end | ||
24 | + @blocks.send(:extend, BlockArray) | ||
25 | + end | ||
26 | + @blocks | ||
27 | + end | ||
28 | + | ||
29 | + # returns 3 unless the class table has a boxes_limit column. In that case | ||
30 | + # return the value of the column. | ||
31 | + def boxes_limit layout_template = nil | ||
32 | + layout_template ||= self.layout_template | ||
33 | + @boxes_limit ||= LayoutTemplate.find(layout_template).number_of_boxes || 3 | ||
34 | + end | ||
35 | + | ||
36 | +end | ||
37 | + |
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +module ActsAsHavingImage | ||
2 | + | ||
3 | + module ClassMethods | ||
4 | + def acts_as_having_image | ||
5 | + belongs_to :image, dependent: :destroy | ||
6 | + scope :with_image, -> { where "#{table_name}.image_id IS NOT NULL" } | ||
7 | + scope :without_image, -> { where "#{table_name}.image_id IS NULL" } | ||
8 | + attr_accessible :image_builder | ||
9 | + include ActsAsHavingImage | ||
10 | + end | ||
11 | + end | ||
12 | + | ||
13 | + def image_builder=(img) | ||
14 | + if image && image.id == img[:id] | ||
15 | + image.attributes = img | ||
16 | + else | ||
17 | + build_image(img) | ||
18 | + end unless img[:uploaded_data].blank? | ||
19 | + if img[:remove_image] == 'true' | ||
20 | + self.image_id = nil | ||
21 | + end | ||
22 | + end | ||
23 | + | ||
24 | +end | ||
25 | + |
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +module ActsAsHavingPosts | ||
2 | + | ||
3 | + module ClassMethods | ||
4 | + def acts_as_having_posts(scope = nil) | ||
5 | + has_many :posts, -> { | ||
6 | + s = order('published_at DESC, id DESC').where('articles.type != ?', 'RssFeed') | ||
7 | + s = s.instance_exec(&scope) if scope | ||
8 | + s | ||
9 | + }, class_name: 'Article', foreign_key: 'parent_id', source: :children | ||
10 | + | ||
11 | + attr_accessor :feed_attrs | ||
12 | + | ||
13 | + after_create do |blog| | ||
14 | + blog.children << RssFeed.new(:name => 'feed', :profile => blog.profile) | ||
15 | + blog.feed = blog.feed_attrs | ||
16 | + end | ||
17 | + | ||
18 | + settings_items :posts_per_page, :type => :integer, :default => 5 | ||
19 | + | ||
20 | + self.send(:include, ActsAsHavingPosts) | ||
21 | + end | ||
22 | + end | ||
23 | + | ||
24 | + def has_posts? | ||
25 | + true | ||
26 | + end | ||
27 | + | ||
28 | + def feed | ||
29 | + children.where(:type => 'RssFeed').first | ||
30 | + end | ||
31 | + | ||
32 | + def feed=(attrs) | ||
33 | + if attrs | ||
34 | + if self.feed | ||
35 | + self.feed.update(attrs) | ||
36 | + else | ||
37 | + self.feed_attrs = attrs | ||
38 | + end | ||
39 | + end | ||
40 | + self.feed | ||
41 | + end | ||
42 | + | ||
43 | + def name=(value) | ||
44 | + self.set_name(value) | ||
45 | + self.slug = self.slug.blank? ? self.name.to_slug : self.slug.to_slug | ||
46 | + end | ||
47 | + | ||
48 | +end | ||
49 | + |
@@ -0,0 +1,89 @@ | @@ -0,0 +1,89 @@ | ||
1 | +# declare missing types | ||
2 | +module ActiveRecord | ||
3 | + module Type | ||
4 | + class Symbol < Value | ||
5 | + def cast_value value | ||
6 | + value.to_sym | ||
7 | + end | ||
8 | + end | ||
9 | + class Array < Value | ||
10 | + def cast_value value | ||
11 | + ::Array.wrap(value) | ||
12 | + end | ||
13 | + end | ||
14 | + class Hash < Value | ||
15 | + def cast_value value | ||
16 | + h = ::Hash[value] | ||
17 | + h.symbolize_keys! | ||
18 | + h | ||
19 | + end | ||
20 | + end | ||
21 | + end | ||
22 | +end | ||
23 | + | ||
24 | +module ActsAsHavingSettings | ||
25 | + | ||
26 | + def self.type_cast value, type | ||
27 | + # do not cast nil | ||
28 | + return value if value.nil? | ||
29 | + type.send :cast_value, value | ||
30 | + end | ||
31 | + | ||
32 | + module ClassMethods | ||
33 | + | ||
34 | + def acts_as_having_settings(*args) | ||
35 | + options = args.last.is_a?(Hash) ? args.pop : {} | ||
36 | + field = (options[:field] || :settings).to_sym | ||
37 | + | ||
38 | + serialize field, Hash | ||
39 | + class_attribute :settings_field | ||
40 | + self.settings_field = field | ||
41 | + | ||
42 | + class_eval do | ||
43 | + def settings_field | ||
44 | + self[self.class.settings_field] ||= Hash.new | ||
45 | + end | ||
46 | + | ||
47 | + def setting_changed? setting_field | ||
48 | + setting_field = setting_field.to_sym | ||
49 | + changed_settings = self.changes[self.class.settings_field] | ||
50 | + return false if changed_settings.nil? | ||
51 | + | ||
52 | + old_setting_value = changed_settings.first.nil? ? nil : changed_settings.first[setting_field] | ||
53 | + new_setting_value = changed_settings.last[setting_field] | ||
54 | + old_setting_value != new_setting_value | ||
55 | + end | ||
56 | + end | ||
57 | + | ||
58 | + settings_items *args | ||
59 | + end | ||
60 | + | ||
61 | + def settings_items *names | ||
62 | + | ||
63 | + options = names.extract_options! | ||
64 | + default = options[:default] | ||
65 | + type = options[:type] | ||
66 | + type = if type.present? then ActiveRecord::Type.const_get(type.to_s.camelize.to_sym).new else nil end | ||
67 | + | ||
68 | + names.each do |setting| | ||
69 | + # symbolize key | ||
70 | + setting = setting.to_sym | ||
71 | + | ||
72 | + define_method setting do | ||
73 | + h = send self.class.settings_field | ||
74 | + val = h[setting] | ||
75 | + # translate default value if it is used | ||
76 | + if not val.nil? then val elsif default.is_a? String then gettext default else default end | ||
77 | + end | ||
78 | + | ||
79 | + define_method "#{setting}=" do |value| | ||
80 | + h = send self.class.settings_field | ||
81 | + h[setting] = if type then ActsAsHavingSettings.type_cast value, type else value end | ||
82 | + end | ||
83 | + end | ||
84 | + end | ||
85 | + | ||
86 | + end | ||
87 | + | ||
88 | +end | ||
89 | + |
@@ -0,0 +1,57 @@ | @@ -0,0 +1,57 @@ | ||
1 | +module CodeNumbering | ||
2 | + module ClassMethods | ||
3 | + def code_numbering field, options = {} | ||
4 | + class_attribute :code_numbering_field | ||
5 | + class_attribute :code_numbering_options | ||
6 | + | ||
7 | + self.code_numbering_field = field | ||
8 | + self.code_numbering_options = options | ||
9 | + | ||
10 | + before_create :create_code_numbering | ||
11 | + | ||
12 | + include CodeNumbering::InstanceMethods | ||
13 | + end | ||
14 | + end | ||
15 | + | ||
16 | + module InstanceMethods | ||
17 | + | ||
18 | + def code | ||
19 | + self.attributes[self.code_numbering_field.to_s] | ||
20 | + end | ||
21 | + | ||
22 | + def code_scope | ||
23 | + scope = self.code_numbering_options[:scope] | ||
24 | + case scope | ||
25 | + when Symbol | ||
26 | + self.send scope | ||
27 | + when Proc | ||
28 | + instance_exec &scope | ||
29 | + else | ||
30 | + self.class | ||
31 | + end | ||
32 | + end | ||
33 | + | ||
34 | + def code_maximum | ||
35 | + self.code_scope.maximum(self.code_numbering_field) || 0 | ||
36 | + end | ||
37 | + | ||
38 | + def create_code_numbering | ||
39 | + max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start] | ||
40 | + max = self.code_maximum | ||
41 | + self.send "#{self.code_numbering_field}=", max+1 | ||
42 | + end | ||
43 | + | ||
44 | + def reset_scope_code_numbering | ||
45 | + max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start] | ||
46 | + max ||= 1 | ||
47 | + | ||
48 | + self.code_scope.order(:created_at).each do |record| | ||
49 | + record.update_column self.code_numbering_field, max | ||
50 | + max += 1 | ||
51 | + end | ||
52 | + self.reload | ||
53 | + end | ||
54 | + | ||
55 | + end | ||
56 | +end | ||
57 | + |
@@ -0,0 +1,124 @@ | @@ -0,0 +1,124 @@ | ||
1 | +module Customizable | ||
2 | + | ||
3 | + def self.included(base) | ||
4 | + base.attr_accessible :custom_values | ||
5 | + base.extend ClassMethods | ||
6 | + end | ||
7 | + | ||
8 | + module ClassMethods | ||
9 | + def acts_as_customizable(options = {}) | ||
10 | + attr_accessor :custom_values | ||
11 | + has_many :custom_field_values, :dependent => :delete_all, :as => :customized | ||
12 | + send :include, Customizable::InstanceMethods | ||
13 | + after_save :save_custom_values | ||
14 | + validate :valid_custom_values? | ||
15 | + end | ||
16 | + | ||
17 | + def active_custom_fields environment | ||
18 | + environment.custom_fields.select{|cf| customized_ancestors_list.include?(cf.customized_type) && cf.active} | ||
19 | + end | ||
20 | + | ||
21 | + def required_custom_fields environment | ||
22 | + environment.custom_fields.select{|cf| customized_ancestors_list.include?(cf.customized_type) && cf.required} | ||
23 | + end | ||
24 | + | ||
25 | + def signup_custom_fields environment | ||
26 | + environment.custom_fields.select{|cf| customized_ancestors_list.include?(cf.customized_type) && cf.signup} | ||
27 | + end | ||
28 | + | ||
29 | + def custom_fields environment | ||
30 | + environment.custom_fields.select{|cf| customized_ancestors_list.include?(cf.customized_type)} | ||
31 | + end | ||
32 | + | ||
33 | + def customized_ancestors_list | ||
34 | + current=self | ||
35 | + result=[] | ||
36 | + while current.instance_methods.include? :custom_value do | ||
37 | + result << current.name | ||
38 | + current=current.superclass | ||
39 | + end | ||
40 | + result | ||
41 | + end | ||
42 | + | ||
43 | + end | ||
44 | + | ||
45 | + module InstanceMethods | ||
46 | + | ||
47 | + def valid_custom_values? | ||
48 | + is_valid = true | ||
49 | + parse_custom_values.each do |cv| | ||
50 | + unless cv.valid? | ||
51 | + name = cv.custom_field.name | ||
52 | + errors.add(name, cv.errors.messages[name.to_sym].first) | ||
53 | + is_valid = false | ||
54 | + end | ||
55 | + end | ||
56 | + is_valid | ||
57 | + end | ||
58 | + | ||
59 | + def customized_class | ||
60 | + current=self.class | ||
61 | + while current.instance_methods.include? :custom_fields do | ||
62 | + result=current | ||
63 | + current=current.superclass | ||
64 | + end | ||
65 | + result.name | ||
66 | + end | ||
67 | + | ||
68 | + def is_public(field_name) | ||
69 | + cv = self.custom_field_values.detect{|cv| cv.custom_field.name==field_name} | ||
70 | + cv.nil? ? false : cv.public | ||
71 | + end | ||
72 | + | ||
73 | + def public_values | ||
74 | + self.custom_field_values.select{|cv| cv.public} | ||
75 | + end | ||
76 | + | ||
77 | + def custom_value(field_name) | ||
78 | + cv = self.custom_field_values.detect{|cv| cv.custom_field.name==field_name} | ||
79 | + cv.nil? ? default_value_for(field_name) : cv.value | ||
80 | + end | ||
81 | + | ||
82 | + def default_value_for(field_name) | ||
83 | + field=self.class.custom_fields(environment).detect {|c| c.name == field_name} | ||
84 | + field.nil? ? nil : field.default_value | ||
85 | + end | ||
86 | + | ||
87 | + def parse_custom_values | ||
88 | + return_list = [] | ||
89 | + return return_list if custom_values.blank? | ||
90 | + custom_values.each_pair do |key, value| | ||
91 | + custom_field = environment.custom_fields.detect{|cf|cf.name==key} | ||
92 | + next if custom_field.blank? | ||
93 | + custom_field_value = self.custom_field_values(true).detect{|cv| cv.custom_field.name==key} | ||
94 | + | ||
95 | + if custom_field_value.nil? | ||
96 | + custom_field_value = CustomFieldValue.new | ||
97 | + custom_field_value.custom_field = custom_field | ||
98 | + custom_field_value.customized = self | ||
99 | + end | ||
100 | + | ||
101 | + if value.is_a?(Hash) | ||
102 | + custom_field_value.value = value['value'].to_s | ||
103 | + if value.has_key?('public') | ||
104 | + is_public = value['public']=="true" || value['public']==true | ||
105 | + custom_field_value.public = is_public | ||
106 | + else | ||
107 | + custom_field_value.public = false | ||
108 | + end | ||
109 | + else | ||
110 | + custom_field_value.value = value.to_s | ||
111 | + custom_field_value.public = false | ||
112 | + end | ||
113 | + return_list << custom_field_value | ||
114 | + end | ||
115 | + return_list | ||
116 | + end | ||
117 | + | ||
118 | + def save_custom_values | ||
119 | + parse_custom_values.each(&:save) | ||
120 | + end | ||
121 | + | ||
122 | + end | ||
123 | +end | ||
124 | + |
@@ -0,0 +1,55 @@ | @@ -0,0 +1,55 @@ | ||
1 | +module DelayedAttachmentFu | ||
2 | + | ||
3 | + module ClassMethods | ||
4 | + def delay_attachment_fu_thumbnails | ||
5 | + include DelayedAttachmentFu::InstanceMethods | ||
6 | + after_create do |file| | ||
7 | + if file.thumbnailable? | ||
8 | + Delayed::Job.enqueue CreateThumbnailsJob.new(file.class.name, file.id) | ||
9 | + end | ||
10 | + end | ||
11 | + end | ||
12 | + end | ||
13 | + | ||
14 | + module InstanceMethods | ||
15 | + # skip processing with RMagick | ||
16 | + def process_attachment | ||
17 | + end | ||
18 | + | ||
19 | + def after_process_attachment | ||
20 | + save_to_storage | ||
21 | + @temp_paths.clear | ||
22 | + @saved_attachment = nil | ||
23 | + run_callbacks :after_attachment_saved | ||
24 | + end | ||
25 | + | ||
26 | + def create_thumbnails | ||
27 | + if thumbnailable? | ||
28 | + self.class.with_image(full_filename) do |img| | ||
29 | + self.width = img.columns | ||
30 | + self.height = img.rows | ||
31 | + self.save! | ||
32 | + end | ||
33 | + self.class.attachment_options[:thumbnails].each do |suffix, size| | ||
34 | + self.create_or_update_thumbnail(self.full_filename, suffix, size) | ||
35 | + end | ||
36 | + self.thumbnails_processed = true | ||
37 | + self.save! | ||
38 | + end | ||
39 | + end | ||
40 | + | ||
41 | + def public_filename(size=nil) | ||
42 | + force, size = true, nil if size == :uploaded | ||
43 | + if !self.thumbnailable? || self.thumbnails_processed || force | ||
44 | + super size | ||
45 | + else | ||
46 | + size ||= :thumb | ||
47 | + '/images/icons-app/image-loading-%s.png' % size | ||
48 | + end | ||
49 | + end | ||
50 | + | ||
51 | + | ||
52 | + end | ||
53 | +end | ||
54 | + | ||
55 | + |
app/models/concerns/set_profile_region_from_city_state.rb
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +module SetProfileRegionFromCityState | ||
2 | + | ||
3 | + module ClassMethods | ||
4 | + def set_profile_region_from_city_state | ||
5 | + before_save :region_from_city_and_state | ||
6 | + | ||
7 | + include InstanceMethods | ||
8 | + alias_method_chain :city=, :region | ||
9 | + alias_method_chain :state=, :region | ||
10 | + end | ||
11 | + end | ||
12 | + | ||
13 | + module InstanceMethods | ||
14 | + include Noosfero::Plugin::HotSpot | ||
15 | + | ||
16 | + def city_with_region=(value) | ||
17 | + self.city_without_region = value | ||
18 | + @change_region = true | ||
19 | + end | ||
20 | + | ||
21 | + def state_with_region=(value) | ||
22 | + self.state_without_region = value | ||
23 | + @change_region = true | ||
24 | + end | ||
25 | + | ||
26 | + def region_from_city_and_state | ||
27 | + if @change_region | ||
28 | + self.region = nil | ||
29 | + state = search_region(State, self.state) | ||
30 | + self.region = search_region(City.where(:parent_id => state.id), self.city) if state | ||
31 | + end | ||
32 | + end | ||
33 | + | ||
34 | + private | ||
35 | + | ||
36 | + def search_region(scope, query) | ||
37 | + return nil if !query | ||
38 | + query = query.downcase.strip | ||
39 | + scope.where(['lower(name)=? OR lower(abbreviation)=? OR lower(acronym)=?', query, query, query]).first | ||
40 | + end | ||
41 | + | ||
42 | + end | ||
43 | + | ||
44 | +end |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +module WhiteListFilter | ||
2 | + | ||
3 | + def check_iframe_on_content(content, trusted_sites) | ||
4 | + if content.blank? || !content.include?('iframe') | ||
5 | + return content | ||
6 | + end | ||
7 | + content.gsub!(/<iframe[^>]*>\s*<\/iframe>/i) do |iframe| | ||
8 | + result = '' | ||
9 | + unless iframe =~ /src=['"].*src=['"]/ | ||
10 | + trusted_sites.each do |trusted_site| | ||
11 | + re_dom = trusted_site.gsub('.', '\.') | ||
12 | + if iframe =~ /src=["'](https?:)?\/\/(www\.)?#{re_dom}\// | ||
13 | + result = iframe | ||
14 | + end | ||
15 | + end | ||
16 | + end | ||
17 | + result | ||
18 | + end | ||
19 | + content | ||
20 | + end | ||
21 | + | ||
22 | + module ClassMethods | ||
23 | + def filter_iframes(*opts) | ||
24 | + options = opts.last.is_a?(Hash) && opts.pop || {} | ||
25 | + white_list_method = options[:whitelist] || :iframe_whitelist | ||
26 | + opts.each do |field| | ||
27 | + before_validation do |obj| | ||
28 | + obj.check_iframe_on_content(obj.send(field), obj.send(white_list_method)) | ||
29 | + end | ||
30 | + end | ||
31 | + end | ||
32 | + end | ||
33 | + | ||
34 | + def self.included(c) | ||
35 | + c.send(:extend, WhiteListFilter::ClassMethods) | ||
36 | + end | ||
37 | +end |
app/models/create_community.rb
@@ -12,6 +12,7 @@ class CreateCommunity < Task | @@ -12,6 +12,7 @@ class CreateCommunity < Task | ||
12 | attr_accessible :environment, :requestor, :target | 12 | attr_accessible :environment, :requestor, :target |
13 | attr_accessible :reject_explanation, :template_id | 13 | attr_accessible :reject_explanation, :template_id |
14 | 14 | ||
15 | + extend ActsAsHavingImage::ClassMethods | ||
15 | acts_as_having_image | 16 | acts_as_having_image |
16 | 17 | ||
17 | DATA_FIELDS = Community.fields + ['name', 'closed', 'description'] | 18 | DATA_FIELDS = Community.fields + ['name', 'closed', 'description'] |
app/models/environment.rb
@@ -200,6 +200,7 @@ class Environment < ApplicationRecord | @@ -200,6 +200,7 @@ class Environment < ApplicationRecord | ||
200 | # Relationships and applied behaviour | 200 | # Relationships and applied behaviour |
201 | # ################################################# | 201 | # ################################################# |
202 | 202 | ||
203 | + extend ActsAsHavingBoxes::ClassMethods | ||
203 | acts_as_having_boxes | 204 | acts_as_having_boxes |
204 | 205 | ||
205 | after_create do |env| | 206 | after_create do |env| |
@@ -251,7 +252,8 @@ class Environment < ApplicationRecord | @@ -251,7 +252,8 @@ class Environment < ApplicationRecord | ||
251 | # ################################################# | 252 | # ################################################# |
252 | 253 | ||
253 | # store the Environment settings as YAML-serialized Hash. | 254 | # store the Environment settings as YAML-serialized Hash. |
254 | - acts_as_having_settings :field => :settings | 255 | + extend ActsAsHavingSettings::ClassMethods |
256 | + acts_as_having_settings field: :settings | ||
255 | 257 | ||
256 | # introduce and explain to users something about the signup | 258 | # introduce and explain to users something about the signup |
257 | settings_items :signup_intro, :type => String | 259 | settings_items :signup_intro, :type => String |
app/models/event.rb
1 | -require 'noosfero/translatable_content' | ||
2 | require 'builder' | 1 | require 'builder' |
3 | 2 | ||
4 | class Event < Article | 3 | class Event < Article |
@@ -139,7 +138,7 @@ class Event < Article | @@ -139,7 +138,7 @@ class Event < Article | ||
139 | false | 138 | false |
140 | end | 139 | end |
141 | 140 | ||
142 | - include Noosfero::TranslatableContent | 141 | + include TranslatableContent |
143 | include MaybeAddHttp | 142 | include MaybeAddHttp |
144 | 143 | ||
145 | end | 144 | end |
app/models/folder.rb
@@ -10,7 +10,8 @@ class Folder < Article | @@ -10,7 +10,8 @@ class Folder < Article | ||
10 | errors.add(:parent, "A folder should not belong to a blog.") if parent && parent.blog? | 10 | errors.add(:parent, "A folder should not belong to a blog.") if parent && parent.blog? |
11 | end | 11 | end |
12 | 12 | ||
13 | - acts_as_having_settings :field => :setting | 13 | + extend ActsAsHavingSettings::ClassMethods |
14 | + acts_as_having_settings field: :setting | ||
14 | 15 | ||
15 | xss_terminate :only => [ :name, :body ], :with => 'white_list', :on => 'validation' | 16 | xss_terminate :only => [ :name, :body ], :with => 'white_list', :on => 'validation' |
16 | 17 |
app/models/forum.rb
1 | class Forum < Folder | 1 | class Forum < Folder |
2 | 2 | ||
3 | + extend ActsAsHavingPosts::ClassMethods | ||
3 | acts_as_having_posts -> { reorder 'updated_at DESC' } | 4 | acts_as_having_posts -> { reorder 'updated_at DESC' } |
5 | + | ||
4 | include PostsLimit | 6 | include PostsLimit |
5 | 7 | ||
6 | attr_accessible :has_terms_of_use, :terms_of_use, :topic_creation | 8 | attr_accessible :has_terms_of_use, :terms_of_use, :topic_creation |
app/models/image.rb
@@ -23,6 +23,7 @@ class Image < ApplicationRecord | @@ -23,6 +23,7 @@ class Image < ApplicationRecord | ||
23 | 23 | ||
24 | validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of 5.0 MB").fix_i18n | 24 | validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of 5.0 MB").fix_i18n |
25 | 25 | ||
26 | + extend DelayedAttachmentFu::ClassMethods | ||
26 | delay_attachment_fu_thumbnails | 27 | delay_attachment_fu_thumbnails |
27 | 28 | ||
28 | postgresql_attachment_fu | 29 | postgresql_attachment_fu |
app/models/profile.rb
@@ -8,6 +8,13 @@ class Profile < ApplicationRecord | @@ -8,6 +8,13 @@ class Profile < ApplicationRecord | ||
8 | :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification, | 8 | :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification, |
9 | :custom_fields, :region, :region_id | 9 | :custom_fields, :region, :region_id |
10 | 10 | ||
11 | + extend ActsAsHavingSettings::ClassMethods | ||
12 | + acts_as_having_settings field: :data | ||
13 | + | ||
14 | + def settings | ||
15 | + data | ||
16 | + end | ||
17 | + | ||
11 | # use for internationalizable human type names in search facets | 18 | # use for internationalizable human type names in search facets |
12 | # reimplement on subclasses | 19 | # reimplement on subclasses |
13 | def self.type_name | 20 | def self.type_name |
@@ -117,6 +124,8 @@ class Profile < ApplicationRecord | @@ -117,6 +124,8 @@ class Profile < ApplicationRecord | ||
117 | } | 124 | } |
118 | 125 | ||
119 | acts_as_accessible | 126 | acts_as_accessible |
127 | + | ||
128 | + include Customizable | ||
120 | acts_as_customizable | 129 | acts_as_customizable |
121 | 130 | ||
122 | include Noosfero::Plugin::HotSpot | 131 | include Noosfero::Plugin::HotSpot |
@@ -214,6 +223,7 @@ class Profile < ApplicationRecord | @@ -214,6 +223,7 @@ class Profile < ApplicationRecord | ||
214 | Person.members_of(self).by_role(roles) | 223 | Person.members_of(self).by_role(roles) |
215 | end | 224 | end |
216 | 225 | ||
226 | + extend ActsAsHavingBoxes::ClassMethods | ||
217 | acts_as_having_boxes | 227 | acts_as_having_boxes |
218 | 228 | ||
219 | acts_as_taggable | 229 | acts_as_taggable |
@@ -260,12 +270,6 @@ class Profile < ApplicationRecord | @@ -260,12 +270,6 @@ class Profile < ApplicationRecord | ||
260 | scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) | 270 | scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) |
261 | end | 271 | end |
262 | 272 | ||
263 | - acts_as_having_settings :field => :data | ||
264 | - | ||
265 | - def settings | ||
266 | - data | ||
267 | - end | ||
268 | - | ||
269 | settings_items :redirect_l10n, :type => :boolean, :default => false | 273 | settings_items :redirect_l10n, :type => :boolean, :default => false |
270 | settings_items :public_content, :type => :boolean, :default => true | 274 | settings_items :public_content, :type => :boolean, :default => true |
271 | settings_items :description | 275 | settings_items :description |
@@ -314,6 +318,7 @@ class Profile < ApplicationRecord | @@ -314,6 +318,7 @@ class Profile < ApplicationRecord | ||
314 | 318 | ||
315 | has_many :files, :class_name => 'UploadedFile' | 319 | has_many :files, :class_name => 'UploadedFile' |
316 | 320 | ||
321 | + extend ActsAsHavingImage::ClassMethods | ||
317 | acts_as_having_image | 322 | acts_as_having_image |
318 | 323 | ||
319 | has_many :tasks, :dependent => :destroy, :as => 'target' | 324 | has_many :tasks, :dependent => :destroy, :as => 'target' |
app/models/profile_suggestion.rb
@@ -17,7 +17,8 @@ class ProfileSuggestion < ApplicationRecord | @@ -17,7 +17,8 @@ class ProfileSuggestion < ApplicationRecord | ||
17 | self.class.generate_profile_suggestions(profile_suggestion.person) | 17 | self.class.generate_profile_suggestions(profile_suggestion.person) |
18 | end | 18 | end |
19 | 19 | ||
20 | - acts_as_having_settings :field => :categories | 20 | + extend ActsAsHavingSettings::ClassMethods |
21 | + acts_as_having_settings field: :categories | ||
21 | 22 | ||
22 | validate :must_be_a_valid_category, :on => :create | 23 | validate :must_be_a_valid_category, :on => :create |
23 | def must_be_a_valid_category | 24 | def must_be_a_valid_category |
app/models/task.rb
@@ -11,7 +11,8 @@ | @@ -11,7 +11,8 @@ | ||
11 | # will need to declare <ttserialize</tt> itself). | 11 | # will need to declare <ttserialize</tt> itself). |
12 | class Task < ApplicationRecord | 12 | class Task < ApplicationRecord |
13 | 13 | ||
14 | - acts_as_having_settings :field => :data | 14 | + extend ActsAsHavingSettings::ClassMethods |
15 | + acts_as_having_settings field: :data | ||
15 | acts_as_ordered_taggable | 16 | acts_as_ordered_taggable |
16 | 17 | ||
17 | module Status | 18 | module Status |
app/models/text_article.rb
1 | -require 'noosfero/translatable_content' | ||
2 | - | ||
3 | # a base class for all text article types. | 1 | # a base class for all text article types. |
4 | class TextArticle < Article | 2 | class TextArticle < Article |
5 | 3 | ||
@@ -9,7 +7,7 @@ class TextArticle < Article | @@ -9,7 +7,7 @@ class TextArticle < Article | ||
9 | _('Article') | 7 | _('Article') |
10 | end | 8 | end |
11 | 9 | ||
12 | - include Noosfero::TranslatableContent | 10 | + include TranslatableContent |
13 | 11 | ||
14 | def self.icon_name(article = nil) | 12 | def self.icon_name(article = nil) |
15 | if article && !article.parent.nil? && article.parent.kind_of?(Blog) | 13 | if article && !article.parent.nil? && article.parent.kind_of?(Blog) |
app/models/tiny_mce_article.rb
app/models/uploaded_file.rb
@@ -84,6 +84,7 @@ class UploadedFile < Article | @@ -84,6 +84,7 @@ class UploadedFile < Article | ||
84 | 84 | ||
85 | validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of %{size}").sub('%{size}', self.max_size.to_humanreadable).fix_i18n | 85 | validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of %{size}").sub('%{size}', self.max_size.to_humanreadable).fix_i18n |
86 | 86 | ||
87 | + extend DelayedAttachmentFu::ClassMethods | ||
87 | delay_attachment_fu_thumbnails | 88 | delay_attachment_fu_thumbnails |
88 | 89 | ||
89 | postgresql_attachment_fu | 90 | postgresql_attachment_fu |
config/initializers/00_dependencies.rb
@@ -16,15 +16,6 @@ end | @@ -16,15 +16,6 @@ end | ||
16 | require 'extensions' | 16 | require 'extensions' |
17 | 17 | ||
18 | # locally-developed modules | 18 | # locally-developed modules |
19 | -require 'acts_as_filesystem' | ||
20 | -require 'acts_as_having_settings' | ||
21 | -require 'acts_as_having_boxes' | ||
22 | -require 'acts_as_having_image' | ||
23 | -require 'acts_as_having_posts' | ||
24 | -require 'acts_as_customizable' | ||
25 | require 'route_if' | 19 | require 'route_if' |
26 | require 'maybe_add_http' | 20 | require 'maybe_add_http' |
27 | -require 'set_profile_region_from_city_state' | ||
28 | -require 'needs_profile' | ||
29 | -require 'white_list_filter' | ||
30 | 21 |
config/initializers/delayed_attachment_fu.rb
@@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
1 | -require 'delayed_attachment_fu' |
db/migrate/20160422163123_enable_products_plugin_on_environments.rb
@@ -7,6 +7,7 @@ class Environment < ApplicationRecord | @@ -7,6 +7,7 @@ class Environment < ApplicationRecord | ||
7 | has_many :profiles | 7 | has_many :profiles |
8 | has_many :products, through: :profiles | 8 | has_many :products, through: :profiles |
9 | 9 | ||
10 | + extend ActsAsHavingSettings::ClassMethods | ||
10 | acts_as_having_settings field: :settings | 11 | acts_as_having_settings field: :settings |
11 | settings_items :enabled_plugins, type: Array | 12 | settings_items :enabled_plugins, type: Array |
12 | end | 13 | end |
lib/acts_as_customizable.rb
@@ -1,125 +0,0 @@ | @@ -1,125 +0,0 @@ | ||
1 | -module Customizable | ||
2 | - | ||
3 | - def self.included(base) | ||
4 | - base.attr_accessible :custom_values | ||
5 | - base.extend ClassMethods | ||
6 | - end | ||
7 | - | ||
8 | - module ClassMethods | ||
9 | - def acts_as_customizable(options = {}) | ||
10 | - attr_accessor :custom_values | ||
11 | - has_many :custom_field_values, :dependent => :delete_all, :as => :customized | ||
12 | - send :include, Customizable::InstanceMethods | ||
13 | - after_save :save_custom_values | ||
14 | - validate :valid_custom_values? | ||
15 | - end | ||
16 | - | ||
17 | - def active_custom_fields environment | ||
18 | - environment.custom_fields.select{|cf| customized_ancestors_list.include?(cf.customized_type) && cf.active} | ||
19 | - end | ||
20 | - | ||
21 | - def required_custom_fields environment | ||
22 | - environment.custom_fields.select{|cf| customized_ancestors_list.include?(cf.customized_type) && cf.required} | ||
23 | - end | ||
24 | - | ||
25 | - def signup_custom_fields environment | ||
26 | - environment.custom_fields.select{|cf| customized_ancestors_list.include?(cf.customized_type) && cf.signup} | ||
27 | - end | ||
28 | - | ||
29 | - def custom_fields environment | ||
30 | - environment.custom_fields.select{|cf| customized_ancestors_list.include?(cf.customized_type)} | ||
31 | - end | ||
32 | - | ||
33 | - def customized_ancestors_list | ||
34 | - current=self | ||
35 | - result=[] | ||
36 | - while current.instance_methods.include? :custom_value do | ||
37 | - result << current.name | ||
38 | - current=current.superclass | ||
39 | - end | ||
40 | - result | ||
41 | - end | ||
42 | - | ||
43 | - end | ||
44 | - | ||
45 | - module InstanceMethods | ||
46 | - | ||
47 | - def valid_custom_values? | ||
48 | - is_valid = true | ||
49 | - parse_custom_values.each do |cv| | ||
50 | - unless cv.valid? | ||
51 | - name = cv.custom_field.name | ||
52 | - errors.add(name, cv.errors.messages[name.to_sym].first) | ||
53 | - is_valid = false | ||
54 | - end | ||
55 | - end | ||
56 | - is_valid | ||
57 | - end | ||
58 | - | ||
59 | - def customized_class | ||
60 | - current=self.class | ||
61 | - while current.instance_methods.include? :custom_fields do | ||
62 | - result=current | ||
63 | - current=current.superclass | ||
64 | - end | ||
65 | - result.name | ||
66 | - end | ||
67 | - | ||
68 | - def is_public(field_name) | ||
69 | - cv = self.custom_field_values.detect{|cv| cv.custom_field.name==field_name} | ||
70 | - cv.nil? ? false : cv.public | ||
71 | - end | ||
72 | - | ||
73 | - def public_values | ||
74 | - self.custom_field_values.select{|cv| cv.public} | ||
75 | - end | ||
76 | - | ||
77 | - def custom_value(field_name) | ||
78 | - cv = self.custom_field_values.detect{|cv| cv.custom_field.name==field_name} | ||
79 | - cv.nil? ? default_value_for(field_name) : cv.value | ||
80 | - end | ||
81 | - | ||
82 | - def default_value_for(field_name) | ||
83 | - field=self.class.custom_fields(environment).detect {|c| c.name == field_name} | ||
84 | - field.nil? ? nil : field.default_value | ||
85 | - end | ||
86 | - | ||
87 | - def parse_custom_values | ||
88 | - return_list = [] | ||
89 | - return return_list if custom_values.blank? | ||
90 | - custom_values.each_pair do |key, value| | ||
91 | - custom_field = environment.custom_fields.detect{|cf|cf.name==key} | ||
92 | - next if custom_field.blank? | ||
93 | - custom_field_value = self.custom_field_values(true).detect{|cv| cv.custom_field.name==key} | ||
94 | - | ||
95 | - if custom_field_value.nil? | ||
96 | - custom_field_value = CustomFieldValue.new | ||
97 | - custom_field_value.custom_field = custom_field | ||
98 | - custom_field_value.customized = self | ||
99 | - end | ||
100 | - | ||
101 | - if value.is_a?(Hash) | ||
102 | - custom_field_value.value = value['value'].to_s | ||
103 | - if value.has_key?('public') | ||
104 | - is_public = value['public']=="true" || value['public']==true | ||
105 | - custom_field_value.public = is_public | ||
106 | - else | ||
107 | - custom_field_value.public = false | ||
108 | - end | ||
109 | - else | ||
110 | - custom_field_value.value = value.to_s | ||
111 | - custom_field_value.public = false | ||
112 | - end | ||
113 | - return_list << custom_field_value | ||
114 | - end | ||
115 | - return_list | ||
116 | - end | ||
117 | - | ||
118 | - def save_custom_values | ||
119 | - parse_custom_values.each(&:save) | ||
120 | - end | ||
121 | - | ||
122 | - end | ||
123 | -end | ||
124 | - | ||
125 | -ActiveRecord::Base.include Customizable |
lib/acts_as_filesystem.rb
@@ -1,267 +0,0 @@ | @@ -1,267 +0,0 @@ | ||
1 | -module ActsAsFileSystem | ||
2 | - | ||
3 | - module ActsMethods | ||
4 | - | ||
5 | - # Declares the ActiveRecord model to acts like a filesystem: objects are | ||
6 | - # arranged in a tree (liks acts_as_tree), and . The underlying table must | ||
7 | - # have the following fields: | ||
8 | - # | ||
9 | - # * name (+:string+) - the title of the object | ||
10 | - # * slug (+:string+)- the title turned in a URL-friendly string (downcased, | ||
11 | - # non-ascii chars transliterated into ascii, all sequences of | ||
12 | - # non-alphanumericd characters changed into dashed) | ||
13 | - # * path (+:text+)- stores the full path of the object (the full path of | ||
14 | - # the parent, a "/" and the slug of the object) | ||
15 | - # * children_count - a cache of the number of children elements. | ||
16 | - def acts_as_filesystem | ||
17 | - # a filesystem is a tree | ||
18 | - acts_as_tree :counter_cache => :children_count | ||
19 | - | ||
20 | - extend ClassMethods | ||
21 | - include InstanceMethods | ||
22 | - if self.has_path? | ||
23 | - after_update :update_children_path | ||
24 | - before_create :set_path | ||
25 | - include InstanceMethods::PathMethods | ||
26 | - end | ||
27 | - | ||
28 | - before_save :set_ancestry | ||
29 | - end | ||
30 | - | ||
31 | - end | ||
32 | - | ||
33 | - module ClassMethods | ||
34 | - | ||
35 | - def build_ancestry(parent_id = nil, ancestry = '') | ||
36 | - ActiveRecord::Base.transaction do | ||
37 | - self.base_class.where(parent_id: parent_id).each do |node| | ||
38 | - node.update_column :ancestry, ancestry | ||
39 | - | ||
40 | - build_ancestry node.id, (ancestry.empty? ? "#{node.formatted_ancestry_id}" : | ||
41 | - "#{ancestry}#{node.ancestry_sep}#{node.formatted_ancestry_id}") | ||
42 | - end | ||
43 | - end | ||
44 | - | ||
45 | - #raise "Couldn't reach and set ancestry on every record" if self.base_class.where('ancestry is null').count != 0 | ||
46 | - end | ||
47 | - | ||
48 | - def has_path? | ||
49 | - (['name', 'slug', 'path'] - self.column_names).blank? | ||
50 | - end | ||
51 | - | ||
52 | - end | ||
53 | - | ||
54 | - module InstanceMethods | ||
55 | - | ||
56 | - def ancestry_column | ||
57 | - 'ancestry' | ||
58 | - end | ||
59 | - def ancestry_sep | ||
60 | - '.' | ||
61 | - end | ||
62 | - def has_ancestry? | ||
63 | - self.class.column_names.include? self.ancestry_column | ||
64 | - end | ||
65 | - | ||
66 | - def formatted_ancestry_id | ||
67 | - "%010d" % self.id if self.id | ||
68 | - end | ||
69 | - | ||
70 | - def ancestry | ||
71 | - self[ancestry_column] | ||
72 | - end | ||
73 | - def ancestor_ids | ||
74 | - return nil if !has_ancestry? or ancestry.nil? | ||
75 | - @ancestor_ids ||= ancestry.split(ancestry_sep).map{ |id| id.to_i } | ||
76 | - end | ||
77 | - | ||
78 | - def ancestry=(value) | ||
79 | - self[ancestry_column] = value | ||
80 | - end | ||
81 | - def set_ancestry | ||
82 | - return unless self.has_ancestry? | ||
83 | - if self.ancestry.nil? or (new_record? or parent_id_changed?) or recalculate_path | ||
84 | - self.ancestry = self.hierarchy(true)[0...-1].map{ |p| p.formatted_ancestry_id }.join(ancestry_sep) | ||
85 | - end | ||
86 | - end | ||
87 | - | ||
88 | - def descendents_options | ||
89 | - ["#{self.ancestry_column} LIKE ?", "%#{self.formatted_ancestry_id}%"] | ||
90 | - end | ||
91 | - def descendents | ||
92 | - self.class.where descendents_options | ||
93 | - end | ||
94 | - | ||
95 | - # calculates the level of the record in the records hierarchy. Top-level | ||
96 | - # records have level 0; the children of the top-level records have | ||
97 | - # level 1; the children of records with level 1 have level 2, and so on. | ||
98 | - # | ||
99 | - # A level 0 | ||
100 | - # / \ | ||
101 | - # B C level 1 | ||
102 | - # / \ / \ | ||
103 | - # E F G H level 2 | ||
104 | - # ... | ||
105 | - def level | ||
106 | - self.hierarchy.size - 1 | ||
107 | - end | ||
108 | - | ||
109 | - # Is this record a top-level record? | ||
110 | - def top_level? | ||
111 | - self.parent.nil? | ||
112 | - end | ||
113 | - | ||
114 | - # Is this record a leaf in the hierarchy tree of records? | ||
115 | - # | ||
116 | - # Being a leaf means that this record has no subrecord. | ||
117 | - def leaf? | ||
118 | - self.children.empty? | ||
119 | - end | ||
120 | - | ||
121 | - def top_ancestor | ||
122 | - if has_ancestry? and !ancestry.blank? | ||
123 | - self.class.base_class.find_by id: self.top_ancestor_id | ||
124 | - else | ||
125 | - self.hierarchy.first | ||
126 | - end | ||
127 | - end | ||
128 | - def top_ancestor_id | ||
129 | - if has_ancestry? and !ancestry.nil? | ||
130 | - self.ancestor_ids.first | ||
131 | - else | ||
132 | - self.hierarchy.first.id | ||
133 | - end | ||
134 | - end | ||
135 | - | ||
136 | - # returns the full hierarchy from the top-level item to this one. For | ||
137 | - # example, if item1 has a children item2 and item2 has a children item3, | ||
138 | - # then item3's hierarchy would be [item1, item2, item3]. | ||
139 | - # | ||
140 | - # If +reload+ is passed as +true+, then the hierarchy is reload (usefull | ||
141 | - # when the ActiveRecord object was modified in some way, or just after | ||
142 | - # changing parent) | ||
143 | - def hierarchy(reload = false) | ||
144 | - @hierarchy = nil if reload or recalculate_path | ||
145 | - | ||
146 | - if @hierarchy.nil? | ||
147 | - @hierarchy = [] | ||
148 | - | ||
149 | - if !reload and !recalculate_path and ancestor_ids | ||
150 | - objects = self.class.base_class.where(id: ancestor_ids) | ||
151 | - ancestor_ids.each{ |id| @hierarchy << objects.find{ |t| t.id == id } } | ||
152 | - @hierarchy << self | ||
153 | - else | ||
154 | - item = self | ||
155 | - while item | ||
156 | - @hierarchy.unshift(item) | ||
157 | - item = item.parent | ||
158 | - end | ||
159 | - end | ||
160 | - end | ||
161 | - | ||
162 | - @hierarchy | ||
163 | - end | ||
164 | - | ||
165 | - def map_traversal(&block) | ||
166 | - result = [] | ||
167 | - current_level = [self] | ||
168 | - | ||
169 | - while !current_level.empty? | ||
170 | - result += current_level | ||
171 | - ids = current_level.select {|item| item.children_count > 0}.map(&:id) | ||
172 | - break if ids.empty? | ||
173 | - current_level = self.class.base_class.where(parent_id: ids) | ||
174 | - end | ||
175 | - block ||= (lambda { |x| x }) | ||
176 | - result.map(&block) | ||
177 | - end | ||
178 | - | ||
179 | - def all_children | ||
180 | - res = map_traversal | ||
181 | - res.shift | ||
182 | - res | ||
183 | - end | ||
184 | - | ||
185 | - ##### | ||
186 | - # Path methods | ||
187 | - # These methods are used when _path_, _name_ and _slug_ attributes exist | ||
188 | - # and should be calculated based on the tree | ||
189 | - ##### | ||
190 | - module PathMethods | ||
191 | - # used to know when to trigger batch renaming | ||
192 | - attr_accessor :recalculate_path | ||
193 | - | ||
194 | - # calculates the full path to this record using parent's path. | ||
195 | - def calculate_path | ||
196 | - self.hierarchy.map{ |obj| obj.slug }.join('/') | ||
197 | - end | ||
198 | - def set_path | ||
199 | - if self.path == self.slug && !self.top_level? | ||
200 | - self.path = self.calculate_path | ||
201 | - end | ||
202 | - end | ||
203 | - def explode_path | ||
204 | - path.split(/\//) | ||
205 | - end | ||
206 | - | ||
207 | - def update_children_path | ||
208 | - if self.recalculate_path | ||
209 | - self.children.each do |child| | ||
210 | - child.path = child.calculate_path | ||
211 | - child.recalculate_path = true | ||
212 | - child.save! | ||
213 | - end | ||
214 | - end | ||
215 | - self.recalculate_path = false | ||
216 | - end | ||
217 | - | ||
218 | - # calculates the full name of a record by accessing the name of all its | ||
219 | - # ancestors. | ||
220 | - # | ||
221 | - # If you have this record hierarchy: | ||
222 | - # Record "A" | ||
223 | - # Record "B" | ||
224 | - # Record "C" | ||
225 | - # | ||
226 | - # Then Record "C" will have "A/B/C" as its full name. | ||
227 | - def full_name(sep = '/') | ||
228 | - self.hierarchy.map {|item| item.name || '?' }.join(sep) | ||
229 | - end | ||
230 | - | ||
231 | - # gets the name without leading parents. Useful when dividing records | ||
232 | - # in top-level groups and full names must not include the top-level | ||
233 | - # record which is already a emphasized label | ||
234 | - def full_name_without_leading(count, sep = '/') | ||
235 | - parts = self.full_name(sep).split(sep) | ||
236 | - count.times { parts.shift } | ||
237 | - parts.join(sep) | ||
238 | - end | ||
239 | - | ||
240 | - def set_name(value) | ||
241 | - if self.name != value | ||
242 | - self.recalculate_path = true | ||
243 | - end | ||
244 | - self[:name] = value | ||
245 | - end | ||
246 | - | ||
247 | - # sets the name of the record. Also sets #slug accordingly. | ||
248 | - def name=(value) | ||
249 | - self.set_name(value) | ||
250 | - unless self.name.blank? | ||
251 | - self.slug = self.name.to_slug | ||
252 | - end | ||
253 | - end | ||
254 | - | ||
255 | - # sets the slug of the record. Also sets the path with the new slug value. | ||
256 | - def slug=(value) | ||
257 | - self[:slug] = value | ||
258 | - unless self.slug.blank? | ||
259 | - self.path = self.calculate_path | ||
260 | - end | ||
261 | - end | ||
262 | - end | ||
263 | - end | ||
264 | -end | ||
265 | - | ||
266 | -ActiveRecord::Base.extend ActsAsFileSystem::ActsMethods | ||
267 | - |
lib/acts_as_having_boxes.rb
@@ -1,38 +0,0 @@ | @@ -1,38 +0,0 @@ | ||
1 | -module ActsAsHavingBoxes | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - def acts_as_having_boxes | ||
5 | - has_many :boxes, -> { order :position }, as: :owner, dependent: :destroy | ||
6 | - self.send(:include, ActsAsHavingBoxes) | ||
7 | - end | ||
8 | - end | ||
9 | - | ||
10 | - module BlockArray | ||
11 | - def find(id) | ||
12 | - select { |item| item.id == id.to_i }.first | ||
13 | - end | ||
14 | - end | ||
15 | - | ||
16 | - def blocks(reload = false) | ||
17 | - if (reload) | ||
18 | - @blocks = nil | ||
19 | - end | ||
20 | - if @blocks.nil? | ||
21 | - @blocks = boxes.includes(:blocks).inject([]) do |acc,obj| | ||
22 | - acc.concat(obj.blocks) | ||
23 | - end | ||
24 | - @blocks.send(:extend, BlockArray) | ||
25 | - end | ||
26 | - @blocks | ||
27 | - end | ||
28 | - | ||
29 | - # returns 3 unless the class table has a boxes_limit column. In that case | ||
30 | - # return the value of the column. | ||
31 | - def boxes_limit layout_template = nil | ||
32 | - layout_template ||= self.layout_template | ||
33 | - @boxes_limit ||= LayoutTemplate.find(layout_template).number_of_boxes || 3 | ||
34 | - end | ||
35 | - | ||
36 | -end | ||
37 | - | ||
38 | -ActiveRecord::Base.extend ActsAsHavingBoxes::ClassMethods |
lib/acts_as_having_image.rb
@@ -1,27 +0,0 @@ | @@ -1,27 +0,0 @@ | ||
1 | -module ActsAsHavingImage | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - def acts_as_having_image | ||
5 | - belongs_to :image, dependent: :destroy | ||
6 | - scope :with_image, -> { where "#{table_name}.image_id IS NOT NULL" } | ||
7 | - scope :without_image, -> { where "#{table_name}.image_id IS NULL" } | ||
8 | - attr_accessible :image_builder | ||
9 | - include ActsAsHavingImage | ||
10 | - end | ||
11 | - end | ||
12 | - | ||
13 | - def image_builder=(img) | ||
14 | - if image && image.id == img[:id] | ||
15 | - image.attributes = img | ||
16 | - else | ||
17 | - build_image(img) | ||
18 | - end unless img[:uploaded_data].blank? | ||
19 | - if img[:remove_image] == 'true' | ||
20 | - self.image_id = nil | ||
21 | - end | ||
22 | - end | ||
23 | - | ||
24 | -end | ||
25 | - | ||
26 | -ActiveRecord::Base.extend ActsAsHavingImage::ClassMethods | ||
27 | - |
lib/acts_as_having_posts.rb
@@ -1,51 +0,0 @@ | @@ -1,51 +0,0 @@ | ||
1 | -module ActsAsHavingPosts | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - def acts_as_having_posts(scope = nil) | ||
5 | - has_many :posts, -> { | ||
6 | - s = order('published_at DESC, id DESC').where('articles.type != ?', 'RssFeed') | ||
7 | - s = s.instance_exec(&scope) if scope | ||
8 | - s | ||
9 | - }, class_name: 'Article', foreign_key: 'parent_id', source: :children | ||
10 | - | ||
11 | - attr_accessor :feed_attrs | ||
12 | - | ||
13 | - after_create do |blog| | ||
14 | - blog.children << RssFeed.new(:name => 'feed', :profile => blog.profile) | ||
15 | - blog.feed = blog.feed_attrs | ||
16 | - end | ||
17 | - | ||
18 | - settings_items :posts_per_page, :type => :integer, :default => 5 | ||
19 | - | ||
20 | - self.send(:include, ActsAsHavingPosts) | ||
21 | - end | ||
22 | - end | ||
23 | - | ||
24 | - def has_posts? | ||
25 | - true | ||
26 | - end | ||
27 | - | ||
28 | - def feed | ||
29 | - children.where(:type => 'RssFeed').first | ||
30 | - end | ||
31 | - | ||
32 | - def feed=(attrs) | ||
33 | - if attrs | ||
34 | - if self.feed | ||
35 | - self.feed.update(attrs) | ||
36 | - else | ||
37 | - self.feed_attrs = attrs | ||
38 | - end | ||
39 | - end | ||
40 | - self.feed | ||
41 | - end | ||
42 | - | ||
43 | - def name=(value) | ||
44 | - self.set_name(value) | ||
45 | - self.slug = self.slug.blank? ? self.name.to_slug : self.slug.to_slug | ||
46 | - end | ||
47 | - | ||
48 | -end | ||
49 | - | ||
50 | -ActiveRecord::Base.extend ActsAsHavingPosts::ClassMethods | ||
51 | - |
lib/acts_as_having_settings.rb
@@ -1,91 +0,0 @@ | @@ -1,91 +0,0 @@ | ||
1 | -# declare missing types | ||
2 | -module ActiveRecord | ||
3 | - module Type | ||
4 | - class Symbol < Value | ||
5 | - def cast_value value | ||
6 | - value.to_sym | ||
7 | - end | ||
8 | - end | ||
9 | - class Array < Value | ||
10 | - def cast_value value | ||
11 | - ::Array.wrap(value) | ||
12 | - end | ||
13 | - end | ||
14 | - class Hash < Value | ||
15 | - def cast_value value | ||
16 | - h = ::Hash[value] | ||
17 | - h.symbolize_keys! | ||
18 | - h | ||
19 | - end | ||
20 | - end | ||
21 | - end | ||
22 | -end | ||
23 | - | ||
24 | -module ActsAsHavingSettings | ||
25 | - | ||
26 | - def self.type_cast value, type | ||
27 | - # do not cast nil | ||
28 | - return value if value.nil? | ||
29 | - type.send :cast_value, value | ||
30 | - end | ||
31 | - | ||
32 | - module ClassMethods | ||
33 | - | ||
34 | - def acts_as_having_settings(*args) | ||
35 | - options = args.last.is_a?(Hash) ? args.pop : {} | ||
36 | - field = (options[:field] || :settings).to_sym | ||
37 | - | ||
38 | - serialize field, Hash | ||
39 | - class_attribute :settings_field | ||
40 | - self.settings_field = field | ||
41 | - | ||
42 | - class_eval do | ||
43 | - def settings_field | ||
44 | - self[self.class.settings_field] ||= Hash.new | ||
45 | - end | ||
46 | - | ||
47 | - def setting_changed? setting_field | ||
48 | - setting_field = setting_field.to_sym | ||
49 | - changed_settings = self.changes[self.class.settings_field] | ||
50 | - return false if changed_settings.nil? | ||
51 | - | ||
52 | - old_setting_value = changed_settings.first.nil? ? nil : changed_settings.first[setting_field] | ||
53 | - new_setting_value = changed_settings.last[setting_field] | ||
54 | - old_setting_value != new_setting_value | ||
55 | - end | ||
56 | - end | ||
57 | - | ||
58 | - settings_items *args | ||
59 | - end | ||
60 | - | ||
61 | - def settings_items *names | ||
62 | - | ||
63 | - options = names.extract_options! | ||
64 | - default = options[:default] | ||
65 | - type = options[:type] | ||
66 | - type = if type.present? then ActiveRecord::Type.const_get(type.to_s.camelize.to_sym).new else nil end | ||
67 | - | ||
68 | - names.each do |setting| | ||
69 | - # symbolize key | ||
70 | - setting = setting.to_sym | ||
71 | - | ||
72 | - define_method setting do | ||
73 | - h = send self.class.settings_field | ||
74 | - val = h[setting] | ||
75 | - # translate default value if it is used | ||
76 | - if not val.nil? then val elsif default.is_a? String then gettext default else default end | ||
77 | - end | ||
78 | - | ||
79 | - define_method "#{setting}=" do |value| | ||
80 | - h = send self.class.settings_field | ||
81 | - h[setting] = if type then ActsAsHavingSettings.type_cast value, type else value end | ||
82 | - end | ||
83 | - end | ||
84 | - end | ||
85 | - | ||
86 | - end | ||
87 | - | ||
88 | -end | ||
89 | - | ||
90 | -ActiveRecord::Base.extend ActsAsHavingSettings::ClassMethods | ||
91 | - |
lib/code_numbering.rb
@@ -1,58 +0,0 @@ | @@ -1,58 +0,0 @@ | ||
1 | -module CodeNumbering | ||
2 | - module ClassMethods | ||
3 | - def code_numbering field, options = {} | ||
4 | - class_attribute :code_numbering_field | ||
5 | - class_attribute :code_numbering_options | ||
6 | - | ||
7 | - self.code_numbering_field = field | ||
8 | - self.code_numbering_options = options | ||
9 | - | ||
10 | - before_create :create_code_numbering | ||
11 | - | ||
12 | - include CodeNumbering::InstanceMethods | ||
13 | - end | ||
14 | - end | ||
15 | - | ||
16 | - module InstanceMethods | ||
17 | - | ||
18 | - def code | ||
19 | - self.attributes[self.code_numbering_field.to_s] | ||
20 | - end | ||
21 | - | ||
22 | - def code_scope | ||
23 | - scope = self.code_numbering_options[:scope] | ||
24 | - case scope | ||
25 | - when Symbol | ||
26 | - self.send scope | ||
27 | - when Proc | ||
28 | - instance_exec &scope | ||
29 | - else | ||
30 | - self.class | ||
31 | - end | ||
32 | - end | ||
33 | - | ||
34 | - def code_maximum | ||
35 | - self.code_scope.maximum(self.code_numbering_field) || 0 | ||
36 | - end | ||
37 | - | ||
38 | - def create_code_numbering | ||
39 | - max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start] | ||
40 | - max = self.code_maximum | ||
41 | - self.send "#{self.code_numbering_field}=", max+1 | ||
42 | - end | ||
43 | - | ||
44 | - def reset_scope_code_numbering | ||
45 | - max = self.code_numbering_options[:start].to_i - 1 if self.code_numbering_options[:start] | ||
46 | - max ||= 1 | ||
47 | - | ||
48 | - self.code_scope.order(:created_at).each do |record| | ||
49 | - record.update_column self.code_numbering_field, max | ||
50 | - max += 1 | ||
51 | - end | ||
52 | - self.reload | ||
53 | - end | ||
54 | - | ||
55 | - end | ||
56 | -end | ||
57 | - | ||
58 | -ActiveRecord::Base.extend CodeNumbering::ClassMethods |
lib/delayed_attachment_fu.rb
@@ -1,56 +0,0 @@ | @@ -1,56 +0,0 @@ | ||
1 | -module DelayedAttachmentFu | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - def delay_attachment_fu_thumbnails | ||
5 | - include DelayedAttachmentFu::InstanceMethods | ||
6 | - after_create do |file| | ||
7 | - if file.thumbnailable? | ||
8 | - Delayed::Job.enqueue CreateThumbnailsJob.new(file.class.name, file.id) | ||
9 | - end | ||
10 | - end | ||
11 | - end | ||
12 | - end | ||
13 | - | ||
14 | - module InstanceMethods | ||
15 | - # skip processing with RMagick | ||
16 | - def process_attachment | ||
17 | - end | ||
18 | - | ||
19 | - def after_process_attachment | ||
20 | - save_to_storage | ||
21 | - @temp_paths.clear | ||
22 | - @saved_attachment = nil | ||
23 | - run_callbacks :after_attachment_saved | ||
24 | - end | ||
25 | - | ||
26 | - def create_thumbnails | ||
27 | - if thumbnailable? | ||
28 | - self.class.with_image(full_filename) do |img| | ||
29 | - self.width = img.columns | ||
30 | - self.height = img.rows | ||
31 | - self.save! | ||
32 | - end | ||
33 | - self.class.attachment_options[:thumbnails].each do |suffix, size| | ||
34 | - self.create_or_update_thumbnail(self.full_filename, suffix, size) | ||
35 | - end | ||
36 | - self.thumbnails_processed = true | ||
37 | - self.save! | ||
38 | - end | ||
39 | - end | ||
40 | - | ||
41 | - def public_filename(size=nil) | ||
42 | - force, size = true, nil if size == :uploaded | ||
43 | - if !self.thumbnailable? || self.thumbnails_processed || force | ||
44 | - super size | ||
45 | - else | ||
46 | - size ||= :thumb | ||
47 | - '/images/icons-app/image-loading-%s.png' % size | ||
48 | - end | ||
49 | - end | ||
50 | - | ||
51 | - | ||
52 | - end | ||
53 | -end | ||
54 | - | ||
55 | -ActiveRecord::Base.extend DelayedAttachmentFu::ClassMethods | ||
56 | - |
lib/needs_profile.rb
@@ -1,44 +0,0 @@ | @@ -1,44 +0,0 @@ | ||
1 | -module NeedsProfile | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - def needs_profile | ||
5 | - before_filter :load_profile | ||
6 | - end | ||
7 | - end | ||
8 | - | ||
9 | - def self.included(including) | ||
10 | - including.send(:extend, NeedsProfile::ClassMethods) | ||
11 | - end | ||
12 | - | ||
13 | - def boxes_holder | ||
14 | - profile || environment # prefers profile, but defaults to environment | ||
15 | - end | ||
16 | - | ||
17 | - def profile | ||
18 | - @profile | ||
19 | - end | ||
20 | - | ||
21 | - protected | ||
22 | - | ||
23 | - def load_profile | ||
24 | - if params[:profile] | ||
25 | - params[:profile].downcase! | ||
26 | - @profile ||= environment.profiles.where(identifier: params[:profile]).first | ||
27 | - end | ||
28 | - | ||
29 | - if @profile | ||
30 | - profile_hostname = @profile.hostname | ||
31 | - if profile_hostname && profile_hostname != request.host | ||
32 | - if params[:controller] == 'content_viewer' | ||
33 | - params[:profile] = nil | ||
34 | - else | ||
35 | - params.delete(:profile) | ||
36 | - end | ||
37 | - redirect_to(Noosfero.url_options.merge(params).merge(:host => profile_hostname)) | ||
38 | - end | ||
39 | - else | ||
40 | - render_not_found | ||
41 | - end | ||
42 | - end | ||
43 | - | ||
44 | -end |
lib/noosfero/translatable_content.rb
lib/set_profile_region_from_city_state.rb
@@ -1,44 +0,0 @@ | @@ -1,44 +0,0 @@ | ||
1 | -module SetProfileRegionFromCityState | ||
2 | - | ||
3 | - module ClassMethods | ||
4 | - def set_profile_region_from_city_state | ||
5 | - before_save :region_from_city_and_state | ||
6 | - | ||
7 | - include InstanceMethods | ||
8 | - alias_method_chain :city=, :region | ||
9 | - alias_method_chain :state=, :region | ||
10 | - end | ||
11 | - end | ||
12 | - | ||
13 | - module InstanceMethods | ||
14 | - include Noosfero::Plugin::HotSpot | ||
15 | - | ||
16 | - def city_with_region=(value) | ||
17 | - self.city_without_region = value | ||
18 | - @change_region = true | ||
19 | - end | ||
20 | - | ||
21 | - def state_with_region=(value) | ||
22 | - self.state_without_region = value | ||
23 | - @change_region = true | ||
24 | - end | ||
25 | - | ||
26 | - def region_from_city_and_state | ||
27 | - if @change_region | ||
28 | - self.region = nil | ||
29 | - state = search_region(State, self.state) | ||
30 | - self.region = search_region(City.where(:parent_id => state.id), self.city) if state | ||
31 | - end | ||
32 | - end | ||
33 | - | ||
34 | - private | ||
35 | - | ||
36 | - def search_region(scope, query) | ||
37 | - return nil if !query | ||
38 | - query = query.downcase.strip | ||
39 | - scope.where(['lower(name)=? OR lower(abbreviation)=? OR lower(acronym)=?', query, query, query]).first | ||
40 | - end | ||
41 | - | ||
42 | - end | ||
43 | - | ||
44 | -end |
lib/white_list_filter.rb
@@ -1,37 +0,0 @@ | @@ -1,37 +0,0 @@ | ||
1 | -module WhiteListFilter | ||
2 | - | ||
3 | - def check_iframe_on_content(content, trusted_sites) | ||
4 | - if content.blank? || !content.include?('iframe') | ||
5 | - return content | ||
6 | - end | ||
7 | - content.gsub!(/<iframe[^>]*>\s*<\/iframe>/i) do |iframe| | ||
8 | - result = '' | ||
9 | - unless iframe =~ /src=['"].*src=['"]/ | ||
10 | - trusted_sites.each do |trusted_site| | ||
11 | - re_dom = trusted_site.gsub('.', '\.') | ||
12 | - if iframe =~ /src=["'](https?:)?\/\/(www\.)?#{re_dom}\// | ||
13 | - result = iframe | ||
14 | - end | ||
15 | - end | ||
16 | - end | ||
17 | - result | ||
18 | - end | ||
19 | - content | ||
20 | - end | ||
21 | - | ||
22 | - module ClassMethods | ||
23 | - def filter_iframes(*opts) | ||
24 | - options = opts.last.is_a?(Hash) && opts.pop || {} | ||
25 | - white_list_method = options[:whitelist] || :iframe_whitelist | ||
26 | - opts.each do |field| | ||
27 | - before_validation do |obj| | ||
28 | - obj.check_iframe_on_content(obj.send(field), obj.send(white_list_method)) | ||
29 | - end | ||
30 | - end | ||
31 | - end | ||
32 | - end | ||
33 | - | ||
34 | - def self.included(c) | ||
35 | - c.send(:extend, WhiteListFilter::ClassMethods) | ||
36 | - end | ||
37 | -end |
plugins/admin_notifications/test/functional/account_controller_test.rb
@@ -8,8 +8,7 @@ end | @@ -8,8 +8,7 @@ end | ||
8 | class AccountControllerTest < ActionController::TestCase | 8 | class AccountControllerTest < ActionController::TestCase |
9 | def setup | 9 | def setup |
10 | @controller = AccountController.new | 10 | @controller = AccountController.new |
11 | - @request = ActionController::TestRequest.new | ||
12 | - @response = ActionController::TestResponse.new | 11 | + |
13 | @person = create_user('person').person | 12 | @person = create_user('person').person |
14 | 13 | ||
15 | @environment = Environment.default | 14 | @environment = Environment.default |
plugins/admin_notifications/test/functional/admin_notifications_plugin_admin_controller_test.rb
@@ -4,8 +4,6 @@ require_relative '../../controllers/admin_notifications_plugin_admin_controller' | @@ -4,8 +4,6 @@ require_relative '../../controllers/admin_notifications_plugin_admin_controller' | ||
4 | class AdminNotificationsPluginAdminControllerTest < ActionController::TestCase | 4 | class AdminNotificationsPluginAdminControllerTest < ActionController::TestCase |
5 | def setup | 5 | def setup |
6 | @controller = AdminNotificationsPluginAdminController.new | 6 | @controller = AdminNotificationsPluginAdminController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | ||
9 | @person = create_user('person').person | 7 | @person = create_user('person').person |
10 | 8 | ||
11 | @environment = Environment.default | 9 | @environment = Environment.default |
plugins/admin_notifications/test/functional/admin_notifications_plugin_myprofile_controller_test.rb
@@ -7,8 +7,6 @@ require( | @@ -7,8 +7,6 @@ require( | ||
7 | class AdminNotificationsPluginMyprofileControllerTest < ActionController::TestCase | 7 | class AdminNotificationsPluginMyprofileControllerTest < ActionController::TestCase |
8 | def setup | 8 | def setup |
9 | @controller = AdminNotificationsPluginMyprofileController.new | 9 | @controller = AdminNotificationsPluginMyprofileController.new |
10 | - @request = ActionController::TestRequest.new | ||
11 | - @response = ActionController::TestResponse.new | ||
12 | @person = create_user('person').person | 10 | @person = create_user('person').person |
13 | @community = fast_create(Community) | 11 | @community = fast_create(Community) |
14 | 12 |
plugins/admin_notifications/test/functional/admin_notifications_plugin_public_controller_test.rb
@@ -7,8 +7,6 @@ require( | @@ -7,8 +7,6 @@ require( | ||
7 | class AdminNotificationsPluginPublicControllerTest < ActionController::TestCase | 7 | class AdminNotificationsPluginPublicControllerTest < ActionController::TestCase |
8 | def setup | 8 | def setup |
9 | @controller = AdminNotificationsPluginPublicController.new | 9 | @controller = AdminNotificationsPluginPublicController.new |
10 | - @request = ActionController::TestRequest.new | ||
11 | - @response = ActionController::TestResponse.new | ||
12 | @person = create_user('person').person | 10 | @person = create_user('person').person |
13 | 11 | ||
14 | @environment = Environment.default | 12 | @environment = Environment.default |
plugins/admin_notifications/test/functional/home_controller_test.rb
@@ -7,8 +7,7 @@ end | @@ -7,8 +7,7 @@ end | ||
7 | class HomeControllerTest < ActionController::TestCase | 7 | class HomeControllerTest < ActionController::TestCase |
8 | def setup | 8 | def setup |
9 | @controller = HomeController.new | 9 | @controller = HomeController.new |
10 | - @request = ActionController::TestRequest.new | ||
11 | - @response = ActionController::TestResponse.new | 10 | + |
12 | @person = create_user('person').person | 11 | @person = create_user('person').person |
13 | 12 | ||
14 | @environment = Environment.default | 13 | @environment = Environment.default |
plugins/analytics/models/analytics_plugin/page_view.rb
@@ -8,6 +8,7 @@ class AnalyticsPlugin::PageView < ApplicationRecord | @@ -8,6 +8,7 @@ class AnalyticsPlugin::PageView < ApplicationRecord | ||
8 | attr_accessor :request | 8 | attr_accessor :request |
9 | attr_accessible :request | 9 | attr_accessible :request |
10 | 10 | ||
11 | + extend ActsAsHavingSettings::ClassMethods | ||
11 | acts_as_having_settings field: :options | 12 | acts_as_having_settings field: :options |
12 | 13 | ||
13 | belongs_to :profile, validate: true | 14 | belongs_to :profile, validate: true |
plugins/analytics/test/functional/content_viewer_controller_test.rb
@@ -5,8 +5,6 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -5,8 +5,6 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = ContentViewerController.new | 7 | @controller = ContentViewerController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | ||
10 | 8 | ||
11 | @environment = Environment.default | 9 | @environment = Environment.default |
12 | @environment.enabled_plugins += ['AnalyticsPlugin'] | 10 | @environment.enabled_plugins += ['AnalyticsPlugin'] |
plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb
@@ -5,8 +5,6 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase | @@ -5,8 +5,6 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = CommentGroupPluginProfileController.new | 7 | @controller = CommentGroupPluginProfileController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | ||
10 | 8 | ||
11 | @profile = create_user('testuser').person | 9 | @profile = create_user('testuser').person |
12 | @article = profile.articles.build(:name => 'test') | 10 | @article = profile.articles.build(:name => 'test') |
plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb
@@ -5,8 +5,6 @@ class CommentGroupPluginPublicControllerTest < ActionController::TestCase | @@ -5,8 +5,6 @@ class CommentGroupPluginPublicControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = CommentGroupPluginPublicController.new | 7 | @controller = CommentGroupPluginPublicController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | ||
10 | 8 | ||
11 | @profile = create_user('testuser').person | 9 | @profile = create_user('testuser').person |
12 | @article = profile.articles.build(:name => 'test') | 10 | @article = profile.articles.build(:name => 'test') |
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
@@ -4,8 +4,7 @@ require_relative '../../controllers/custom_forms_plugin_myprofile_controller' | @@ -4,8 +4,7 @@ require_relative '../../controllers/custom_forms_plugin_myprofile_controller' | ||
4 | class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase | 4 | class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
5 | def setup | 5 | def setup |
6 | @controller = CustomFormsPluginMyprofileController.new | 6 | @controller = CustomFormsPluginMyprofileController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | 7 | + |
9 | @profile = create_user('profile').person | 8 | @profile = create_user('profile').person |
10 | login_as(@profile.identifier) | 9 | login_as(@profile.identifier) |
11 | environment = Environment.default | 10 | environment = Environment.default |
plugins/custom_forms/test/functional/custom_forms_plugin_profile_controller_test.rb
@@ -4,8 +4,7 @@ require_relative '../../controllers/custom_forms_plugin_profile_controller' | @@ -4,8 +4,7 @@ require_relative '../../controllers/custom_forms_plugin_profile_controller' | ||
4 | class CustomFormsPluginProfileControllerTest < ActionController::TestCase | 4 | class CustomFormsPluginProfileControllerTest < ActionController::TestCase |
5 | def setup | 5 | def setup |
6 | @controller = CustomFormsPluginProfileController.new | 6 | @controller = CustomFormsPluginProfileController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | 7 | + |
9 | @profile = create_user('profile').person | 8 | @profile = create_user('profile').person |
10 | login_as(@profile.identifier) | 9 | login_as(@profile.identifier) |
11 | environment = Environment.default | 10 | environment = Environment.default |
plugins/display_content/test/functional/display_content_plugin_admin_controller_test.rb
@@ -5,8 +5,6 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | @@ -5,8 +5,6 @@ class DisplayContentPluginAdminControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = DisplayContentPluginAdminController.new | 7 | @controller = DisplayContentPluginAdminController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | ||
10 | 8 | ||
11 | @environment = Environment.default | 9 | @environment = Environment.default |
12 | user_login = create_admin_user(@environment) | 10 | user_login = create_admin_user(@environment) |
plugins/display_content/test/functional/display_content_plugin_myprofile_controller_test.rb
@@ -5,8 +5,6 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | @@ -5,8 +5,6 @@ class DisplayContentPluginMyprofileControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = DisplayContentPluginMyprofileController.new | 7 | @controller = DisplayContentPluginMyprofileController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | ||
10 | 8 | ||
11 | user = create_user('testinguser') | 9 | user = create_user('testinguser') |
12 | login_as(user.login) | 10 | login_as(user.login) |
plugins/driven_signup/test/integration/account_controller_test.rb
@@ -7,8 +7,7 @@ class AccountControllerTest < ActionDispatch::IntegrationTest | @@ -7,8 +7,7 @@ class AccountControllerTest < ActionDispatch::IntegrationTest | ||
7 | 7 | ||
8 | def setup | 8 | def setup |
9 | @controller = AccountController.new | 9 | @controller = AccountController.new |
10 | - @request = ActionController::TestRequest.new | ||
11 | - @response = ActionController::TestResponse.new | 10 | + @request = ActionController::TestRequest.new |
12 | 11 | ||
13 | e = Environment.default | 12 | e = Environment.default |
14 | e.enable 'skip_new_user_email_confirmation', true | 13 | e.enable 'skip_new_user_email_confirmation', true |
plugins/fb_app/models/fb_app_plugin/page_tab.rb
@@ -9,6 +9,7 @@ class FbAppPlugin::PageTab < ApplicationRecord | @@ -9,6 +9,7 @@ class FbAppPlugin::PageTab < ApplicationRecord | ||
9 | 9 | ||
10 | belongs_to :owner_profile, foreign_key: :profile_id, class_name: 'Profile' | 10 | belongs_to :owner_profile, foreign_key: :profile_id, class_name: 'Profile' |
11 | 11 | ||
12 | + extend ActsAsHavingSettings::ClassMethods | ||
12 | acts_as_having_settings field: :config | 13 | acts_as_having_settings field: :config |
13 | 14 | ||
14 | ConfigTypes = [:profile, :profiles, :query] | 15 | ConfigTypes = [:profile, :profiles, :query] |
plugins/google_analytics/test/functional/profile_editor_controller_test.rb
@@ -5,8 +5,7 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -5,8 +5,7 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = ProfileEditorController.new | 7 | @controller = ProfileEditorController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | 8 | + |
10 | @profile = create_user('default_user').person | 9 | @profile = create_user('default_user').person |
11 | login_as(@profile.identifier) | 10 | login_as(@profile.identifier) |
12 | Environment.default.enable_plugin(GoogleAnalyticsPlugin.name) | 11 | Environment.default.enable_plugin(GoogleAnalyticsPlugin.name) |
plugins/google_cse/test/functional/google_cse_plugin_controller_test.rb
@@ -5,8 +5,6 @@ class GoogleCsePluginControllerTest < ActionController::TestCase | @@ -5,8 +5,6 @@ class GoogleCsePluginControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = GoogleCsePluginController.new | 7 | @controller = GoogleCsePluginController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | ||
10 | end | 8 | end |
11 | 9 | ||
12 | should 'get results page' do | 10 | should 'get results page' do |
plugins/html5_video/test/functional/content_viewer_controler_test.rb
@@ -7,8 +7,6 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -7,8 +7,6 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
7 | 7 | ||
8 | def setup | 8 | def setup |
9 | @controller = ContentViewerController.new | 9 | @controller = ContentViewerController.new |
10 | - @request = ActionController::TestRequest.new | ||
11 | - @response = ActionController::TestResponse.new | ||
12 | 10 | ||
13 | @profile = create_user('testinguser').person | 11 | @profile = create_user('testinguser').person |
14 | @environment = @profile.environment | 12 | @environment = @profile.environment |
plugins/ldap/test/functional/account_controller_plugin_test.rb
@@ -4,8 +4,6 @@ class AccountControllerPluginTest < ActionController::TestCase | @@ -4,8 +4,6 @@ class AccountControllerPluginTest < ActionController::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @controller = AccountController.new | 6 | @controller = AccountController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | ||
9 | 7 | ||
10 | @environment = Environment.default | 8 | @environment = Environment.default |
11 | @environment.enabled_plugins = ['LdapPlugin'] | 9 | @environment.enabled_plugins = ['LdapPlugin'] |
plugins/mark_comment_as_read/test/functional/mark_comment_as_read_plugin_profile_controller_test.rb
@@ -4,8 +4,7 @@ require_relative '../../controllers/mark_comment_as_read_plugin_profile_controll | @@ -4,8 +4,7 @@ require_relative '../../controllers/mark_comment_as_read_plugin_profile_controll | ||
4 | class MarkCommentAsReadPluginProfileControllerTest < ActionController::TestCase | 4 | class MarkCommentAsReadPluginProfileControllerTest < ActionController::TestCase |
5 | def setup | 5 | def setup |
6 | @controller = MarkCommentAsReadPluginProfileController.new | 6 | @controller = MarkCommentAsReadPluginProfileController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | 7 | + |
9 | @profile = create_user('profile').person | 8 | @profile = create_user('profile').person |
10 | @article = TinyMceArticle.create!(:profile => @profile, :name => 'An article') | 9 | @article = TinyMceArticle.create!(:profile => @profile, :name => 'An article') |
11 | @comment = Comment.new(:source => @article, :author => @profile, :body => 'test') | 10 | @comment = Comment.new(:source => @article, :author => @profile, :body => 'test') |
plugins/metadata/test/functional/content_viewer_controller_test.rb
@@ -6,8 +6,6 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -6,8 +6,6 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
6 | 6 | ||
7 | def setup | 7 | def setup |
8 | @controller = ContentViewerController.new | 8 | @controller = ContentViewerController.new |
9 | - @request = ActionController::TestRequest.new | ||
10 | - @response = ActionController::TestResponse.new | ||
11 | 9 | ||
12 | @profile = create_user('testinguser').person | 10 | @profile = create_user('testinguser').person |
13 | @environment = @profile.environment | 11 | @environment = @profile.environment |
plugins/metadata/test/functional/home_controller_test.rb
@@ -5,8 +5,6 @@ class HomeControllerTest < ActionController::TestCase | @@ -5,8 +5,6 @@ class HomeControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = HomeController.new | 7 | @controller = HomeController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | ||
10 | 8 | ||
11 | @environment = Environment.default | 9 | @environment = Environment.default |
12 | @environment.enabled_plugins += ['MetadataPlugin'] | 10 | @environment.enabled_plugins += ['MetadataPlugin'] |
plugins/metadata/test/functional/products_plugin/page_controller_test.rb
@@ -6,8 +6,6 @@ if defined? ProductsPlugin | @@ -6,8 +6,6 @@ if defined? ProductsPlugin | ||
6 | 6 | ||
7 | def setup | 7 | def setup |
8 | @controller = PageController.new | 8 | @controller = PageController.new |
9 | - @request = ActionController::TestRequest.new | ||
10 | - @response = ActionController::TestResponse.new | ||
11 | @enterprise = fast_create(Enterprise, name: 'test', identifier: 'test_ent') | 9 | @enterprise = fast_create(Enterprise, name: 'test', identifier: 'test_ent') |
12 | @user = create_user_with_permission('test_user', 'manage_products', @enterprise) | 10 | @user = create_user_with_permission('test_user', 'manage_products', @enterprise) |
13 | login_as :test_user | 11 | login_as :test_user |
plugins/newsletter/lib/newsletter_plugin/newsletter.rb
@@ -167,6 +167,7 @@ class NewsletterPlugin::Newsletter < ApplicationRecord | @@ -167,6 +167,7 @@ class NewsletterPlugin::Newsletter < ApplicationRecord | ||
167 | end | 167 | end |
168 | end | 168 | end |
169 | 169 | ||
170 | + extend ActsAsHavingImage::ClassMethods | ||
170 | acts_as_having_image | 171 | acts_as_having_image |
171 | 172 | ||
172 | def last_send_at | 173 | def last_send_at |
plugins/newsletter/test/functional/newsletter_plugin_admin_controller_test.rb
@@ -4,8 +4,6 @@ class NewsletterPluginAdminControllerTest < ActionController::TestCase | @@ -4,8 +4,6 @@ class NewsletterPluginAdminControllerTest < ActionController::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @controller = NewsletterPluginAdminController.new | 6 | @controller = NewsletterPluginAdminController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | ||
9 | 7 | ||
10 | @admin = create_user('admin_newsletter').person | 8 | @admin = create_user('admin_newsletter').person |
11 | @environment = @admin.environment | 9 | @environment = @admin.environment |
plugins/newsletter/test/functional/newsletter_plugin_controller_test.rb
@@ -4,8 +4,7 @@ class NewsletterPluginControllerTest < ActionController::TestCase | @@ -4,8 +4,7 @@ class NewsletterPluginControllerTest < ActionController::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @controller = NewsletterPluginController.new | 6 | @controller = NewsletterPluginController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | 7 | + |
9 | environment = fast_create(Environment) | 8 | environment = fast_create(Environment) |
10 | environment.enable_plugin(NewsletterPlugin) | 9 | environment.enable_plugin(NewsletterPlugin) |
11 | @controller.stubs(:environment).returns(environment) | 10 | @controller.stubs(:environment).returns(environment) |
plugins/oauth_client/models/oauth_client_plugin/auth.rb
@@ -10,6 +10,7 @@ class OauthClientPlugin::Auth < ApplicationRecord | @@ -10,6 +10,7 @@ class OauthClientPlugin::Auth < ApplicationRecord | ||
10 | validates_presence_of :provider | 10 | validates_presence_of :provider |
11 | validates_uniqueness_of :profile_id, scope: :provider_id | 11 | validates_uniqueness_of :profile_id, scope: :provider_id |
12 | 12 | ||
13 | + extend ActsAsHavingSettings::ClassMethods | ||
13 | acts_as_having_settings field: :data | 14 | acts_as_having_settings field: :data |
14 | 15 | ||
15 | serialize :oauth_data, Hash | 16 | serialize :oauth_data, Hash |
plugins/oauth_client/models/oauth_client_plugin/provider.rb
@@ -4,7 +4,10 @@ class OauthClientPlugin::Provider < ApplicationRecord | @@ -4,7 +4,10 @@ class OauthClientPlugin::Provider < ApplicationRecord | ||
4 | 4 | ||
5 | validates_presence_of :name, :strategy | 5 | validates_presence_of :name, :strategy |
6 | 6 | ||
7 | + extend ActsAsHavingImage::ClassMethods | ||
7 | acts_as_having_image | 8 | acts_as_having_image |
9 | + | ||
10 | + extend ActsAsHavingSettings::ClassMethods | ||
8 | acts_as_having_settings field: :options | 11 | acts_as_having_settings field: :options |
9 | 12 | ||
10 | settings_items :site, type: String | 13 | settings_items :site, type: String |
@@ -16,6 +19,4 @@ class OauthClientPlugin::Provider < ApplicationRecord | @@ -16,6 +19,4 @@ class OauthClientPlugin::Provider < ApplicationRecord | ||
16 | 19 | ||
17 | scope :enabled, -> { where enabled: true } | 20 | scope :enabled, -> { where enabled: true } |
18 | 21 | ||
19 | - acts_as_having_image | ||
20 | - | ||
21 | end | 22 | end |
plugins/open_graph/test/functional/open_graph_graph/my_profile_controller_test.rb
@@ -8,8 +8,7 @@ class OpenGraphPlugin::MyprofileControllerTest < ActionController::TestCase | @@ -8,8 +8,7 @@ class OpenGraphPlugin::MyprofileControllerTest < ActionController::TestCase | ||
8 | 8 | ||
9 | def setup | 9 | def setup |
10 | @controller = OpenGraphPlugin::MyprofileController.new | 10 | @controller = OpenGraphPlugin::MyprofileController.new |
11 | - @request = ActionController::TestRequest.new | ||
12 | - @response = ActionController::TestResponse.new | 11 | + |
13 | @actor = create_user.person | 12 | @actor = create_user.person |
14 | end | 13 | end |
15 | 14 |
plugins/organization_ratings/test/functional/organization_ratings_plugin_admin_controller_test.rb
@@ -8,8 +8,6 @@ class OrganizationRatingsPluginAdminControllerTest < ActionController::TestCase | @@ -8,8 +8,6 @@ class OrganizationRatingsPluginAdminControllerTest < ActionController::TestCase | ||
8 | 8 | ||
9 | def setup | 9 | def setup |
10 | @controller = OrganizationRatingsPluginAdminController.new | 10 | @controller = OrganizationRatingsPluginAdminController.new |
11 | - @request = ActionController::TestRequest.new | ||
12 | - @response = ActionController::TestResponse.new | ||
13 | 11 | ||
14 | @environment = Environment.default | 12 | @environment = Environment.default |
15 | @environment.enabled_plugins = ['OrganizationRatingsPlugin'] | 13 | @environment.enabled_plugins = ['OrganizationRatingsPlugin'] |
plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
@@ -8,8 +8,6 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas | @@ -8,8 +8,6 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas | ||
8 | 8 | ||
9 | def setup | 9 | def setup |
10 | @controller = OrganizationRatingsPluginProfileController.new | 10 | @controller = OrganizationRatingsPluginProfileController.new |
11 | - @request = ActionController::TestRequest.new | ||
12 | - @response = ActionController::TestResponse.new | ||
13 | 11 | ||
14 | @environment = Environment.default | 12 | @environment = Environment.default |
15 | @environment.enabled_plugins = ['OrganizationRatingsPlugin'] | 13 | @environment.enabled_plugins = ['OrganizationRatingsPlugin'] |
plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb
@@ -4,8 +4,7 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -4,8 +4,7 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @controller = EnvironmentDesignController.new | 6 | @controller = EnvironmentDesignController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | 7 | + |
9 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) | 8 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) |
10 | end | 9 | end |
11 | 10 |
plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb
@@ -4,8 +4,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -4,8 +4,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @controller = ProfileDesignController.new | 6 | @controller = ProfileDesignController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | 7 | + |
9 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) | 8 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) |
10 | end | 9 | end |
11 | 10 |
plugins/people_block/test/functional/profile_controller_test.rb
@@ -4,8 +4,7 @@ class ProfileControllerTest < ActionController::TestCase | @@ -4,8 +4,7 @@ class ProfileControllerTest < ActionController::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @controller = ProfileController.new | 6 | @controller = ProfileController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | 7 | + |
9 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) | 8 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) |
10 | end | 9 | end |
11 | 10 |
plugins/products/models/products_plugin/product.rb
@@ -45,6 +45,7 @@ class ProductsPlugin::Product < ApplicationRecord | @@ -45,6 +45,7 @@ class ProductsPlugin::Product < ApplicationRecord | ||
45 | has_many :qualifiers, through: :product_qualifiers | 45 | has_many :qualifiers, through: :product_qualifiers |
46 | has_many :certifiers, through: :product_qualifiers | 46 | has_many :certifiers, through: :product_qualifiers |
47 | 47 | ||
48 | + extend ActsAsHavingSettings::ClassMethods | ||
48 | acts_as_having_settings field: :data | 49 | acts_as_having_settings field: :data |
49 | 50 | ||
50 | track_actions :create_product, :after_create, keep_params: [:name, :url ], if: Proc.new { |a| a.is_trackable? }, custom_user: :action_tracker_user | 51 | track_actions :create_product, :after_create, keep_params: [:name, :url ], if: Proc.new { |a| a.is_trackable? }, custom_user: :action_tracker_user |
@@ -129,6 +130,7 @@ class ProductsPlugin::Product < ApplicationRecord | @@ -129,6 +130,7 @@ class ProductsPlugin::Product < ApplicationRecord | ||
129 | image ? image.public_filename(size) : '/images/icons-app/product-default-pic-%s.png' % size | 130 | image ? image.public_filename(size) : '/images/icons-app/product-default-pic-%s.png' % size |
130 | end | 131 | end |
131 | 132 | ||
133 | + extend ActsAsHavingImage::ClassMethods | ||
132 | acts_as_having_image | 134 | acts_as_having_image |
133 | 135 | ||
134 | def save_image | 136 | def save_image |
plugins/relevant_content/test/unit/article.rb
@@ -8,8 +8,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -8,8 +8,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
8 | 8 | ||
9 | def setup | 9 | def setup |
10 | @controller = CommentController.new | 10 | @controller = CommentController.new |
11 | - @request = ActionController::TestRequest.new | ||
12 | - @response = ActionController::TestResponse.new | 11 | + |
13 | @profile = create_user('testinguser').person | 12 | @profile = create_user('testinguser').person |
14 | @environment = @profile.environment | 13 | @environment = @profile.environment |
15 | end | 14 | end |
plugins/relevant_content/test/unit/relevant_content_block_test.rb
@@ -9,8 +9,6 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -9,8 +9,6 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
9 | 9 | ||
10 | def setup | 10 | def setup |
11 | @controller = CommentController.new | 11 | @controller = CommentController.new |
12 | - @request = ActionController::TestRequest.new | ||
13 | - @response = ActionController::TestResponse.new | ||
14 | 12 | ||
15 | @profile = create_user('testinguser').person | 13 | @profile = create_user('testinguser').person |
16 | @environment = @profile.environment | 14 | @environment = @profile.environment |
plugins/remote_user/test/functional/remote_user_plugin_test.rb
@@ -2,6 +2,8 @@ require 'test_helper' | @@ -2,6 +2,8 @@ require 'test_helper' | ||
2 | 2 | ||
3 | class AccountControllerTest < ActionController::TestCase | 3 | class AccountControllerTest < ActionController::TestCase |
4 | def setup | 4 | def setup |
5 | + @controller = AccountController.new | ||
6 | + | ||
5 | @environment = Environment.default | 7 | @environment = Environment.default |
6 | @environment.enabled_plugins = ['RemoteUserPlugin'] | 8 | @environment.enabled_plugins = ['RemoteUserPlugin'] |
7 | @environment.save | 9 | @environment.save |
@@ -9,10 +11,6 @@ class AccountControllerTest < ActionController::TestCase | @@ -9,10 +11,6 @@ class AccountControllerTest < ActionController::TestCase | ||
9 | @another_environment = Environment.new(name: "AnotherEnvironment") | 11 | @another_environment = Environment.new(name: "AnotherEnvironment") |
10 | @another_environment.enabled_plugins = ['RemoteUserPlugin'] | 12 | @another_environment.enabled_plugins = ['RemoteUserPlugin'] |
11 | @another_environment.save | 13 | @another_environment.save |
12 | - | ||
13 | - @controller = AccountController.new | ||
14 | - @request = ActionController::TestRequest.new | ||
15 | - @response = ActionController::TestResponse.new | ||
16 | end | 14 | end |
17 | 15 | ||
18 | should 'not authenticate user if there is no remote user' do | 16 | should 'not authenticate user if there is no remote user' do |
plugins/shopping_cart/db/migrate/20131226125124_move_shopping_cart_purchase_order_to_orders_plugin_order.rb
@@ -2,6 +2,7 @@ OrdersPlugin.send :remove_const, :Item if defined? OrdersPlugin::Item | @@ -2,6 +2,7 @@ OrdersPlugin.send :remove_const, :Item if defined? OrdersPlugin::Item | ||
2 | OrdersPlugin.send :remove_const, :Order if defined? OrdersPlugin::Order | 2 | OrdersPlugin.send :remove_const, :Order if defined? OrdersPlugin::Order |
3 | 3 | ||
4 | class ShoppingCartPlugin::PurchaseOrder < ApplicationRecord | 4 | class ShoppingCartPlugin::PurchaseOrder < ApplicationRecord |
5 | + extend ActsAsHavingSettings::ClassMethods | ||
5 | acts_as_having_settings field: :data | 6 | acts_as_having_settings field: :data |
6 | 7 | ||
7 | module Status | 8 | module Status |
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
@@ -5,8 +5,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -5,8 +5,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = ShoppingCartPluginController.new | 7 | @controller = ShoppingCartPluginController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | 8 | + |
10 | @profile = fast_create(Enterprise) | 9 | @profile = fast_create(Enterprise) |
11 | @profile.contact_email = 'enterprise@noosfero.org';@profile.save | 10 | @profile.contact_email = 'enterprise@noosfero.org';@profile.save |
12 | @product = fast_create(Product, profile_id: @profile.id) | 11 | @product = fast_create(Product, profile_id: @profile.id) |
plugins/social_share_privacy/test/functional/content_viewer_controller_test.rb
@@ -5,8 +5,6 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -5,8 +5,6 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = ContentViewerController.new | 7 | @controller = ContentViewerController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | ||
10 | 8 | ||
11 | @profile = create_user('testinguser').person | 9 | @profile = create_user('testinguser').person |
12 | @environment = @profile.environment | 10 | @environment = @profile.environment |
plugins/solr/test/functional/search_controller_test.rb
@@ -4,14 +4,12 @@ require_relative '../../lib/ext/facets_browse' | @@ -4,14 +4,12 @@ require_relative '../../lib/ext/facets_browse' | ||
4 | class SearchControllerTest < ActionController::TestCase | 4 | class SearchControllerTest < ActionController::TestCase |
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | + @controller = SearchController.new | ||
8 | + | ||
7 | TestSolr.enable | 9 | TestSolr.enable |
8 | p1 = File.join(RAILS_ROOT, 'app', 'views') | 10 | p1 = File.join(RAILS_ROOT, 'app', 'views') |
9 | p2 = File.join(File.dirname(__FILE__) + '/../../views') | 11 | p2 = File.join(File.dirname(__FILE__) + '/../../views') |
10 | SearchController.append_view_path([p1,p2]) | 12 | SearchController.append_view_path([p1,p2]) |
11 | - @controller = SearchController.new | ||
12 | - @request = ActionController::TestRequest.new | ||
13 | - @request.stubs(:ssl?).returns(false) | ||
14 | - @response = ActionController::TestResponse.new | ||
15 | 13 | ||
16 | @category = Category.create!(:name => 'my category', :environment => Environment.default) | 14 | @category = Category.create!(:name => 'my category', :environment => Environment.default) |
17 | 15 |
plugins/spaminator/test/functional/spaminator_plugin_admin_controller_test.rb
@@ -4,8 +4,7 @@ require_relative '../../controllers/spaminator_plugin_admin_controller' | @@ -4,8 +4,7 @@ require_relative '../../controllers/spaminator_plugin_admin_controller' | ||
4 | class SpaminatorPluginAdminControllerTest < ActionController::TestCase | 4 | class SpaminatorPluginAdminControllerTest < ActionController::TestCase |
5 | def setup | 5 | def setup |
6 | @controller = SpaminatorPluginAdminController.new | 6 | @controller = SpaminatorPluginAdminController.new |
7 | - @request = ActionController::TestRequest.new | ||
8 | - @response = ActionController::TestResponse.new | 7 | + |
9 | @environment = Environment.default | 8 | @environment = Environment.default |
10 | @settings = Noosfero::Plugin::Settings.new(@environment, SpaminatorPlugin) | 9 | @settings = Noosfero::Plugin::Settings.new(@environment, SpaminatorPlugin) |
11 | login_as(create_admin_user(@environment)) | 10 | login_as(create_admin_user(@environment)) |
plugins/stoa/test/functional/account_controller_test.rb
@@ -19,8 +19,6 @@ class AccountControllerTest < ActionController::TestCase | @@ -19,8 +19,6 @@ class AccountControllerTest < ActionController::TestCase | ||
19 | 19 | ||
20 | def setup | 20 | def setup |
21 | @controller = AccountController.new | 21 | @controller = AccountController.new |
22 | - @request = ActionController::TestRequest.new | ||
23 | - @response = ActionController::TestResponse.new | ||
24 | StoaPlugin::UspUser.create!({:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true) | 22 | StoaPlugin::UspUser.create!({:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true) |
25 | Environment.default.enable_plugin(StoaPlugin.name) | 23 | Environment.default.enable_plugin(StoaPlugin.name) |
26 | @user = create_user('joao-stoa', {:password => 'pass', :password_confirmation => 'pass'},:usp_id=>'87654321') | 24 | @user = create_user('joao-stoa', {:password => 'pass', :password_confirmation => 'pass'},:usp_id=>'87654321') |
plugins/stoa/test/functional/invite_controller_test.rb
@@ -5,8 +5,7 @@ class InviteControllerTest < ActionController::TestCase | @@ -5,8 +5,7 @@ class InviteControllerTest < ActionController::TestCase | ||
5 | 5 | ||
6 | def setup | 6 | def setup |
7 | @controller = InviteController.new | 7 | @controller = InviteController.new |
8 | - @request = ActionController::TestRequest.new | ||
9 | - @response = ActionController::TestResponse.new | 8 | + |
10 | environment = Environment.default | 9 | environment = Environment.default |
11 | environment.enabled_plugins = ['StoaPlugin'] | 10 | environment.enabled_plugins = ['StoaPlugin'] |
12 | environment.save! | 11 | environment.save! |
plugins/stoa/test/functional/profile_editor_controller_test.rb
@@ -7,8 +7,7 @@ class StoaPluginProfileEditorControllerTest < ActionController::TestCase | @@ -7,8 +7,7 @@ class StoaPluginProfileEditorControllerTest < ActionController::TestCase | ||
7 | 7 | ||
8 | def setup | 8 | def setup |
9 | @controller = ProfileEditorController.new | 9 | @controller = ProfileEditorController.new |
10 | - @request = ActionController::TestRequest.new | ||
11 | - @response = ActionController::TestResponse.new | 10 | + |
12 | @person = User.create(:login => 'test_user', :email => 'test_user@example.com', :password => 'test', :password_confirmation => 'test').person | 11 | @person = User.create(:login => 'test_user', :email => 'test_user@example.com', :password => 'test', :password_confirmation => 'test').person |
13 | login_as(@person.identifier) | 12 | login_as(@person.identifier) |
14 | Environment.default.enable_plugin(StoaPlugin.name) | 13 | Environment.default.enable_plugin(StoaPlugin.name) |
plugins/stoa/test/functional/stoa_plugin_controller_test.rb
@@ -7,8 +7,6 @@ class StoaPluginControllerTest < ActionController::TestCase | @@ -7,8 +7,6 @@ class StoaPluginControllerTest < ActionController::TestCase | ||
7 | 7 | ||
8 | def setup | 8 | def setup |
9 | @controller = StoaPluginController.new | 9 | @controller = StoaPluginController.new |
10 | - @request = ActionController::TestRequest.new | ||
11 | - @response = ActionController::TestResponse.new | ||
12 | ApplicationRecord.configurations['stoa'] = {:adapter => 'sqlite3', :database => ':memory:', :verbosity => 'quiet'} | 10 | ApplicationRecord.configurations['stoa'] = {:adapter => 'sqlite3', :database => ':memory:', :verbosity => 'quiet'} |
13 | env = Environment.default | 11 | env = Environment.default |
14 | env.enable_plugin(StoaPlugin.name) | 12 | env.enable_plugin(StoaPlugin.name) |
plugins/sub_organizations/test/functional/sub_organizations_plugin_myprofile_controller_test.rb
@@ -7,8 +7,7 @@ class SubOrganizationsPluginMyprofileController; def rescue_action(e) raise e en | @@ -7,8 +7,7 @@ class SubOrganizationsPluginMyprofileController; def rescue_action(e) raise e en | ||
7 | class SubOrganizationsPluginMyprofileControllerTest < ActionController::TestCase | 7 | class SubOrganizationsPluginMyprofileControllerTest < ActionController::TestCase |
8 | def setup | 8 | def setup |
9 | @controller = SubOrganizationsPluginMyprofileController.new | 9 | @controller = SubOrganizationsPluginMyprofileController.new |
10 | - @request = ActionController::TestRequest.new | ||
11 | - @response = ActionController::TestResponse.new | 10 | + |
12 | @organization = Organization.create!(:name => 'My Organization', :identifier => 'my-organization') | 11 | @organization = Organization.create!(:name => 'My Organization', :identifier => 'my-organization') |
13 | @person = create_user('person').person | 12 | @person = create_user('person').person |
14 | @organization.add_admin(@person) | 13 | @organization.add_admin(@person) |
plugins/sub_organizations/test/functional/sub_organizations_plugin_profile_controller_test.rb
@@ -8,8 +8,7 @@ class SubOrganizationsPluginProfileControllerTest < ActionController::TestCase | @@ -8,8 +8,7 @@ class SubOrganizationsPluginProfileControllerTest < ActionController::TestCase | ||
8 | 8 | ||
9 | def setup | 9 | def setup |
10 | @controller = SubOrganizationsPluginProfileController.new | 10 | @controller = SubOrganizationsPluginProfileController.new |
11 | - @request = ActionController::TestRequest.new | ||
12 | - @response = ActionController::TestResponse.new | 11 | + |
13 | @organization = Organization.create!(:name => 'My Organization', :identifier => 'my-organization') | 12 | @organization = Organization.create!(:name => 'My Organization', :identifier => 'my-organization') |
14 | @person = create_user('person').person | 13 | @person = create_user('person').person |
15 | @organization.add_admin(@person) | 14 | @organization.add_admin(@person) |