Commit 29151d665bacf2e3e8d12604a1cabdfd25a71f03

Authored by Leandro Santos
2 parents 5a628522 b7e8d430
Exists in staging and in 1 other branch production

merging with master

Showing 415 changed files with 5782 additions and 4483 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 415 files displayed.

.gitlab-ci.yml
... ... @@ -14,6 +14,10 @@ stages:
14 14 # script: bundle exec rake ci:smoke
15 15 # stage: smoke-tests
16 16  
  17 +api:
  18 + script: bundle exec rake test:api
  19 + stage: all-tests
  20 +
17 21 units:
18 22 script: bundle exec rake test:units
19 23 stage: all-tests
... ...
.travis.yml
... ... @@ -5,24 +5,21 @@ notifications:
5 5 template:
6 6 - "%{repository_slug} %{branch} %{commit} %{commit_subject} - %{result} %{build_url}"
7 7  
  8 +# trusty constainers take more time to start
  9 +#dist: trusty
  10 +
8 11 language: ruby
9 12 rvm:
10   - - 2.2.3
  13 + - 2.2
  14 + # ruby 2.3 works but isn't stable on travis
  15 +
  16 +cache: bundler
11 17  
12   -sudo: false
13 18 addons:
14 19 apt:
15 20 packages:
16   - - po4a
17   - - iso-codes
18 21 - tango-icon-theme
19 22 - pidgin-data
20   - # for gem extensions
21   - - libmagickwand-dev
22   - - libpq-dev
23   - - libreadline-dev
24   - - libsqlite3-dev
25   - - libxslt1-dev
26 23 artifacts:
27 24 paths:
28 25 - $(ls tmp/artifact* | tr "\n" ":")
... ... @@ -37,7 +34,7 @@ before_install:
37 34 - gem install bundler
38 35 - sed -i 's/softwarepublico.gov.br\/gitlab/github.com/' .gitmodules
39 36 - git submodule update --init --recursive
40   -cache: bundler
  37 +#cache: bundler
41 38  
42 39 before_script:
43 40 - mkdir -p tmp/{pids,cache} log cache
... ... @@ -46,19 +43,25 @@ before_script:
46 43 # database
47 44 - cp config/database.yml.travis config/database.yml
48 45 - psql -c 'create database myapp_test;' -U postgres
49   - - bundle exec rake db:schema:load &>/dev/null
  46 + - bundle exec rake db:schema:load
50 47 - bundle exec rake db:migrate &>/dev/null
51 48  
52 49 env:
  50 + - TASK=test:api
53 51 - TASK=test:units
54 52 - TASK=test:functionals
55 53 - TASK=test:integration
56   - - TASK=cucumber LANG=en
57   - - TASK=selenium
58   - - SLICE=1/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install
59   - - SLICE=2/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install
60   - - SLICE=3/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install
61   - - SLICE=4/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  54 + - SLICE=1/2 TASK=cucumber LANG=en
  55 + - SLICE=2/2 TASK=cucumber LANG=en
  56 + - SLICE=1/4 TASK=selenium
  57 + - SLICE=2/4 TASK=selenium
  58 + - SLICE=3/4 TASK=selenium
  59 + - SLICE=4/4 TASK=selenium
  60 + - SLICE=1/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  61 + - SLICE=2/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  62 + - SLICE=3/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  63 + - SLICE=4/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  64 + - SLICE=5/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
62 65  
63 66 script:
64 67 - ./script/ci
... ...
Gemfile
... ... @@ -31,6 +31,7 @@ gem 'whenever', :require => false
31 31 gem 'eita-jrails', '~> 0.10.0', require: 'jrails'
32 32 gem 'diffy', '~> 3.0'
33 33 gem 'slim'
  34 +gem 'activerecord-session_store', ('1.0.0.pre' if RUBY_VERSION >= '2.3.0')
34 35  
35 36 # API dependencies
36 37 gem 'grape', '~> 0.12'
... ... @@ -44,6 +45,7 @@ gem 'rack-contrib'
44 45 gem 'liquid', '~> 3.0.3'
45 46  
46 47 gem 'api-pagination', '>= 4.1.1'
  48 +gem 'liquid', '~> 3.0.3'
47 49  
48 50 # asset pipeline
49 51 gem 'uglifier', '>= 1.0.3'
... ... @@ -55,8 +57,6 @@ gem 'protected_attributes'
55 57 gem 'rails-observers'
56 58 gem 'actionpack-page_caching'
57 59 gem 'actionpack-action_caching'
58   -gem 'activerecord-session_store'
59   -gem 'activerecord-deprecated_finders', require: 'active_record/deprecated_finders'
60 60  
61 61 # gem for error reporting
62 62 gem 'airbrake', '~> 4'
... ...
Gemfile.lock
... ... @@ -141,7 +141,6 @@ GEM
141 141 activemodel (= 4.2.5)
142 142 activesupport (= 4.2.5)
143 143 arel (~> 6.0)
144   - activerecord-deprecated_finders (1.0.4)
145 144 activerecord-session_store (0.1.2)
146 145 actionpack (>= 4.0.0, < 5)
147 146 activerecord (>= 4.0.0, < 5)
... ... @@ -417,7 +416,6 @@ DEPENDENCIES
417 416 action_tracker_has_comments (= 0.0.0)!
418 417 actionpack-action_caching
419 418 actionpack-page_caching
420   - activerecord-deprecated_finders
421 419 activerecord-jdbcpostgresql-adapter
422 420 activerecord-session_store
423 421 acts-as-taggable-on (~> 3.5)
... ...
app/controllers/admin/admin_panel_controller.rb
... ... @@ -34,7 +34,7 @@ class AdminPanelController &lt; AdminController
34 34 env = environment
35 35 @portal_community = env.portal_community || Community.new
36 36 if request.post?
37   - portal_community = env.communities.find_by_identifier(params[:portal_community_identifier])
  37 + portal_community = env.communities.where(identifier: params[:portal_community_identifier]).first
38 38 if portal_community
39 39 if (env.portal_community != portal_community)
40 40 env.portal_community = portal_community
... ...
app/controllers/admin/environment_role_manager_controller.rb
... ... @@ -7,7 +7,7 @@ class EnvironmentRoleManagerController &lt; AdminController
7 7  
8 8 def change_roles
9 9 @admin = Person.find(params[:id])
10   - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) }
  10 + @roles = Role.all.select{ |r| r.has_kind?(:environment) }
11 11 end
12 12  
13 13 def update_roles
... ... @@ -22,7 +22,7 @@ class EnvironmentRoleManagerController &lt; AdminController
22 22 end
23 23  
24 24 def change_role
25   - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) }
  25 + @roles = Role.all.select{ |r| r.has_kind?(:environment) }
26 26 @admin = Person.find(params[:id])
27 27 @associations = @admin.find_roles(environment)
28 28 end
... ... @@ -34,7 +34,7 @@ class EnvironmentRoleManagerController &lt; AdminController
34 34 redirect_to :action => 'index'
35 35 else
36 36 @admin = Person.find(params[:person])
37   - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) }
  37 + @roles = Role.all.select{ |r| r.has_kind?(:environment) }
38 38 render :action => 'affiliate'
39 39 end
40 40 end
... ... @@ -60,7 +60,7 @@ class EnvironmentRoleManagerController &lt; AdminController
60 60 end
61 61  
62 62 def make_admin
63   - @people = Person.find(:all)
64   - @roles = Role.find(:all).select{|r|r.has_kind?(:environment)}
  63 + @people = Person.all
  64 + @roles = Role.all.select{|r|r.has_kind?(:environment)}
65 65 end
66 66 end
... ...
app/controllers/admin/features_controller.rb
... ... @@ -100,7 +100,7 @@ class FeaturesController &lt; AdminController
100 100 CustomField.destroy(custom_fields_to_destroy)
101 101  
102 102 custom_field_list.each_pair do |id, custom_field|
103   - field = CustomField.find_by_id(id)
  103 + field = CustomField.find_by(id: id)
104 104 if not field.blank?
105 105 params_to_update = custom_field.except(:format, :extras, :customized_type,:environment)
106 106 field.update_attributes(params_to_update)
... ...
app/controllers/admin/organizations_controller.rb
... ... @@ -7,7 +7,11 @@ class OrganizationsController &lt; AdminController
7 7 @title = _('Organization profiles')
8 8 @type = params[:type] || "any"
9 9 @types_filter = [[_('All'), 'any'], [_('Community'), 'Community'], [_('Enterprise'), 'Enterprise']]
10   - @types_filter = @types_filter | @plugins.dispatch(:organization_types_filter_options)
  10 + @plugins.dispatch_without_flatten(:organization_types_filter_options).each do |plugin_response|
  11 + @types_filter = @types_filter | plugin_response
  12 + end
  13 + @types_hash = {}
  14 + @types_filter.each{|list| @types_hash[list.last] = list.first}
11 15  
12 16 scope = @plugins.dispatch_first(:filter_manage_organization_scope, @type)
13 17 if scope.blank?
... ...
app/controllers/admin/role_controller.rb
... ... @@ -2,7 +2,7 @@ class RoleController &lt; AdminController
2 2 protect 'manage_environment_roles', :environment
3 3  
4 4 def index
5   - @roles = environment.roles.find(:all, :conditions => {:profile_id => nil})
  5 + @roles = environment.roles.where profile_id: nil
6 6 end
7 7  
8 8 def new
... ...
app/controllers/admin/users_controller.rb
... ... @@ -48,7 +48,7 @@ class UsersController &lt; AdminController
48 48  
49 49 def destroy_user
50 50 if request.post?
51   - person = environment.people.find_by_id(params[:id])
  51 + person = environment.people.find_by id: params[:id]
52 52 if person && person.destroy
53 53 session[:notice] = _('The profile was deleted.')
54 54 else
... ...
app/controllers/application_controller.rb
... ... @@ -128,7 +128,7 @@ class ApplicationController &lt; ActionController::Base
128 128 # Sets text domain based on request host for custom internationalization
129 129 FastGettext.text_domain = Domain.custom_locale(request.host)
130 130  
131   - @domain = Domain.find_by_name(request.host)
  131 + @domain = Domain.by_name(request.host)
132 132 if @domain.nil?
133 133 @environment = Environment.default
134 134 # Avoid crashes on test and development setups
... ... @@ -143,7 +143,7 @@ class ApplicationController &lt; ActionController::Base
143 143  
144 144 # Check if the requested profile belongs to another domain
145 145 if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier
146   - @profile = @environment.profiles.find_by_identifier params[:profile]
  146 + @profile = @environment.profiles.find_by(identifier: params[:profile])
147 147 redirect_to url_for(params.merge host: @profile.default_hostname)
148 148 end
149 149 end
... ... @@ -175,7 +175,7 @@ class ApplicationController &lt; ActionController::Base
175 175 def load_category
176 176 unless params[:category_path].blank?
177 177 path = params[:category_path]
178   - @category = environment.categories.find_by_path(path)
  178 + @category = environment.categories.find_by(path: path)
179 179 if @category.nil?
180 180 render_not_found(path)
181 181 end
... ...
app/controllers/box_organizer_controller.rb
... ... @@ -16,10 +16,9 @@ class BoxOrganizerController &lt; ApplicationController
16 16 target_position = block_before.position
17 17  
18 18 @target_box = block_before.box
19   - else
20   - (params[:target] =~ /end-of-box-([0-9]+)/)
  19 + elsif params[:target] =~ /end-of-box-([0-9]+)/
21 20  
22   - @target_box = boxes_holder.boxes.find_by_id($1)
  21 + @target_box = boxes_holder.boxes.find_by id: $1
23 22 end
24 23  
25 24 @block = new_block(params[:type], @target_box) if @block.nil?
... ... @@ -35,8 +34,8 @@ class BoxOrganizerController &lt; ApplicationController
35 34 @block.insert_at(@target_box.blocks.size + 1)
36 35 @block.move_to_bottom
37 36 else
38   - # insert the block in the given position
39   - @block.insert_at(@block.position && @block.position < target_position ? target_position - 1 : target_position)
  37 + new_position = if @block.position and @block.position < target_position then target_position - 1 else target_position end
  38 + @block.insert_at new_position
40 39 end
41 40  
42 41 @block.save!
... ...
app/controllers/email_templates_controller.rb
... ... @@ -1,62 +0,0 @@
1   -class EmailTemplatesController < ApplicationController
2   -
3   - def index
4   - @email_templates = owner.email_templates
5   - end
6   -
7   - def show
8   - @email_template = owner.email_templates.find(params[:id])
9   -
10   - respond_to do |format|
11   - format.html # show.html.erb
12   - format.json { render json: @email_template }
13   - end
14   - end
15   -
16   - def show_parsed
17   - @email_template = owner.email_templates.find(params[:id])
18   - template_params = {:profile => owner, :environment => environment}
19   - render json: {:parsed_body => @email_template.parsed_body(template_params), :parsed_subject => @email_template.parsed_subject(template_params)}
20   - end
21   -
22   - def new
23   - @email_template = owner.email_templates.build(:owner => owner)
24   - end
25   -
26   - def edit
27   - @email_template = owner.email_templates.find(params[:id])
28   - end
29   -
30   - def create
31   - @email_template = owner.email_templates.build(params[:email_template])
32   - @email_template.owner = owner
33   -
34   - if @email_template.save
35   - session[:notice] = _('Email template was successfully created.')
36   - redirect_to url_for(:action => :index)
37   - else
38   - render action: "new"
39   - end
40   - end
41   -
42   - def update
43   - @email_template = owner.email_templates.find(params[:id])
44   -
45   - if @email_template.update_attributes(params[:email_template])
46   - session[:notice] = _('Email template was successfully updated.')
47   - redirect_to url_for(:action => :index)
48   - else
49   - render action: "edit"
50   - end
51   - end
52   -
53   - def destroy
54   - @email_template = owner.email_templates.find(params[:id])
55   - @email_template.destroy
56   -
57   - respond_to do |format|
58   - format.html { redirect_to url_for(:action => :index)}
59   - format.json { head :no_content }
60   - end
61   - end
62   -end
app/controllers/my_profile/cms_controller.rb
... ... @@ -3,6 +3,7 @@ class CmsController &lt; MyProfileController
3 3 protect 'edit_profile', :profile, :only => [:set_home_page]
4 4  
5 5 include ArticleHelper
  6 + include CategoriesHelper
6 7  
7 8 def search_tags
8 9 arg = params[:term].downcase
... ... @@ -33,7 +34,7 @@ class CmsController &lt; MyProfileController
33 34  
34 35 protect_if :only => [:new, :upload_files] do |c, user, profile|
35 36 parent_id = c.params[:article].present? ? c.params[:article][:parent_id] : c.params[:parent_id]
36   - parent = profile.articles.find_by_id(parent_id)
  37 + parent = profile.articles.find_by(id: parent_id)
37 38 user && user.can_post_content?(profile, parent)
38 39 end
39 40  
... ... @@ -58,11 +59,10 @@ class CmsController &lt; MyProfileController
58 59  
59 60 def index
60 61 @article = nil
61   - @articles = profile.top_level_articles.paginate(
62   - :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC",
63   - :per_page => per_page,
64   - :page => params[:npage]
65   - )
  62 + @articles = profile.top_level_articles
  63 + .order("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC")
  64 + .paginate(per_page: per_page, page: params[:npage])
  65 +
66 66 render :action => 'view'
67 67 end
68 68  
... ... @@ -256,12 +256,7 @@ class CmsController &lt; MyProfileController
256 256  
257 257 def update_categories
258 258 @object = params[:id] ? @profile.articles.find(params[:id]) : Article.new
259   - @categories = @toplevel_categories = environment.top_level_categories
260   - if params[:category_id]
261   - @current_category = Category.find(params[:category_id])
262   - @categories = @current_category.children
263   - end
264   - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'article' }
  259 + render_categories 'article'
265 260 end
266 261  
267 262 def search_communities_to_publish
... ...
app/controllers/my_profile/email_templates_controller.rb 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +class EmailTemplatesController < ApplicationController
  2 +
  3 + def index
  4 + @email_templates = owner.email_templates
  5 + end
  6 +
  7 + def show
  8 + @email_template = owner.email_templates.find(params[:id])
  9 +
  10 + respond_to do |format|
  11 + format.html # show.html.erb
  12 + format.json { render json: @email_template }
  13 + end
  14 + end
  15 +
  16 + def show_parsed
  17 + @email_template = owner.email_templates.find(params[:id])
  18 + template_params = {:profile => owner, :environment => environment}
  19 + render json: {:parsed_body => @email_template.parsed_body(template_params), :parsed_subject => @email_template.parsed_subject(template_params)}
  20 + end
  21 +
  22 + def new
  23 + @email_template = owner.email_templates.build(:owner => owner)
  24 + @template_params_allowed = template_params_allowed template_params.keys
  25 + end
  26 +
  27 + def edit
  28 + @email_template = owner.email_templates.find(params[:id])
  29 + @template_params_allowed = template_params_allowed template_params.keys
  30 + end
  31 +
  32 + def create
  33 + @email_template = owner.email_templates.build(params[:email_template])
  34 + @email_template.owner = owner
  35 +
  36 + if @email_template.save
  37 + session[:notice] = _('Email template was successfully created.')
  38 + redirect_to url_for(:action => :index)
  39 + else
  40 + render action: "new"
  41 + end
  42 + end
  43 +
  44 + def update
  45 + @email_template = owner.email_templates.find(params[:id])
  46 +
  47 + if @email_template.update_attributes(params[:email_template])
  48 + session[:notice] = _('Email template was successfully updated.')
  49 + redirect_to url_for(:action => :index)
  50 + else
  51 + render action: "edit"
  52 + end
  53 + end
  54 +
  55 + def destroy
  56 + @email_template = owner.email_templates.find(params[:id])
  57 + @email_template.destroy
  58 +
  59 + respond_to do |format|
  60 + format.html { redirect_to url_for(:action => :index)}
  61 + format.json { head :no_content }
  62 + end
  63 + end
  64 +
  65 + private
  66 +
  67 + def template_params
  68 + {:profile_name => current_user.name, :environment_name => environment.name }
  69 + end
  70 +
  71 + def template_params_allowed params
  72 + result = ""
  73 + params.each{ |param| result << "{{ #{param} }} " } if params
  74 + result
  75 + end
  76 +
  77 +end
... ...
app/controllers/my_profile/friends_controller.rb
... ... @@ -22,7 +22,7 @@ class FriendsController &lt; MyProfileController
22 22 end
23 23  
24 24 def remove_suggestion
25   - @person = profile.suggested_people.find_by_identifier(params[:id])
  25 + @person = profile.suggested_people.find_by(identifier: params[:id])
26 26 redirect_to :action => 'suggest' unless @person
27 27 if @person && request.post?
28 28 profile.remove_suggestion(@person)
... ... @@ -32,7 +32,7 @@ class FriendsController &lt; MyProfileController
32 32 end
33 33  
34 34 def connections
35   - @suggestion = profile.suggested_profiles.of_person.enabled.find_by_suggestion_id(params[:id])
  35 + @suggestion = profile.suggested_profiles.of_person.enabled.find_by(suggestion_id: params[:id])
36 36 if @suggestion
37 37 @tags = @suggestion.tag_connections
38 38 @profiles = @suggestion.profile_connections
... ...
app/controllers/my_profile/manage_products_controller.rb
... ... @@ -35,7 +35,7 @@ class ManageProductsController &lt; ApplicationController
35 35 end
36 36  
37 37 def categories_for_selection
38   - @category = environment.categories.find_by_id params[:category_id]
  38 + @category = environment.categories.find_by id: params[:category_id]
39 39 @object_name = params[:object_name]
40 40 if @category
41 41 @categories = @category.children
... ... @@ -103,7 +103,7 @@ class ManageProductsController &lt; ApplicationController
103 103 def search_categories
104 104 @term = params[:term].downcase
105 105 conditions = ['LOWER(name) LIKE ? OR LOWER(name) LIKE ?', "#{@term}%", "% #{@term}%"]
106   - @categories = ProductCategory.all :conditions => conditions, :limit => 10
  106 + @categories = ProductCategory.where(conditions).limit(10)
107 107 render :json => (@categories.map do |category|
108 108 {:label => category.name, :value => category.id}
109 109 end)
... ... @@ -169,7 +169,7 @@ class ManageProductsController &lt; ApplicationController
169 169  
170 170 def edit_input
171 171 if request.xhr?
172   - @input = @profile.inputs.find_by_id(params[:id])
  172 + @input = @profile.inputs.find_by id: params[:id]
173 173 if @input
174 174 if request.post?
175 175 if @input.update(params[:input])
... ... @@ -206,7 +206,6 @@ class ManageProductsController &lt; ApplicationController
206 206 end
207 207  
208 208 def certifiers_for_selection
209   - # updated to use hash as argument to exists? to avoid sql injection vunerabillity (http://brakemanscanner.org/docs/warning_types/sql_injection/)
210 209 @qualifier = Qualifier.exists?(:id => params[:id]) ? Qualifier.find(params[:id]) : nil
211 210 render :update do |page|
212 211 page.replace_html params[:certifier_area], :partial => 'certifiers_for_selection'
... ...
app/controllers/my_profile/memberships_controller.rb
... ... @@ -5,7 +5,7 @@ class MembershipsController &lt; MyProfileController
5 5  
6 6 def index
7 7 @roles = environment.roles.select do |role|
8   - ra = profile.role_assignments.find_by_role_id(role.id)
  8 + ra = profile.role_assignments.find_by(role_id: role.id)
9 9 ra.present? && ra.resource_type == 'Profile'
10 10 end
11 11 @filter = params[:filter_type].to_i
... ... @@ -47,7 +47,7 @@ class MembershipsController &lt; MyProfileController
47 47 end
48 48  
49 49 def remove_suggestion
50   - @community = profile.suggested_communities.find_by_identifier(params[:id])
  50 + @community = profile.suggested_communities.find_by(identifier: params[:id])
51 51 custom_per_page = params[:per_page] || per_page
52 52 redirect_to :action => 'suggest' unless @community
53 53 if @community && request.post?
... ... @@ -58,7 +58,7 @@ class MembershipsController &lt; MyProfileController
58 58 end
59 59  
60 60 def connections
61   - @suggestion = profile.suggested_profiles.of_community.enabled.find_by_suggestion_id(params[:id])
  61 + @suggestion = profile.suggested_profiles.of_community.enabled.find_by(suggestion_id: params[:id])
62 62 if @suggestion
63 63 @tags = @suggestion.tag_connections
64 64 @profiles = @suggestion.profile_connections
... ...
app/controllers/my_profile/profile_design_controller.rb
... ... @@ -6,6 +6,7 @@ class ProfileDesignController &lt; BoxOrganizerController
6 6  
7 7 before_filter :protect_uneditable_block, :only => [:save]
8 8 before_filter :protect_fixed_block, :only => [:move_block]
  9 + include CategoriesHelper
9 10  
10 11 def protect_uneditable_block
11 12 block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, ''))
... ... @@ -67,4 +68,9 @@ class ProfileDesignController &lt; BoxOrganizerController
67 68 blocks
68 69 end
69 70  
  71 + def update_categories
  72 + @object = params[:id] ? @profile.blocks.find(params[:id]) : Block.new
  73 + render_categories 'block'
  74 + end
  75 +
70 76 end
... ...
app/controllers/my_profile/profile_editor_controller.rb
... ... @@ -9,6 +9,7 @@ class ProfileEditorController &lt; MyProfileController
9 9 before_filter :check_user_can_edit_header_footer, :only => [:header_footer]
10 10 helper_method :has_welcome_page
11 11 helper CustomFieldsHelper
  12 + include CategoriesHelper
12 13  
13 14 def index
14 15 @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)}
... ... @@ -63,12 +64,7 @@ class ProfileEditorController &lt; MyProfileController
63 64  
64 65 def update_categories
65 66 @object = profile
66   - @categories = @toplevel_categories = environment.top_level_categories
67   - if params[:category_id]
68   - @current_category = Category.find(params[:category_id])
69   - @categories = @current_category.children
70   - end
71   - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'profile_data' }
  67 + render_categories 'profile_data'
72 68 end
73 69  
74 70 def header_footer
... ...
app/controllers/my_profile/profile_members_controller.rb
... ... @@ -60,7 +60,7 @@ class ProfileMembersController &lt; MyProfileController
60 60 redirect_to :action => 'index'
61 61 else
62 62 @member = Person.find(params[:person])
63   - @roles = environment.roles.find(:all).select{ |r| r.has_kind?('Profile') }
  63 + @roles = environment.roles.all.select{ |r| r.has_kind?('Profile') }
64 64 render :action => 'affiliate'
65 65 end
66 66 end
... ... @@ -120,7 +120,7 @@ class ProfileMembersController &lt; MyProfileController
120 120 @collection = :profile_admins
121 121  
122 122 if profile.community?
123   - member = profile.members.find_by_identifier(params[:id])
  123 + member = profile.members.find_by(identifier: params[:id])
124 124 profile.add_admin(member)
125 125 end
126 126 render :layout => false
... ... @@ -131,7 +131,7 @@ class ProfileMembersController &lt; MyProfileController
131 131 @collection = :profile_admins
132 132  
133 133 if profile.community?
134   - member = profile.members.find_by_identifier(params[:id])
  134 + member = profile.members.find_by(identifier: params[:id])
135 135 profile.remove_admin(member)
136 136 end
137 137 render :layout => false
... ...
app/controllers/my_profile/spam_controller.rb
... ... @@ -15,12 +15,12 @@ class SpamController &lt; MyProfileController
15 15 profile.comments_received.find(params[:remove_comment]).destroy
16 16 end
17 17 if params[:remove_task]
18   - Task.to(profile).find_by_id(params[:remove_task]).destroy
  18 + Task.to(profile).find_by(id: params[:remove_task]).destroy
19 19 end
20 20 if params[:mark_comment_as_ham]
21 21 profile.comments_received.find(params[:mark_comment_as_ham]).ham!
22 22 end
23   - if params[:mark_task_as_ham] && (t = Task.to(profile).find_by_id(params[:mark_task_as_ham]))
  23 + if params[:mark_task_as_ham] && (t = Task.to(profile).find_by(id: params[:mark_task_as_ham]))
24 24 t.ham!
25 25 end
26 26 if request.xhr?
... ...
app/controllers/my_profile/tasks_controller.rb
1 1 class TasksController < MyProfileController
2 2  
3   - protect [:perform_task, :view_tasks], :profile, :only => [:index, :save_tags, :search_tags]
4   - protect :perform_task, :profile, :only => [:processed, :change_responsible, :close, :new, :list_requested, :ticket_details, :search_tags]
5 3 include TasksHelper
6 4  
  5 + protect [:perform_task, :view_tasks], :profile, :only => [:index, :save_tags, :search_tags]
  6 + protect :perform_task, :profile, :except => [:index, :save_tags, :search_tags]
  7 + helper CustomFieldsHelper
7 8  
8 9 def index
9   - @rejection_email_templates = profile.email_templates.find_all_by_template_type(:task_rejection)
10   - @acceptance_email_templates = profile.email_templates.find_all_by_template_type(:task_acceptance)
  10 + @rejection_email_templates = profile.email_templates.where template_type: :task_rejection
  11 + @acceptance_email_templates = profile.email_templates.where template_type: :task_acceptance
11 12  
12 13 @filter_type = params[:filter_type].presence
13 14 @filter_text = params[:filter_text].presence
... ... @@ -110,7 +111,7 @@ class TasksController &lt; MyProfileController
110 111 end
111 112  
112 113 def list_requested
113   - @tasks = Task.without_spam.find_all_by_requestor_id(profile.id)
  114 + @tasks = Task.without_spam.where requestor_id: profile.id
114 115 end
115 116  
116 117 def ticket_details
... ...
app/controllers/public/account_controller.rb
... ... @@ -17,7 +17,7 @@ class AccountController &lt; ApplicationController
17 17 end
18 18  
19 19 def activate
20   - @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code]
  20 + @user = User.find_by(activation_code: params[:activation_code]) if params[:activation_code]
21 21 if @user
22 22 unless @user.environment.enabled?('admin_must_approve_new_users')
23 23 if @user.activate
... ... @@ -126,7 +126,7 @@ class AccountController &lt; ApplicationController
126 126 end
127 127 @user.community_to_join = session[:join]
128 128 @user.signup!
129   - owner_role = Role.find_by_name('owner')
  129 + owner_role = Role.find_by(name: 'owner')
130 130 @user.person.affiliate(@user.person, [owner_role]) if owner_role
131 131 invitation = Task.from_code(@invitation_code).first
132 132 if invitation
... ... @@ -313,7 +313,7 @@ class AccountController &lt; ApplicationController
313 313 end
314 314  
315 315 def check_email
316   - if User.find_by_email_and_environment_id(params[:address], environment.id).nil?
  316 + if User.find_by(email: params[:address], environment_id: environment.id).nil?
317 317 @status = _('This e-mail address is available')
318 318 @status_class = 'validated'
319 319 else
... ... @@ -510,7 +510,7 @@ class AccountController &lt; ApplicationController
510 510 def check_join_in_community(user)
511 511 profile_to_join = session[:join]
512 512 unless profile_to_join.blank?
513   - environment.profiles.find_by_identifier(profile_to_join).add_member(user.person)
  513 + environment.profiles.find_by(identifier: profile_to_join).add_member(user.person)
514 514 session.delete(:join)
515 515 end
516 516 end
... ...
app/controllers/public/chat_controller.rb
... ... @@ -44,7 +44,7 @@ class ChatController &lt; PublicController
44 44 end
45 45  
46 46 def avatar
47   - profile = environment.profiles.find_by_identifier(params[:id])
  47 + profile = environment.profiles.find_by(identifier: params[:id])
48 48 filename, mimetype = profile_icon(profile, :minor, true)
49 49 if filename =~ /^(https?:)?\/\//
50 50 redirect_to filename
... ... @@ -87,7 +87,7 @@ class ChatController &lt; PublicController
87 87 end
88 88  
89 89 def recent_messages
90   - other = environment.profiles.find_by_identifier(params[:identifier])
  90 + other = environment.profiles.find_by(identifier: params[:identifier])
91 91 if other.kind_of?(Organization)
92 92 messages = ChatMessage.where('to_id=:other', :other => other.id)
93 93 else
... ...
app/controllers/public/contact_controller.rb
... ... @@ -6,7 +6,6 @@ class ContactController &lt; PublicController
6 6 def new
7 7 @contact = build_contact
8 8 if request.post? && params[:confirm] == 'true'
9   - # updated to use hash as argument to exists? to avoid sql injection vunerabillity (http://brakemanscanner.org/docs/warning_types/sql_injection/)
10 9 @contact.city = (!params[:city].blank? && City.exists?(:id => params[:city])) ? City.find(params[:city]).name : nil
11 10 @contact.state = (!params[:state].blank? && State.exists?(:id => params[:state])) ? State.find(params[:state]).name : nil
12 11 if @contact.deliver
... ...
app/controllers/public/content_viewer_controller.rb
... ... @@ -22,7 +22,7 @@ class ContentViewerController &lt; ApplicationController
22 22 @page = profile.home_page
23 23 return if redirected_to_profile_index
24 24 else
25   - @page = profile.articles.find_by_path(path)
  25 + @page = profile.articles.find_by path: path
26 26 return if redirected_page_from_old_path(path)
27 27 end
28 28  
... ... @@ -80,13 +80,13 @@ class ContentViewerController &lt; ApplicationController
80 80  
81 81 def versions_diff
82 82 path = params[:page]
83   - @page = profile.articles.find_by_path(path)
84   - @v1, @v2 = @page.versions.find_by_version(params[:v1]), @page.versions.find_by_version(params[:v2])
  83 + @page = profile.articles.find_by path: path
  84 + @v1, @v2 = @page.versions.find_by(version: params[:v1]), @page.versions.find_by(version: params[:v2])
85 85 end
86 86  
87 87 def article_versions
88 88 path = params[:page]
89   - @page = profile.articles.find_by_path(path)
  89 + @page = profile.articles.find_by path: path
90 90 return unless allow_access_to_page(path)
91 91  
92 92 render_access_denied unless @page.display_versions?
... ... @@ -173,7 +173,7 @@ class ContentViewerController &lt; ApplicationController
173 173  
174 174 def redirected_page_from_old_path(path)
175 175 unless @page
176   - page_from_old_path = profile.articles.find_by_old_path(path)
  176 + page_from_old_path = profile.articles.find_by_old_path path
177 177 if page_from_old_path
178 178 redirect_to profile.url.merge(:page => page_from_old_path.explode_path)
179 179 return true
... ... @@ -194,7 +194,7 @@ class ContentViewerController &lt; ApplicationController
194 194 end
195 195  
196 196 def rendered_versioned_article
197   - @versioned_article = @page.versions.find_by_version(@version)
  197 + @versioned_article = @page.versions.find_by version: @version
198 198 if @versioned_article && @page.versions.latest.version != @versioned_article.version
199 199 render :template => 'content_viewer/versioned_article.html.erb'
200 200 return true
... ...
app/controllers/public/enterprise_registration_controller.rb
... ... @@ -68,7 +68,7 @@ class EnterpriseRegistrationController &lt; ApplicationController
68 68 # saying to the user that the enterprise was created.
69 69 def creation
70 70 @create_enterprise.perform
71   - @enterprise = @create_enterprise.target.profiles.find_by_identifier(@create_enterprise.identifier)
  71 + @enterprise = @create_enterprise.target.profiles.find_by identifier: @create_enterprise.identifier
72 72 end
73 73  
74 74 end
... ...
app/controllers/public/profile_controller.rb
... ... @@ -339,7 +339,7 @@ class ProfileController &lt; PublicController
339 339 user.register_report(abuse_report, profile)
340 340  
341 341 if !params[:content_type].blank?
342   - abuse_report = AbuseReport.find_by_reporter_id_and_abuse_complaint_id(user.id, profile.opened_abuse_complaint.id)
  342 + abuse_report = AbuseReport.find_by(reporter_id: user.id, abuse_complaint_id: profile.opened_abuse_complaint.id)
343 343 Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article)
344 344 end
345 345  
... ... @@ -373,8 +373,8 @@ class ProfileController &lt; PublicController
373 373  
374 374 def send_mail
375 375 @mailing = profile.mailings.build(params[:mailing])
376   - @email_templates = profile.email_templates.find_all_by_template_type(:organization_members)
377 376 @mailing.data = session[:members_filtered] ? {:members_filtered => session[:members_filtered]} : {}
  377 + @email_templates = profile.email_templates.where template_type: :organization_members
378 378 if request.post?
379 379 @mailing.locale = locale
380 380 @mailing.person = user
... ...
app/controllers/public/search_controller.rb
... ... @@ -171,7 +171,7 @@ class SearchController &lt; PublicController
171 171 render_not_found if params[:action] == 'category_index'
172 172 else
173 173 path = params[:category_path]
174   - @category = environment.categories.find_by_path(path)
  174 + @category = environment.categories.find_by path: path
175 175 if @category.nil?
176 176 render_not_found(path)
177 177 else
... ... @@ -181,14 +181,14 @@ class SearchController &lt; PublicController
181 181 end
182 182  
183 183 def available_searches
184   - @available_searches ||= ActiveSupport::OrderedHash[
185   - :articles, _('Contents'),
186   - :people, _('People'),
187   - :communities, _('Communities'),
188   - :enterprises, _('Enterprises'),
189   - :products, _('Products and Services'),
190   - :events, _('Events'),
191   - ]
  184 + @available_searches ||= {
  185 + articles: _('Contents'),
  186 + people: _('People'),
  187 + communities: _('Communities'),
  188 + enterprises: _('Enterprises'),
  189 + products: _('Products and Services'),
  190 + events: _('Events'),
  191 + }
192 192 end
193 193  
194 194 def load_search_assets
... ... @@ -248,7 +248,11 @@ class SearchController &lt; PublicController
248 248 def visible_profiles(klass, *extra_relations)
249 249 relations = [:image, :domains, :environment, :preferred_domain]
250 250 relations += extra_relations
251   - @environment.send(klass.name.underscore.pluralize).visible.includes(relations)
  251 + if current_user && current_user.person.is_admin?
  252 + @environment.send(klass.name.underscore.pluralize).includes(relations)
  253 + else
  254 + @environment.send(klass.name.underscore.pluralize).visible.includes(relations)
  255 + end
252 256 end
253 257  
254 258 def per_page
... ... @@ -256,13 +260,13 @@ class SearchController &lt; PublicController
256 260 end
257 261  
258 262 def available_assets
259   - assets = ActiveSupport::OrderedHash[
260   - :articles, _('Contents'),
261   - :enterprises, _('Enterprises'),
262   - :people, _('People'),
263   - :communities, _('Communities'),
264   - :products, _('Products and Services'),
265   - ]
  263 + assets = {
  264 + articles: _('Contents'),
  265 + enterprises: _('Enterprises'),
  266 + people: _('People'),
  267 + communities: _('Communities'),
  268 + products: _('Products and Services'),
  269 + }
266 270 end
267 271  
268 272 end
... ...
app/helpers/application_helper.rb
... ... @@ -56,6 +56,8 @@ module ApplicationHelper
56 56  
57 57 include ThemeLoaderHelper
58 58  
  59 + include TaskHelper
  60 +
59 61 def locale
60 62 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale
61 63 end
... ... @@ -318,7 +320,7 @@ module ApplicationHelper
318 320 if File.exists?(Rails.root.join('public', theme_path, 'favicon.ico'))
319 321 '/designs/themes/' + profile.theme + '/favicon.ico'
320 322 else
321   - favicon = profile.articles.find_by_path('favicon.ico')
  323 + favicon = profile.articles.find_by path: 'favicon.ico'
322 324 if favicon
323 325 favicon.public_filename
324 326 else
... ... @@ -1165,8 +1167,8 @@ module ApplicationHelper
1165 1167 end
1166 1168  
1167 1169 def default_folder_for_image_upload(profile)
1168   - default_folder = profile.folders.find_by_type('Gallery')
1169   - default_folder = profile.folders.find_by_type('Folder') if default_folder.nil?
  1170 + default_folder = profile.folders.find_by type: 'Gallery'
  1171 + default_folder = profile.folders.find_by type: 'Folder' if default_folder.nil?
1170 1172 default_folder
1171 1173 end
1172 1174  
... ...
app/helpers/block_helper.rb
1 1 module BlockHelper
2 2  
3   - def block_title(title)
4   - tag_class = 'block-title'
  3 + def block_title(title, subtitle=nil)
  4 + block_header = block_heading title
  5 + block_header += block_heading(subtitle, 'h4') if subtitle
  6 + content_tag 'div', block_header, :class => 'block-header'
  7 + end
  8 +
  9 + def block_heading(title, heading='h3')
  10 + tag_class = 'block-' + (heading == 'h3' ? 'title' : 'subtitle')
5 11 tag_class += ' empty' if title.empty?
6   - content_tag 'h3', content_tag('span', h(title)), :class => tag_class
  12 + content_tag heading, content_tag('span', h(title)), :class => tag_class
7 13 end
8 14  
9 15 def highlights_block_config_image_fields(block, image={}, row_number=nil)
... ...
app/helpers/categories_helper.rb
... ... @@ -34,4 +34,15 @@ module CategoriesHelper
34 34 {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => html_class}.merge(html_options)
35 35 end
36 36  
  37 + def render_categories object_name
  38 + @toplevel_categories = environment.top_level_categories
  39 + if params[:category_id]
  40 + @current_category = Category.find(params[:category_id])
  41 + @categories = @current_category.children
  42 + else
  43 + @categories = @toplevel_categories
  44 + end
  45 + render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => object_name }
  46 + end
  47 +
37 48 end
... ...
app/helpers/custom_fields_helper.rb
... ... @@ -37,8 +37,15 @@ module CustomFieldsHelper
37 37 end
38 38  
39 39 def display_custom_field_value(custom_field_value)
40   - value = profile.custom_value(custom_field_value.custom_field.name)
41   - case custom_field_value.custom_field.format
  40 + value_for_format custom_field_value.custom_field.format, custom_field_value.value
  41 + end
  42 +
  43 + def display_value_for_custom_field(custom_field, value)
  44 + value_for_format custom_field.format, value
  45 + end
  46 +
  47 + def value_for_format format, value
  48 + case format
42 49 when 'text', 'list', 'numeric', 'date', 'string'
43 50 value
44 51 when 'checkbox'
... ... @@ -47,6 +54,7 @@ module CustomFieldsHelper
47 54 url = value[/\Ahttps?:\/\//i] ? value : "http://#{value}"
48 55 link_to(value, url, :target => '_blank')
49 56 end
  57 +
50 58 end
51 59  
52 60 private
... ...
app/helpers/forms_helper.rb
... ... @@ -50,15 +50,15 @@ module FormsHelper
50 50 end
51 51  
52 52 def select_city( simple=false )
53   - states = State.find(:all, :order => 'name')
54   -
  53 + states = State.order(:name).all
  54 +
55 55 state_id = 'state-' + FormsHelper.next_id_number
56 56 city_id = 'city-' + FormsHelper.next_id_number
57 57  
58 58 if states.length < 1
59 59 return
60 60 end
61   -
  61 +
62 62 if simple
63 63 states = [State.new(:name => _('Select the State'))] + states
64 64 cities = [City.new(:name => _('Select the City'))]
... ... @@ -82,7 +82,7 @@ module FormsHelper
82 82 states = [State.new(:name => '---')] + states
83 83 cities = [City.new(:name => '---')]
84 84  
85   - html =
  85 + html =
86 86 content_tag( 'div',
87 87 labelled_select( _('State:'), 'state', :id, :name, nil, states, :id => state_id ),
88 88 :class => 'select_state_for_origin' ) +
... ... @@ -90,7 +90,7 @@ module FormsHelper
90 90 labelled_select( _('City:'), 'city', :id, :name, nil, cities, :id => city_id ),
91 91 :class => 'select_city_for_origin' )
92 92 end
93   -
  93 +
94 94 html +
95 95 observe_field( state_id, :update => city_id, :function => "new Ajax.Updater(#{city_id.inspect}, #{url_for(:controller => 'search', :action => 'cities').inspect}, {asynchronous:true, evalScripts:true, parameters:'state_id=' + value}); $(#{city_id.inspect}).innerHTML = '<option>#{_('Loading...')}</option>'", :with => 'state_id')
96 96 end
... ...
app/helpers/manage_products_helper.rb
... ... @@ -222,7 +222,7 @@ module ManageProductsHelper
222 222 end
223 223 def select_certifiers(qualifier, product = nil)
224 224 if qualifier
225   - selected = product ? product.product_qualifiers.find_by_qualifier_id(qualifier.id).certifier_id : nil
  225 + selected = product ? product.product_qualifiers.find_by(qualifier_id: qualifier.id).certifier_id : nil
226 226 select_tag("product[qualifiers_list][#{qualifier.id}]", options_for_select(certifiers_for_select(qualifier), selected))
227 227 else
228 228 select_tag("product[qualifiers_list][nil]")
... ...
app/helpers/profile_helper.rb
1 1 module ProfileHelper
2 2  
3   - COMMON_CATEGORIES = ActiveSupport::OrderedHash.new
  3 + COMMON_CATEGORIES = {}
4 4 COMMON_CATEGORIES[:content] = [:blogs, :image_galleries, :events, :article_tags]
5 5 COMMON_CATEGORIES[:interests] = [:interests]
6 6 COMMON_CATEGORIES[:general] = nil
7 7  
8   - PERSON_CATEGORIES = ActiveSupport::OrderedHash.new
  8 + PERSON_CATEGORIES = {}
9 9 PERSON_CATEGORIES[:basic_information] = [:nickname, :sex, :birth_date, :location, :privacy_setting, :created_at]
10 10 PERSON_CATEGORIES[:contact] = [:contact_phone, :cell_phone, :comercial_phone, :contact_information, :email, :personal_website, :jabber_id]
11 11 PERSON_CATEGORIES[:location] = [:address, :address_reference, :zip_code, :city, :state, :district, :country, :nationality]
... ... @@ -14,13 +14,13 @@ module ProfileHelper
14 14 PERSON_CATEGORIES[:network] = [:friends, :communities, :enterprises]
15 15 PERSON_CATEGORIES.merge!(COMMON_CATEGORIES)
16 16  
17   - ORGANIZATION_CATEGORIES = ActiveSupport::OrderedHash.new
  17 + ORGANIZATION_CATEGORIES = {}
18 18 ORGANIZATION_CATEGORIES[:basic_information] = [:display_name, :created_at, :foundation_year, :type, :language, :members_count, :location, :address_reference, :historic_and_current_context, :admins]
19 19 ORGANIZATION_CATEGORIES[:contact] = [:contact_person, :contact_phone, :contact_email, :organization_website, :jabber_id]
20 20 ORGANIZATION_CATEGORIES[:economic] = [:business_name, :acronym, :economic_activity, :legal_form, :products, :activities_short_description, :management_information]
21 21 ORGANIZATION_CATEGORIES.merge!(COMMON_CATEGORIES)
22 22  
23   - CATEGORY_MAP = ActiveSupport::OrderedHash.new
  23 + CATEGORY_MAP = {}
24 24 CATEGORY_MAP[:person] = PERSON_CATEGORIES
25 25 CATEGORY_MAP[:organization] = ORGANIZATION_CATEGORIES
26 26  
... ...
app/helpers/profile_image_helper.rb
... ... @@ -114,7 +114,12 @@ module ProfileImageHelper
114 114 end
115 115  
116 116 extra_info_tag = ''
117   - img_class = 'profile-image'
  117 +
  118 + if profile.secret?
  119 + img_class = 'profile-image secret-profile'
  120 + else
  121 + img_class = 'profile-image'
  122 + end
118 123  
119 124 if extra_info.is_a? Hash
120 125 extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class])
... ... @@ -137,4 +142,4 @@ module ProfileImageHelper
137 142 :title => profile.name ),
138 143 :class => 'vcard'), :class => 'common-profile-list-block')
139 144 end
140   -end
141 145 \ No newline at end of file
  146 +end
... ...
app/mailers/task_mailer.rb
... ... @@ -14,7 +14,7 @@ class TaskMailer &lt; ApplicationMailer
14 14 mail(
15 15 to: task.target.notification_emails.compact,
16 16 from: self.class.generate_from(task),
17   - subject: "[%s] %s" % [self.environment.name, task.target_notification_description]
  17 + subject: "[%s] %s" % [task.environment.name, task.target_notification_description]
18 18 )
19 19 end
20 20  
... ... @@ -27,7 +27,7 @@ class TaskMailer &lt; ApplicationMailer
27 27 mail(
28 28 to: task.friend_email,
29 29 from: self.class.generate_from(task),
30   - subject: '[%s] %s' % [ self.environment.name, task.target_notification_description ]
  30 + subject: '[%s] %s' % [ task.requestor.environment.name, task.target_notification_description ]
31 31 )
32 32 end
33 33  
... ... @@ -38,14 +38,14 @@ class TaskMailer &lt; ApplicationMailer
38 38  
39 39 @message = extract_message(task.send("#{name}_message"))
40 40 @requestor = task.requestor.name
41   - @url = url_for(:host => self.environment.default_hostname, :controller => 'home')
  41 + @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home')
42 42  
43 43 mail_with_template(
44 44 to: task.requestor.notification_emails,
45 45 from: self.class.generate_from(task),
46   - subject: '[%s] %s' % [self.environment.name, task.target_notification_description],
  46 + subject: '[%s] %s' % [task.requestor.environment.name, task.target_notification_description],
47 47 email_template: task.email_template,
48   - template_params: {:environment => self.environment, :task => task, :message => @message, :url => @url, :requestor => task.requestor}
  48 + template_params: {:environment => task.requestor.environment, :task => task, :message => @message, :url => @url, :requestor => task.requestor}
49 49 )
50 50 end
51 51  
... ...
app/mailers/user_mailer.rb
... ... @@ -31,7 +31,7 @@ class UserMailer &lt; ApplicationMailer
31 31 from: "#{user.environment.name} <#{user.environment.contact_email}>",
32 32 to: user.email,
33 33 subject: _("[%s] Activate your account") % [user.environment.name],
34   - template_params: {:environment => user.environment, :activation_code => @activation_code, :redirection => @redirection, :join => @join},
  34 + template_params: {:environment => user.environment, :activation_code => @activation_code, :redirection => @redirection, :join => @join, :person => user.person, :url => @url},
35 35 email_template: user.environment.email_templates.find_by_template_type(:user_activation),
36 36 )
37 37 end
... ...
app/models/add_friend.rb
... ... @@ -57,7 +57,7 @@ class AddFriend &lt; Task
57 57 end
58 58  
59 59 def remove_from_suggestion_list(task)
60   - suggestion = task.requestor.suggested_profiles.find_by_suggestion_id task.target.id
  60 + suggestion = task.requestor.suggested_profiles.find_by suggestion_id: task.target.id
61 61 suggestion.disable if suggestion
62 62 end
63 63 end
... ...
app/models/add_member.rb
... ... @@ -59,7 +59,7 @@ class AddMember &lt; Task
59 59 end
60 60  
61 61 def remove_from_suggestion_list(task)
62   - suggestion = task.requestor.profile_suggestions.find_by_suggestion_id task.target.id
  62 + suggestion = task.requestor.profile_suggestions.find_by suggestion_id: task.target.id
63 63 suggestion.disable if suggestion
64 64 end
65 65  
... ...
app/models/approve_article.rb
... ... @@ -20,7 +20,7 @@ class ApproveArticle &lt; Task
20 20 end
21 21  
22 22 def article
23   - Article.find_by_id data[:article_id]
  23 + Article.find_by id: data[:article_id]
24 24 end
25 25  
26 26 def article= value
... ... @@ -39,7 +39,7 @@ class ApproveArticle &lt; Task
39 39 settings_items :create_link, :type => :boolean, :default => false
40 40  
41 41 def article_parent
42   - Article.find_by_id article_parent_id.to_i
  42 + Article.find_by id: article_parent_id.to_i
43 43 end
44 44  
45 45 def article_parent= value
... ...
app/models/approve_comment.rb
... ... @@ -18,7 +18,7 @@ class ApproveComment &lt; Task
18 18 end
19 19  
20 20 def article
21   - Article.find_by_id comment.source_id unless self.comment.nil?
  21 + Article.find_by id: comment.source_id unless self.comment.nil?
22 22 end
23 23  
24 24 def article_name
... ...
app/models/article.rb
... ... @@ -13,6 +13,7 @@ class Article &lt; ActiveRecord::Base
13 13 :archived
14 14  
15 15 acts_as_having_image
  16 + include Noosfero::Plugin::HotSpot
16 17  
17 18 SEARCHABLE_FIELDS = {
18 19 :name => {:label => _('Name'), :weight => 10},
... ... @@ -29,17 +30,13 @@ class Article &lt; ActiveRecord::Base
29 30  
30 31 def initialize(*params)
31 32 super
32   -
33   - if !params.blank?
34   - if params.first.has_key?(:profile) && !params.first[:profile].blank?
35   - profile = params.first[:profile]
36   - self.published = false unless profile.public_profile
  33 + if params.present? && params.first.present?
  34 + if params.first.symbolize_keys.has_key?(:published)
  35 + self.published = params.first.symbolize_keys[:published]
  36 + elsif params.first[:profile].present? && !params.first[:profile].public_profile
  37 + self.published = false
37 38 end
38   -
39   - self.published = params.first["published"] if params.first.has_key?("published")
40   - self.published = params.first[:published] if params.first.has_key?(:published)
41 39 end
42   -
43 40 end
44 41  
45 42 def self.default_search_display
... ... @@ -78,15 +75,11 @@ class Article &lt; ActiveRecord::Base
78 75 belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id'
79 76 belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id'
80 77  
81   - #Article followers relation
82   - has_many :article_followers, :dependent => :destroy
83   - has_many :person_followers, :class_name => 'Person', :through => :article_followers, :source => :person
84   -
85   - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc'
  78 + has_many :comments, -> { order 'created_at asc' }, class_name: 'Comment', as: 'source', dependent: :destroy
86 79  
87 80 has_many :article_followers, :dependent => :destroy
88 81 has_many :person_followers, :class_name => 'Person', :through => :article_followers, :source => :person
89   - has_many :person_followers_emails, :class_name => 'User', :through => :person_followers, :source => :user, :select => :email
  82 + has_many :person_followers_emails, -> { select :email }, class_name: 'User', through: :person_followers, source: :user
90 83  
91 84 has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false }
92 85 has_many :categories, :through => :article_categorizations
... ... @@ -289,7 +282,7 @@ class Article &lt; ActiveRecord::Base
289 282 # retrives the most commented articles, sorted by the comment count (largest
290 283 # first)
291 284 def self.most_commented(limit)
292   - paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit)
  285 + order('comments_count DESC').paginate(page: 1, per_page: limit)
293 286 end
294 287  
295 288 scope :more_popular, -> { order 'hits DESC' }
... ... @@ -298,7 +291,7 @@ class Article &lt; ActiveRecord::Base
298 291 }
299 292  
300 293 def self.recent(limit = nil, extra_conditions = {}, pagination = true)
301   - result = scoped({:conditions => extra_conditions}).
  294 + result = where(extra_conditions).
302 295 is_public.
303 296 relevant_as_recent.
304 297 limit(limit).
... ... @@ -480,7 +473,7 @@ class Article &lt; ActiveRecord::Base
480 473  
481 474 def rotate_translations
482 475 unless self.translations.empty?
483   - rotate = self.translations.all
  476 + rotate = self.translations.to_a
484 477 root = rotate.shift
485 478 root.update_attribute(:translation_of_id, nil)
486 479 root.translations = rotate
... ... @@ -774,7 +767,7 @@ class Article &lt; ActiveRecord::Base
774 767  
775 768 def version_license(version_number = nil)
776 769 return license if version_number.nil?
777   - profile.environment.licenses.find_by_id(get_version(version_number).license_id)
  770 + profile.environment.licenses.find_by(id: get_version(version_number).license_id)
778 771 end
779 772  
780 773 alias :active_record_cache_key :cache_key
... ... @@ -863,6 +856,7 @@ class Article &lt; ActiveRecord::Base
863 856 true
864 857 end
865 858  
  859 + # FIXME see if it's needed
866 860 def view_page
867 861 "content_viewer/view_page"
868 862 end
... ...
app/models/block.rb
1 1 class Block < ActiveRecord::Base
2 2  
3   - attr_accessible :title, :display, :limit, :box_id, :posts_per_page,
  3 + attr_accessible :title, :subtitle, :display, :limit, :box_id, :posts_per_page,
4 4 :visualization_format, :language, :display_user,
5 5 :box, :edit_modes, :move_modes, :mirror
6 6  
7   - # to be able to generate HTML
8   - include ActionView::Helpers::UrlHelper
9 7 include ActionView::Helpers::TagHelper
10 8  
11 9 # Block-specific stuff
... ... @@ -13,7 +11,8 @@ class Block &lt; ActiveRecord::Base
13 11  
14 12 delegate :environment, :to => :box, :allow_nil => true
15 13  
16   - acts_as_list :scope => :box
  14 + acts_as_list scope: -> block { where box_id: block.box_id }
  15 +
17 16 belongs_to :box
18 17 belongs_to :mirror_block, :class_name => "Block"
19 18 has_many :observers, :class_name => "Block", :foreign_key => "mirror_block_id"
... ...
app/models/blog.rb
... ... @@ -98,8 +98,9 @@ class Blog &lt; Folder
98 98 when :by_year
99 99 posts.published.native_translations
100 100 .except(:order)
101   - .count(:all, :group => 'EXTRACT(YEAR FROM published_at)')
102   - .sort_by {|year, count| -year.to_i}
  101 + .group('EXTRACT(YEAR FROM published_at)')
  102 + .count
  103 + .sort_by{ |year, count| -year.to_i }
103 104 when :by_month
104 105 posts.published.native_translations
105 106 .except(:order)
... ...
app/models/box.rb
1 1 class Box < ActiveRecord::Base
  2 +
  3 + acts_as_list scope: -> box { where owner_id: box.owner_id, owner_type: box.owner_type }
  4 +
2 5 belongs_to :owner, :polymorphic => true
3   - acts_as_list :scope => 'owner_id = #{owner_id} and owner_type = \'#{owner_type}\''
4   - has_many :blocks, :dependent => :destroy, :order => 'position'
  6 + has_many :blocks, -> { order 'position' }, dependent: :destroy
5 7  
6 8 attr_accessible :owner
7 9  
... ...
app/models/category.rb
... ... @@ -90,7 +90,7 @@ class Category &lt; ActiveRecord::Base
90 90  
91 91 def children_for_menu
92 92 results = []
93   - pending = children.where(display_in_menu: true).all
  93 + pending = children.where(display_in_menu: true).to_a
94 94 while pending.present?
95 95 cat = pending.shift
96 96 results << cat
... ...
app/models/comment.rb
... ... @@ -94,7 +94,7 @@ class Comment &lt; ActiveRecord::Base
94 94 end
95 95  
96 96 def self.recent(limit = nil)
97   - self.find(:all, :order => 'created_at desc, id desc', :limit => limit)
  97 + self.order('created_at desc, id desc').limit(limit).all
98 98 end
99 99  
100 100 def notification_emails
... ...
app/models/community.rb
... ... @@ -33,7 +33,7 @@ class Community &lt; Organization
33 33 community = Community.new(attributes)
34 34 community.environment = environment
35 35 if community.environment.enabled?('admin_must_approve_new_communities')
36   - CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment).except(:custom_values))
  36 + CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment))
37 37 else
38 38 community.save!
39 39 community.add_admin(requestor)
... ... @@ -77,7 +77,7 @@ class Community &lt; Organization
77 77 end
78 78  
79 79 def each_member(offset=0)
80   - while member = self.members.first(:order => :id, :offset => offset)
  80 + while member = self.members.order(:id).offset(offset).first
81 81 yield member
82 82 offset = offset + 1
83 83 end
... ...
app/models/create_community.rb
... ... @@ -20,6 +20,9 @@ class CreateCommunity &lt; Task
20 20 attr_accessible field.to_sym
21 21 end
22 22  
  23 + settings_items :custom_values
  24 + attr_accessible :custom_values
  25 +
23 26 def validate
24 27 self.environment.required_community_fields.each do |field|
25 28 if self.send(field).blank?
... ... @@ -36,6 +39,7 @@ class CreateCommunity &lt; Task
36 39  
37 40 community.update(community_data)
38 41 community.image = image if image
  42 + community.custom_values = custom_values
39 43 community.environment = self.environment
40 44 community.save!
41 45 community.add_admin(self.requestor)
... ... @@ -63,6 +67,14 @@ class CreateCommunity &lt; Task
63 67 end
64 68 end
65 69  
  70 + def reject_details
  71 + true
  72 + end
  73 +
  74 + def custom_fields_moderate
  75 + true
  76 + end
  77 +
66 78 # tells if this request was rejected
67 79 def rejected?
68 80 self.status == Task::Status::CANCELLED
... ...
app/models/custom_field.rb
1 1 class CustomField < ActiveRecord::Base
2   - attr_accessible :name, :default_value, :format, :extras, :customized_type, :active, :required, :signup, :environment
  2 + attr_accessible :name, :default_value, :format, :extras, :customized_type, :active, :required, :signup, :environment, :moderation_task
3 3 serialize :customized_type
4 4 serialize :extras
5 5 has_many :custom_field_values, :dependent => :delete_all
... ...
app/models/domain.rb
... ... @@ -36,8 +36,8 @@ class Domain &lt; ActiveRecord::Base
36 36 # finds a domain by its name. The argument <tt>name</tt> can start with
37 37 # "www.", but it will be removed before searching. So searching for
38 38 # 'www.example.net' is exactly the same as searching for just 'example.net'
39   - def self.find_by_name(name)
40   - self.where('name = ?', self.extract_domain_name(name)).first
  39 + def self.by_name(name)
  40 + self.find_by(name: self.extract_domain_name(name))
41 41 end
42 42  
43 43 # turns the argument (expected to be a String) into a domain name that is
... ... @@ -82,7 +82,7 @@ class Domain &lt; ActiveRecord::Base
82 82 Noosfero::MultiTenancy.setup!(domainname)
83 83 @hosting[domainname] ||=
84 84 begin
85   - domain = Domain.find_by_name(domainname)
  85 + domain = Domain.by_name(domainname)
86 86 !domain.nil? && (domain.owner_type == 'Profile')
87 87 end
88 88 end
... ...
app/models/environment.rb
... ... @@ -61,7 +61,7 @@ class Environment &lt; ActiveRecord::Base
61 61  
62 62 module Roles
63 63 def self.admin(env_id)
64   - Role.find_by_key_and_environment_id('environment_administrator', env_id)
  64 + Role.find_by(key: 'environment_administrator', environment_id: env_id)
65 65 end
66 66 end
67 67  
... ... @@ -248,7 +248,7 @@ class Environment &lt; ActiveRecord::Base
248 248  
249 249 acts_as_accessible
250 250  
251   - has_many :units, :order => 'position'
  251 + has_many :units, -> { order 'position' }
252 252 has_many :production_costs, :as => :owner
253 253  
254 254 def superior_intances
... ... @@ -714,7 +714,7 @@ class Environment &lt; ActiveRecord::Base
714 714 def default_hostname(email_hostname = false)
715 715 domain = 'localhost'
716 716 unless self.domains(true).empty?
717   - domain = (self.domains.find_by_is_default(true) || self.domains.find(:first, :order => 'id')).name
  717 + domain = (self.domains.find_by(is_default: true) || self.domains.order(:id).first).name
718 718 domain = email_hostname ? domain : (force_www ? ('www.' + domain) : domain)
719 719 end
720 720 domain
... ... @@ -808,7 +808,7 @@ class Environment &lt; ActiveRecord::Base
808 808 end
809 809  
810 810 def community_default_template
811   - template = Community.find_by_id settings[:community_template_id]
  811 + template = Community.find_by id: settings[:community_template_id]
812 812 template if template && template.is_template?
813 813 end
814 814  
... ... @@ -821,7 +821,7 @@ class Environment &lt; ActiveRecord::Base
821 821 end
822 822  
823 823 def person_default_template
824   - template = Person.find_by_id settings[:person_template_id]
  824 + template = Person.find_by id: settings[:person_template_id]
825 825 template if template && template.is_template?
826 826 end
827 827  
... ... @@ -834,7 +834,7 @@ class Environment &lt; ActiveRecord::Base
834 834 end
835 835  
836 836 def enterprise_default_template
837   - template = Enterprise.find_by_id settings[:enterprise_template_id]
  837 + template = Enterprise.find_by id: settings[:enterprise_template_id]
838 838 template if template && template.is_template?
839 839 end
840 840  
... ... @@ -843,7 +843,7 @@ class Environment &lt; ActiveRecord::Base
843 843 end
844 844  
845 845 def inactive_enterprise_template
846   - template = Enterprise.find_by_id settings[:inactive_enterprise_template_id]
  846 + template = Enterprise.find_by id: settings[:inactive_enterprise_template_id]
847 847 template if template && template.is_template
848 848 end
849 849  
... ...
app/models/forum.rb
1 1 class Forum < Folder
2 2  
3   - acts_as_having_posts :order => 'updated_at DESC'
  3 + acts_as_having_posts -> { reorder 'updated_at DESC' }
4 4 include PostsLimit
5 5  
6 6 attr_accessible :has_terms_of_use, :terms_of_use, :topic_creation
... ... @@ -12,7 +12,7 @@ class Forum &lt; Folder
12 12  
13 13 before_save do |forum|
14 14 if forum.has_terms_of_use
15   - last_editor = forum.profile.environment.people.find_by_id(forum.last_changed_by_id)
  15 + last_editor = forum.profile.environment.people.find_by(id: forum.last_changed_by_id)
16 16 if last_editor && !forum.users_with_agreement.exists?(last_editor)
17 17 forum.users_with_agreement << last_editor
18 18 end
... ... @@ -34,14 +34,14 @@ class Forum &lt; Folder
34 34 end
35 35  
36 36 module TopicCreation
37   - BASE = ActiveSupport::OrderedHash.new
  37 + BASE = {}
38 38 BASE['users'] = _('Logged users')
39 39  
40   - PERSON = ActiveSupport::OrderedHash.new
  40 + PERSON = {}
41 41 PERSON['self'] = _('Me')
42 42 PERSON['related'] = _('Friends')
43 43  
44   - GROUP = ActiveSupport::OrderedHash.new
  44 + GROUP = {}
45 45 GROUP['self'] = _('Administrators')
46 46 GROUP['related'] = _('Members')
47 47  
... ...
app/models/input.rb
... ... @@ -9,7 +9,7 @@ class Input &lt; ActiveRecord::Base
9 9 validates_presence_of :product
10 10 validates_presence_of :product_category
11 11  
12   - acts_as_list :scope => :product
  12 + acts_as_list scope: -> input { where product_id: input.product_id }
13 13  
14 14 belongs_to :unit
15 15  
... ...
app/models/invitation.rb
... ... @@ -67,7 +67,7 @@ class Invitation &lt; Task
67 67 end
68 68  
69 69 begin
70   - user = find_by_profile_id ? Person.find_by_id(contact_to_invite).user : User.find_by_email(friend_email)
  70 + user = find_by_profile_id ? Person.find_by(id: contact_to_invite).user : User.find_by(email: friend_email)
71 71 rescue
72 72 user = nil
73 73 end
... ...
app/models/moderate_user_registration.rb
... ... @@ -22,8 +22,12 @@ class ModerateUserRegistration &lt; Task
22 22 "#{name} (#{email})"
23 23 end
24 24  
  25 + def custom_fields_moderate
  26 + true
  27 + end
  28 +
25 29 def perform
26   - user=environment.users.find_by_id(user_id)
  30 + user=environment.users.find_by(id: user_id)
27 31 user.activate
28 32 end
29 33  
... ... @@ -58,4 +62,4 @@ class ModerateUserRegistration &lt; Task
58 62 _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name }
59 63 end
60 64  
61   -end
62 65 \ No newline at end of file
  66 +end
... ...
app/models/national_region.rb
... ... @@ -27,12 +27,13 @@ class NationalRegion &lt; ActiveRecord::Base
27 27 :type => NationalRegionType::CITY,
28 28 :state => state}];
29 29  
30   - region = NationalRegion.find(find_return,
31   - :select => "national_regions.name as city, nr.name as state, national_regions.national_region_code",
32   - :conditions => conditions,
33   - :joins => "LEFT JOIN national_regions as nr ON national_regions.parent_national_region_code = nr.national_region_code",
34   - :limit => 10
35   - )
  30 + region = NationalRegion
  31 + .select('national_regions.name as city, nr.name as state, national_regions.national_region_code')
  32 + .where(conditions)
  33 + .joins('LEFT JOIN national_regions as nr ON national_regions.parent_national_region_code = nr.national_region_code')
  34 + .limit(10)
  35 + region = region.send find_return
  36 +
36 37 return region
37 38 end
38 39  
... ... @@ -50,19 +51,19 @@ class NationalRegion &lt; ActiveRecord::Base
50 51 {:name => state_name,
51 52 :type => NationalRegionType::STATE}];
52 53  
53   - region = NationalRegion.find(find_return,
54   - :select => "national_regions.name as state, national_regions.national_region_code",
55   - :conditions => conditions,
56   - :limit => 10
57   - )
  54 + region = NationalRegion
  55 + .select('national_regions.name as state, national_regions.national_region_code')
  56 + .where(conditions)
  57 + .limit(10)
  58 + region = region.send find_return
  59 +
58 60 return region
59 61 end
60 62  
61 63 def self.validate!(city, state, country)
62 64  
63   - country_region = NationalRegion.find_by_national_region_code(country,
64   - :conditions => ["national_region_type_id = :type",
65   - {:type => NationalRegionType::COUNTRY}])
  65 + country_region = NationalRegion
  66 + .find_by(national_region_code: country, national_region_type_id: NationalRegionType::COUNTRY)
66 67  
67 68 if(country_region)
68 69  
... ...
app/models/organization.rb
... ... @@ -55,7 +55,7 @@ class Organization &lt; Profile
55 55  
56 56 has_many :custom_roles, :class_name => 'Role', :foreign_key => :profile_id
57 57  
58   - scope :more_popular, :order => 'members_count DESC'
  58 + scope :more_popular, -> { order 'members_count DESC' }
59 59  
60 60 validate :presence_of_required_fieds, :unless => :is_template
61 61  
... ...
app/models/person.rb
... ... @@ -112,7 +112,8 @@ class Person &lt; Profile
112 112 has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people'
113 113 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions'
114 114  
115   - has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy
  115 + has_many :suggested_profiles, -> { order 'score DESC' },
  116 + class_name: 'ProfileSuggestion', foreign_key: :person_id, dependent: :destroy
116 117 has_many :suggested_people, -> {
117 118 where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true
118 119 }, through: :suggested_profiles, source: :suggestion
... ... @@ -397,7 +398,7 @@ class Person &lt; Profile
397 398  
398 399  
399 400 def self.with_pending_tasks
400   - Person.find(:all).select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? }
  401 + Person.all.select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? }
401 402 end
402 403  
403 404 def has_organization_pending_tasks?
... ... @@ -491,7 +492,7 @@ class Person &lt; Profile
491 492 end
492 493  
493 494 def each_friend(offset=0)
494   - while friend = self.friends.first(:order => :id, :offset => offset)
  495 + while friend = self.friends.order(:id).offset(offset).first
495 496 yield friend
496 497 offset = offset + 1
497 498 end
... ... @@ -573,7 +574,7 @@ class Person &lt; Profile
573 574 end
574 575  
575 576 def remove_suggestion(profile)
576   - suggestion = suggested_profiles.find_by_suggestion_id profile.id
  577 + suggestion = suggested_profiles.find_by suggestion_id: profile.id
577 578 suggestion.disable if suggestion
578 579 end
579 580  
... ...
app/models/product.rb
... ... @@ -28,7 +28,7 @@ class Product &lt; ActiveRecord::Base
28 28  
29 29 belongs_to :product_category
30 30  
31   - has_many :inputs, :dependent => :destroy, :order => 'position'
  31 + has_many :inputs, -> { order 'position' }, dependent: :destroy
32 32 has_many :price_details, :dependent => :destroy
33 33 has_many :production_costs, :through => :price_details
34 34  
... ... @@ -50,7 +50,7 @@ class Product &lt; ActiveRecord::Base
50 50 validates_numericality_of :price, :allow_nil => true
51 51 validates_numericality_of :discount, :allow_nil => true
52 52  
53   - scope :more_recent, :order => "created_at DESC"
  53 + scope :more_recent, -> { order 'created_at DESC' }
54 54  
55 55 scope :from_category, -> category {
56 56 joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category
... ... @@ -75,6 +75,8 @@ class Product &lt; ActiveRecord::Base
75 75 ).uniq
76 76 }
77 77  
  78 + scope :recent, -> limit=nil { order('id DESC').limit(limit) }
  79 +
78 80 after_update :save_image
79 81  
80 82 def lat
... ... @@ -128,10 +130,6 @@ class Product &lt; ActiveRecord::Base
128 130 product_category ? product_category.name : _('Uncategorized product')
129 131 end
130 132  
131   - def self.recent(limit = nil)
132   - self.find(:all, :order => 'id desc', :limit => limit)
133   - end
134   -
135 133 def url
136 134 self.profile.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => id)
137 135 end
... ...
app/models/product_category.rb
... ... @@ -5,7 +5,7 @@ class ProductCategory &lt; Category
5 5  
6 6 attr_accessible :name, :parent, :environment
7 7  
8   - scope :unique, :select => 'DISTINCT ON (path) categories.*'
  8 + scope :unique, -> { select 'DISTINCT ON (path) categories.*' }
9 9 scope :by_enterprise, -> enterprise {
10 10 distinct.joins(:products).
11 11 where('products.profile_id = ?', enterprise.id)
... ... @@ -14,6 +14,10 @@ class ProductCategory &lt; Category
14 14 where 'environment_id = ?', environment.id
15 15 }
16 16  
  17 + scope :unique_by_level, lambda { |level| {
  18 + :select => "DISTINCT ON (filtered_category) split_part(path, '/', #{level.to_i}) AS filtered_category, categories.*"
  19 + }}
  20 +
17 21 def all_products
18 22 Product.where(product_category_id: (all_children << self).map(&:id))
19 23 end
... ...
app/models/profile.rb
... ... @@ -91,7 +91,7 @@ class Profile &lt; ActiveRecord::Base
91 91 end
92 92 private
93 93 def self.find_role(name, env_id)
94   - ::Role.find_by_key_and_environment_id("profile_#{name}", env_id)
  94 + ::Role.find_by key: "profile_#{name}", environment_id: env_id
95 95 end
96 96 end
97 97  
... ... @@ -144,6 +144,9 @@ class Profile &lt; ActiveRecord::Base
144 144 }
145 145 scope :no_templates, -> { where is_template: false }
146 146  
  147 + scope :recent, -> limit=nil { order('id DESC').limit(limit) }
  148 +
  149 +
147 150 # Returns a scoped object to select profiles in a given location or in a radius
148 151 # distance from the given location center.
149 152 # The parameter can be the `request.params` with the keys:
... ... @@ -207,14 +210,6 @@ class Profile &lt; ActiveRecord::Base
207 210 members(field).where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value
208 211 end
209 212  
210   - class << self
211   - def count_with_distinct(*args)
212   - options = args.last || {}
213   - count_without_distinct(:id, {:distinct => true}.merge(options))
214   - end
215   - alias_method_chain :count, :distinct
216   - end
217   -
218 213 def members_by_role(roles)
219 214 Person.members_of(self).by_role(roles)
220 215 end
... ... @@ -232,18 +227,17 @@ class Profile &lt; ActiveRecord::Base
232 227 scope :is_public, -> { where visible: true, public_profile: true, secret: false }
233 228 scope :enabled, -> { where enabled: true }
234 229  
235   - # Subclasses must override this method
236   - scope :more_popular
237   -
238   - scope :more_active, :order => 'activities_count DESC'
239   - scope :more_recent, :order => "created_at DESC"
  230 + # subclass specific
  231 + scope :more_popular, -> { }
  232 + scope :more_active, -> { order 'activities_count DESC' }
  233 + scope :more_recent, -> { order "created_at DESC" }
240 234  
241 235 acts_as_trackable :dependent => :destroy
242 236  
243 237 has_many :profile_activities
244 238 has_many :action_tracker_notifications, :foreign_key => 'profile_id'
245   - has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC'
246   - has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC", :dependent => :destroy
  239 + has_many :tracked_notifications, -> { order 'updated_at DESC' }, through: :action_tracker_notifications, source: :action_tracker
  240 + has_many :scraps_received, -> { order 'updated_at DESC' }, class_name: 'Scrap', foreign_key: :receiver_id, dependent: :destroy
247 241 belongs_to :template, :class_name => 'Profile', :foreign_key => 'template_id'
248 242  
249 243 has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments
... ... @@ -324,7 +318,7 @@ class Profile &lt; ActiveRecord::Base
324 318  
325 319 has_many :tasks, :dependent => :destroy, :as => 'target'
326 320  
327   - has_many :events, :source => 'articles', :class_name => 'Event', :order => 'start_date'
  321 + has_many :events, -> { order 'start_date' }, source: 'articles', class_name: 'Event'
328 322  
329 323 def find_in_all_tasks(task_id)
330 324 begin
... ... @@ -588,7 +582,7 @@ class Profile &lt; ActiveRecord::Base
588 582 # person = Profile['username']
589 583 # org = Profile.['orgname']
590 584 def [](identifier)
591   - self.find_by_identifier(identifier)
  585 + self.find_by identifier: identifier
592 586 end
593 587  
594 588 end
... ... @@ -767,11 +761,11 @@ private :generate_url, :url_options
767 761  
768 762 def copy_article_tree(article, parent=nil)
769 763 return if !copy_article?(article)
770   - original_article = self.articles.find_by_name(article.name)
  764 + original_article = self.articles.find_by name: article.name
771 765 if original_article
772 766 num = 2
773 767 new_name = original_article.name + ' ' + num.to_s
774   - while self.articles.find_by_name(new_name)
  768 + while self.articles.find_by name: new_name
775 769 num = num + 1
776 770 new_name = original_article.name + ' ' + num.to_s
777 771 end
... ... @@ -851,10 +845,6 @@ private :generate_url, :url_options
851 845 end
852 846 end
853 847  
854   - def self.recent(limit = nil)
855   - self.find(:all, :order => 'id desc', :limit => limit)
856   - end
857   -
858 848 # returns +true+ if the given +user+ can see profile information about this
859 849 # +profile+, and +false+ otherwise.
860 850 def display_info_to?(user)
... ... @@ -948,7 +938,7 @@ private :generate_url, :url_options
948 938 has_many :blogs, :source => 'articles', :class_name => 'Blog'
949 939  
950 940 def blog
951   - self.has_blog? ? self.blogs.first(:order => 'id') : nil
  941 + self.has_blog? ? self.blogs.order(:id).first : nil
952 942 end
953 943  
954 944 def has_blog?
... ... @@ -958,7 +948,7 @@ private :generate_url, :url_options
958 948 has_many :forums, :source => 'articles', :class_name => 'Forum'
959 949  
960 950 def forum
961   - self.has_forum? ? self.forums.first(:order => 'id') : nil
  951 + self.has_forum? ? self.forums.order(:id).first : nil
962 952 end
963 953  
964 954 def has_forum?
... ... @@ -1186,7 +1176,7 @@ private :generate_url, :url_options
1186 1176 settings_items :custom_url_redirection, type: String, default: nil
1187 1177  
1188 1178 def remove_from_suggestion_list(person)
1189   - suggestion = person.suggested_profiles.find_by_suggestion_id self.id
  1179 + suggestion = person.suggested_profiles.find_by suggestion_id: self.id
1190 1180 suggestion.disable if suggestion
1191 1181 end
1192 1182  
... ...
app/models/profile_activity.rb
... ... @@ -9,8 +9,12 @@ class ProfileActivity &lt; ActiveRecord::Base
9 9 belongs_to :activity, polymorphic: true
10 10  
11 11 # non polymorphic versions
12   - belongs_to :scrap, foreign_key: :activity_id, class_name: 'Scrap', conditions: {profile_activities: {activity_type: 'Scrap'}}
13   - belongs_to :action_tracker, foreign_key: :activity_id, class_name: 'ActionTracker::Record', conditions: {profile_activities: {activity_type: 'ActionTracker::Record'}}
  12 + belongs_to :scrap, -> {
  13 + where profile_activities: {activity_type: 'Scrap'}
  14 + }, foreign_key: :activity_id, class_name: 'Scrap'
  15 + belongs_to :action_tracker, -> {
  16 + where profile_activities: {activity_type: 'ActionTracker::Record'}
  17 + }, foreign_key: :activity_id, class_name: 'ActionTracker::Record'
14 18  
15 19 before_validation :copy_timestamps
16 20  
... ...
app/models/profile_list_block.rb
... ... @@ -18,11 +18,11 @@ class ProfileListBlock &lt; Block
18 18 result = nil
19 19 public_profiles = profiles.is_public.includes([:image,:domains,:preferred_domain,:environment])
20 20 if !prioritize_profiles_with_image
21   -result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand }
  21 + result = public_profiles.limit(get_limit).order('profiles.updated_at DESC').sort_by{ rand }
22 22 elsif profiles.visible.with_image.count >= get_limit
23   - result = public_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
  23 + result = public_profiles.with_image.limit(get_limit * 5).order('profiles.updated_at DESC').sort_by{ rand }
24 24 else
25   - result = public_profiles.with_image.sort_by{ rand } + public_profiles.without_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
  25 + result = public_profiles.with_image.sort_by{ rand } + public_profiles.without_image.limit(get_limit * 5).order('profiles.updated_at DESC').sort_by{ rand }
26 26 end
27 27 result.slice(0..get_limit-1)
28 28 end
... ...
app/models/profile_suggestion.rb
... ... @@ -120,7 +120,8 @@ class ProfileSuggestion &lt; ActiveRecord::Base
120 120 return if suggested_profiles.blank?
121 121  
122 122 suggested_profiles.each do |suggested_profile|
123   - suggestion = person.suggested_profiles.find_or_initialize_by_suggestion_id(suggested_profile.id)
  123 + suggestion = person.suggested_profiles.find_by suggestion_id: suggested_profile.id
  124 + suggestion ||= person.suggested_profiles.build({suggestion_id: suggested_profile.id}, without_protection: true)
124 125 RULES.each do |rule, options|
125 126 begin
126 127 value = suggested_profile.send("#{rule}_count").to_i
... ...
app/models/region.rb
1   -# Region is a special type of category that is related to geographical issues.
  1 +# Region is a special type of category that is related to geographical issues.
2 2 class Region < Category
3   -
4   - attr_accessible :name
5   -
  3 +
  4 + attr_accessible :name
  5 +
6 6 has_and_belongs_to_many :validators, :class_name => 'Organization', :join_table => :region_validators
7 7  
8 8 require_dependency 'enterprise' # enterprises can also be validators
... ... @@ -11,8 +11,10 @@ class Region &lt; Category
11 11 validators.count > 0
12 12 end
13 13  
14   - scope :with_validators, :select => 'DISTINCT ON (categories.id) *',
15   - :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)'
  14 + scope :with_validators, -> {
  15 + select('DISTINCT ON (categories.id) *')
  16 + .joins('INNER JOIN region_validators on (region_validators.region_id = categories.id)')
  17 + }
16 18  
17 19 end
18 20  
... ...
app/models/scrap.rb
... ... @@ -13,7 +13,9 @@ class Scrap &lt; ActiveRecord::Base
13 13 has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy
14 14 belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id'
15 15  
16   - has_many :profile_activities, foreign_key: :activity_id, conditions: {profile_activities: {activity_type: 'Scrap'}}, dependent: :destroy
  16 + has_many :profile_activities, -> {
  17 + where profile_activities: {activity_type: 'Scrap'}
  18 + }, foreign_key: :activity_id, dependent: :destroy
17 19  
18 20 after_create :create_activity
19 21 after_update :update_activity
... ...
app/models/search_term.rb
... ... @@ -25,7 +25,7 @@ class SearchTerm &lt; ActiveRecord::Base
25 25 # Therefore the score is 97. Them we sum every score to get the total score
26 26 # for a search term.
27 27 def self.occurrences_scores
28   - ActiveSupport::OrderedHash[*ActiveRecord::Base.connection.execute(
  28 + Hash[*ActiveRecord::Base.connection.execute(
29 29 joins(:occurrences).
30 30 select("search_terms.id, sum(#{SearchTermOccurrence::EXPIRATION_TIME.to_i} - extract(epoch from (now() - search_term_occurrences.created_at))) as value").
31 31 where("search_term_occurrences.created_at > ?", DateTime.now - SearchTermOccurrence::EXPIRATION_TIME).
... ...
app/models/session.rb
1 1 class Session < ActiveRecord::SessionStore::Session
2 2  
  3 + attr_accessible :session_id, :data
  4 +
3 5 # removed and redefined on super class
4 6 def self.find_by_session_id session_id
5 7 super
... ...
app/models/task.rb
... ... @@ -32,6 +32,8 @@ class Task &lt; ActiveRecord::Base
32 32 end
33 33 end
34 34  
  35 + include Noosfero::Plugin::HotSpot
  36 +
35 37 belongs_to :requestor, :class_name => 'Profile', :foreign_key => :requestor_id
36 38 belongs_to :target, :foreign_key => :target_id, :polymorphic => true
37 39 belongs_to :responsible, :class_name => 'Person', :foreign_key => :responsible_id
... ... @@ -136,9 +138,9 @@ class Task &lt; ActiveRecord::Base
136 138 group = klass.to_s.downcase.pluralize
137 139 id = attribute.to_s + "_id"
138 140 if environment.respond_to?(group)
139   - attrb = value || environment.send(group).find_by_id(record.send(id))
  141 + attrb = value || environment.send(group).find_by(id: record.send(id))
140 142 else
141   - attrb = value || klass.find_by_id(record.send(id))
  143 + attrb = value || klass.find_by(id: record.send(id))
142 144 end
143 145 if attrb.respond_to?(klass.to_s.downcase + "?")
144 146 unless attrb.send(klass.to_s.downcase + "?")
... ... @@ -207,6 +209,10 @@ class Task &lt; ActiveRecord::Base
207 209 true
208 210 end
209 211  
  212 + def custom_fields_moderate
  213 + false
  214 + end
  215 +
210 216 def icon
211 217 {:type => :defined_image, :src => "/images/icons-app/user-minor.png", :name => requestor.name, :url => requestor.url}
212 218 end
... ... @@ -272,6 +278,7 @@ class Task &lt; ActiveRecord::Base
272 278 end
273 279  
274 280 def environment
  281 + return target if target.kind_of?(Environment)
275 282 self.target.environment unless self.target.nil?
276 283 end
277 284  
... ... @@ -312,9 +319,19 @@ class Task &lt; ActiveRecord::Base
312 319 scope :canceled, -> { where status: Task::Status::CANCELLED }
313 320 scope :closed, -> { where status: [Task::Status::CANCELLED, Task::Status::FINISHED] }
314 321 scope :opened, -> { where status: [Task::Status::ACTIVE, Task::Status::HIDDEN] }
315   - scope :of, -> type { where "tasks.type LIKE ?", type if type }
316   - scope :order_by, -> attribute, ord { order "#{attribute} #{ord}" }
317   - scope :like, -> field, value { where "LOWER(#{field}) LIKE ?", "%#{value.downcase}%" if value }
  322 + scope :of, -> type { where :type => type if type }
  323 + scope :order_by, -> attribute, ord {
  324 + if ord.downcase.include? 'desc'
  325 + order attribute.to_sym => :desc
  326 + else
  327 + order attribute.to_sym
  328 + end
  329 + }
  330 + scope :like, -> field, value {
  331 + if value
  332 + where "LOWER(#{field}) LIKE ?", "%#{value.downcase}%"
  333 + end
  334 + }
318 335 scope :pending_all, -> profile, filter_type, filter_text {
319 336 self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text)
320 337 }
... ...
app/models/unit.rb
1 1 class Unit < ActiveRecord::Base
2 2  
  3 + acts_as_list scope: -> unit { where environment_id: unit.environment_id }
  4 +
3 5 attr_accessible :name, :singular, :plural, :environment
4 6  
5 7 validates_presence_of :singular
6 8 validates_presence_of :plural
7 9  
8 10 belongs_to :environment
  11 +
9 12 validates_presence_of :environment_id
10   - acts_as_list :scope => :environment
  13 + validates_presence_of :singular
  14 + validates_presence_of :plural
11 15  
12 16 def name
13 17 self.singular
... ...
app/models/user.rb
... ... @@ -25,7 +25,7 @@ class User &lt; ActiveRecord::Base
25 25 end
26 26  
27 27 def self.[](login)
28   - self.find_by_login(login)
  28 + self.find_by login: login
29 29 end
30 30  
31 31 # FIXME ugly workaround
... ...
app/views/blocks/article.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2 <% if block.article %>
3 3 <%=
4 4 h(article_to_html(FilePresenter.for(block.article),
... ...
app/views/blocks/blog_archives.html.erb
1 1 <% if block.blog %>
2   - <%= block_title(block.title) %>
  2 + <%= block_title(block.title, block.subtitle) %>
3 3  
4 4 <ul class='blog-archives'>
5 5 <% block.blog.total_number_of_posts(:by_year).each do |year, count| %>
... ...
app/views/blocks/categories.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%= display_category_menu block, block.selected_categories %>
... ...
app/views/blocks/featured_products.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2 <% unless block.products.blank? %>
3 3 <%= link_to content_tag(:span, _('Previous')), '#', :class => 'featured-product-prev featured-product-arrow' %>
4 4 <div class="featured-products-block-container">
... ...
app/views/blocks/feed_reader.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%=
4 4 if block.error_message.blank?
... ...
app/views/blocks/highlights.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
  2 +
2 3 <% if !block.featured_images.empty? %>
3 4 <div class='highlights-border'>
4 5 <div class='highlights-container'>
... ...
app/views/blocks/link_list.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%= block.links.empty? && block.title.empty? ? content_tag('em', _('Please, edit this block to add links')) : '' %>
4 4  
... ...
app/views/blocks/location.html.erb
1 1 <% if block.owner.lat %>
2   - <%= block_title block.title %>
  2 + <%= block_title(block.title, block.subtitle) %>
3 3 <div class='the-localization-map'>
4 4 <img src="https://maps.google.com/maps/api/staticmap?center=<%=block.owner.lat%>,<%=block.owner.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=block.owner.lat%>,<%=block.owner.lng%>&sensor=false"/>
5 5 </div>
... ...
app/views/blocks/my_network.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <ul>
4 4 <li><%= link_to(_('Homepage'), block.owner.url, :class => 'url') %></li>
... ...
app/views/blocks/products.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <ul>
4 4 <% block.products.each do |product| %>
... ...
app/views/blocks/profile_list.html.erb
1   -<%= block_title(block.view_title) %>
  1 +<%= block_title(block.view_title, block.subtitle) %>
2 2  
3 3 <%
4 4 list = block.profile_list.map do |item|
... ...
app/views/blocks/profile_search.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%= render :partial => 'shared/profile_search_form' %>
... ...
app/views/blocks/raw_html.html.erb
1   -<%=h block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%=h block.html %>
... ...
app/views/blocks/recent_documents.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <ul>
4 4 <% block.docs.map do |item| %>
... ...
app/views/blocks/slideshow.html.erb
... ... @@ -7,7 +7,7 @@
7 7 end
8 8 %>
9 9  
10   -<%= block_title(block.title) %>
  10 +<%= block_title(block.title, block.subtitle) %>
11 11  
12 12 <% if images %>
13 13 <% description = images.any? { |img| !img.abstract.blank? } %>
... ...
app/views/blocks/tags.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%
4 4 is_env = block.owner.class == Environment
... ...
app/views/box_organizer/edit.html.erb
... ... @@ -4,6 +4,7 @@
4 4 <%= form_tag(:action => 'save', :id => @block.id) do %>
5 5  
6 6 <%= labelled_form_field(_('Custom title for this block: '), text_field(:block, :title, :maxlength => 20)) %>
  7 + <%= labelled_form_field(_('Custom subtitle for this block: '), text_field(:block, :subtitle)) %>
7 8  
8 9 <%= render :partial => partial_for_class(@block.class) %>
9 10  
... ...
app/views/email_templates/_form.html.erb
... ... @@ -16,7 +16,7 @@
16 16 <%= _('The following parameters may be used in subject and body:') %>
17 17 </div>
18 18 <div class="values">
19   - {{profile.name}}, {{profile.identifier}}, {{environment.name}}
  19 + <%= @template_params_allowed %>
20 20 </div>
21 21 </div>
22 22 <%= render :file => 'shared/tiny_mce' %>
... ...
app/views/features/custom_fields/_form.html.erb
... ... @@ -16,6 +16,7 @@
16 16 <%= labelled_check_box _('Active'), "custom_fields[#{id}][active]", 1, field.active, :id => "active_checkbox", :onclick => "active_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %>
17 17 <%= labelled_check_box _('Required'), "custom_fields[#{id}][required]", 1, field.required, :id => "required_checkbox", :onclick => "required_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %>
18 18 <%= labelled_check_box _('Display on creation?'), "custom_fields[#{id}][signup]", 1, field.signup, :id => "signup_checkbox",:onclick => "signup_action('custom_fields[#{id}][active]','custom_fields[#{id}][required]', 'custom_fields[#{id}][signup]')" %>
  19 + <%= labelled_check_box _('Display on moderation?'), "custom_fields[#{id}][moderation_task]", 1, field.moderation_task %>
19 20 </div>
20 21  
21 22 <% if field.format == "list" %>
... ...
app/views/layouts/_user.html.erb
1 1 <div id="user">
2   - <% user = (session[:user] && User.find_by_id(session[:user])) || nil %>
  2 + <% user = (session[:user] && User.find_by(id: session[:user])) || nil %>
3 3 <% if user.present? %>
4 4 <% user = user.person %>
5 5 <span class='logged-in'>
... ...
app/views/organizations/_results.html.erb
... ... @@ -30,7 +30,7 @@
30 30 </div>
31 31 </td>
32 32  
33   - <td> <%= _(p.type) %> </td>
  33 + <td> <%= @types_hash[p.type] %> </td>
34 34 </tr>
35 35 <% end %>
36 36 </table>
... ...
app/views/profile/send_mail.html.erb
... ... @@ -12,6 +12,11 @@
12 12  
13 13 <% to = @mailing.data[:members_filtered].present? ? @mailing.recipients.map{|r| r.name}.join(', ') : _('All members')%>
14 14 <%= labelled_form_field(_('To:'), text_area(:data, 'members_filtered', :value => to, :rows => 4, :disabled => 'disabled', :class => 'send-mail-recipients')) %>
  15 +<div class="template-selection">
  16 + <% if @email_templates.present? %>
  17 + <%= labelled_form_field(_('Select a template:'), select_tag(:template, options_from_collection_for_select(@email_templates, :id, :name), :include_blank => true, 'data-url' => url_for(:controller => 'email_templates', :action => 'show_parsed'))) %>
  18 + </div>
  19 +<% end %>
15 20  
16 21 <%= form_for :mailing, :url => {:action => 'send_mail'}, :html => {:id => 'mailing-form'} do |f| %>
17 22  
... ...
app/views/shared/_list_groups.html.erb
... ... @@ -6,7 +6,7 @@
6 6 </div>
7 7 <span class='profile-details'>
8 8 <strong><%= group.name %></strong><br/>
9   - <%= _('Role: %s') % rolename_for(profile, group) + '<br/>' if profile.role_assignments.find_by_resource_id(group.id) %>
  9 + <%= _('Role: %s') % rolename_for(profile, group) + '<br/>' if profile.role_assignments.find_by(resource_id: group.id) %>
10 10 <%= _('Type: %s') % _(group.class.identification) %> <br/>
11 11 <%= _('Description: %s') % group.description + '<br/>' if group.community? %>
12 12 <%= _('Members: %s') % group.members_count.to_s %> <br/>
... ...
app/views/spam/_suggest_article.html.erb
... ... @@ -9,7 +9,7 @@
9 9 <li><strong><%=_('Email')%></strong>: <%=task.email%> </li>
10 10 <li><strong><%=_('Source')%></strong>: <%=task.article_object.source_name%> </li>
11 11 <li><strong><%=_('Source URL')%></strong>: <%=task.article_object.source%> </li>
12   - <li><strong><%=_('Folder')%></strong>: <%=(a = Article.find_by_id(task.article_object.parent_id))?a.name : '<em>' + s_('Folder|none') + '</em>'%> </li>
  12 + <li><strong><%=_('Folder')%></strong>: <%=if (a = Article.find_by(id: task.article_object.parent_id)) then a.name else '<em>' + s_('Folder|none') + '</em>' end%> </li>
13 13 <li><strong><%=_('Lead')%></strong>: <%=task.article_object.abstract.blank? ? '<em>' + s_('Abstract|empty') + '</em>' : task.article_object.abstract%> </li>
14 14 <li><strong><%=_('Body')%></strong>:
15 15 <div class='suggest-article-body'>
... ...
app/views/tasks/_create_community_custom_fields.html.erb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<% if task.custom_values.present? %>
  2 + <% task.custom_values.each_pair do |name, value| %>
  3 + <% custom_field = CustomField.where(:name =>name, :environment => task.environment).first%>
  4 + <% if custom_field.moderation_task %>
  5 + <div class="field-name">
  6 + <%= name +": " + display_value_for_custom_field(custom_field, value['value']) %>
  7 + </div>
  8 + <% end %>
  9 + <% end %>
  10 +<% end %>
... ...