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