Commit 815ff510e89f8e3b38928d6e30630a73f73b003c
Exists in
staging
and in
3 other branches
Merge branch 'master' into export-comment-paragraph
Conflicts: app/helpers/forms_helper.rb app/views/cms/edit.html.erb plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb plugins/comment_paragraph/test/functional/comment_paragraph_plugin_profile_controller_test.rb
Showing
1543 changed files
with
76044 additions
and
82153 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 1543 files displayed.
.gitlab-ci.yml
1 | +image: noosfero/ci | ||
2 | + | ||
1 | before_script: | 3 | before_script: |
2 | - - mkdir -p tmp/{pids,cache} log | ||
3 | - - bundle check || bundle install | ||
4 | -# workaround for plugins with Gemfile | ||
5 | - - perl -pi -e 's/--local //' script/noosfero-plugins | ||
6 | - - script/noosfero-plugins disableall | ||
7 | - - bundle exec rake makemo &>/dev/null | ||
8 | -# database | ||
9 | - - cp config/database.yml.gitlab-ci config/database.yml | ||
10 | - - createdb gitlab_ci_test || true | ||
11 | - - bundle exec rake db:schema:load &>/dev/null | ||
12 | - - bundle exec rake db:migrate &>/dev/null | 4 | + - mkdir -p locale # makes quick-start skip compiling translations |
5 | + - ./script/set-apt-proxy | ||
6 | + - ./script/silent-quick-start | ||
7 | + | ||
8 | +stages: | ||
9 | + - smoke-tests | ||
10 | + - all-tests | ||
11 | + | ||
12 | +smoke: | ||
13 | + script: bundle exec rake ci:smoke | ||
14 | + stage: smoke-tests | ||
13 | 15 | ||
14 | units: | 16 | units: |
15 | script: bundle exec rake test:units | 17 | script: bundle exec rake test:units |
18 | + stage: all-tests | ||
19 | + | ||
16 | functionals: | 20 | functionals: |
17 | script: bundle exec rake test:functionals | 21 | script: bundle exec rake test:functionals |
22 | + stage: all-tests | ||
23 | + | ||
18 | integration: | 24 | integration: |
19 | script: bundle exec rake test:integration | 25 | script: bundle exec rake test:integration |
26 | + stage: all-tests | ||
27 | + | ||
20 | cucumber: | 28 | cucumber: |
21 | script: bundle exec rake cucumber | 29 | script: bundle exec rake cucumber |
30 | + stage: all-tests | ||
31 | + | ||
22 | selenium: | 32 | selenium: |
23 | script: bundle exec rake selenium | 33 | script: bundle exec rake selenium |
34 | + stage: all-tests | ||
35 | + | ||
24 | plugins: | 36 | plugins: |
25 | script: bundle exec rake test:noosfero_plugins | 37 | script: bundle exec rake test:noosfero_plugins |
26 | - | 38 | + stage: all-tests |
.travis.yml
@@ -8,8 +8,7 @@ notifications: | @@ -8,8 +8,7 @@ notifications: | ||
8 | 8 | ||
9 | language: ruby | 9 | language: ruby |
10 | rvm: | 10 | rvm: |
11 | -# for 2.2 support we need to upgrade the pg gem | ||
12 | - - 2.1.6 | 11 | + - 2.2.3 |
13 | 12 | ||
14 | sudo: false | 13 | sudo: false |
15 | addons: | 14 | addons: |
@@ -26,19 +25,16 @@ addons: | @@ -26,19 +25,16 @@ addons: | ||
26 | - libsqlite3-dev | 25 | - libsqlite3-dev |
27 | - libxslt1-dev | 26 | - libxslt1-dev |
28 | 27 | ||
29 | -before_install: | ||
30 | - - gem env | ||
31 | - | ||
32 | # workaround for https://github.com/travis-ci/travis-ci/issues/4536 | 28 | # workaround for https://github.com/travis-ci/travis-ci/issues/4536 |
33 | before_install: | 29 | before_install: |
34 | - - export GEM_HOME=$PWD/vendor/bundle/ruby/2.1.0 | 30 | + - export GEM_HOME=$PWD/vendor/bundle/ruby/2.2.0 |
35 | - gem install bundler | 31 | - gem install bundler |
36 | cache: bundler | 32 | cache: bundler |
37 | 33 | ||
38 | before_script: | 34 | before_script: |
39 | - mkdir -p tmp/{pids,cache} log | 35 | - mkdir -p tmp/{pids,cache} log |
40 | - script/noosfero-plugins disableall | 36 | - script/noosfero-plugins disableall |
41 | - - bundle exec rake makemo &>/dev/null | 37 | + #- bundle exec rake makemo &>/dev/null |
42 | # database | 38 | # database |
43 | - cp config/database.yml.travis config/database.yml | 39 | - cp config/database.yml.travis config/database.yml |
44 | - psql -c 'create database myapp_test;' -U postgres | 40 | - psql -c 'create database myapp_test;' -U postgres |
@@ -49,7 +45,7 @@ env: | @@ -49,7 +45,7 @@ env: | ||
49 | - TASK=test:units | 45 | - TASK=test:units |
50 | - TASK=test:functionals | 46 | - TASK=test:functionals |
51 | - TASK=test:integration | 47 | - TASK=test:integration |
52 | - - TASK=cucumber | 48 | + - TASK=cucumber LANG=en |
53 | - TASK=selenium | 49 | - TASK=selenium |
54 | - TASK=test:noosfero_plugins BUNDLE_OPTS=install | 50 | - TASK=test:noosfero_plugins BUNDLE_OPTS=install |
55 | 51 |
AUTHORS.md
@@ -11,6 +11,7 @@ Developers | @@ -11,6 +11,7 @@ Developers | ||
11 | Ábner Silva de Oliveira <abner.oliveira@serpro.gov.br> | 11 | Ábner Silva de Oliveira <abner.oliveira@serpro.gov.br> |
12 | Alan Freihof Tygel <alantygel@gmail.com> | 12 | Alan Freihof Tygel <alantygel@gmail.com> |
13 | Alessandro Palmeira <alessandro.palmeira@gmail.com> | 13 | Alessandro Palmeira <alessandro.palmeira@gmail.com> |
14 | +Alexandre Barbosa <alexandreab@live.com> | ||
14 | Alexandre Torres <alexandrekry@gmail.com> | 15 | Alexandre Torres <alexandrekry@gmail.com> |
15 | Alex Campelo <campelo.al1@gmail.com> | 16 | Alex Campelo <campelo.al1@gmail.com> |
16 | Álvaro Fernando <alvarofernandoms@gmail.com> | 17 | Álvaro Fernando <alvarofernandoms@gmail.com> |
@@ -31,6 +32,7 @@ Caio SBA <caio@colivre.coop.br> | @@ -31,6 +32,7 @@ Caio SBA <caio@colivre.coop.br> | ||
31 | Caio Tiago Oliveira <caiotiago@colivre.coop.br> | 32 | Caio Tiago Oliveira <caiotiago@colivre.coop.br> |
32 | Carlos Andre de Souza <carlos.andre.souza@msn.com> | 33 | Carlos Andre de Souza <carlos.andre.souza@msn.com> |
33 | Carlos Morais <carlos88morais@gmail.com> | 34 | Carlos Morais <carlos88morais@gmail.com> |
35 | +Carlos Purificacao <carloseugenio@gmail.com> | ||
34 | Christophe DANIEL <papaeng@gmail.com> | 36 | Christophe DANIEL <papaeng@gmail.com> |
35 | Daniela Feitosa <alessandro.palmeira@gmail.com> | 37 | Daniela Feitosa <alessandro.palmeira@gmail.com> |
36 | Daniel Alves <danpaulalves@gmail.com> | 38 | Daniel Alves <danpaulalves@gmail.com> |
@@ -52,10 +54,12 @@ Fernanda Lopes <nanda.listas+psl@gmail.com> | @@ -52,10 +54,12 @@ Fernanda Lopes <nanda.listas+psl@gmail.com> | ||
52 | Filipe Ribeiro <firibeiro77@live.com> | 54 | Filipe Ribeiro <firibeiro77@live.com> |
53 | Francisco Marcelo de Araújo Lima Júnior <francisco.lima-junior@serpro.gov.br> | 55 | Francisco Marcelo de Araújo Lima Júnior <francisco.lima-junior@serpro.gov.br> |
54 | Gabriela Navarro <navarro1703@gmail.com> | 56 | Gabriela Navarro <navarro1703@gmail.com> |
57 | +Gabriel Silva <gabriel93.silva@gmail.com> | ||
55 | Gonzalo Exequiel Pedone <hipersayan.x@gmail.com> | 58 | Gonzalo Exequiel Pedone <hipersayan.x@gmail.com> |
56 | Grazieno Pellegrino <grazieno@gmail.com> | 59 | Grazieno Pellegrino <grazieno@gmail.com> |
57 | Guilherme C. Muniz <guilherme.cmuniz@gmail.com> | 60 | Guilherme C. Muniz <guilherme.cmuniz@gmail.com> |
58 | Guilherme Rojas <guilhermehrojas@gmail.com> | 61 | Guilherme Rojas <guilhermehrojas@gmail.com> |
62 | +Gustavo Coelho <gust.rod.coelho@gmail.com> | ||
59 | Gustavo Jaruga <darksshades@gmail.com> | 63 | Gustavo Jaruga <darksshades@gmail.com> |
60 | Hebert Douglas <hebertdougl@gmail.com> | 64 | Hebert Douglas <hebertdougl@gmail.com> |
61 | Hugo Melo <hugo@riseup.net> | 65 | Hugo Melo <hugo@riseup.net> |
@@ -84,14 +88,16 @@ Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> | @@ -84,14 +88,16 @@ Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> | ||
84 | Luis David Aguilar Carlos <ludwig9003@gmail.com> | 88 | Luis David Aguilar Carlos <ludwig9003@gmail.com> |
85 | Luiz Fernando de Freitas Matos <luiz@luizff.matos@gmail.com> | 89 | Luiz Fernando de Freitas Matos <luiz@luizff.matos@gmail.com> |
86 | Luiz Matos <luizff.matos@gmail.com> | 90 | Luiz Matos <luizff.matos@gmail.com> |
91 | +Macartur de Sousa <macartur.sc@gmail.com> | ||
87 | Marcelo Júnior <maljunior@gmail.com> | 92 | Marcelo Júnior <maljunior@gmail.com> |
88 | Marcos Ramos <ms.ramos@outlook.com> | 93 | Marcos Ramos <ms.ramos@outlook.com> |
89 | Marcos Ronaldo <marcos.rpj2@gmail.com> | 94 | Marcos Ronaldo <marcos.rpj2@gmail.com> |
95 | +María Vecino <mariavecino@ecoalternative.net> | ||
90 | Mariel Zasso <noosfero-br@listas.softwarelivre.org> | 96 | Mariel Zasso <noosfero-br@listas.softwarelivre.org> |
91 | Martín Olivera <molivera@solar.org.ar> | 97 | Martín Olivera <molivera@solar.org.ar> |
92 | Matheus Faria <matheus.sousa.faria@gmail.com> | 98 | Matheus Faria <matheus.sousa.faria@gmail.com> |
93 | Maurilio Atila <cabelotaina@gmail.com> | 99 | Maurilio Atila <cabelotaina@gmail.com> |
94 | -Melissa Wen <melissa@colivre.coop.br> | 100 | +Melissa Wen <melissa.srw@gmail.com> |
95 | M for Momo <mo@rtnp.org> | 101 | M for Momo <mo@rtnp.org> |
96 | Michal Čihař <michal@cihar.com> | 102 | Michal Čihař <michal@cihar.com> |
97 | Michel Felipe de Oliveira Ferreira <michel.ferreira@serpro.gov.br> | 103 | Michel Felipe de Oliveira Ferreira <michel.ferreira@serpro.gov.br> |
@@ -115,6 +121,7 @@ Raquel <rcordioli@gmail.com> | @@ -115,6 +121,7 @@ Raquel <rcordioli@gmail.com> | ||
115 | Renan Costa <renan2727@hotmail.com> | 121 | Renan Costa <renan2727@hotmail.com> |
116 | Renan Teruo <renanteruoc@gmail.com> | 122 | Renan Teruo <renanteruoc@gmail.com> |
117 | Rodrigo Medeiros <rodrigo.mss01@gmail.com> | 123 | Rodrigo Medeiros <rodrigo.mss01@gmail.com> |
124 | +Rodrigo Siqueira <siqueira@kuniri.org> | ||
118 | Rodrigo Souto <rodrigo@colivre.coop.br> | 125 | Rodrigo Souto <rodrigo@colivre.coop.br> |
119 | Ronnie Simon <ronniesimonf@gmail.com> | 126 | Ronnie Simon <ronniesimonf@gmail.com> |
120 | Ronny Kursawe <kursawe.ronny@googlemail.com> | 127 | Ronny Kursawe <kursawe.ronny@googlemail.com> |
@@ -131,7 +138,7 @@ Valessio Brito <contato@valessiobrito.com.br> | @@ -131,7 +138,7 @@ Valessio Brito <contato@valessiobrito.com.br> | ||
131 | Victor Costa <vfcosta@gmail.com> | 138 | Victor Costa <vfcosta@gmail.com> |
132 | Victor Hugo Alves de Carvalho <victorhugodf.ac@gmail.com> | 139 | Victor Hugo Alves de Carvalho <victorhugodf.ac@gmail.com> |
133 | Victor Navarro <victor.matias.navarro@gmail.com> | 140 | Victor Navarro <victor.matias.navarro@gmail.com> |
134 | -Vinicius Cubas Brand <viniciuscb@gmail.com> | 141 | +Vinicius Brand <viniciuscb@gmail.com> |
135 | Vitor Barbosa <vitornga15@gmail.com> | 142 | Vitor Barbosa <vitornga15@gmail.com> |
136 | Wilton Rodrigues <braynwilton@gmail.com> | 143 | Wilton Rodrigues <braynwilton@gmail.com> |
137 | Yann Lugrin <yann.lugrin@liquid-concept.ch> | 144 | Yann Lugrin <yann.lugrin@liquid-concept.ch> |
Gemfile
1 | source "https://rubygems.org" | 1 | source "https://rubygems.org" |
2 | -gem 'rails', '~> 3.2.22' | ||
3 | -gem 'minitest', '~> 3.2.0' | ||
4 | -gem 'fast_gettext', '~> 0.6.8' | ||
5 | -gem 'acts-as-taggable-on', '~> 3.4.2' | 2 | + |
3 | +platform :ruby do | ||
4 | + gem 'pg', '~> 0.17' | ||
5 | + gem 'rmagick', '~> 2.13' | ||
6 | +end | ||
7 | +platform :jruby do | ||
8 | + gem 'activerecord-jdbcpostgresql-adapter' | ||
9 | + gem 'rmagick4j' | ||
10 | +end | ||
11 | + | ||
12 | +gem 'rails', '~> 4.2.4' | ||
13 | +gem 'fast_gettext', '~> 0.9' | ||
14 | +gem 'acts-as-taggable-on', '~> 3.5' | ||
6 | gem 'rails_autolink', '~> 1.1.5' | 15 | gem 'rails_autolink', '~> 1.1.5' |
7 | -gem 'pg', '~> 0.13.2' | ||
8 | -gem 'rmagick', '~> 2.13.1' | ||
9 | -gem 'RedCloth', '~> 4.2.9' | ||
10 | -gem 'will_paginate', '~> 3.0.3' | 16 | +gem 'RedCloth', '~> 4.2' |
11 | gem 'ruby-feedparser', '~> 0.7' | 17 | gem 'ruby-feedparser', '~> 0.7' |
12 | -gem 'daemons', '~> 1.1.5' | 18 | +gem 'daemons', '~> 1.1' |
13 | gem 'unicorn', '~> 4.8' | 19 | gem 'unicorn', '~> 4.8' |
14 | -gem 'nokogiri', '~> 1.5.5' | 20 | +gem 'nokogiri', '~> 1.6.0' |
21 | +gem 'will_paginate', '~> 3.0.7' | ||
22 | +gem 'pothoven-attachment_fu', '~> 3.2.16' | ||
23 | +gem 'delayed_job' | ||
24 | +gem 'delayed_job_active_record' | ||
15 | gem 'rake', :require => false | 25 | gem 'rake', :require => false |
16 | -gem 'rest-client', '~> 1.6.7' | 26 | +gem 'rest-client', '~> 1.6' |
17 | gem 'exception_notification', '~> 4.0.1' | 27 | gem 'exception_notification', '~> 4.0.1' |
18 | -gem 'gettext', '~> 2.2.1', :require => false | ||
19 | -gem 'locale', '~> 2.0.5' | 28 | +gem 'gettext', '~> 3.1', :require => false |
29 | +gem 'locale', '~> 2.1' | ||
20 | gem 'whenever', :require => false | 30 | gem 'whenever', :require => false |
21 | -gem 'eita-jrails', '~> 0.9.5', require: 'jrails' | 31 | +gem 'eita-jrails', '~> 0.10.0', require: 'jrails' |
32 | +gem 'diffy', '~> 3.0' | ||
33 | +gem 'slim' | ||
22 | 34 | ||
23 | # API dependencies | 35 | # API dependencies |
24 | gem 'grape', '~> 0.12' | 36 | gem 'grape', '~> 0.12' |
@@ -30,30 +42,53 @@ gem 'rack-contrib' | @@ -30,30 +42,53 @@ gem 'rack-contrib' | ||
30 | # asset pipeline | 42 | # asset pipeline |
31 | gem 'uglifier', '>= 1.0.3' | 43 | gem 'uglifier', '>= 1.0.3' |
32 | gem 'sass-rails' | 44 | gem 'sass-rails' |
33 | -gem 'sass', '~> 3.1.19' | 45 | +gem 'sprockets-rails', '~> 2.1' |
46 | + | ||
47 | +# gems to enable rails3 behaviour | ||
48 | +gem 'protected_attributes' | ||
49 | +gem 'rails-observers' | ||
50 | +gem 'actionpack-page_caching' | ||
51 | +gem 'actionpack-action_caching' | ||
52 | +gem 'activerecord-session_store' | ||
53 | +gem 'activerecord-deprecated_finders', require: 'active_record/deprecated_finders' | ||
34 | 54 | ||
35 | group :production do | 55 | group :production do |
36 | gem 'dalli', '~> 2.7.0' | 56 | gem 'dalli', '~> 2.7.0' |
37 | end | 57 | end |
38 | 58 | ||
59 | +group :development, :test do | ||
60 | + gem 'spring' | ||
61 | +end | ||
62 | + | ||
39 | group :test do | 63 | group :test do |
40 | - gem 'rspec', '~> 2.14.0' | ||
41 | - gem 'rspec-rails', '~> 2.14.1' | 64 | + gem 'rspec', '~> 3.3', require: false |
65 | + gem 'rspec-rails', '~> 3.2', require: false | ||
42 | gem 'mocha', '~> 1.1.0', :require => false | 66 | gem 'mocha', '~> 1.1.0', :require => false |
43 | gem 'test-unit' if RUBY_VERSION >= '2.2.0' | 67 | gem 'test-unit' if RUBY_VERSION >= '2.2.0' |
68 | + gem 'minitest' | ||
69 | + gem 'minitest-reporters' | ||
44 | end | 70 | end |
45 | 71 | ||
46 | group :cucumber do | 72 | group :cucumber do |
47 | - gem 'cucumber-rails', '~> 1.0.6', :require => false | ||
48 | - gem 'capybara', '~> 2.1.0' | ||
49 | - gem 'cucumber', '~> 1.0.6' | ||
50 | - gem 'database_cleaner', '~> 1.2.0' | ||
51 | - gem 'selenium-webdriver', '~> 2.47.0' | 73 | + gem 'capybara', '~> 2.2' |
74 | + gem 'launchy' | ||
75 | + gem 'cucumber' | ||
76 | + gem 'cucumber-rails', '~> 1.4.2', :require => false | ||
77 | + gem 'database_cleaner', '~> 1.3' | ||
78 | + gem 'selenium-webdriver', '>= 2.50' | ||
52 | end | 79 | end |
53 | 80 | ||
54 | # Requires custom dependencies | 81 | # Requires custom dependencies |
55 | eval(File.read('config/Gemfile'), binding) rescue nil | 82 | eval(File.read('config/Gemfile'), binding) rescue nil |
56 | 83 | ||
84 | +vendor = Dir.glob('vendor/{,plugins/}*') - ['vendor/plugins'] | ||
85 | +vendor.each do |dir| | ||
86 | + plugin = File.basename dir | ||
87 | + version = if Dir.glob("#{dir}/*.gemspec").length > 0 then '> 0.0.0' else '0.0.0' end | ||
88 | + | ||
89 | + gem plugin, version, path: dir | ||
90 | +end | ||
91 | + | ||
57 | # include gemfiles from enabled plugins | 92 | # include gemfiles from enabled plugins |
58 | # plugins in baseplugins/ are not included on purpose. They should not have any | 93 | # plugins in baseplugins/ are not included on purpose. They should not have any |
59 | # dependencies. | 94 | # dependencies. |
Rakefile
@@ -17,36 +17,3 @@ end.flatten.each do |taskfile| | @@ -17,36 +17,3 @@ end.flatten.each do |taskfile| | ||
17 | load taskfile | 17 | load taskfile |
18 | end | 18 | end |
19 | 19 | ||
20 | -# plugins' tasks | ||
21 | -plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort + | ||
22 | - Dir.glob("config/plugins/*/vendor/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort | ||
23 | -plugins_tasks.each{ |ext| load ext } | ||
24 | - | ||
25 | - | ||
26 | -desc "Print out grape routes" | ||
27 | -task :grape_routes => :environment do | ||
28 | - #require 'api/api.rb' | ||
29 | - Noosfero::API::API.routes.each do |route| | ||
30 | - puts route | ||
31 | - method = route.route_method | ||
32 | - path = route.route_path | ||
33 | - puts " #{method} #{path}" | ||
34 | - end | ||
35 | -end | ||
36 | - | ||
37 | -# plugins' tasks | ||
38 | -plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort + | ||
39 | - Dir.glob("config/plugins/*/vendor/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort | ||
40 | -plugins_tasks.each{ |ext| load ext } | ||
41 | - | ||
42 | - | ||
43 | -desc "Print out grape routes" | ||
44 | -task :grape_routes => :environment do | ||
45 | - #require 'api/api.rb' | ||
46 | - Noosfero::API::API.routes.each do |route| | ||
47 | - puts route | ||
48 | - method = route.route_method | ||
49 | - path = route.route_path | ||
50 | - puts " #{method} #{path}" | ||
51 | - end | ||
52 | -end |
Vagrantfile
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | 3 | ||
4 | VAGRANTFILE_API_VERSION = "2" | 4 | VAGRANTFILE_API_VERSION = "2" |
5 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | 5 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| |
6 | - config.vm.box = ENV.fetch('VAGRANT_BOX', "debian-wheezy") | 6 | + config.vm.box = ENV.fetch('VAGRANT_BOX', "debian/jessie64") |
7 | config.vm.network :forwarded_port, host: 3000, guest: 3000 | 7 | config.vm.network :forwarded_port, host: 3000, guest: 3000 |
8 | config.vm.provision :shell do |shell| | 8 | config.vm.provision :shell do |shell| |
9 | shell.inline = 'su vagrant -c /vagrant/script/vagrant' | 9 | shell.inline = 'su vagrant -c /vagrant/script/vagrant' |
app/controllers/admin/admin_panel_controller.rb
@@ -12,7 +12,7 @@ class AdminPanelController < AdminController | @@ -12,7 +12,7 @@ class AdminPanelController < AdminController | ||
12 | if params[:environment][:languages] | 12 | if params[:environment][:languages] |
13 | params[:environment][:languages] = params[:environment][:languages].map {|lang, value| lang if value=='true'}.compact | 13 | params[:environment][:languages] = params[:environment][:languages].map {|lang, value| lang if value=='true'}.compact |
14 | end | 14 | end |
15 | - if @environment.update_attributes(params[:environment]) | 15 | + if @environment.update(params[:environment]) |
16 | session[:notice] = _('Environment settings updated') | 16 | session[:notice] = _('Environment settings updated') |
17 | redirect_to :action => 'index' | 17 | redirect_to :action => 'index' |
18 | end | 18 | end |
@@ -54,7 +54,7 @@ class AdminPanelController < AdminController | @@ -54,7 +54,7 @@ class AdminPanelController < AdminController | ||
54 | 54 | ||
55 | if request.post? | 55 | if request.post? |
56 | env = environment | 56 | env = environment |
57 | - folders = params[:folders].map{|fid| Folder.find(:first, :conditions => {:profile_id => env.portal_community, :id => fid})} if params[:folders] | 57 | + folders = env.portal_community.folders.where(id: params[:folders]).order(params[:folders].reverse.map{ |f| "id=#{f}" }) if params[:folders] |
58 | env.portal_folders = folders | 58 | env.portal_folders = folders |
59 | if env.save | 59 | if env.save |
60 | session[:notice] = _('Saved the portal folders') | 60 | session[:notice] = _('Saved the portal folders') |
@@ -65,7 +65,7 @@ class AdminPanelController < AdminController | @@ -65,7 +65,7 @@ class AdminPanelController < AdminController | ||
65 | 65 | ||
66 | def set_portal_news_amount | 66 | def set_portal_news_amount |
67 | if request.post? | 67 | if request.post? |
68 | - if @environment.update_attributes(params[:environment]) | 68 | + if @environment.update(params[:environment]) |
69 | session[:notice] = _('Saved the number of news on folders') | 69 | session[:notice] = _('Saved the number of news on folders') |
70 | redirect_to :action => 'index' | 70 | redirect_to :action => 'index' |
71 | end | 71 | end |
app/controllers/admin/categories_controller.rb
1 | class CategoriesController < AdminController | 1 | class CategoriesController < AdminController |
2 | 2 | ||
3 | protect 'manage_environment_categories', :environment | 3 | protect 'manage_environment_categories', :environment |
4 | - | 4 | + |
5 | helper :categories | 5 | helper :categories |
6 | 6 | ||
7 | def index | 7 | def index |
8 | - @categories = environment.categories.find(:all, :conditions => "parent_id is null AND type is null") | ||
9 | - @regions = environment.regions.find(:all, :conditions => {:parent_id => nil}) | ||
10 | - @product_categories = environment.product_categories.find(:all, :conditions => {:parent_id => nil}) | 8 | + @categories = environment.categories.where("parent_id is null AND type is null") |
9 | + @regions = environment.regions.where(:parent_id => nil) | ||
10 | + @product_categories = environment.product_categories.where(:parent_id => nil) | ||
11 | end | 11 | end |
12 | 12 | ||
13 | def get_children | 13 | def get_children |
@@ -43,7 +43,7 @@ class CategoriesController < AdminController | @@ -43,7 +43,7 @@ class CategoriesController < AdminController | ||
43 | begin | 43 | begin |
44 | @category = environment.categories.find(params[:id]) | 44 | @category = environment.categories.find(params[:id]) |
45 | if request.post? | 45 | if request.post? |
46 | - @category.update_attributes!(params[:category]) | 46 | + @category.update!(params[:category]) |
47 | @saved = true | 47 | @saved = true |
48 | session[:notice] = _("Category %s saved." % @category.name) | 48 | session[:notice] = _("Category %s saved." % @category.name) |
49 | redirect_to :action => 'index' | 49 | redirect_to :action => 'index' |
app/controllers/admin/environment_role_manager_controller.rb
@@ -2,7 +2,7 @@ class EnvironmentRoleManagerController < AdminController | @@ -2,7 +2,7 @@ class EnvironmentRoleManagerController < AdminController | ||
2 | protect 'manage_environment_roles', :environment | 2 | protect 'manage_environment_roles', :environment |
3 | 3 | ||
4 | def index | 4 | def index |
5 | - @admins = Person.find(:all, :conditions => ['role_assignments.resource_type = ?', 'Environment'], :include => :role_assignments ) | 5 | + @admins = Person.where('role_assignments.resource_type = ?', 'Environment').includes(:role_assignments) |
6 | end | 6 | end |
7 | 7 | ||
8 | def change_roles | 8 | def change_roles |
app/controllers/admin/features_controller.rb
1 | class FeaturesController < AdminController | 1 | class FeaturesController < AdminController |
2 | protect 'edit_environment_features', :environment | 2 | protect 'edit_environment_features', :environment |
3 | - | 3 | + helper CustomFieldsHelper |
4 | + | ||
4 | def index | 5 | def index |
5 | @features = Environment.available_features.sort_by{|k,v|v} | 6 | @features = Environment.available_features.sort_by{|k,v|v} |
6 | end | 7 | end |
7 | 8 | ||
8 | post_only :update | 9 | post_only :update |
9 | def update | 10 | def update |
10 | - if @environment.update_attributes(params[:environment]) | 11 | + if @environment.update(params[:environment]) |
11 | session[:notice] = _('Features updated successfully.') | 12 | session[:notice] = _('Features updated successfully.') |
12 | redirect_to :action => 'index' | 13 | redirect_to :action => 'index' |
13 | else | 14 | else |
@@ -51,9 +52,37 @@ class FeaturesController < AdminController | @@ -51,9 +52,37 @@ class FeaturesController < AdminController | ||
51 | redirect_to :action => 'manage_fields' | 52 | redirect_to :action => 'manage_fields' |
52 | end | 53 | end |
53 | 54 | ||
55 | + def manage_custom_fields | ||
56 | + custom_field_list = params[:custom_fields] || {} | ||
57 | + | ||
58 | + custom_fields_to_destroy = | ||
59 | + params[:customized_type].constantize.custom_fields(environment).map(&:id) - custom_field_list.keys.map(&:to_i) | ||
60 | + CustomField.destroy(custom_fields_to_destroy) | ||
61 | + | ||
62 | + custom_field_list.each_pair do |id, custom_field| | ||
63 | + field = CustomField.find_by_id(id) | ||
64 | + if not field.blank? | ||
65 | + params_to_update = custom_field.except(:format, :extras, :customized_type,:environment) | ||
66 | + field.update_attributes(params_to_update) | ||
67 | + else | ||
68 | + if !custom_field[:extras].nil? | ||
69 | + tmp = [] | ||
70 | + custom_field[:extras].each_pair do |k, v| | ||
71 | + tmp << v | ||
72 | + end | ||
73 | + custom_field[:extras] = tmp | ||
74 | + end | ||
75 | + field = CustomField.new custom_field.except(:environment) | ||
76 | + field.environment=environment | ||
77 | + field.save if field.valid? | ||
78 | + end | ||
79 | + end | ||
80 | + redirect_to :action => 'manage_fields' | ||
81 | + end | ||
82 | + | ||
54 | def search_members | 83 | def search_members |
55 | arg = params[:q].downcase | 84 | arg = params[:q].downcase |
56 | - result = environment.people.find(:all, :conditions => ['LOWER(name) LIKE ? OR identifier LIKE ?', "%#{arg}%", "%#{arg}%"]) | 85 | + result = environment.people.where('LOWER(name) LIKE ? OR identifier LIKE ?', "%#{arg}%", "%#{arg}%") |
57 | render :text => prepare_to_token_input(result).to_json | 86 | render :text => prepare_to_token_input(result).to_json |
58 | end | 87 | end |
59 | 88 |
app/controllers/admin/licenses_controller.rb
@@ -23,7 +23,7 @@ class LicensesController < AdminController | @@ -23,7 +23,7 @@ class LicensesController < AdminController | ||
23 | @license = environment.licenses.find(params[:license_id]) | 23 | @license = environment.licenses.find(params[:license_id]) |
24 | if request.post? | 24 | if request.post? |
25 | begin | 25 | begin |
26 | - @license.update_attributes!(params[:license]) | 26 | + @license.update!(params[:license]) |
27 | session[:notice] = _('License updated') | 27 | session[:notice] = _('License updated') |
28 | redirect_to :action => 'index' | 28 | redirect_to :action => 'index' |
29 | rescue | 29 | rescue |
app/controllers/admin/plugins_controller.rb
@@ -8,7 +8,7 @@ class PluginsController < AdminController | @@ -8,7 +8,7 @@ class PluginsController < AdminController | ||
8 | post_only :update | 8 | post_only :update |
9 | def update | 9 | def update |
10 | params[:environment][:enabled_plugins].delete('') | 10 | params[:environment][:enabled_plugins].delete('') |
11 | - if @environment.update_attributes(params[:environment]) | 11 | + if @environment.update(params[:environment]) |
12 | session[:notice] = _('Plugins updated successfully.') | 12 | session[:notice] = _('Plugins updated successfully.') |
13 | else | 13 | else |
14 | session[:error] = _('Plugins were not updated successfully.') | 14 | session[:error] = _('Plugins were not updated successfully.') |
app/controllers/admin/role_controller.rb
@@ -29,7 +29,7 @@ class RoleController < AdminController | @@ -29,7 +29,7 @@ class RoleController < AdminController | ||
29 | 29 | ||
30 | def update | 30 | def update |
31 | @role = environment.roles.find(params[:id]) | 31 | @role = environment.roles.find(params[:id]) |
32 | - if @role.update_attributes(params[:role]) | 32 | + if @role.update(params[:role]) |
33 | redirect_to :action => 'show', :id => @role | 33 | redirect_to :action => 'show', :id => @role |
34 | else | 34 | else |
35 | session[:notice] = _('Failed to edit role') | 35 | session[:notice] = _('Failed to edit role') |
app/controllers/admin/users_controller.rb
@@ -63,7 +63,7 @@ class UsersController < AdminController | @@ -63,7 +63,7 @@ class UsersController < AdminController | ||
63 | respond_to do |format| | 63 | respond_to do |format| |
64 | format.html | 64 | format.html |
65 | format.xml do | 65 | format.xml do |
66 | - users = User.find(:all, :conditions => {:environment_id => environment.id}, :include => [:person]) | 66 | + users = User.where(:environment_id => environment.id).includes(:person) |
67 | send_data users.to_xml( | 67 | send_data users.to_xml( |
68 | :skip_types => true, | 68 | :skip_types => true, |
69 | :only => %w[email login created_at updated_at], | 69 | :only => %w[email login created_at updated_at], |
app/controllers/application.rb
@@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
1 | -require 'application_controller' |
app/controllers/application_controller.rb
@@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base | @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base | ||
8 | before_filter :init_noosfero_plugins | 8 | before_filter :init_noosfero_plugins |
9 | before_filter :allow_cross_domain_access | 9 | before_filter :allow_cross_domain_access |
10 | 10 | ||
11 | - before_filter :login_from_cookie | 11 | + include AuthenticatedSystem |
12 | before_filter :require_login_for_environment, :if => :private_environment? | 12 | before_filter :require_login_for_environment, :if => :private_environment? |
13 | 13 | ||
14 | before_filter :verify_members_whitelist, :if => [:private_environment?, :user] | 14 | before_filter :verify_members_whitelist, :if => [:private_environment?, :user] |
@@ -45,7 +45,7 @@ class ApplicationController < ActionController::Base | @@ -45,7 +45,7 @@ class ApplicationController < ActionController::Base | ||
45 | include ApplicationHelper | 45 | include ApplicationHelper |
46 | layout :get_layout | 46 | layout :get_layout |
47 | def get_layout | 47 | def get_layout |
48 | - return nil if request.format == :js or request.xhr? | 48 | + return false if request.format == :js or request.xhr? |
49 | 49 | ||
50 | theme_layout = theme_option(:layout) | 50 | theme_layout = theme_option(:layout) |
51 | if theme_layout | 51 | if theme_layout |
@@ -69,15 +69,12 @@ class ApplicationController < ActionController::Base | @@ -69,15 +69,12 @@ class ApplicationController < ActionController::Base | ||
69 | helper :language | 69 | helper :language |
70 | 70 | ||
71 | include DesignHelper | 71 | include DesignHelper |
72 | - | ||
73 | - # Be sure to include AuthenticationSystem in Application Controller instead | ||
74 | - include AuthenticatedSystem | ||
75 | include PermissionCheck | 72 | include PermissionCheck |
76 | 73 | ||
77 | before_filter :set_locale | 74 | before_filter :set_locale |
78 | def set_locale | 75 | def set_locale |
79 | FastGettext.available_locales = environment.available_locales | 76 | FastGettext.available_locales = environment.available_locales |
80 | - FastGettext.default_locale = environment.default_locale | 77 | + FastGettext.default_locale = environment.default_locale || 'en' |
81 | FastGettext.locale = (params[:lang] || session[:lang] || environment.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') | 78 | FastGettext.locale = (params[:lang] || session[:lang] || environment.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') |
82 | I18n.locale = FastGettext.locale.to_s.gsub '_', '-' | 79 | I18n.locale = FastGettext.locale.to_s.gsub '_', '-' |
83 | I18n.default_locale = FastGettext.default_locale.to_s.gsub '_', '-' | 80 | I18n.default_locale = FastGettext.default_locale.to_s.gsub '_', '-' |
@@ -134,12 +131,11 @@ class ApplicationController < ActionController::Base | @@ -134,12 +131,11 @@ class ApplicationController < ActionController::Base | ||
134 | @domain = Domain.find_by_name(request.host) | 131 | @domain = Domain.find_by_name(request.host) |
135 | if @domain.nil? | 132 | if @domain.nil? |
136 | @environment = Environment.default | 133 | @environment = Environment.default |
137 | - if @environment.nil? && Rails.env.development? | ||
138 | - # This should only happen in development ... | 134 | + # Avoid crashes on test and development setups |
135 | + if @environment.nil? && !Rails.env.production? | ||
139 | @environment = Environment.new | 136 | @environment = Environment.new |
140 | @environment.name = "Noosfero" | 137 | @environment.name = "Noosfero" |
141 | @environment.is_default = true | 138 | @environment.is_default = true |
142 | - @environment.save! | ||
143 | end | 139 | end |
144 | else | 140 | else |
145 | @environment = @domain.environment | 141 | @environment = @domain.environment |
@@ -148,7 +144,7 @@ class ApplicationController < ActionController::Base | @@ -148,7 +144,7 @@ class ApplicationController < ActionController::Base | ||
148 | # Check if the requested profile belongs to another domain | 144 | # Check if the requested profile belongs to another domain |
149 | if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier | 145 | if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier |
150 | @profile = @environment.profiles.find_by_identifier params[:profile] | 146 | @profile = @environment.profiles.find_by_identifier params[:profile] |
151 | - redirect_to params.merge(:host => @profile.default_hostname) | 147 | + redirect_to url_for(params.merge host: @profile.default_hostname) |
152 | end | 148 | end |
153 | end | 149 | end |
154 | end | 150 | end |
@@ -163,7 +159,8 @@ class ApplicationController < ActionController::Base | @@ -163,7 +159,8 @@ class ApplicationController < ActionController::Base | ||
163 | def render_not_found(path = nil) | 159 | def render_not_found(path = nil) |
164 | @no_design_blocks = true | 160 | @no_design_blocks = true |
165 | @path ||= request.path | 161 | @path ||= request.path |
166 | - render :template => 'shared/not_found.html.erb', :status => 404, :layout => get_layout | 162 | + # force html template even if the browser asked for a image |
163 | + render template: 'shared/not_found', status: 404, layout: get_layout, formats: [:html] | ||
167 | end | 164 | end |
168 | alias :render_404 :render_not_found | 165 | alias :render_404 :render_not_found |
169 | 166 | ||
@@ -171,7 +168,8 @@ class ApplicationController < ActionController::Base | @@ -171,7 +168,8 @@ class ApplicationController < ActionController::Base | ||
171 | @no_design_blocks = true | 168 | @no_design_blocks = true |
172 | @message = message | 169 | @message = message |
173 | @title = title | 170 | @title = title |
174 | - render :template => 'shared/access_denied.html.erb', :status => 403 | 171 | + # force html template even if the browser asked for a image |
172 | + render template: 'shared/access_denied', status: 403, formats: [:html] | ||
175 | end | 173 | end |
176 | 174 | ||
177 | def load_category | 175 | def load_category |
@@ -185,13 +183,7 @@ class ApplicationController < ActionController::Base | @@ -185,13 +183,7 @@ class ApplicationController < ActionController::Base | ||
185 | end | 183 | end |
186 | 184 | ||
187 | include SearchTermHelper | 185 | include SearchTermHelper |
188 | - | ||
189 | - def find_by_contents(asset, context, scope, query, paginate_options={:page => 1}, options={}) | ||
190 | - scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank? | ||
191 | - search = plugins.dispatch_first(:find_by_contents, asset, scope, query, paginate_options, options) | ||
192 | - register_search_term(query, scope.count, search[:results].count, context, asset) | ||
193 | - search | ||
194 | - end | 186 | + include FindByContents |
195 | 187 | ||
196 | def find_suggestions(query, context, asset, options={}) | 188 | def find_suggestions(query, context, asset, options={}) |
197 | plugins.dispatch_first(:find_suggestions, query, context, asset, options) | 189 | plugins.dispatch_first(:find_suggestions, query, context, asset, options) |
@@ -204,7 +196,7 @@ class ApplicationController < ActionController::Base | @@ -204,7 +196,7 @@ class ApplicationController < ActionController::Base | ||
204 | def redirect_to_current_user | 196 | def redirect_to_current_user |
205 | if params[:profile] == '~' | 197 | if params[:profile] == '~' |
206 | if logged_in? | 198 | if logged_in? |
207 | - redirect_to params.merge(:profile => user.identifier) | 199 | + redirect_to url_for(params.merge profile: user.identifier) |
208 | else | 200 | else |
209 | render_not_found | 201 | render_not_found |
210 | end | 202 | end |
app/controllers/box_organizer_controller.rb
@@ -3,12 +3,11 @@ class BoxOrganizerController < ApplicationController | @@ -3,12 +3,11 @@ class BoxOrganizerController < ApplicationController | ||
3 | before_filter :login_required | 3 | before_filter :login_required |
4 | 4 | ||
5 | def index | 5 | def index |
6 | + @available_blocks = available_blocks.uniq.sort_by(&:pretty_name) | ||
6 | end | 7 | end |
7 | 8 | ||
8 | def move_block | 9 | def move_block |
9 | - @block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) | ||
10 | - | ||
11 | - @source_box = @block.box | 10 | + @block = params[:id] ? boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) : nil |
12 | 11 | ||
13 | target_position = nil | 12 | target_position = nil |
14 | 13 | ||
@@ -20,9 +19,12 @@ class BoxOrganizerController < ApplicationController | @@ -20,9 +19,12 @@ class BoxOrganizerController < ApplicationController | ||
20 | else | 19 | else |
21 | (params[:target] =~ /end-of-box-([0-9]+)/) | 20 | (params[:target] =~ /end-of-box-([0-9]+)/) |
22 | 21 | ||
23 | - @target_box = boxes_holder.boxes.find($1) | 22 | + @target_box = boxes_holder.boxes.find_by_id($1) |
24 | end | 23 | end |
25 | 24 | ||
25 | + @block = new_block(params[:type], @target_box) if @block.nil? | ||
26 | + @source_box = @block.box | ||
27 | + | ||
26 | if (@source_box != @target_box) | 28 | if (@source_box != @target_box) |
27 | @block.remove_from_list | 29 | @block.remove_from_list |
28 | @block.box = @target_box | 30 | @block.box = @target_box |
@@ -58,23 +60,6 @@ class BoxOrganizerController < ApplicationController | @@ -58,23 +60,6 @@ class BoxOrganizerController < ApplicationController | ||
58 | redirect_to :action => 'index' | 60 | redirect_to :action => 'index' |
59 | end | 61 | end |
60 | 62 | ||
61 | - def add_block | ||
62 | - type = params[:type] | ||
63 | - if ! type.blank? | ||
64 | - if available_blocks.map(&:name).include?(type) | ||
65 | - boxes_holder.boxes.find(params[:box_id]).blocks << type.constantize.new | ||
66 | - redirect_to :action => 'index' | ||
67 | - else | ||
68 | - raise ArgumentError.new("Type %s is not allowed. Go away." % type) | ||
69 | - end | ||
70 | - else | ||
71 | - @center_block_types = (Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => 1) | ||
72 | - @side_block_types = (Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => [2,3]) | ||
73 | - @boxes = boxes_holder.boxes.with_position | ||
74 | - render :action => 'add_block', :layout => false | ||
75 | - end | ||
76 | - end | ||
77 | - | ||
78 | def edit | 63 | def edit |
79 | @block = boxes_holder.blocks.find(params[:id]) | 64 | @block = boxes_holder.blocks.find(params[:id]) |
80 | render :action => 'edit', :layout => false | 65 | render :action => 'edit', :layout => false |
@@ -84,9 +69,9 @@ class BoxOrganizerController < ApplicationController | @@ -84,9 +69,9 @@ class BoxOrganizerController < ApplicationController | ||
84 | if request.xhr? and params[:query] | 69 | if request.xhr? and params[:query] |
85 | search = params[:query] | 70 | search = params[:query] |
86 | path_list = if boxes_holder.is_a?(Environment) && boxes_holder.enabled?('use_portal_community') && boxes_holder.portal_community | 71 | path_list = if boxes_holder.is_a?(Environment) && boxes_holder.enabled?('use_portal_community') && boxes_holder.portal_community |
87 | - boxes_holder.portal_community.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{portal}/"+content.path } | 72 | + boxes_holder.portal_community.articles.where("name ILIKE ? OR path ILIKE ?", "%#{search}%", "%#{search}%").limit(20).map { |content| "/{portal}/"+content.path } |
88 | elsif boxes_holder.is_a?(Profile) | 73 | elsif boxes_holder.is_a?(Profile) |
89 | - boxes_holder.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{profile}/"+content.path } | 74 | + boxes_holder.articles.where("name ILIKE ? OR path ILIKE ?", "%#{search}%", "%#{search}%").limit(20).map { |content| "/{profile}/"+content.path } |
90 | else | 75 | else |
91 | [] | 76 | [] |
92 | end | 77 | end |
@@ -98,7 +83,7 @@ class BoxOrganizerController < ApplicationController | @@ -98,7 +83,7 @@ class BoxOrganizerController < ApplicationController | ||
98 | 83 | ||
99 | def save | 84 | def save |
100 | @block = boxes_holder.blocks.find(params[:id]) | 85 | @block = boxes_holder.blocks.find(params[:id]) |
101 | - @block.update_attributes(params[:block]) | 86 | + @block.update(params[:block]) |
102 | redirect_to :action => 'index' | 87 | redirect_to :action => 'index' |
103 | end | 88 | end |
104 | 89 | ||
@@ -121,6 +106,27 @@ class BoxOrganizerController < ApplicationController | @@ -121,6 +106,27 @@ class BoxOrganizerController < ApplicationController | ||
121 | redirect_to :action => 'index' | 106 | redirect_to :action => 'index' |
122 | end | 107 | end |
123 | 108 | ||
109 | + def show_block_type_info | ||
110 | + type = params[:type] | ||
111 | + if type.blank? || !available_blocks.map(&:name).include?(type) | ||
112 | + raise ArgumentError.new("Type %s is not allowed. Go away." % type) | ||
113 | + end | ||
114 | + @block = type.constantize.new | ||
115 | + @block.box = Box.new(:owner => boxes_holder) | ||
116 | + render :action => 'show_block_type_info', :layout => false | ||
117 | + end | ||
118 | + | ||
124 | protected :boxes_editor? | 119 | protected :boxes_editor? |
125 | 120 | ||
121 | + protected | ||
122 | + | ||
123 | + def new_block(type, box) | ||
124 | + if !available_blocks.map(&:name).include?(type) | ||
125 | + raise ArgumentError.new("Type %s is not allowed. Go away." % type) | ||
126 | + end | ||
127 | + block = type.constantize.new | ||
128 | + box.blocks << block | ||
129 | + block | ||
130 | + end | ||
131 | + | ||
126 | end | 132 | end |
app/controllers/my_profile/cms_controller.rb
@@ -6,7 +6,7 @@ class CmsController < MyProfileController | @@ -6,7 +6,7 @@ class CmsController < MyProfileController | ||
6 | 6 | ||
7 | def search_tags | 7 | def search_tags |
8 | arg = params[:term].downcase | 8 | arg = params[:term].downcase |
9 | - result = ActsAsTaggableOn::Tag.where('name ILIKE ?', "%#{arg}%").limit(10) | 9 | + result = Tag.where('name ILIKE ?', "%#{arg}%").limit(10) |
10 | render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' | 10 | render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' |
11 | end | 11 | end |
12 | 12 | ||
@@ -50,16 +50,9 @@ class CmsController < MyProfileController | @@ -50,16 +50,9 @@ class CmsController < MyProfileController | ||
50 | 50 | ||
51 | def view | 51 | def view |
52 | @article = profile.articles.find(params[:id]) | 52 | @article = profile.articles.find(params[:id]) |
53 | - conditions = [] | ||
54 | - if @article.has_posts? | ||
55 | - conditions = ['type != ?', 'RssFeed'] | ||
56 | - end | ||
57 | - | ||
58 | - @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name").paginate( | ||
59 | - :conditions => conditions, | ||
60 | - :per_page => per_page, | ||
61 | - :page => params[:npage] | ||
62 | - ) | 53 | + @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name") |
54 | + @articles = @articles.where "type <> ?", 'RssFeed' if @article.has_posts? | ||
55 | + @articles = @articles.paginate per_page: per_page, page: params[:npage] | ||
63 | end | 56 | end |
64 | 57 | ||
65 | def index | 58 | def index |
@@ -99,7 +92,7 @@ class CmsController < MyProfileController | @@ -99,7 +92,7 @@ class CmsController < MyProfileController | ||
99 | @article.image.save! | 92 | @article.image.save! |
100 | end | 93 | end |
101 | @article.last_changed_by = user | 94 | @article.last_changed_by = user |
102 | - if @article.update_attributes(params[:article]) | 95 | + if @article.update(params[:article]) |
103 | if !continue | 96 | if !continue |
104 | if @article.content_type.nil? || @article.image? | 97 | if @article.content_type.nil? || @article.image? |
105 | success_redirect | 98 | success_redirect |
@@ -230,7 +223,7 @@ class CmsController < MyProfileController | @@ -230,7 +223,7 @@ class CmsController < MyProfileController | ||
230 | else | 223 | else |
231 | session[:notice] = _('File(s) successfully uploaded') | 224 | session[:notice] = _('File(s) successfully uploaded') |
232 | if @back_to | 225 | if @back_to |
233 | - redirect_to @back_to | 226 | + redirect_to url_for(@back_to) |
234 | elsif @parent | 227 | elsif @parent |
235 | redirect_to :action => 'view', :id => @parent.id | 228 | redirect_to :action => 'view', :id => @parent.id |
236 | else | 229 | else |
@@ -381,7 +374,7 @@ class CmsController < MyProfileController | @@ -381,7 +374,7 @@ class CmsController < MyProfileController | ||
381 | 374 | ||
382 | def search_article_privacy_exceptions | 375 | def search_article_privacy_exceptions |
383 | arg = params[:q].downcase | 376 | arg = params[:q].downcase |
384 | - result = profile.members.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) | 377 | + result = profile.members.where('LOWER(name) LIKE ?', "%#{arg}%") |
385 | render :text => prepare_to_token_input(result).to_json | 378 | render :text => prepare_to_token_input(result).to_json |
386 | end | 379 | end |
387 | 380 |
app/controllers/my_profile/enterprise_validation_controller.rb
@@ -54,7 +54,7 @@ class EnterpriseValidationController < MyProfileController | @@ -54,7 +54,7 @@ class EnterpriseValidationController < MyProfileController | ||
54 | def edit_validation_info | 54 | def edit_validation_info |
55 | @info = profile.validation_info | 55 | @info = profile.validation_info |
56 | if request.post? | 56 | if request.post? |
57 | - if @info.update_attributes(params[:info]) | 57 | + if @info.update(params[:info]) |
58 | redirect_to :action => 'index' | 58 | redirect_to :action => 'index' |
59 | end | 59 | end |
60 | end | 60 | end |
app/controllers/my_profile/manage_products_controller.rb
@@ -69,7 +69,7 @@ class ManageProductsController < ApplicationController | @@ -69,7 +69,7 @@ class ManageProductsController < ApplicationController | ||
69 | field = params[:field] | 69 | field = params[:field] |
70 | if request.post? | 70 | if request.post? |
71 | begin | 71 | begin |
72 | - @product.update_attributes!(params[:product]) | 72 | + @product.update!(params[:product]) |
73 | render :partial => "display_#{field}", :locals => {:product => @product} | 73 | render :partial => "display_#{field}", :locals => {:product => @product} |
74 | rescue Exception => e | 74 | rescue Exception => e |
75 | render :partial => "edit_#{field}", :locals => {:product => @product, :errors => true} | 75 | render :partial => "edit_#{field}", :locals => {:product => @product, :errors => true} |
@@ -86,7 +86,7 @@ class ManageProductsController < ApplicationController | @@ -86,7 +86,7 @@ class ManageProductsController < ApplicationController | ||
86 | @edit = true | 86 | @edit = true |
87 | @level = @category.level | 87 | @level = @category.level |
88 | if request.post? | 88 | if request.post? |
89 | - if @product.update_attributes({:product_category_id => params[:selected_category_id]}, :without_protection => true) | 89 | + if @product.update({:product_category_id => params[:selected_category_id]}, :without_protection => true) |
90 | render :partial => 'shared/redirect_via_javascript', | 90 | render :partial => 'shared/redirect_via_javascript', |
91 | :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } | 91 | :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } |
92 | else | 92 | else |
@@ -115,7 +115,7 @@ class ManageProductsController < ApplicationController | @@ -115,7 +115,7 @@ class ManageProductsController < ApplicationController | ||
115 | @categories = ProductCategory.top_level_for(environment) | 115 | @categories = ProductCategory.top_level_for(environment) |
116 | @level = 0 | 116 | @level = 0 |
117 | if request.post? | 117 | if request.post? |
118 | - if @input.update_attributes(:product_category_id => params[:selected_category_id]) | 118 | + if @input.update(:product_category_id => params[:selected_category_id]) |
119 | @inputs = @product.inputs | 119 | @inputs = @product.inputs |
120 | render :partial => 'display_inputs' | 120 | render :partial => 'display_inputs' |
121 | else | 121 | else |
@@ -172,7 +172,7 @@ class ManageProductsController < ApplicationController | @@ -172,7 +172,7 @@ class ManageProductsController < ApplicationController | ||
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_attributes(params[:input]) | 175 | + if @input.update(params[:input]) |
176 | render :partial => 'display_input', :locals => {:input => @input} | 176 | render :partial => 'display_input', :locals => {:input => @input} |
177 | else | 177 | else |
178 | render :partial => 'edit_input' | 178 | render :partial => 'edit_input' |
app/controllers/my_profile/maps_controller.rb
1 | class MapsController < MyProfileController | 1 | class MapsController < MyProfileController |
2 | 2 | ||
3 | + skip_before_filter :verify_authenticity_token, only: [:google_map] | ||
4 | + | ||
3 | protect 'edit_profile', :profile | 5 | protect 'edit_profile', :profile |
4 | 6 | ||
5 | def edit_location | 7 | def edit_location |
@@ -15,7 +17,7 @@ class MapsController < MyProfileController | @@ -15,7 +17,7 @@ class MapsController < MyProfileController | ||
15 | end | 17 | end |
16 | 18 | ||
17 | Profile.transaction do | 19 | Profile.transaction do |
18 | - if profile.update_attributes!(params[:profile_data]) | 20 | + if profile.update!(params[:profile_data]) |
19 | BlockSweeper.expire_blocks profile.blocks.select{ |b| b.class == LocationBlock } | 21 | BlockSweeper.expire_blocks profile.blocks.select{ |b| b.class == LocationBlock } |
20 | session[:notice] = _('Address was updated successfully!') | 22 | session[:notice] = _('Address was updated successfully!') |
21 | redirect_to :action => 'edit_location' | 23 | redirect_to :action => 'edit_location' |
app/controllers/my_profile/memberships_controller.rb
1 | class MembershipsController < MyProfileController | 1 | class MembershipsController < MyProfileController |
2 | 2 | ||
3 | protect 'manage_memberships', :profile | 3 | protect 'manage_memberships', :profile |
4 | + helper CustomFieldsHelper | ||
4 | 5 | ||
5 | def index | 6 | def index |
6 | @roles = environment.roles.select do |role| | 7 | @roles = environment.roles.select do |role| |
@@ -17,12 +18,14 @@ class MembershipsController < MyProfileController | @@ -17,12 +18,14 @@ class MembershipsController < MyProfileController | ||
17 | 18 | ||
18 | def new_community | 19 | def new_community |
19 | @community = Community.new(params[:community]) | 20 | @community = Community.new(params[:community]) |
21 | + custom_values = params[:profile_data][:custom_values] if (params[:profile_data] && params[:profile_data][:custom_values]) | ||
22 | + @community.custom_values = custom_values | ||
20 | @community.environment = environment | 23 | @community.environment = environment |
21 | @back_to = params[:back_to] || url_for(:action => 'index') | 24 | @back_to = params[:back_to] || url_for(:action => 'index') |
22 | if request.post? && @community.valid? | 25 | if request.post? && @community.valid? |
23 | begin | 26 | begin |
24 | # Community was created | 27 | # Community was created |
25 | - @community = Community.create_after_moderation(user, params[:community].merge({:environment => environment})) | 28 | + @community = Community.create_after_moderation(user, params[:community].merge({:environment => environment, :custom_values => custom_values})) |
26 | @community.reload | 29 | @community.reload |
27 | redirect_to :action => 'welcome', :community_id => @community.id, :back_to => @back_to | 30 | redirect_to :action => 'welcome', :community_id => @community.id, :back_to => @back_to |
28 | rescue ActiveRecord::RecordNotFound | 31 | rescue ActiveRecord::RecordNotFound |
app/controllers/my_profile/profile_design_controller.rb
@@ -15,8 +15,9 @@ class ProfileDesignController < BoxOrganizerController | @@ -15,8 +15,9 @@ class ProfileDesignController < BoxOrganizerController | ||
15 | end | 15 | end |
16 | 16 | ||
17 | def protect_fixed_block | 17 | def protect_fixed_block |
18 | + return if params[:id].blank? | ||
18 | block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) | 19 | block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) |
19 | - if !current_person.is_admin? && !block.movable? | 20 | + if block.present? && !current_person.is_admin? && !block.movable? |
20 | render_access_denied | 21 | render_access_denied |
21 | end | 22 | end |
22 | end | 23 | end |
app/controllers/my_profile/profile_editor_controller.rb
@@ -8,6 +8,7 @@ class ProfileEditorController < MyProfileController | @@ -8,6 +8,7 @@ class ProfileEditorController < MyProfileController | ||
8 | before_filter :forbid_destroy_profile, :only => [:destroy_profile] | 8 | before_filter :forbid_destroy_profile, :only => [:destroy_profile] |
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 | 12 | ||
12 | def index | 13 | def index |
13 | @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)} | 14 | @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)} |
@@ -27,7 +28,7 @@ class ProfileEditorController < MyProfileController | @@ -27,7 +28,7 @@ class ProfileEditorController < MyProfileController | ||
27 | Image.transaction do | 28 | Image.transaction do |
28 | begin | 29 | begin |
29 | @plugins.dispatch(:profile_editor_transaction_extras) | 30 | @plugins.dispatch(:profile_editor_transaction_extras) |
30 | - @profile_data.update_attributes!(params[:profile_data]) | 31 | + @profile_data.update!(params[:profile_data]) |
31 | redirect_to :action => 'index', :profile => profile.identifier | 32 | redirect_to :action => 'index', :profile => profile.identifier |
32 | rescue Exception => ex | 33 | rescue Exception => ex |
33 | profile.identifier = params[:profile] if profile.identifier.blank? | 34 | profile.identifier = params[:profile] if profile.identifier.blank? |
@@ -83,7 +84,7 @@ class ProfileEditorController < MyProfileController | @@ -83,7 +84,7 @@ class ProfileEditorController < MyProfileController | ||
83 | if @profile.destroy | 84 | if @profile.destroy |
84 | session[:notice] = _('The profile was deleted.') | 85 | session[:notice] = _('The profile was deleted.') |
85 | if(params[:return_to]) | 86 | if(params[:return_to]) |
86 | - redirect_to params[:return_to] | 87 | + redirect_to url_for(params[:return_to]) |
87 | else | 88 | else |
88 | redirect_to :controller => 'home' | 89 | redirect_to :controller => 'home' |
89 | end | 90 | end |
@@ -97,7 +98,7 @@ class ProfileEditorController < MyProfileController | @@ -97,7 +98,7 @@ class ProfileEditorController < MyProfileController | ||
97 | @welcome_page = profile.welcome_page || TinyMceArticle.new(:name => 'Welcome Page', :profile => profile, :published => false) | 98 | @welcome_page = profile.welcome_page || TinyMceArticle.new(:name => 'Welcome Page', :profile => profile, :published => false) |
98 | if request.post? | 99 | if request.post? |
99 | begin | 100 | begin |
100 | - @welcome_page.update_attributes!(params[:welcome_page]) | 101 | + @welcome_page.update!(params[:welcome_page]) |
101 | profile.welcome_page = @welcome_page | 102 | profile.welcome_page = @welcome_page |
102 | profile.save! | 103 | profile.save! |
103 | session[:notice] = _('Welcome page saved successfully.') | 104 | session[:notice] = _('Welcome page saved successfully.') |
app/controllers/my_profile/profile_members_controller.rb
@@ -47,7 +47,7 @@ class ProfileMembersController < MyProfileController | @@ -47,7 +47,7 @@ class ProfileMembersController < MyProfileController | ||
47 | end | 47 | end |
48 | 48 | ||
49 | def remove_role | 49 | def remove_role |
50 | - @association = RoleAssignment.find(:all, :conditions => {:id => params[:id], :target_id => profile.id}) | 50 | + @association = RoleAssignment.where(:id => params[:id], :target_id => profile.id) |
51 | if @association.destroy | 51 | if @association.destroy |
52 | session[:notice] = 'Member succefully unassociated' | 52 | session[:notice] = 'Member succefully unassociated' |
53 | else | 53 | else |
@@ -120,7 +120,7 @@ class ProfileMembersController < MyProfileController | @@ -120,7 +120,7 @@ class ProfileMembersController < MyProfileController | ||
120 | 120 | ||
121 | def search_user | 121 | def search_user |
122 | role = Role.find(params[:role]) | 122 | role = Role.find(params[:role]) |
123 | - render :text => environment.people.find(:all, :conditions => ['LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?', "%#{params['q_'+role.key]}%", "%#{params['q_'+role.key]}%"]). | 123 | + render :text => environment.people.where('LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?', "%#{params['q_'+role.key]}%", "%#{params['q_'+role.key]}%"). |
124 | select { |person| !profile.members_by_role(role).include?(person) }. | 124 | select { |person| !profile.members_by_role(role).include?(person) }. |
125 | map {|person| {:id => person.id, :name => person.name} }. | 125 | map {|person| {:id => person.id, :name => person.name} }. |
126 | to_json | 126 | to_json |
app/controllers/my_profile/profile_roles_controller.rb
@@ -58,7 +58,7 @@ class ProfileRolesController < MyProfileController | @@ -58,7 +58,7 @@ class ProfileRolesController < MyProfileController | ||
58 | 58 | ||
59 | def update | 59 | def update |
60 | @role = environment.roles.find(params[:id]) | 60 | @role = environment.roles.find(params[:id]) |
61 | - if @role.update_attributes(params[:role]) | 61 | + if @role.update(params[:role]) |
62 | redirect_to :action => 'show', :id => @role | 62 | redirect_to :action => 'show', :id => @role |
63 | else | 63 | else |
64 | session[:notice] = _('Failed to edit role') | 64 | session[:notice] = _('Failed to edit role') |
app/controllers/my_profile/tasks_controller.rb
@@ -48,7 +48,7 @@ class TasksController < MyProfileController | @@ -48,7 +48,7 @@ class TasksController < MyProfileController | ||
48 | if request.post? && VALID_DECISIONS.include?(decision) && id && decision != 'skip' | 48 | if request.post? && VALID_DECISIONS.include?(decision) && id && decision != 'skip' |
49 | task = profile.find_in_all_tasks(id) | 49 | task = profile.find_in_all_tasks(id) |
50 | begin | 50 | begin |
51 | - task.update_attributes(value[:task]) | 51 | + task.update(value[:task]) |
52 | task.send(decision, current_person) | 52 | task.send(decision, current_person) |
53 | rescue Exception => ex | 53 | rescue Exception => ex |
54 | message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" | 54 | message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" |
@@ -86,7 +86,7 @@ class TasksController < MyProfileController | @@ -86,7 +86,7 @@ class TasksController < MyProfileController | ||
86 | end | 86 | end |
87 | 87 | ||
88 | def ticket_details | 88 | def ticket_details |
89 | - @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) | 89 | + @ticket = Ticket.where('(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]).first |
90 | end | 90 | end |
91 | 91 | ||
92 | end | 92 | end |
app/controllers/public/account_controller.rb
@@ -6,6 +6,9 @@ class AccountController < ApplicationController | @@ -6,6 +6,9 @@ class AccountController < ApplicationController | ||
6 | before_filter :redirect_if_logged_in, :only => [:login, :signup] | 6 | before_filter :redirect_if_logged_in, :only => [:login, :signup] |
7 | before_filter :protect_from_bots, :only => :signup | 7 | before_filter :protect_from_bots, :only => :signup |
8 | 8 | ||
9 | + protect_from_forgery except: [:login] | ||
10 | + | ||
11 | + helper CustomFieldsHelper | ||
9 | # say something nice, you goof! something sweet. | 12 | # say something nice, you goof! something sweet. |
10 | def index | 13 | def index |
11 | unless logged_in? | 14 | unless logged_in? |
@@ -117,9 +120,9 @@ class AccountController < ApplicationController | @@ -117,9 +120,9 @@ class AccountController < ApplicationController | ||
117 | @user.signup! | 120 | @user.signup! |
118 | owner_role = Role.find_by_name('owner') | 121 | owner_role = Role.find_by_name('owner') |
119 | @user.person.affiliate(@user.person, [owner_role]) if owner_role | 122 | @user.person.affiliate(@user.person, [owner_role]) if owner_role |
120 | - invitation = Task.find_by_code(@invitation_code) | 123 | + invitation = Task.from_code(@invitation_code).first |
121 | if invitation | 124 | if invitation |
122 | - invitation.update_attributes!({:friend => @user.person}) | 125 | + invitation.update! friend: @user.person |
123 | invitation.finish | 126 | invitation.finish |
124 | end | 127 | end |
125 | 128 | ||
@@ -209,7 +212,7 @@ class AccountController < ApplicationController | @@ -209,7 +212,7 @@ class AccountController < ApplicationController | ||
209 | # | 212 | # |
210 | # Posts back. | 213 | # Posts back. |
211 | def new_password | 214 | def new_password |
212 | - @change_password = ChangePassword.find_by_code(params[:code]) | 215 | + @change_password = ChangePassword.from_code(params[:code]).first |
213 | 216 | ||
214 | unless @change_password | 217 | unless @change_password |
215 | render :action => 'invalid_change_password_code', :status => 403 | 218 | render :action => 'invalid_change_password_code', :status => 403 |
@@ -218,7 +221,7 @@ class AccountController < ApplicationController | @@ -218,7 +221,7 @@ class AccountController < ApplicationController | ||
218 | 221 | ||
219 | if request.post? | 222 | if request.post? |
220 | begin | 223 | begin |
221 | - @change_password.update_attributes!(params[:change_password]) | 224 | + @change_password.update!(params[:change_password]) |
222 | @change_password.finish | 225 | @change_password.finish |
223 | render :action => 'new_password_ok' | 226 | render :action => 'new_password_ok' |
224 | rescue ActiveRecord::RecordInvalid => e | 227 | rescue ActiveRecord::RecordInvalid => e |
@@ -402,7 +405,7 @@ class AccountController < ApplicationController | @@ -402,7 +405,7 @@ class AccountController < ApplicationController | ||
402 | end | 405 | end |
403 | 406 | ||
404 | def load_enterprise_activation | 407 | def load_enterprise_activation |
405 | - @enterprise_activation ||= EnterpriseActivation.find_by_code(params[:enterprise_code]) | 408 | + @enterprise_activation ||= EnterpriseActivation.from_code(params[:enterprise_code]).first |
406 | end | 409 | end |
407 | 410 | ||
408 | def load_enterprise | 411 | def load_enterprise |
@@ -426,7 +429,7 @@ class AccountController < ApplicationController | @@ -426,7 +429,7 @@ class AccountController < ApplicationController | ||
426 | 429 | ||
427 | def go_to_initial_page | 430 | def go_to_initial_page |
428 | if params[:return_to] | 431 | if params[:return_to] |
429 | - redirect_to params[:return_to] | 432 | + redirect_to url_for(params[:return_to]) |
430 | elsif environment.enabled?('allow_change_of_redirection_after_login') | 433 | elsif environment.enabled?('allow_change_of_redirection_after_login') |
431 | check_redirection_options(user, user.preferred_login_redirection, user.admin_url) | 434 | check_redirection_options(user, user.preferred_login_redirection, user.admin_url) |
432 | else | 435 | else |
@@ -487,7 +490,7 @@ class AccountController < ApplicationController | @@ -487,7 +490,7 @@ class AccountController < ApplicationController | ||
487 | def check_redirection | 490 | def check_redirection |
488 | unless params[:redirection].blank? | 491 | unless params[:redirection].blank? |
489 | session[:return_to] = @user.return_to | 492 | session[:return_to] = @user.return_to |
490 | - @user.update_attributes(:return_to => nil) | 493 | + @user.update(:return_to => nil) |
491 | end | 494 | end |
492 | end | 495 | end |
493 | 496 |
app/controllers/public/chat_controller.rb
@@ -67,7 +67,7 @@ class ChatController < PublicController | @@ -67,7 +67,7 @@ class ChatController < PublicController | ||
67 | 67 | ||
68 | def update_presence_status | 68 | def update_presence_status |
69 | if request.xhr? | 69 | if request.xhr? |
70 | - current_user.update_attributes({:chat_status_at => DateTime.now}.merge(params[:status] || {})) | 70 | + current_user.update({:chat_status_at => DateTime.now}.merge(params[:status] || {})) |
71 | end | 71 | end |
72 | render :nothing => true | 72 | render :nothing => true |
73 | end | 73 | end |
app/controllers/public/comment_controller.rb
@@ -78,7 +78,7 @@ class CommentController < ApplicationController | @@ -78,7 +78,7 @@ class CommentController < ApplicationController | ||
78 | respond_to do |format| | 78 | respond_to do |format| |
79 | format.js do | 79 | format.js do |
80 | comment_to_render = @comment.comment_root | 80 | comment_to_render = @comment.comment_root |
81 | - render :json => { | 81 | + render :json => { |
82 | :render_target => comment_to_render.anchor, | 82 | :render_target => comment_to_render.anchor, |
83 | :html => render_to_string(:partial => 'comment', :locals => {:comment => comment_to_render, :display_link => true}), | 83 | :html => render_to_string(:partial => 'comment', :locals => {:comment => comment_to_render, :display_link => true}), |
84 | :msg => _('Comment successfully created.') | 84 | :msg => _('Comment successfully created.') |
@@ -114,7 +114,7 @@ class CommentController < ApplicationController | @@ -114,7 +114,7 @@ class CommentController < ApplicationController | ||
114 | end | 114 | end |
115 | 115 | ||
116 | def update | 116 | def update |
117 | - if @comment.update_attributes(params[:comment]) | 117 | + if @comment.update(params[:comment]) |
118 | @plugins.dispatch(:process_extra_comment_params, [@comment,params]) | 118 | @plugins.dispatch(:process_extra_comment_params, [@comment,params]) |
119 | 119 | ||
120 | respond_to do |format| | 120 | respond_to do |format| |
app/controllers/public/enterprise_registration_controller.rb
@@ -4,7 +4,7 @@ class EnterpriseRegistrationController < ApplicationController | @@ -4,7 +4,7 @@ class EnterpriseRegistrationController < ApplicationController | ||
4 | before_filter :login_required | 4 | before_filter :login_required |
5 | 5 | ||
6 | # Just go to the first step. | 6 | # Just go to the first step. |
7 | - # | 7 | + # |
8 | # FIXME: shouldn't this action present some sort of welcome message and point | 8 | # FIXME: shouldn't this action present some sort of welcome message and point |
9 | # to the first step explicitly? | 9 | # to the first step explicitly? |
10 | def index | 10 | def index |
@@ -15,7 +15,7 @@ class EnterpriseRegistrationController < ApplicationController | @@ -15,7 +15,7 @@ class EnterpriseRegistrationController < ApplicationController | ||
15 | @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) | 15 | @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) |
16 | end | 16 | end |
17 | elsif @validation == :admin || @validation == :none | 17 | elsif @validation == :admin || @validation == :none |
18 | - @create_enterprise.target = environment | 18 | + @create_enterprise.target = environment |
19 | end | 19 | end |
20 | @create_enterprise.requestor = user | 20 | @create_enterprise.requestor = user |
21 | the_action = | 21 | the_action = |
@@ -40,7 +40,7 @@ class EnterpriseRegistrationController < ApplicationController | @@ -40,7 +40,7 @@ class EnterpriseRegistrationController < ApplicationController | ||
40 | 40 | ||
41 | protected | 41 | protected |
42 | 42 | ||
43 | - # Fill in the form and select your Region. | 43 | + # Fill in the form and select your Region. |
44 | # | 44 | # |
45 | # Posts back. | 45 | # Posts back. |
46 | def basic_information | 46 | def basic_information |
app/controllers/public/profile_controller.rb
@@ -7,6 +7,7 @@ class ProfileController < PublicController | @@ -7,6 +7,7 @@ class ProfileController < PublicController | ||
7 | 7 | ||
8 | helper TagsHelper | 8 | helper TagsHelper |
9 | helper ActionTrackerHelper | 9 | helper ActionTrackerHelper |
10 | + helper CustomFieldsHelper | ||
10 | 11 | ||
11 | protect 'send_mail_to_members', :profile, :only => [:send_mail] | 12 | protect 'send_mail_to_members', :profile, :only => [:send_mail] |
12 | 13 | ||
@@ -37,7 +38,7 @@ class ProfileController < PublicController | @@ -37,7 +38,7 @@ class ProfileController < PublicController | ||
37 | 38 | ||
38 | def tag_feed | 39 | def tag_feed |
39 | @tag = params[:id] | 40 | @tag = params[:id] |
40 | - tagged = profile.articles.paginate(:per_page => 20, :page => 1, :order => 'published_at DESC', :include => :tags, :conditions => ['tags.name LIKE ?', @tag]) | 41 | + tagged = profile.articles.paginate(:per_page => 20, :page => 1).order('published_at DESC').joins(:tags).where('tags.name LIKE ?', @tag) |
41 | feed_writer = FeedWriter.new | 42 | feed_writer = FeedWriter.new |
42 | data = feed_writer.write( | 43 | data = feed_writer.write( |
43 | tagged, | 44 | tagged, |
@@ -205,7 +206,7 @@ class ProfileController < PublicController | @@ -205,7 +206,7 @@ class ProfileController < PublicController | ||
205 | 206 | ||
206 | def more_comments | 207 | def more_comments |
207 | profile_filter = @profile.person? ? {:user_id => @profile} : {:target_id => @profile} | 208 | profile_filter = @profile.person? ? {:user_id => @profile} : {:target_id => @profile} |
208 | - activity = ActionTracker::Record.find(:first, :conditions => {:id => params[:activity]}.merge(profile_filter)) | 209 | + activity = ActionTracker::Record.where({:id => params[:activity]}.merge profile_filter).first |
209 | comments_count = activity.comments.count | 210 | comments_count = activity.comments.count |
210 | comment_page = (params[:comment_page] || 1).to_i | 211 | comment_page = (params[:comment_page] || 1).to_i |
211 | comments_per_page = 5 | 212 | comments_per_page = 5 |
@@ -225,7 +226,7 @@ class ProfileController < PublicController | @@ -225,7 +226,7 @@ class ProfileController < PublicController | ||
225 | end | 226 | end |
226 | 227 | ||
227 | def more_replies | 228 | def more_replies |
228 | - activity = Scrap.find(:first, :conditions => {:id => params[:activity], :receiver_id => @profile, :scrap_id => nil}) | 229 | + activity = Scrap.where(:id => params[:activity], :receiver_id => @profile, :scrap_id => nil).first |
229 | comments_count = activity.replies.count | 230 | comments_count = activity.replies.count |
230 | comment_page = (params[:comment_page] || 1).to_i | 231 | comment_page = (params[:comment_page] || 1).to_i |
231 | comments_per_page = 5 | 232 | comments_per_page = 5 |
@@ -272,7 +273,7 @@ class ProfileController < PublicController | @@ -272,7 +273,7 @@ class ProfileController < PublicController | ||
272 | def remove_notification | 273 | def remove_notification |
273 | begin | 274 | begin |
274 | raise if !can_edit_profile | 275 | raise if !can_edit_profile |
275 | - notification = ActionTrackerNotification.find(:first, :conditions => {:profile_id => profile.id, :action_tracker_id => params[:activity_id]}) | 276 | + notification = ActionTrackerNotification.where(profile_id: profile.id, action_tracker_id: params[:activity_id]).first |
276 | notification.destroy | 277 | notification.destroy |
277 | render :text => _('Notification successfully removed.') | 278 | render :text => _('Notification successfully removed.') |
278 | rescue | 279 | rescue |
app/controllers/public/search_controller.rb
@@ -14,7 +14,7 @@ class SearchController < PublicController | @@ -14,7 +14,7 @@ class SearchController < PublicController | ||
14 | # Backwards compatibility with old URLs | 14 | # Backwards compatibility with old URLs |
15 | def redirect_asset_param | 15 | def redirect_asset_param |
16 | return unless params.has_key?(:asset) | 16 | return unless params.has_key?(:asset) |
17 | - redirect_to params.merge(:action => params.delete(:asset)) | 17 | + redirect_to url_for(params.merge action: params.delete(:asset)) |
18 | end | 18 | end |
19 | 19 | ||
20 | no_design_blocks | 20 | no_design_blocks |
@@ -62,12 +62,12 @@ class SearchController < PublicController | @@ -62,12 +62,12 @@ class SearchController < PublicController | ||
62 | end | 62 | end |
63 | 63 | ||
64 | def articles | 64 | def articles |
65 | - @scope = @environment.articles.public | 65 | + @scope = @environment.articles.is_public |
66 | full_text_search | 66 | full_text_search |
67 | end | 67 | end |
68 | 68 | ||
69 | def contents | 69 | def contents |
70 | - redirect_to params.merge(:action => :articles) | 70 | + redirect_to url_for(params.merge action: :articles) |
71 | end | 71 | end |
72 | 72 | ||
73 | def people | 73 | def people |
@@ -122,7 +122,7 @@ class SearchController < PublicController | @@ -122,7 +122,7 @@ class SearchController < PublicController | ||
122 | # keep old URLs workings | 122 | # keep old URLs workings |
123 | def assets | 123 | def assets |
124 | params[:action] = params[:asset].is_a?(Array) ? :index : params.delete(:asset) | 124 | params[:action] = params[:asset].is_a?(Array) ? :index : params.delete(:asset) |
125 | - redirect_to params | 125 | + redirect_to url_for(params) |
126 | end | 126 | end |
127 | 127 | ||
128 | def tags | 128 | def tags |
app/controllers/themes_controller.rb
@@ -13,7 +13,7 @@ class ThemesController < ApplicationController | @@ -13,7 +13,7 @@ class ThemesController < ApplicationController | ||
13 | 13 | ||
14 | def index | 14 | def index |
15 | @environment = environment | 15 | @environment = environment |
16 | - @themes = (environment.themes + Theme.approved_themes(target)).sort_by { |t| t.name } | 16 | + @themes = (environment.themes + Theme.approved_themes(target)).uniq.sort_by { |t| t.name } |
17 | 17 | ||
18 | @current_theme = target.theme | 18 | @current_theme = target.theme |
19 | 19 |
app/helpers/application_helper.rb
@@ -8,6 +8,10 @@ module ApplicationHelper | @@ -8,6 +8,10 @@ module ApplicationHelper | ||
8 | 8 | ||
9 | include PermissionNameHelper | 9 | include PermissionNameHelper |
10 | 10 | ||
11 | + include UrlHelper | ||
12 | + | ||
13 | + include PartialsHelper | ||
14 | + | ||
11 | include ModalHelper | 15 | include ModalHelper |
12 | 16 | ||
13 | include BoxesHelper | 17 | include BoxesHelper |
@@ -281,36 +285,6 @@ module ApplicationHelper | @@ -281,36 +285,6 @@ module ApplicationHelper | ||
281 | concat(content_tag('div', capture(&block).to_s + tag('br', :style => 'clear: left;'), options)) | 285 | concat(content_tag('div', capture(&block).to_s + tag('br', :style => 'clear: left;'), options)) |
282 | end | 286 | end |
283 | 287 | ||
284 | - | ||
285 | - def partial_for_class_in_view_path(klass, view_path, prefix = nil, suffix = nil) | ||
286 | - return nil if klass.nil? | ||
287 | - name = [prefix, klass.name.underscore, suffix].compact.map(&:to_s).join('_') | ||
288 | - | ||
289 | - search_name = String.new(name) | ||
290 | - if search_name.include?("/") | ||
291 | - search_name.gsub!(/(\/)([^\/]*)$/,'\1_\2') | ||
292 | - name = File.join(params[:controller], name) if defined?(params) && params[:controller] | ||
293 | - else | ||
294 | - search_name = "_" + search_name | ||
295 | - end | ||
296 | - | ||
297 | - path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name + '.html.erb') : File.join(view_path, search_name + '.html.erb') | ||
298 | - return name if File.exists?(File.join(path)) | ||
299 | - | ||
300 | - partial_for_class_in_view_path(klass.superclass, view_path, prefix, suffix) | ||
301 | - end | ||
302 | - | ||
303 | - def partial_for_class(klass, prefix=nil, suffix=nil) | ||
304 | - raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? | ||
305 | - name = klass.name.underscore | ||
306 | - controller.view_paths.each do |view_path| | ||
307 | - partial = partial_for_class_in_view_path(klass, view_path, prefix, suffix) | ||
308 | - return partial if partial | ||
309 | - end | ||
310 | - | ||
311 | - raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' | ||
312 | - end | ||
313 | - | ||
314 | def render_profile_actions klass | 288 | def render_profile_actions klass |
315 | name = klass.to_s.underscore | 289 | name = klass.to_s.underscore |
316 | begin | 290 | begin |
@@ -529,32 +503,6 @@ module ApplicationHelper | @@ -529,32 +503,6 @@ module ApplicationHelper | ||
529 | sex | 503 | sex |
530 | end | 504 | end |
531 | 505 | ||
532 | - def profile_cat_icons( profile ) | ||
533 | - if profile.class == Enterprise | ||
534 | - icons = profile.product_categories.unique_by_level(2).limit(3).map do |c| | ||
535 | - filtered_category = c.filtered_category.blank? ? c.path.split('/').last : c.filtered_category | ||
536 | - category_title = filtered_category.split(/[-_\s,.;'"]+/).map(&:capitalize).join(' ') | ||
537 | - category_name = category_title.gsub(' ', '_' ) | ||
538 | - category_icon = "/images/icons-cat/#{category_name}.png" | ||
539 | - if ! File.exists?(Rails.root.join('public', category_icon)) | ||
540 | - category_icon = '/images/icons-cat/undefined.png' | ||
541 | - end | ||
542 | - content_tag('span', | ||
543 | - content_tag( 'span', category_title ), | ||
544 | - :title => category_title, | ||
545 | - :class => 'product-cat-icon cat_icon_' + category_name, | ||
546 | - :style => "background-image:url(#{category_icon})" | ||
547 | - ) | ||
548 | - end.join("\n").html_safe | ||
549 | - content_tag('div', | ||
550 | - content_tag( 'span', _('Principal Product Categories'), :class => 'header' ) +"\n"+ icons, | ||
551 | - :class => 'product-category-icons' | ||
552 | - ) | ||
553 | - else | ||
554 | - '' | ||
555 | - end | ||
556 | - end | ||
557 | - | ||
558 | def links_for_balloon(profile) | 506 | def links_for_balloon(profile) |
559 | if environment.enabled?(:show_balloon_with_profile_links_when_clicked) | 507 | if environment.enabled?(:show_balloon_with_profile_links_when_clicked) |
560 | if profile.kind_of?(Person) | 508 | if profile.kind_of?(Person) |
@@ -613,7 +561,7 @@ module ApplicationHelper | @@ -613,7 +561,7 @@ module ApplicationHelper | ||
613 | link_to( | 561 | link_to( |
614 | content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + | 562 | content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + |
615 | content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + | 563 | content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + |
616 | - extra_info + profile_sex_icon( profile ) + profile_cat_icons( profile ), | 564 | + extra_info + profile_sex_icon( profile ), |
617 | profile.url, | 565 | profile.url, |
618 | :class => 'profile_link url', | 566 | :class => 'profile_link url', |
619 | :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name, | 567 | :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name, |
@@ -907,8 +855,14 @@ module ApplicationHelper | @@ -907,8 +855,14 @@ module ApplicationHelper | ||
907 | end | 855 | end |
908 | alias :top_url :base_url | 856 | alias :top_url :base_url |
909 | 857 | ||
858 | + class View < ActionView::Base | ||
859 | + def url_for *args | ||
860 | + self.controller.url_for *args | ||
861 | + end | ||
862 | + end | ||
863 | + | ||
910 | def helper_for_article(article) | 864 | def helper_for_article(article) |
911 | - article_helper = ActionView::Base.new | 865 | + article_helper = View.new |
912 | article_helper.controller = controller | 866 | article_helper.controller = controller |
913 | article_helper.extend ArticleHelper | 867 | article_helper.extend ArticleHelper |
914 | article_helper.extend Rails.application.routes.url_helpers | 868 | article_helper.extend Rails.application.routes.url_helpers |
app/helpers/article_helper.rb
@@ -119,7 +119,7 @@ module ArticleHelper | @@ -119,7 +119,7 @@ module ArticleHelper | ||
119 | end | 119 | end |
120 | 120 | ||
121 | def add_option_to_followers(article, tokenized_children) | 121 | def add_option_to_followers(article, tokenized_children) |
122 | - label_message = article.profile.organization? ? _('For all community members') : _('For all your friends') | 122 | + label_message = article.profile.organization? ? _('Allow all community members to view this content') : _('Allow all your friends to view this content') |
123 | 123 | ||
124 | check_box( | 124 | check_box( |
125 | :article, | 125 | :article, |
@@ -137,7 +137,7 @@ module ArticleHelper | @@ -137,7 +137,7 @@ module ArticleHelper | ||
137 | 'div', | 137 | 'div', |
138 | content_tag( | 138 | content_tag( |
139 | 'label', | 139 | 'label', |
140 | - _('Fill in the search field to add the exception users to see this content'), | 140 | + _('Allow only community members entered below to view this content'), |
141 | :id => "text-input-search-exception-users" | 141 | :id => "text-input-search-exception-users" |
142 | ) + | 142 | ) + |
143 | token_input_field_tag( | 143 | token_input_field_tag( |
@@ -146,7 +146,7 @@ module ArticleHelper | @@ -146,7 +146,7 @@ module ArticleHelper | ||
146 | {:action => 'search_article_privacy_exceptions'}, | 146 | {:action => 'search_article_privacy_exceptions'}, |
147 | { | 147 | { |
148 | :focus => false, | 148 | :focus => false, |
149 | - :hint_text => _('Type in a search term for a user'), | 149 | + :hint_text => _('Type in a name of a community member'), |
150 | :pre_populate => tokenized_children | 150 | :pre_populate => tokenized_children |
151 | } | 151 | } |
152 | ) | 152 | ) |
app/helpers/block_helper.rb
@@ -19,7 +19,7 @@ module BlockHelper | @@ -19,7 +19,7 @@ module BlockHelper | ||
19 | content_tag('span', _('Title')) + | 19 | content_tag('span', _('Title')) + |
20 | text_field_tag('block[images][][title]', image[:title], :class => 'highlight-title', :size => 45) | 20 | text_field_tag('block[images][][title]', image[:title], :class => 'highlight-title', :size => 45) |
21 | }</label></td> | 21 | }</label></td> |
22 | - <td>#{button_without_text(:delete, _('Remove'), '#', class: 'delete-highlight', :confirm=>_('Are you sure you want to remove this highlight'))}</td> | 22 | + <td>#{button_without_text(:delete, _('Remove'), '#', class: 'delete-highlight', data: {confirm: _('Are you sure you want to remove this highlight')})}</td> |
23 | </tr> | 23 | </tr> |
24 | " | 24 | " |
25 | end | 25 | end |
app/helpers/box_organizer_helper.rb
1 | module BoxOrganizerHelper | 1 | module BoxOrganizerHelper |
2 | 2 | ||
3 | + def display_icon(block) | ||
4 | + image_path = nil | ||
5 | + plugin = @plugins.fetch_first_plugin(:has_block?, block) | ||
6 | + | ||
7 | + theme = Theme.new(environment.theme) # remove this | ||
8 | + if File.exists?(File.join(theme.filesystem_path, block.icon_path)) | ||
9 | + image_path = File.join(theme.public_path, block.icon_path) | ||
10 | + elsif plugin && File.exists?(File.join(Rails.root, 'public', plugin.public_path, block.icon_path)) | ||
11 | + image_path = File.join('/', plugin.public_path, block.icon_path) | ||
12 | + elsif File.exists?(File.join(Rails.root, 'public', block.icon_path)) | ||
13 | + image_path = block.icon_path | ||
14 | + else | ||
15 | + image_path = block.default_icon_path | ||
16 | + end | ||
17 | + | ||
18 | + image_tag(image_path, height: '48', width: '48', class: 'block-type-icon', alt: '' ) | ||
19 | + end | ||
20 | + | ||
21 | + def display_previews(block) | ||
22 | + images_path = nil | ||
23 | + plugin = @plugins.fetch_first_plugin(:has_block?, block) | ||
24 | + | ||
25 | + theme = Theme.new(environment.theme) # remove this | ||
26 | + | ||
27 | + images_path = Dir.glob(File.join(theme.filesystem_path, 'images', block.preview_path, '*')) | ||
28 | + images_path = images_path.map{|path| path.gsub(theme.filesystem_path, theme.public_path) } unless images_path.empty? | ||
29 | + | ||
30 | + images_path = Dir.glob(File.join(Rails.root, 'public', plugin.public_path, 'images', block.preview_path, '*')) if plugin && images_path.empty? | ||
31 | + images_path = images_path.map{|path| path.gsub(File.join(Rails.root, 'public'), '') } unless images_path.empty? | ||
32 | + | ||
33 | + images_path = Dir.glob(File.join(Rails.root, 'public', 'images', block.preview_path, '*')) if images_path.empty? | ||
34 | + images_path = images_path.map{|path| path.gsub(File.join(Rails.root, 'public'), '') } unless images_path.empty? | ||
35 | + | ||
36 | + images_path = 1.upto(3).map{block.default_preview_path} if images_path.empty? | ||
37 | + | ||
38 | + content_tag(:ul, | ||
39 | + images_path.map do |preview| | ||
40 | + content_tag(:li, image_tag(preview, height: '240', alt: '')) | ||
41 | + end.join("\n") | ||
42 | + ) | ||
43 | + end | ||
44 | + | ||
3 | def icon_selector(icon = 'no-ico') | 45 | def icon_selector(icon = 'no-ico') |
4 | render :partial => 'icon_selector', :locals => { :icon => icon } | 46 | render :partial => 'icon_selector', :locals => { :icon => icon } |
5 | end | 47 | end |
@@ -10,4 +52,4 @@ module BoxOrganizerHelper | @@ -10,4 +52,4 @@ module BoxOrganizerHelper | ||
10 | end | 52 | end |
11 | end | 53 | end |
12 | 54 | ||
13 | -end | ||
14 | \ No newline at end of file | 55 | \ No newline at end of file |
56 | +end |
app/helpers/boxes_helper.rb
@@ -190,8 +190,9 @@ module BoxesHelper | @@ -190,8 +190,9 @@ module BoxesHelper | ||
190 | else | 190 | else |
191 | "before-block-#{block.id}" | 191 | "before-block-#{block.id}" |
192 | end | 192 | end |
193 | - if block.nil? || movable?(block) | ||
194 | - content_tag('div', ' ', :id => id, :class => 'block-target' ) + drop_receiving_element(id, :url => { :action => 'move_block', :target => id }, :accept => box.acceptable_blocks, :hoverclass => 'block-target-hover') | 193 | + if block.nil? or movable?(block) |
194 | + url = url_for(:action => 'move_block', :target => id) | ||
195 | + content_tag('div', _('Drop Here'), :id => id, :class => 'block-target' ) + drop_receiving_element(id, :accept => box.acceptable_blocks, :hoverclass => 'block-target-hover', :activeClass => 'block-target-active', :tolerance => 'pointer', :onDrop => "function(ev, ui) { dropBlock('#{url}', '#{_('loading...')}', ev, ui);}") | ||
195 | else | 196 | else |
196 | "" | 197 | "" |
197 | end | 198 | end |
@@ -199,7 +200,25 @@ module BoxesHelper | @@ -199,7 +200,25 @@ module BoxesHelper | ||
199 | 200 | ||
200 | # makes the given block draggable so it can be moved away. | 201 | # makes the given block draggable so it can be moved away. |
201 | def block_handle(block) | 202 | def block_handle(block) |
202 | - movable?(block) ? draggable_element("block-#{block.id}", :revert => true) : "" | 203 | + return "" unless movable?(block) |
204 | + icon = "<div><div>#{display_icon(block.class)}</div><span>#{_(block.class.pretty_name)}</span></div>" | ||
205 | + block_draggable("block-#{block.id}", | ||
206 | + :helper => "function() {return cloneDraggableBlock($(this), '#{icon}')}") | ||
207 | + end | ||
208 | + | ||
209 | + def block_draggable(element_id, options={}) | ||
210 | + draggable_options = { | ||
211 | + :revert => "'invalid'", | ||
212 | + :appendTo => "'#block-store-draggables'", | ||
213 | + :helper => '"clone"', | ||
214 | + :revertDuration => 200, | ||
215 | + :scroll => false, | ||
216 | + :start => "startDragBlock", | ||
217 | + :stop => "stopDragBlock", | ||
218 | + :cursor => "'move'", | ||
219 | + :cursorAt => '{ left: 0, top:0, right:0, bottom:0 }', | ||
220 | + }.merge(options) | ||
221 | + draggable_element(element_id, draggable_options) | ||
203 | end | 222 | end |
204 | 223 | ||
205 | def block_edit_buttons(block) | 224 | def block_edit_buttons(block) |
@@ -236,7 +255,7 @@ module BoxesHelper | @@ -236,7 +255,7 @@ module BoxesHelper | ||
236 | end | 255 | end |
237 | 256 | ||
238 | if movable?(block) && !block.main? | 257 | if movable?(block) && !block.main? |
239 | - buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post', :confirm => _('Are you sure you want to remove this block?')}) | 258 | + buttons << icon_button(:delete, _('Remove block'), { action: 'remove', id: block.id }, method: 'post', data: {confirm: _('Are you sure you want to remove this block?')}) |
240 | buttons << icon_button(:clone, _('Clone'), { :action => 'clone_block', :id => block.id }, { :method => 'post' }) | 259 | buttons << icon_button(:clone, _('Clone'), { :action => 'clone_block', :id => block.id }, { :method => 'post' }) |
241 | end | 260 | end |
242 | 261 |
app/helpers/cms_helper.rb
@@ -34,7 +34,7 @@ module CmsHelper | @@ -34,7 +34,7 @@ module CmsHelper | ||
34 | end | 34 | end |
35 | 35 | ||
36 | def display_delete_button(article) | 36 | def display_delete_button(article) |
37 | - expirable_button article, :delete, _('Delete'), { :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article) | 37 | + expirable_button article, :delete, _('Delete'), { :action => 'destroy', :id => article.id }, :method => :post, 'data-confirm' => delete_article_message(article) |
38 | end | 38 | end |
39 | 39 | ||
40 | def expirable_button(content, action, title, url, options = {}) | 40 | def expirable_button(content, action, title, url, options = {}) |
@@ -42,7 +42,7 @@ module CmsHelper | @@ -42,7 +42,7 @@ module CmsHelper | ||
42 | if reason.present? | 42 | if reason.present? |
43 | options[:class] = (options[:class] || '') + ' disabled' | 43 | options[:class] = (options[:class] || '') + ' disabled' |
44 | options[:disabled] = 'disabled' | 44 | options[:disabled] = 'disabled' |
45 | - options.delete(:confirm) | 45 | + options.delete('data-confirm') |
46 | options.delete(:method) | 46 | options.delete(:method) |
47 | title = reason | 47 | title = reason |
48 | end | 48 | end |
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +module CustomFieldsHelper | ||
2 | + | ||
3 | + def format_name(format) | ||
4 | + names = {} | ||
5 | + names['string'] = _('String') | ||
6 | + names['text'] = _('Text') | ||
7 | + names['date'] = _('Date') | ||
8 | + names['numeric'] = _('Numeric') | ||
9 | + names['link'] = _('Link') | ||
10 | + names['list'] = _('List') | ||
11 | + names['checkbox'] = _('Checkbox') | ||
12 | + names[format] | ||
13 | + end | ||
14 | + | ||
15 | + def custom_field_forms(customized_type) | ||
16 | + forms = [] | ||
17 | + forms << [_('String'), form_for_format(customized_type,'string')] | ||
18 | + forms << [_('Text'), form_for_format(customized_type,'text')] | ||
19 | + forms << [_('Date'), form_for_format(customized_type,'date')] | ||
20 | + forms << [_('Numeric'), form_for_format(customized_type,'numeric')] | ||
21 | + forms << [_('Link'), form_for_format(customized_type,'link')] | ||
22 | + forms << [_('List'), form_for_format(customized_type,'list')] | ||
23 | + forms << [_('Checkbox'), form_for_format(customized_type,'checkbox')] | ||
24 | + forms | ||
25 | + end | ||
26 | + | ||
27 | + def render_extras_field(id, extra=nil, field=nil) | ||
28 | + if extra.nil? | ||
29 | + CGI::escapeHTML((render(:partial => 'features/custom_fields/extras_field', :locals => {:id => id, :extra => nil, :field => field}))) | ||
30 | + else | ||
31 | + render :partial => 'features/custom_fields/extras_field', :locals => {:id => id, :extra => extra, :field => field} | ||
32 | + end | ||
33 | + end | ||
34 | + | ||
35 | + def form_for_field(field, customized_type) | ||
36 | + render :partial => 'features/custom_fields/form', :locals => {:field => field} | ||
37 | + end | ||
38 | + | ||
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 | ||
42 | + when 'text', 'list', 'numeric', 'date', 'string' | ||
43 | + value | ||
44 | + when 'checkbox' | ||
45 | + value == "1" ? _('Yes') : _('No') | ||
46 | + when 'link' | ||
47 | + url = value[/\Ahttps?:\/\//i] ? value : "http://#{value}" | ||
48 | + link_to(value, url, :target => '_blank') | ||
49 | + end | ||
50 | + end | ||
51 | + | ||
52 | + private | ||
53 | + | ||
54 | + def form_for_format(customized_type, format) | ||
55 | + field = CustomField.new(:format => format, :customized_type => customized_type, :environment => environment) | ||
56 | + CGI::escapeHTML((render(:partial => 'features/custom_fields/form', :locals => {:field => field}))) | ||
57 | + end | ||
58 | +end |
app/helpers/events_helper.rb
@@ -24,7 +24,8 @@ module EventsHelper | @@ -24,7 +24,8 @@ module EventsHelper | ||
24 | end | 24 | end |
25 | 25 | ||
26 | def populate_calendar(selected_date, events) | 26 | def populate_calendar(selected_date, events) |
27 | - events.reject! {|event| !event.display_to?(user)} | 27 | + selected_date = selected_date.to_date |
28 | + events = events.reject{ |event| !event.display_to? user } | ||
28 | calendar = Event.date_range(selected_date.year, selected_date.month).map do |date| | 29 | calendar = Event.date_range(selected_date.year, selected_date.month).map do |date| |
29 | [ | 30 | [ |
30 | # the day itself | 31 | # the day itself |
app/helpers/folder_helper.rb
@@ -5,13 +5,11 @@ module FolderHelper | @@ -5,13 +5,11 @@ module FolderHelper | ||
5 | def list_contents(configure={}) | 5 | def list_contents(configure={}) |
6 | configure[:recursive] ||= false | 6 | configure[:recursive] ||= false |
7 | configure[:list_type] ||= :folder | 7 | configure[:list_type] ||= :folder |
8 | - if !configure[:contents].blank? | ||
9 | - configure[:contents] = configure[:contents].paginate( | ||
10 | - :order => "name ASC", | ||
11 | - :per_page => 30, | ||
12 | - :page => params[:npage] | ||
13 | - ) | ||
14 | - | 8 | + contents = configure[:contents] |
9 | + contents = contents.order('name ASC') unless contents.is_a? Array | ||
10 | + contents = contents.paginate per_page: 30, page: params[:npage] | ||
11 | + configure[:contents] = contents | ||
12 | + if contents.present? | ||
15 | render :file => 'shared/content_list', :locals => configure | 13 | render :file => 'shared/content_list', :locals => configure |
16 | else | 14 | else |
17 | content_tag('em', _('(empty folder)')) | 15 | content_tag('em', _('(empty folder)')) |
app/helpers/forms_helper.rb
@@ -184,9 +184,9 @@ module FormsHelper | @@ -184,9 +184,9 @@ module FormsHelper | ||
184 | datepicker_options[:year_suffix] ||= '' | 184 | datepicker_options[:year_suffix] ||= '' |
185 | 185 | ||
186 | element_id = html_options[:id] || 'datepicker-date' | 186 | element_id = html_options[:id] || 'datepicker-date' |
187 | - value_js_formatted = value.strftime('%Y-%m-%d %H:%S') | ||
188 | value = value.strftime(format) if value.present? | 187 | value = value.strftime(format) if value.present? |
189 | method = datepicker_options[:time] ? 'datetimepicker' : 'datepicker' | 188 | method = datepicker_options[:time] ? 'datetimepicker' : 'datepicker' |
189 | + current_date_or_nil = value.present? ? "new Date('#{value}')" : "null" | ||
190 | result = text_field_tag(name, value, html_options) | 190 | result = text_field_tag(name, value, html_options) |
191 | result += | 191 | result += |
192 | " | 192 | " |
@@ -237,7 +237,7 @@ module FormsHelper | @@ -237,7 +237,7 @@ module FormsHelper | ||
237 | weekHeader: #{datepicker_options[:week_header].to_json}, | 237 | weekHeader: #{datepicker_options[:week_header].to_json}, |
238 | yearRange: #{datepicker_options[:year_range].to_json}, | 238 | yearRange: #{datepicker_options[:year_range].to_json}, |
239 | yearSuffix: #{datepicker_options[:year_suffix].to_json} | 239 | yearSuffix: #{datepicker_options[:year_suffix].to_json} |
240 | - }).datepicker('setDate', new Date('#{value_js_formatted}')) | 240 | + }).datepicker('setDate', current_date_or_nil) |
241 | </script> | 241 | </script> |
242 | ".html_safe | 242 | ".html_safe |
243 | result | 243 | result |
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +module PartialsHelper | ||
2 | + | ||
3 | + def partial_for_class_in_view_path(klass, view_path, prefix = nil, suffix = nil) | ||
4 | + return nil if klass.nil? | ||
5 | + name = [prefix, klass.name.underscore, suffix].compact.map(&:to_s).join('_') | ||
6 | + | ||
7 | + search_name = String.new(name) | ||
8 | + if search_name.include?("/") | ||
9 | + search_name.gsub!(/(\/)([^\/]*)$/,'\1_\2') | ||
10 | + name = File.join(params[:controller], name) if defined?(params) && params[:controller] | ||
11 | + else | ||
12 | + search_name = "_" + search_name | ||
13 | + end | ||
14 | + | ||
15 | + path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name + '.html.erb') : File.join(view_path, search_name + '.html.erb') | ||
16 | + return name if File.exists?(File.join(path)) | ||
17 | + | ||
18 | + partial_for_class_in_view_path(klass.superclass, view_path, prefix, suffix) | ||
19 | + end | ||
20 | + | ||
21 | + def partial_for_class(klass, prefix=nil, suffix=nil) | ||
22 | + raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? | ||
23 | + name = klass.name.underscore | ||
24 | + controller.view_paths.each do |view_path| | ||
25 | + partial = partial_for_class_in_view_path(klass, view_path, prefix, suffix) | ||
26 | + return partial if partial | ||
27 | + end | ||
28 | + | ||
29 | + raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' | ||
30 | + end | ||
31 | + | ||
32 | + def render_partial_for_class klass, *args | ||
33 | + raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? | ||
34 | + begin | ||
35 | + partial = klass.name.underscore | ||
36 | + partial = "#{params[:controller]}/#{partial}" if params[:controller] and partial.index '/' | ||
37 | + return render partial, *args | ||
38 | + rescue ActionView::MissingTemplate | ||
39 | + return render_partial_for_class klass.superclass, *args | ||
40 | + end | ||
41 | + end | ||
42 | + | ||
43 | +end |
app/helpers/tinymce_helper.rb
@@ -20,18 +20,9 @@ module TinymceHelper | @@ -20,18 +20,9 @@ module TinymceHelper | ||
20 | :image_advtab => true, | 20 | :image_advtab => true, |
21 | :language => tinymce_language | 21 | :language => tinymce_language |
22 | 22 | ||
23 | - options[:toolbar1] = "fullscreen | insertfile undo redo | copy paste | bold italic underline | styleselect fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" | ||
24 | - if options[:mode] == 'simple' | ||
25 | - options[:menubar] = false | ||
26 | - else | ||
27 | - options[:menubar] = 'edit insert view tools' | ||
28 | - options[:toolbar2] = 'print preview code media | table' | ||
29 | - | ||
30 | - options[:toolbar2] += ' | macros' | ||
31 | - macros_with_buttons.each do |macro| | ||
32 | - options[:toolbar2] += " #{macro.identifier}" | ||
33 | - end | ||
34 | - end | 23 | + options[:toolbar1] = toolbar1(options[:mode]) |
24 | + options[:menubar] = menubar(options[:mode]) | ||
25 | + options[:toolbar2] = toolbar2(options[:mode]) | ||
35 | 26 | ||
36 | options[:macros_setup] = macros_with_buttons.map do |macro| | 27 | options[:macros_setup] = macros_with_buttons.map do |macro| |
37 | <<-EOS | 28 | <<-EOS |
@@ -49,4 +40,29 @@ module TinymceHelper | @@ -49,4 +40,29 @@ module TinymceHelper | ||
49 | "noosfero.tinymce.init(#{options.to_json})" | 40 | "noosfero.tinymce.init(#{options.to_json})" |
50 | end | 41 | end |
51 | 42 | ||
43 | + def menubar mode | ||
44 | + if mode =='restricted' || mode == 'simple' | ||
45 | + return false | ||
46 | + end | ||
47 | + return 'edit insert view tools' | ||
48 | + end | ||
49 | + | ||
50 | + def toolbar1 mode | ||
51 | + if mode == 'restricted' | ||
52 | + return "bold italic underline | link" | ||
53 | + end | ||
54 | + return "fullscreen | insertfile undo redo | copy paste | bold italic underline | styleselect fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" | ||
55 | + end | ||
56 | + | ||
57 | + def toolbar2 mode | ||
58 | + if mode.blank? | ||
59 | + toolbar2 = 'print preview code media | table' | ||
60 | + toolbar2 += ' | macros' | ||
61 | + macros_with_buttons.each do |macro| | ||
62 | + toolbar2 += " #{macro.identifier}" | ||
63 | + end | ||
64 | + return toolbar2 | ||
65 | + end | ||
66 | + end | ||
67 | + | ||
52 | end | 68 | end |
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +require_relative '../helpers/application_helper' | ||
2 | + | ||
3 | +class ApplicationMailer < ActionMailer::Base | ||
4 | + | ||
5 | + include AuthenticatedSystem | ||
6 | + | ||
7 | + helper ApplicationHelper | ||
8 | + | ||
9 | + attr_accessor :environment | ||
10 | + | ||
11 | + def default_url_options options = nil | ||
12 | + options ||= {} | ||
13 | + options[:host] = environment.default_hostname if environment | ||
14 | + options | ||
15 | + end | ||
16 | + | ||
17 | +end | ||
18 | + |
app/mailers/comment_notifier.rb
1 | -class CommentNotifier < ActionMailer::Base | 1 | +class CommentNotifier < ApplicationMailer |
2 | + | ||
2 | def notification(comment) | 3 | def notification(comment) |
3 | profile = comment.article.profile | 4 | profile = comment.article.profile |
5 | + self.environment = profile.environment | ||
4 | @recipient = profile.nickname || profile.name | 6 | @recipient = profile.nickname || profile.name |
5 | @sender = comment.author_name | 7 | @sender = comment.author_name |
6 | @sender_link = comment.author_link | 8 | @sender_link = comment.author_link |
@@ -8,7 +10,6 @@ class CommentNotifier < ActionMailer::Base | @@ -8,7 +10,6 @@ class CommentNotifier < ActionMailer::Base | ||
8 | @comment_url = comment.url | 10 | @comment_url = comment.url |
9 | @comment_title = comment.title | 11 | @comment_title = comment.title |
10 | @comment_body = comment.body | 12 | @comment_body = comment.body |
11 | - @environment = profile.environment.name | ||
12 | @url = profile.environment.top_url | 13 | @url = profile.environment.top_url |
13 | 14 | ||
14 | mail( | 15 | mail( |
@@ -20,6 +21,8 @@ class CommentNotifier < ActionMailer::Base | @@ -20,6 +21,8 @@ class CommentNotifier < ActionMailer::Base | ||
20 | 21 | ||
21 | def mail_to_followers(comment, emails) | 22 | def mail_to_followers(comment, emails) |
22 | profile = comment.article.profile | 23 | profile = comment.article.profile |
24 | + self.environment = profile.environment | ||
25 | + | ||
23 | @recipient = profile.nickname || profile.name | 26 | @recipient = profile.nickname || profile.name |
24 | @sender = comment.author_name | 27 | @sender = comment.author_name |
25 | @sender_link = comment.author_link | 28 | @sender_link = comment.author_link |
@@ -28,7 +31,6 @@ class CommentNotifier < ActionMailer::Base | @@ -28,7 +31,6 @@ class CommentNotifier < ActionMailer::Base | ||
28 | @unsubscribe_url = comment.article.view_url.merge({:unfollow => true}) | 31 | @unsubscribe_url = comment.article.view_url.merge({:unfollow => true}) |
29 | @comment_title = comment.title | 32 | @comment_title = comment.title |
30 | @comment_body = comment.body | 33 | @comment_body = comment.body |
31 | - @environment = profile.environment.name | ||
32 | @url = profile.environment.top_url | 34 | @url = profile.environment.top_url |
33 | 35 | ||
34 | mail( | 36 | mail( |
app/mailers/contact.rb
@@ -30,14 +30,16 @@ class Contact | @@ -30,14 +30,16 @@ class Contact | ||
30 | Contact::Sender.notification(self).deliver | 30 | Contact::Sender.notification(self).deliver |
31 | end | 31 | end |
32 | 32 | ||
33 | - class Sender < ActionMailer::Base | 33 | + class Sender < ApplicationMailer |
34 | + | ||
34 | def notification(contact) | 35 | def notification(contact) |
36 | + self.environment = contact.dest.environment | ||
37 | + | ||
35 | @name = contact.name | 38 | @name = contact.name |
36 | @email = contact.email | 39 | @email = contact.email |
37 | @city = contact.city | 40 | @city = contact.city |
38 | @state = contact.state | 41 | @state = contact.state |
39 | @message = contact.message | 42 | @message = contact.message |
40 | - @environment = contact.dest.environment.name | ||
41 | @url = url_for(:host => contact.dest.environment.default_hostname, :controller => 'home') | 43 | @url = url_for(:host => contact.dest.environment.default_hostname, :controller => 'home') |
42 | @target = contact.dest.name | 44 | @target = contact.dest.name |
43 | 45 |
app/mailers/environment_mailing.rb
1 | class EnvironmentMailing < Mailing | 1 | class EnvironmentMailing < Mailing |
2 | 2 | ||
3 | def recipients(offset=0, limit=100) | 3 | def recipients(offset=0, limit=100) |
4 | - source.people.all(:order => :id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil }) | 4 | + source.people.order(:id).offset(offset).limit(limit) |
5 | + .joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)") | ||
6 | + .where("m.person_id" => nil) | ||
5 | end | 7 | end |
6 | 8 | ||
7 | def each_recipient | 9 | def each_recipient |
app/mailers/mailing.rb
@@ -46,7 +46,8 @@ class Mailing < ActiveRecord::Base | @@ -46,7 +46,8 @@ class Mailing < ActiveRecord::Base | ||
46 | end | 46 | end |
47 | end | 47 | end |
48 | 48 | ||
49 | - class Sender < ActionMailer::Base | 49 | + class Sender < ApplicationMailer |
50 | + | ||
50 | def notification(mailing, recipient) | 51 | def notification(mailing, recipient) |
51 | @message = mailing.body | 52 | @message = mailing.body |
52 | @signature_message = mailing.signature_message | 53 | @signature_message = mailing.signature_message |
app/mailers/organization_mailing.rb
@@ -5,7 +5,9 @@ class OrganizationMailing < Mailing | @@ -5,7 +5,9 @@ class OrganizationMailing < Mailing | ||
5 | end | 5 | end |
6 | 6 | ||
7 | def recipients(offset=0, limit=100) | 7 | def recipients(offset=0, limit=100) |
8 | - source.members.all(:order => :id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil }) | 8 | + source.members.order(:id).offset(offset).limit(limit) |
9 | + .joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)") | ||
10 | + .where("m.person_id" => nil) | ||
9 | end | 11 | end |
10 | 12 | ||
11 | def each_recipient | 13 | def each_recipient |
app/mailers/pending_task_notifier.rb
1 | -class PendingTaskNotifier < ActionMailer::Base | 1 | +class PendingTaskNotifier < ApplicationMailer |
2 | 2 | ||
3 | def notification(person) | 3 | def notification(person) |
4 | + self.environment = person.environment | ||
5 | + | ||
4 | @person = person | 6 | @person = person |
5 | @tasks = person.tasks.pending | 7 | @tasks = person.tasks.pending |
6 | @organizations_with_pending_tasks = person.organizations_with_pending_tasks | 8 | @organizations_with_pending_tasks = person.organizations_with_pending_tasks |
7 | - @environment = person.environment.name | ||
8 | @url = url_for(:host => person.environment.default_hostname, :controller => 'home') | 9 | @url = url_for(:host => person.environment.default_hostname, :controller => 'home') |
9 | @default_hostname = person.environment.default_hostname | 10 | @default_hostname = person.environment.default_hostname |
10 | @url_for_pending_tasks = url_for(:host => person.environment.default_hostname, :controller => 'tasks', :profile => person.identifier) | 11 | @url_for_pending_tasks = url_for(:host => person.environment.default_hostname, :controller => 'tasks', :profile => person.identifier) |
app/mailers/scrap_notifier.rb
1 | -class ScrapNotifier < ActionMailer::Base | 1 | +class ScrapNotifier < ApplicationMailer |
2 | + | ||
2 | def notification(scrap) | 3 | def notification(scrap) |
3 | sender, receiver = scrap.sender, scrap.receiver | 4 | sender, receiver = scrap.sender, scrap.receiver |
5 | + self.environment = sender.environment | ||
4 | # for tests | 6 | # for tests |
5 | return unless receiver.email | 7 | return unless receiver.email |
6 | 8 | ||
@@ -9,7 +11,6 @@ class ScrapNotifier < ActionMailer::Base | @@ -9,7 +11,6 @@ class ScrapNotifier < ActionMailer::Base | ||
9 | @sender_link = sender.url | 11 | @sender_link = sender.url |
10 | @scrap_content = scrap.content | 12 | @scrap_content = scrap.content |
11 | @wall_url = scrap.scrap_wall_url | 13 | @wall_url = scrap.scrap_wall_url |
12 | - @environment = sender.environment.name | ||
13 | @url = sender.environment.top_url | 14 | @url = sender.environment.top_url |
14 | mail( | 15 | mail( |
15 | to: receiver.email, | 16 | to: receiver.email, |
app/mailers/task_mailer.rb
1 | -class TaskMailer < ActionMailer::Base | 1 | +class TaskMailer < ApplicationMailer |
2 | 2 | ||
3 | def target_notification(task, message) | 3 | def target_notification(task, message) |
4 | + self.environment = task.environment | ||
5 | + | ||
4 | @message = extract_message(message) | 6 | @message = extract_message(message) |
5 | @target = task.target.name | 7 | @target = task.target.name |
6 | - @environment = task.environment.name | ||
7 | @url = generate_environment_url(task, :controller => 'home') | 8 | @url = generate_environment_url(task, :controller => 'home') |
8 | url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url.merge(:script_name => Noosfero.root('/'))) | 9 | url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url.merge(:script_name => Noosfero.root('/'))) |
9 | @tasks_url = url_for_tasks_list | 10 | @tasks_url = url_for_tasks_list |
@@ -16,6 +17,8 @@ class TaskMailer < ActionMailer::Base | @@ -16,6 +17,8 @@ class TaskMailer < ActionMailer::Base | ||
16 | end | 17 | end |
17 | 18 | ||
18 | def invitation_notification(task) | 19 | def invitation_notification(task) |
20 | + self.environment = task.requestor.environment | ||
21 | + | ||
19 | msg = task.expanded_message | 22 | msg = task.expanded_message |
20 | @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code) | 23 | @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code) |
21 | 24 | ||
@@ -27,11 +30,12 @@ class TaskMailer < ActionMailer::Base | @@ -27,11 +30,12 @@ class TaskMailer < ActionMailer::Base | ||
27 | end | 30 | end |
28 | 31 | ||
29 | def generic_message(name, task) | 32 | def generic_message(name, task) |
33 | + self.environment = task.requestor.environment | ||
34 | + | ||
30 | return if !task.respond_to?("#{name}_message") | 35 | return if !task.respond_to?("#{name}_message") |
31 | 36 | ||
32 | @message = extract_message(task.send("#{name}_message")) | 37 | @message = extract_message(task.send("#{name}_message")) |
33 | @requestor = task.requestor.name | 38 | @requestor = task.requestor.name |
34 | - @environment = task.requestor.environment.name | ||
35 | @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home') | 39 | @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home') |
36 | 40 | ||
37 | mail( | 41 | mail( |
app/mailers/user_mailer.rb
1 | -class UserMailer < ActionMailer::Base | 1 | +class UserMailer < ApplicationMailer |
2 | + | ||
2 | def activation_email_notify(user) | 3 | def activation_email_notify(user) |
4 | + self.environment = user.environment | ||
5 | + | ||
3 | user_email = "#{user.login}@#{user.email_domain}" | 6 | user_email = "#{user.login}@#{user.email_domain}" |
4 | @name = user.name | 7 | @name = user.name |
5 | @email = user_email | 8 | @email = user_email |
6 | @webmail = MailConf.webmail_url(user.login, user.email_domain) | 9 | @webmail = MailConf.webmail_url(user.login, user.email_domain) |
7 | - @environment = user.environment.name | ||
8 | @url = url_for(:host => user.environment.default_hostname, :controller => 'home') | 10 | @url = url_for(:host => user.environment.default_hostname, :controller => 'home') |
9 | 11 | ||
10 | mail( | 12 | mail( |
@@ -15,9 +17,10 @@ class UserMailer < ActionMailer::Base | @@ -15,9 +17,10 @@ class UserMailer < ActionMailer::Base | ||
15 | end | 17 | end |
16 | 18 | ||
17 | def activation_code(user) | 19 | def activation_code(user) |
20 | + self.environment = user.environment | ||
21 | + | ||
18 | @recipient = user.name | 22 | @recipient = user.name |
19 | @activation_code = user.activation_code | 23 | @activation_code = user.activation_code |
20 | - @environment = user.environment.name | ||
21 | @url = user.environment.top_url | 24 | @url = user.environment.top_url |
22 | @redirection = (true if user.return_to) | 25 | @redirection = (true if user.return_to) |
23 | @join = (user.community_to_join if user.community_to_join) | 26 | @join = (user.community_to_join if user.community_to_join) |
@@ -30,6 +33,8 @@ class UserMailer < ActionMailer::Base | @@ -30,6 +33,8 @@ class UserMailer < ActionMailer::Base | ||
30 | end | 33 | end |
31 | 34 | ||
32 | def signup_welcome_email(user) | 35 | def signup_welcome_email(user) |
36 | + self.environment = user.environment | ||
37 | + | ||
33 | @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) | 38 | @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) |
34 | email_subject = user.environment.signup_welcome_text_subject | 39 | email_subject = user.environment.signup_welcome_text_subject |
35 | mail( | 40 | mail( |
@@ -42,8 +47,9 @@ class UserMailer < ActionMailer::Base | @@ -42,8 +47,9 @@ class UserMailer < ActionMailer::Base | ||
42 | end | 47 | end |
43 | 48 | ||
44 | def profiles_suggestions_email(user) | 49 | def profiles_suggestions_email(user) |
50 | + self.environment = user.environment | ||
51 | + | ||
45 | @recipient = user.name | 52 | @recipient = user.name |
46 | - @environment = user.environment.name | ||
47 | @url = user.environment.top_url | 53 | @url = user.environment.top_url |
48 | @people_suggestions_url = user.people_suggestions_url | 54 | @people_suggestions_url = user.people_suggestions_url |
49 | @people_suggestions = user.suggested_people.sample(3) | 55 | @people_suggestions = user.suggested_people.sample(3) |
app/models/add_member.rb
@@ -11,7 +11,7 @@ class AddMember < Task | @@ -11,7 +11,7 @@ class AddMember < Task | ||
11 | alias :organization :target | 11 | alias :organization :target |
12 | alias :organization= :target= | 12 | alias :organization= :target= |
13 | 13 | ||
14 | - settings_items :roles | 14 | + settings_items :roles, type: Array |
15 | 15 | ||
16 | after_create do |task| | 16 | after_create do |task| |
17 | remove_from_suggestion_list(task) | 17 | remove_from_suggestion_list(task) |
app/models/approve_comment.rb
@@ -8,7 +8,7 @@ class ApproveComment < Task | @@ -8,7 +8,7 @@ class ApproveComment < Task | ||
8 | def comment | 8 | def comment |
9 | unless @comment || self.comment_attributes.nil? | 9 | unless @comment || self.comment_attributes.nil? |
10 | @comment = Comment.new | 10 | @comment = Comment.new |
11 | - @comment.assign_attributes(ActiveSupport::JSON.decode(self.comment_attributes), :without_protection => true) | 11 | + @comment.assign_attributes(ActiveSupport::JSON.decode(self.comment_attributes.to_s), :without_protection => true) |
12 | end | 12 | end |
13 | @comment | 13 | @comment |
14 | end | 14 | end |
app/models/article.rb
@@ -79,9 +79,9 @@ class Article < ActiveRecord::Base | @@ -79,9 +79,9 @@ class Article < ActiveRecord::Base | ||
79 | belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' | 79 | belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' |
80 | belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id' | 80 | belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id' |
81 | 81 | ||
82 | - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' | 82 | + has_many :comments, :class_name => 'Comment', :as => 'source', :dependent => :destroy, :order => 'created_at asc' |
83 | 83 | ||
84 | - has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] | 84 | + has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false } |
85 | has_many :categories, :through => :article_categorizations | 85 | has_many :categories, :through => :article_categorizations |
86 | 86 | ||
87 | has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' | 87 | has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' |
@@ -133,17 +133,15 @@ class Article < ActiveRecord::Base | @@ -133,17 +133,15 @@ class Article < ActiveRecord::Base | ||
133 | 133 | ||
134 | xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' | 134 | xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' |
135 | 135 | ||
136 | - scope :in_category, lambda { |category| | ||
137 | - {:include => 'categories_including_virtual', :conditions => { 'categories.id' => category.id }} | 136 | + scope :in_category, -> category { |
137 | + includes('categories_including_virtual').where('categories.id' => category.id) | ||
138 | } | 138 | } |
139 | 139 | ||
140 | include TimeScopes | 140 | include TimeScopes |
141 | 141 | ||
142 | - scope :by_range, lambda { |range| { | ||
143 | - :conditions => [ | ||
144 | - 'articles.published_at BETWEEN :start_date AND :end_date', { :start_date => range.first, :end_date => range.last } | ||
145 | - ] | ||
146 | - }} | 142 | + scope :by_range, -> range { |
143 | + where 'articles.published_at BETWEEN :start_date AND :end_date', { start_date: range.first, end_date: range.last } | ||
144 | + } | ||
147 | 145 | ||
148 | URL_FORMAT = /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\Z/ix | 146 | URL_FORMAT = /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\Z/ix |
149 | 147 | ||
@@ -267,19 +265,21 @@ class Article < ActiveRecord::Base | @@ -267,19 +265,21 @@ class Article < ActiveRecord::Base | ||
267 | 265 | ||
268 | # retrieves all articles belonging to the given +profile+ that are not | 266 | # retrieves all articles belonging to the given +profile+ that are not |
269 | # sub-articles of any other article. | 267 | # sub-articles of any other article. |
270 | - scope :top_level_for, lambda { |profile| | ||
271 | - {:conditions => [ 'parent_id is null and profile_id = ?', profile.id ]} | 268 | + scope :top_level_for, -> profile { |
269 | + where 'parent_id is null and profile_id = ?', profile.id | ||
272 | } | 270 | } |
273 | 271 | ||
274 | - scope :public, | ||
275 | - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ], :joins => [:profile] | 272 | + scope :is_public, -> { |
273 | + joins(:profile). | ||
274 | + where("articles.advertise = ? AND articles.published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true) | ||
275 | + } | ||
276 | 276 | ||
277 | - scope :more_recent, | ||
278 | - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND | ||
279 | - ((articles.type != ?) OR articles.type is NULL)", | ||
280 | - true, true, true, true, 'RssFeed' | ||
281 | - ], | ||
282 | - :order => 'articles.published_at desc, articles.id desc' | 277 | + scope :more_recent, -> { |
278 | + order('articles.published_at desc, articles.id desc') | ||
279 | + .where("articles.advertise = ? AND articles.published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND | ||
280 | + ((articles.type != ?) OR articles.type is NULL)", | ||
281 | + true, true, true, true, 'RssFeed') | ||
282 | + } | ||
283 | 283 | ||
284 | # retrives the most commented articles, sorted by the comment count (largest | 284 | # retrives the most commented articles, sorted by the comment count (largest |
285 | # first) | 285 | # first) |
@@ -287,12 +287,14 @@ class Article < ActiveRecord::Base | @@ -287,12 +287,14 @@ class Article < ActiveRecord::Base | ||
287 | paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) | 287 | paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) |
288 | end | 288 | end |
289 | 289 | ||
290 | - scope :more_popular, :order => 'hits DESC' | ||
291 | - scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"] | 290 | + scope :more_popular, -> { order 'hits DESC' } |
291 | + scope :relevant_as_recent, -> { | ||
292 | + where "(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL" | ||
293 | + } | ||
292 | 294 | ||
293 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) | 295 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) |
294 | result = scoped({:conditions => extra_conditions}). | 296 | result = scoped({:conditions => extra_conditions}). |
295 | - public. | 297 | + is_public. |
296 | relevant_as_recent. | 298 | relevant_as_recent. |
297 | limit(limit). | 299 | limit(limit). |
298 | order(['articles.published_at desc', 'articles.id desc']) | 300 | order(['articles.published_at desc', 'articles.id desc']) |
@@ -417,7 +419,7 @@ class Article < ActiveRecord::Base | @@ -417,7 +419,7 @@ class Article < ActiveRecord::Base | ||
417 | self.translations.map(&:language) | 419 | self.translations.map(&:language) |
418 | end | 420 | end |
419 | 421 | ||
420 | - scope :native_translations, :conditions => { :translation_of_id => nil } | 422 | + scope :native_translations, -> { where :translation_of_id => nil } |
421 | 423 | ||
422 | def translatable? | 424 | def translatable? |
423 | false | 425 | false |
@@ -459,7 +461,7 @@ class Article < ActiveRecord::Base | @@ -459,7 +461,7 @@ class Article < ActiveRecord::Base | ||
459 | 461 | ||
460 | def rotate_translations | 462 | def rotate_translations |
461 | unless self.translations.empty? | 463 | unless self.translations.empty? |
462 | - rotate = self.translations | 464 | + rotate = self.translations.all |
463 | root = rotate.shift | 465 | root = rotate.shift |
464 | root.update_attribute(:translation_of_id, nil) | 466 | root.update_attribute(:translation_of_id, nil) |
465 | root.translations = rotate | 467 | root.translations = rotate |
@@ -472,7 +474,7 @@ class Article < ActiveRecord::Base | @@ -472,7 +474,7 @@ class Article < ActiveRecord::Base | ||
472 | elsif self.native_translation.language == locale | 474 | elsif self.native_translation.language == locale |
473 | self.native_translation | 475 | self.native_translation |
474 | else | 476 | else |
475 | - self.native_translation.translations.first(:conditions => { :language => locale }) | 477 | + self.native_translation.translations.where(:language => locale).first |
476 | end | 478 | end |
477 | end | 479 | end |
478 | 480 | ||
@@ -500,19 +502,19 @@ class Article < ActiveRecord::Base | @@ -500,19 +502,19 @@ class Article < ActiveRecord::Base | ||
500 | ['TextArticle', 'TextileArticle', 'TinyMceArticle'] | 502 | ['TextArticle', 'TextileArticle', 'TinyMceArticle'] |
501 | end | 503 | end |
502 | 504 | ||
503 | - scope :published, :conditions => ['articles.published = ?', true] | ||
504 | - scope :folders, lambda {|profile|{:conditions => ['articles.type IN (?)', profile.folder_types] }} | ||
505 | - scope :no_folders, lambda {|profile|{:conditions => ['articles.type NOT IN (?)', profile.folder_types]}} | ||
506 | - scope :galleries, :conditions => [ "articles.type IN ('Gallery')" ] | ||
507 | - scope :images, :conditions => { :is_image => true } | ||
508 | - scope :no_images, :conditions => { :is_image => false } | ||
509 | - scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] | ||
510 | - scope :files, :conditions => { :type => 'UploadedFile' } | ||
511 | - scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } | 505 | + scope :published, -> { where 'articles.published = ?', true } |
506 | + scope :folders, -> profile { where 'articles.type IN (?)', profile.folder_types } | ||
507 | + scope :no_folders, -> profile { where 'articles.type NOT IN (?)', profile.folder_types } | ||
508 | + scope :galleries, -> { where "articles.type IN ('Gallery')" } | ||
509 | + scope :images, -> { where :is_image => true } | ||
510 | + scope :no_images, -> { where :is_image => false } | ||
511 | + scope :text_articles, -> { where 'articles.type IN (?)', text_article_types } | ||
512 | + scope :files, -> { where :type => 'UploadedFile' } | ||
513 | + scope :with_types, -> types { where 'articles.type IN (?)', types } | ||
512 | 514 | ||
513 | - scope :more_popular, :order => 'hits DESC' | ||
514 | - scope :more_comments, :order => "comments_count DESC" | ||
515 | - scope :more_recent, :order => "created_at DESC" | 515 | + scope :more_popular, -> { order 'hits DESC' } |
516 | + scope :more_comments, -> { order "comments_count DESC" } | ||
517 | + scope :more_recent, -> { order "created_at DESC" } | ||
516 | 518 | ||
517 | scope :display_filter, lambda {|user, profile| | 519 | scope :display_filter, lambda {|user, profile| |
518 | return published if (user.nil? && profile && profile.public?) | 520 | return published if (user.nil? && profile && profile.public?) |
@@ -634,7 +636,7 @@ class Article < ActiveRecord::Base | @@ -634,7 +636,7 @@ class Article < ActiveRecord::Base | ||
634 | ] | 636 | ] |
635 | 637 | ||
636 | def self.find_by_old_path(old_path) | 638 | def self.find_by_old_path(old_path) |
637 | - find(:first, :include => :versions, :conditions => ['article_versions.path = ?', old_path], :order => 'article_versions.id desc') | 639 | + self.includes(:versions).where('article_versions.path = ?', old_path).order('article_versions.id DESC').first |
638 | end | 640 | end |
639 | 641 | ||
640 | def hit | 642 | def hit |
@@ -720,11 +722,11 @@ class Article < ActiveRecord::Base | @@ -720,11 +722,11 @@ class Article < ActiveRecord::Base | ||
720 | end | 722 | end |
721 | 723 | ||
722 | def get_version(version_number = nil) | 724 | def get_version(version_number = nil) |
723 | - version_number ? versions.find(:first, :order => 'version', :offset => version_number - 1) : versions.earliest | 725 | + if version_number then self.versions.order('version').offset(version_number - 1).first else self.versions.earliest end |
724 | end | 726 | end |
725 | 727 | ||
726 | def author_by_version(version_number = nil) | 728 | def author_by_version(version_number = nil) |
727 | - version_number ? profile.environment.people.find_by_id(get_version(version_number).author_id) : author | 729 | + if version_number then profile.environment.people.where(id: get_version(version_number).author_id).first else author end |
728 | end | 730 | end |
729 | 731 | ||
730 | def author_name(version_number = nil) | 732 | def author_name(version_number = nil) |
@@ -820,7 +822,7 @@ class Article < ActiveRecord::Base | @@ -820,7 +822,7 @@ class Article < ActiveRecord::Base | ||
820 | end | 822 | end |
821 | 823 | ||
822 | def activity | 824 | def activity |
823 | - ActionTracker::Record.find_by_target_type_and_target_id 'Article', self.id | 825 | + ActionTracker::Record.where(target_type: 'Article', target_id: self.id).first |
824 | end | 826 | end |
825 | 827 | ||
826 | def create_activity | 828 | def create_activity |
app/models/article_block.rb
@@ -3,7 +3,15 @@ class ArticleBlock < Block | @@ -3,7 +3,15 @@ class ArticleBlock < Block | ||
3 | attr_accessible :article_id | 3 | attr_accessible :article_id |
4 | 4 | ||
5 | def self.description | 5 | def self.description |
6 | - _('Display one of your contents') | 6 | + _('Display one of your contents.') |
7 | + end | ||
8 | + | ||
9 | + def self.short_description | ||
10 | + _('Show one article') | ||
11 | + end | ||
12 | + | ||
13 | + def self.pretty_name | ||
14 | + _('Article') | ||
7 | end | 15 | end |
8 | 16 | ||
9 | def help | 17 | def help |
app/models/article_categorization.rb
app/models/block.rb
@@ -20,7 +20,7 @@ class Block < ActiveRecord::Base | @@ -20,7 +20,7 @@ class Block < ActiveRecord::Base | ||
20 | 20 | ||
21 | acts_as_having_settings | 21 | acts_as_having_settings |
22 | 22 | ||
23 | - scope :enabled, :conditions => { :enabled => true } | 23 | + scope :enabled, -> { where :enabled => true } |
24 | 24 | ||
25 | after_save do |block| | 25 | after_save do |block| |
26 | if block.owner.kind_of?(Profile) && block.owner.is_template? && block.mirror? | 26 | if block.owner.kind_of?(Profile) && block.owner.is_template? && block.mirror? |
@@ -141,6 +141,36 @@ class Block < ActiveRecord::Base | @@ -141,6 +141,36 @@ class Block < ActiveRecord::Base | ||
141 | '(dummy)' | 141 | '(dummy)' |
142 | end | 142 | end |
143 | 143 | ||
144 | + def self.short_description | ||
145 | + self.pretty_name | ||
146 | + end | ||
147 | + | ||
148 | + def self.icon | ||
149 | + "/images/icon_block.png" | ||
150 | + end | ||
151 | + | ||
152 | + def self.icon_path | ||
153 | + basename = self.name.split('::').last.underscore | ||
154 | + File.join('images', 'blocks', basename, 'icon.png') | ||
155 | + end | ||
156 | + | ||
157 | + def self.pretty_name | ||
158 | + self.name.split('::').last.gsub('Block','') | ||
159 | + end | ||
160 | + | ||
161 | + def self.default_icon_path | ||
162 | + '/images/icon_block.png' | ||
163 | + end | ||
164 | + | ||
165 | + def self.preview_path | ||
166 | + base_name = self.name.split('::').last.underscore | ||
167 | + File.join('blocks', base_name,'previews') | ||
168 | + end | ||
169 | + | ||
170 | + def self.default_preview_path | ||
171 | + "/images/block_preview.png" | ||
172 | + end | ||
173 | + | ||
144 | # Returns the content to be used for this block. | 174 | # Returns the content to be used for this block. |
145 | # | 175 | # |
146 | # This method can return several types of objects: | 176 | # This method can return several types of objects: |
app/models/blog_archives_block.rb
@@ -15,7 +15,7 @@ class BlogArchivesBlock < Block | @@ -15,7 +15,7 @@ class BlogArchivesBlock < Block | ||
15 | _('Blog posts') | 15 | _('Blog posts') |
16 | end | 16 | end |
17 | 17 | ||
18 | - settings_items :blog_id, Integer | 18 | + settings_items :blog_id, type: Integer |
19 | 19 | ||
20 | def blog | 20 | def blog |
21 | blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog | 21 | blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog |
@@ -33,10 +33,10 @@ class BlogArchivesBlock < Block | @@ -33,10 +33,10 @@ class BlogArchivesBlock < Block | ||
33 | results = '' | 33 | results = '' |
34 | posts = visible_posts(args[:person]) | 34 | posts = visible_posts(args[:person]) |
35 | posts.except(:order).count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count| | 35 | posts.except(:order).count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count| |
36 | - results << content_tag('li', content_tag('strong', "#{year} (#{count})")) | ||
37 | - results << "<ul class='#{year}-archive'>" | ||
38 | - posts.except(:order).count(:all, :conditions => ['EXTRACT(YEAR FROM published_at)=?', year], :group => 'EXTRACT(MONTH FROM published_at)').sort_by {|month, count| -month.to_i}.each do |month, count| | ||
39 | - results << content_tag('li', link_to("#{month_name(month.to_i)} (#{count})", owner_blog.url.merge(:year => year, :month => month))) | 36 | + results << content_tag('li', content_tag('strong', "#{year.to_i} (#{count})")) |
37 | + results << "<ul class='#{year.to_i}-archive'>" | ||
38 | + posts.except(:order).where('EXTRACT(YEAR FROM published_at)=?', year.to_i).group('EXTRACT(MONTH FROM published_at)').count.sort_by {|month, count| -month.to_i}.each do |month, count| | ||
39 | + results << content_tag('li', link_to("#{month_name(month.to_i)} (#{count})", owner_blog.url.merge(year: year.to_i, month: month.to_i))) | ||
40 | end | 40 | end |
41 | results << "</ul>" | 41 | results << "</ul>" |
42 | end | 42 | end |
app/models/box.rb
@@ -7,7 +7,7 @@ class Box < ActiveRecord::Base | @@ -7,7 +7,7 @@ class Box < ActiveRecord::Base | ||
7 | 7 | ||
8 | include Noosfero::Plugin::HotSpot | 8 | include Noosfero::Plugin::HotSpot |
9 | 9 | ||
10 | - scope :with_position, :conditions => ['boxes.position > 0'] | 10 | + scope :with_position, -> { where 'boxes.position > 0' } |
11 | 11 | ||
12 | def environment | 12 | def environment |
13 | owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil | 13 | owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil |
app/models/categorization.rb
1 | module Categorization | 1 | module Categorization |
2 | 2 | ||
3 | def add_category_to_object(category, object) | 3 | def add_category_to_object(category, object) |
4 | - if !find(:first, :conditions => {object_id_column => object, :category_id => category} ) | 4 | + if !self.where(object_id_column => object, :category_id => category).first |
5 | connection.execute("insert into #{table_name} (category_id, #{object_id_column}) values(#{category.id}, #{object.id})") | 5 | connection.execute("insert into #{table_name} (category_id, #{object_id_column}) values(#{category.id}, #{object.id})") |
6 | 6 | ||
7 | c = category.parent | 7 | c = category.parent |
8 | - while !c.nil? && !self.find(:first, :conditions => {object_id_column => object, :category_id => c}) | 8 | + while !c.nil? && !self.where(object_id_column => object, :category_id => c).first |
9 | connection.execute("insert into #{table_name} (category_id, #{object_id_column}, virtual) values(#{c.id}, #{object.id}, 1>0)") | 9 | connection.execute("insert into #{table_name} (category_id, #{object_id_column}, virtual) values(#{c.id}, #{object.id}, 1>0)") |
10 | c = c.parent | 10 | c = c.parent |
11 | end | 11 | end |
app/models/category.rb
@@ -14,12 +14,12 @@ class Category < ActiveRecord::Base | @@ -14,12 +14,12 @@ class Category < ActiveRecord::Base | ||
14 | validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('{fn} is already being used by another category.').fix_i18n | 14 | validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('{fn} is already being used by another category.').fix_i18n |
15 | belongs_to :environment | 15 | belongs_to :environment |
16 | 16 | ||
17 | - # Finds all top level categories for a given environment. | ||
18 | - scope :top_level_for, lambda { |environment| | ||
19 | - {:conditions => ['parent_id is null and environment_id = ?', environment.id ]} | 17 | + # Finds all top level categories for a given environment. |
18 | + scope :top_level_for, -> environment { | ||
19 | + where 'parent_id is null and environment_id = ?', environment.id | ||
20 | } | 20 | } |
21 | 21 | ||
22 | - scope :on_level, lambda { |parent| {:conditions => {:parent_id => parent}} } | 22 | + scope :on_level, -> parent { where :parent_id => parent } |
23 | 23 | ||
24 | acts_as_filesystem | 24 | acts_as_filesystem |
25 | 25 | ||
@@ -46,26 +46,26 @@ class Category < ActiveRecord::Base | @@ -46,26 +46,26 @@ class Category < ActiveRecord::Base | ||
46 | display_color = nil if display_color.blank? | 46 | display_color = nil if display_color.blank? |
47 | end | 47 | end |
48 | 48 | ||
49 | - scope :from_types, lambda { |types| | ||
50 | - types.select{ |t| t.blank? }.empty? ? | ||
51 | - { :conditions => { :type => types } } : | ||
52 | - { :conditions => [ "type IN (?) OR type IS NULL", types.reject{ |t| t.blank? } ] } | 49 | + scope :from_types, -> types { |
50 | + if types.select{ |t| t.blank? }.empty? then | ||
51 | + where(type: types) else | ||
52 | + where("type IN (?) OR type IS NULL", types.reject{ |t| t.blank? }) end | ||
53 | } | 53 | } |
54 | 54 | ||
55 | def recent_people(limit = 10) | 55 | def recent_people(limit = 10) |
56 | - self.people.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit) | 56 | + self.people.reorder('created_at DESC, id DESC').paginate(page: 1, per_page: limit) |
57 | end | 57 | end |
58 | 58 | ||
59 | def recent_enterprises(limit = 10) | 59 | def recent_enterprises(limit = 10) |
60 | - self.enterprises.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit) | 60 | + self.enterprises.reorder('created_at DESC, id DESC').paginate(page: 1, per_page: limit) |
61 | end | 61 | end |
62 | 62 | ||
63 | def recent_communities(limit = 10) | 63 | def recent_communities(limit = 10) |
64 | - self.communities.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit) | 64 | + self.communities.reorder('created_at DESC, id DESC').paginate(page: 1, per_page: limit) |
65 | end | 65 | end |
66 | 66 | ||
67 | def recent_products(limit = 10) | 67 | def recent_products(limit = 10) |
68 | - self.products.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit) | 68 | + self.products.reorder('created_at DESC, id DESC').paginate(page: 1, per_page: limit) |
69 | end | 69 | end |
70 | 70 | ||
71 | def recent_articles(limit = 10) | 71 | def recent_articles(limit = 10) |
@@ -73,7 +73,7 @@ class Category < ActiveRecord::Base | @@ -73,7 +73,7 @@ class Category < ActiveRecord::Base | ||
73 | end | 73 | end |
74 | 74 | ||
75 | def recent_comments(limit = 10) | 75 | def recent_comments(limit = 10) |
76 | - comments.paginate(:order => 'created_at DESC, comments.id DESC', :page => 1, :per_page => limit) | 76 | + self.comments.reorder('created_at DESC, comments.id DESC').paginate(page: 1, per_page: limit) |
77 | end | 77 | end |
78 | 78 | ||
79 | def most_commented_articles(limit = 10) | 79 | def most_commented_articles(limit = 10) |
@@ -81,7 +81,7 @@ class Category < ActiveRecord::Base | @@ -81,7 +81,7 @@ class Category < ActiveRecord::Base | ||
81 | end | 81 | end |
82 | 82 | ||
83 | def upcoming_events(limit = 10) | 83 | def upcoming_events(limit = 10) |
84 | - self.events.paginate(:conditions => [ 'start_date >= ?', DateTime.now.beginning_of_day ], :order => 'start_date', :page => 1, :per_page => limit) | 84 | + self.events.where('start_date >= ?', DateTime.now.beginning_of_day).order('start_date').paginate(page: 1, per_page: limit) |
85 | end | 85 | end |
86 | 86 | ||
87 | def display_in_menu? | 87 | def display_in_menu? |
@@ -90,11 +90,11 @@ class Category < ActiveRecord::Base | @@ -90,11 +90,11 @@ class Category < ActiveRecord::Base | ||
90 | 90 | ||
91 | def children_for_menu | 91 | def children_for_menu |
92 | results = [] | 92 | results = [] |
93 | - pending = children.find(:all, :conditions => { :display_in_menu => true}) | ||
94 | - while !pending.empty? | 93 | + pending = children.where(display_in_menu: true).all |
94 | + while pending.present? | ||
95 | cat = pending.shift | 95 | cat = pending.shift |
96 | results << cat | 96 | results << cat |
97 | - pending += cat.children.find(:all, :conditions => { :display_in_menu => true} ) | 97 | + pending += cat.children.where :display_in_menu => true |
98 | end | 98 | end |
99 | 99 | ||
100 | results | 100 | results |
@@ -102,7 +102,7 @@ class Category < ActiveRecord::Base | @@ -102,7 +102,7 @@ class Category < ActiveRecord::Base | ||
102 | 102 | ||
103 | def is_leaf_displayable_in_menu? | 103 | def is_leaf_displayable_in_menu? |
104 | return false if self.display_in_menu == false | 104 | return false if self.display_in_menu == false |
105 | - self.children.find(:all, :conditions => {:display_in_menu => true}).empty? | 105 | + self.children.where(:display_in_menu => true).empty? |
106 | end | 106 | end |
107 | 107 | ||
108 | def with_color | 108 | def with_color |
app/models/certifier.rb
@@ -20,7 +20,7 @@ class Certifier < ActiveRecord::Base | @@ -20,7 +20,7 @@ class Certifier < ActiveRecord::Base | ||
20 | validates_presence_of :name | 20 | validates_presence_of :name |
21 | 21 | ||
22 | def destroy | 22 | def destroy |
23 | - product_qualifiers.each { |pq| pq.update_attributes! :certifier => nil } | 23 | + product_qualifiers.each { |pq| pq.update! :certifier => nil } |
24 | super | 24 | super |
25 | end | 25 | end |
26 | 26 |
app/models/comment.rb
@@ -18,7 +18,7 @@ class Comment < ActiveRecord::Base | @@ -18,7 +18,7 @@ class Comment < ActiveRecord::Base | ||
18 | has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy | 18 | has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy |
19 | belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id' | 19 | belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id' |
20 | 20 | ||
21 | - scope :without_reply, :conditions => ['reply_of_id IS NULL'] | 21 | + scope :without_reply, -> { where 'reply_of_id IS NULL' } |
22 | 22 | ||
23 | include TimeScopes | 23 | include TimeScopes |
24 | 24 |
app/models/communities_block.rb
@@ -3,9 +3,17 @@ class CommunitiesBlock < ProfileListBlock | @@ -3,9 +3,17 @@ class CommunitiesBlock < ProfileListBlock | ||
3 | attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type | 3 | attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type |
4 | 4 | ||
5 | def self.description | 5 | def self.description |
6 | + _("<p>Display all of your communities.</p><p>You could choose the amount of communities will be displayed and you could priorize that profiles with images.</p> <p>The view all button is always present in the block.</p>") | ||
7 | + end | ||
8 | + | ||
9 | + def self.short_description | ||
6 | _('Communities') | 10 | _('Communities') |
7 | end | 11 | end |
8 | 12 | ||
13 | + def self.pretty_name | ||
14 | + _('Communities Block') | ||
15 | + end | ||
16 | + | ||
9 | def default_title | 17 | def default_title |
10 | n_('{#} community', '{#} communities', profile_count) | 18 | n_('{#} community', '{#} communities', profile_count) |
11 | end | 19 | end |
app/models/community.rb
@@ -29,11 +29,11 @@ class Community < Organization | @@ -29,11 +29,11 @@ class Community < Organization | ||
29 | # places that call this method are safe from mass-assignment by setting the | 29 | # places that call this method are safe from mass-assignment by setting the |
30 | # environment key themselves. | 30 | # environment key themselves. |
31 | def self.create_after_moderation(requestor, attributes = {}) | 31 | def self.create_after_moderation(requestor, attributes = {}) |
32 | - environment = attributes.delete(:environment) | 32 | + environment = attributes[:environment] |
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)) | 36 | + CreateCommunity.create!(attributes.merge(:requestor => requestor, :environment => environment).except(:custom_values)) |
37 | else | 37 | else |
38 | community.save! | 38 | community.save! |
39 | community.add_admin(requestor) | 39 | community.add_admin(requestor) |
app/models/create_community.rb
@@ -34,7 +34,7 @@ class CreateCommunity < Task | @@ -34,7 +34,7 @@ class CreateCommunity < Task | ||
34 | ! DATA_FIELDS.include?(key.to_s) | 34 | ! DATA_FIELDS.include?(key.to_s) |
35 | end | 35 | end |
36 | 36 | ||
37 | - community.update_attributes(community_data) | 37 | + community.update(community_data) |
38 | community.image = image if image | 38 | community.image = image if image |
39 | community.environment = self.environment | 39 | community.environment = self.environment |
40 | community.save! | 40 | community.save! |
app/models/create_enterprise.rb
@@ -16,13 +16,13 @@ class CreateEnterprise < Task | @@ -16,13 +16,13 @@ class CreateEnterprise < Task | ||
16 | settings_items field.to_sym | 16 | settings_items field.to_sym |
17 | end | 17 | end |
18 | 18 | ||
19 | - # checks for virtual attributes | 19 | + # checks for virtual attributes |
20 | validates_presence_of :name, :identifier | 20 | validates_presence_of :name, :identifier |
21 | 21 | ||
22 | #checks if the validation method is region to validates | 22 | #checks if the validation method is region to validates |
23 | validates_presence_of :region_id, :if => lambda { |obj| obj.environment.organization_approval_method == :region } | 23 | validates_presence_of :region_id, :if => lambda { |obj| obj.environment.organization_approval_method == :region } |
24 | 24 | ||
25 | - validates_format_of :foundation_year, :with => /^\d*$/ | 25 | + validates_numericality_of :foundation_year, only_integer: true, if: -> o { o.foundation_year.present? } |
26 | 26 | ||
27 | # checks for actual attributes | 27 | # checks for actual attributes |
28 | validates_presence_of :requestor_id, :target_id | 28 | validates_presence_of :requestor_id, :target_id |
@@ -129,7 +129,7 @@ class CreateEnterprise < Task | @@ -129,7 +129,7 @@ class CreateEnterprise < Task | ||
129 | finish | 129 | finish |
130 | end | 130 | end |
131 | 131 | ||
132 | - # tells if this request was appoved | 132 | + # tells if this request was appoved |
133 | def approved? | 133 | def approved? |
134 | self.status == Task::Status::FINISHED | 134 | self.status == Task::Status::FINISHED |
135 | end | 135 | end |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +class CustomField < ActiveRecord::Base | ||
2 | + attr_accessible :name, :default_value, :format, :extras, :customized_type, :active, :required, :signup, :environment | ||
3 | + serialize :customized_type | ||
4 | + serialize :extras | ||
5 | + has_many :custom_field_values, :dependent => :delete_all | ||
6 | + belongs_to :environment | ||
7 | + | ||
8 | + validates_presence_of :name, :format, :customized_type, :environment | ||
9 | + validate :related_to_other? | ||
10 | + validate :unique? | ||
11 | + | ||
12 | + def unique? | ||
13 | + if environment.custom_fields.any?{|cf| cf.name==name && cf.environment == environment && cf.customized_type==customized_type && new_record?} | ||
14 | + errors.add(:body, N_("There is a field with the same name for this type in this environment")) | ||
15 | + return false | ||
16 | + end | ||
17 | + true | ||
18 | + end | ||
19 | + | ||
20 | + def related_to_other? | ||
21 | + environment.custom_fields.any? do |cf| | ||
22 | + if cf.name == name && cf.customized_type != customized_type | ||
23 | + ancestor = cf.customized_type.constantize < customized_type.constantize | ||
24 | + descendant = cf.customized_type.constantize > customized_type.constantize | ||
25 | + if ancestor || descendant | ||
26 | + errors.add(:body, N_("New field related to existent one with same name")) | ||
27 | + return false | ||
28 | + end | ||
29 | + end | ||
30 | + end | ||
31 | + true | ||
32 | + end | ||
33 | +end | ||
34 | + |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +class CustomFieldValue < ActiveRecord::Base | ||
2 | + belongs_to :custom_field | ||
3 | + belongs_to :customized, :polymorphic => true | ||
4 | + attr_accessible :value, :public, :customized, :custom_field, :customized_type | ||
5 | + validate :can_save? | ||
6 | + | ||
7 | + def can_save? | ||
8 | + if value.blank? && custom_field.required | ||
9 | + errors.add(custom_field.name, _("can't be blank")) | ||
10 | + return false | ||
11 | + end | ||
12 | + return true | ||
13 | + end | ||
14 | +end |
app/models/domain.rb
@@ -14,7 +14,7 @@ class Domain < ActiveRecord::Base | @@ -14,7 +14,7 @@ class Domain < ActiveRecord::Base | ||
14 | 14 | ||
15 | # <tt>name</tt> must be sequences of alphanumeric characters (a to z, | 15 | # <tt>name</tt> must be sequences of alphanumeric characters (a to z, |
16 | # 0 to 9), plus '_' or '-', separated by dots. Letters must be lowercase. | 16 | # 0 to 9), plus '_' or '-', separated by dots. Letters must be lowercase. |
17 | - validates_format_of :name, :with => /^([a-z0-9_-]+\.)+[a-z0-9_-]+$/, :message => N_('{fn} must be composed of sequences of lowercase letters (a to z), numbers (0 to 9), "_" and "-", separated by dots.').fix_i18n | 17 | + validates_format_of :name, with: /\A([a-z0-9_-]+\.)+[a-z0-9_-]+\z/, message: N_('{fn} must be composed of sequences of lowercase letters (a to z), numbers (0 to 9), "_" and "-", separated by dots.').fix_i18n |
18 | 18 | ||
19 | # checks validations that could not be expressed using Rails' predefined | 19 | # checks validations that could not be expressed using Rails' predefined |
20 | # validations. In particular: | 20 | # validations. In particular: |
@@ -37,7 +37,7 @@ class Domain < ActiveRecord::Base | @@ -37,7 +37,7 @@ class Domain < ActiveRecord::Base | ||
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) | 39 | def self.find_by_name(name) |
40 | - self.find(:first, :conditions => [ 'name = ?', self.extract_domain_name(name) ]) | 40 | + self.where('name = ?', self.extract_domain_name(name)).first |
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 |
app/models/enterprise.rb
@@ -25,10 +25,6 @@ class Enterprise < Organization | @@ -25,10 +25,6 @@ class Enterprise < Organization | ||
25 | has_many :favorite_enterprise_people | 25 | has_many :favorite_enterprise_people |
26 | has_many :fans, source: :person, through: :favorite_enterprise_people | 26 | has_many :fans, source: :person, through: :favorite_enterprise_people |
27 | 27 | ||
28 | - def product_categories | ||
29 | - ProductCategory.by_enterprise(self) | ||
30 | - end | ||
31 | - | ||
32 | N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code') | 28 | N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code') |
33 | 29 | ||
34 | settings_items :organization_website, :historic_and_current_context, :activities_short_description | 30 | settings_items :organization_website, :historic_and_current_context, :activities_short_description |
@@ -71,7 +67,7 @@ class Enterprise < Organization | @@ -71,7 +67,7 @@ class Enterprise < Organization | ||
71 | end | 67 | end |
72 | 68 | ||
73 | def highlighted_products_with_image(options = {}) | 69 | def highlighted_products_with_image(options = {}) |
74 | - Product.find(:all, {:conditions => {:highlighted => true}, :joins => :image}.merge(options)) | 70 | + Product.where(:highlighted => true).joins(:image) |
75 | end | 71 | end |
76 | 72 | ||
77 | def required_fields | 73 | def required_fields |
app/models/environment.rb
@@ -17,10 +17,14 @@ class Environment < ActiveRecord::Base | @@ -17,10 +17,14 @@ class Environment < ActiveRecord::Base | ||
17 | 17 | ||
18 | has_many :users | 18 | has_many :users |
19 | 19 | ||
20 | - self.partial_updates = false | 20 | + # allow roles use |
21 | + def self.dangerous_attribute_method? name | ||
22 | + false | ||
23 | + end | ||
21 | 24 | ||
22 | has_many :tasks, :dependent => :destroy, :as => 'target' | 25 | has_many :tasks, :dependent => :destroy, :as => 'target' |
23 | has_many :search_terms, :as => :context | 26 | has_many :search_terms, :as => :context |
27 | + has_many :custom_fields, :dependent => :destroy | ||
24 | 28 | ||
25 | IDENTIFY_SCRIPTS = /(php[0-9s]?|[sp]htm[l]?|pl|py|cgi|rb)/ | 29 | IDENTIFY_SCRIPTS = /(php[0-9s]?|[sp]htm[l]?|pl|py|cgi|rb)/ |
26 | 30 | ||
@@ -108,7 +112,7 @@ class Environment < ActiveRecord::Base | @@ -108,7 +112,7 @@ class Environment < ActiveRecord::Base | ||
108 | def admins | 112 | def admins |
109 | admin_role = Environment::Roles.admin(self) | 113 | admin_role = Environment::Roles.admin(self) |
110 | return [] if admin_role.blank? | 114 | return [] if admin_role.blank? |
111 | - Person.members_of(self).all(:conditions => ['role_assignments.role_id = ?', admin_role.id]) | 115 | + Person.members_of(self).where 'role_assignments.role_id = ?', admin_role.id |
112 | end | 116 | end |
113 | 117 | ||
114 | # returns the available features for a Environment, in the form of a | 118 | # returns the available features for a Environment, in the form of a |
@@ -223,9 +227,11 @@ class Environment < ActiveRecord::Base | @@ -223,9 +227,11 @@ class Environment < ActiveRecord::Base | ||
223 | has_many :licenses | 227 | has_many :licenses |
224 | 228 | ||
225 | has_many :categories | 229 | has_many :categories |
226 | - has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' | 230 | + has_many :display_categories, -> { |
231 | + order('display_color').where('display_color is not null and parent_id is null') | ||
232 | + }, class_name: 'Category' | ||
227 | 233 | ||
228 | - has_many :product_categories, :conditions => { :type => 'ProductCategory'} | 234 | + has_many :product_categories, -> { where type: 'ProductCategory'} |
229 | has_many :regions | 235 | has_many :regions |
230 | has_many :states | 236 | has_many :states |
231 | has_many :cities | 237 | has_many :cities |
@@ -690,7 +696,7 @@ class Environment < ActiveRecord::Base | @@ -690,7 +696,7 @@ class Environment < ActiveRecord::Base | ||
690 | 696 | ||
691 | # the default Environment. | 697 | # the default Environment. |
692 | def self.default | 698 | def self.default |
693 | - self.find(:first, :conditions => [ 'is_default = ?', true ] ) | 699 | + self.where('is_default = ?', true).first |
694 | end | 700 | end |
695 | 701 | ||
696 | # returns an array with the top level categories for this environment. | 702 | # returns an array with the top level categories for this environment. |
@@ -871,7 +877,7 @@ class Environment < ActiveRecord::Base | @@ -871,7 +877,7 @@ class Environment < ActiveRecord::Base | ||
871 | end | 877 | end |
872 | 878 | ||
873 | def portal_folders | 879 | def portal_folders |
874 | - (settings[:portal_folders] || []).map{|fid| portal_community.articles.find(:first, :conditions => { :id => fid }) }.compact | 880 | + (settings[:portal_folders] || []).map{|fid| portal_community.articles.where(id: fid).first }.compact |
875 | end | 881 | end |
876 | 882 | ||
877 | def portal_folders=(folders) | 883 | def portal_folders=(folders) |
@@ -958,7 +964,7 @@ class Environment < ActiveRecord::Base | @@ -958,7 +964,7 @@ class Environment < ActiveRecord::Base | ||
958 | end | 964 | end |
959 | 965 | ||
960 | def highlighted_products_with_image(options = {}) | 966 | def highlighted_products_with_image(options = {}) |
961 | - Product.find(:all, {:conditions => {:highlighted => true, :profile_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) | 967 | + self.products.where(highlighted: true).joins(:image).order('created_at ASC') |
962 | end | 968 | end |
963 | 969 | ||
964 | settings_items :home_cache_in_minutes, :type => :integer, :default => 5 | 970 | settings_items :home_cache_in_minutes, :type => :integer, :default => 5 |
app/models/event.rb
@@ -12,14 +12,14 @@ class Event < Article | @@ -12,14 +12,14 @@ class Event < Article | ||
12 | settings_items :address, :type => :string | 12 | settings_items :address, :type => :string |
13 | 13 | ||
14 | def link=(value) | 14 | def link=(value) |
15 | - self.setting[:link] = maybe_add_http(value) | 15 | + self.setting[:link] = maybe_add_http(URI.escape value.to_s) |
16 | end | 16 | end |
17 | 17 | ||
18 | def link | 18 | def link |
19 | maybe_add_http(self.setting[:link]) | 19 | maybe_add_http(self.setting[:link]) |
20 | end | 20 | end |
21 | 21 | ||
22 | - xss_terminate :only => [ :name, :body, :link, :address ], :with => 'white_list', :on => 'validation' | 22 | + xss_terminate :only => [ :name, :body, :address ], :with => 'white_list', :on => 'validation' |
23 | 23 | ||
24 | def initialize(*args) | 24 | def initialize(*args) |
25 | super(*args) | 25 | super(*args) |
@@ -34,23 +34,21 @@ class Event < Article | @@ -34,23 +34,21 @@ class Event < Article | ||
34 | end | 34 | end |
35 | end | 35 | end |
36 | 36 | ||
37 | - scope :by_day, lambda { |date| | ||
38 | - { :conditions => [' start_date >= :start_date AND start_date <= :end_date AND end_date IS NULL OR (start_date <= :end_date AND end_date >= :start_date)', {:start_date => date.beginning_of_day, :end_date => date.end_of_day}], | ||
39 | - :order => 'start_date ASC' | ||
40 | - } | 37 | + scope :by_day, -> date { |
38 | + where('start_date >= :start_date AND start_date <= :end_date AND end_date IS NULL OR (start_date <= :end_date AND end_date >= :start_date)', | ||
39 | + start_date: date.beginning_of_day, end_date: date.end_of_day). | ||
40 | + order('start_date ASC') | ||
41 | } | 41 | } |
42 | 42 | ||
43 | - scope :next_events_from_month, lambda { |date| | 43 | + scope :next_events_from_month, -> date { |
44 | date_temp = date.strftime("%Y-%m-%d") | 44 | date_temp = date.strftime("%Y-%m-%d") |
45 | - { :conditions => ["start_date >= ?","#{date_temp}"], | ||
46 | - :order => 'start_date ASC' | ||
47 | - } | 45 | + order('start_date ASC') |
46 | + .where("start_date >= ?","#{date_temp}") | ||
48 | } | 47 | } |
49 | 48 | ||
50 | - scope :by_month, lambda { |date| | ||
51 | - { :conditions => ["EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?",date.year,date.month], | ||
52 | - :order => 'start_date ASC' | ||
53 | - } | 49 | + scope :by_month, -> date { |
50 | + order('start_date ASC') | ||
51 | + .where("EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?", date.year, date.month) | ||
54 | } | 52 | } |
55 | 53 | ||
56 | include WhiteListFilter | 54 | include WhiteListFilter |
@@ -71,12 +69,10 @@ class Event < Article | @@ -71,12 +69,10 @@ class Event < Article | ||
71 | 'event' | 69 | 'event' |
72 | end | 70 | end |
73 | 71 | ||
74 | - scope :by_range, lambda { |range| { | ||
75 | - :conditions => [ | ||
76 | - 'start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day', | ||
77 | - { :start_day => range.first, :end_day => range.last } | ||
78 | - ] | ||
79 | - }} | 72 | + scope :by_range, -> range { |
73 | + where('start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day', | ||
74 | + {:start_day => range.first, :end_day => range.last}) | ||
75 | + } | ||
80 | 76 | ||
81 | def self.date_range(year, month) | 77 | def self.date_range(year, month) |
82 | if year.nil? || month.nil? | 78 | if year.nil? || month.nil? |
@@ -91,11 +87,11 @@ class Event < Article | @@ -91,11 +87,11 @@ class Event < Article | ||
91 | first_day = DateTime.new(year, month, 1) | 87 | first_day = DateTime.new(year, month, 1) |
92 | last_day = first_day + 1.month - 1.day | 88 | last_day = first_day + 1.month - 1.day |
93 | 89 | ||
94 | - first_day..last_day | 90 | + first_day.to_date..last_day.to_date |
95 | end | 91 | end |
96 | 92 | ||
97 | def date_range | 93 | def date_range |
98 | - start_date..(end_date||start_date) | 94 | + start_date.to_date..(end_date||start_date).to_date |
99 | end | 95 | end |
100 | 96 | ||
101 | def first_paragraph | 97 | def first_paragraph |
@@ -114,7 +110,7 @@ class Event < Article | @@ -114,7 +110,7 @@ class Event < Article | ||
114 | end | 110 | end |
115 | 111 | ||
116 | def duration | 112 | def duration |
117 | - (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) | 113 | + (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) + 1 |
118 | end | 114 | end |
119 | 115 | ||
120 | alias_method :article_lead, :lead | 116 | alias_method :article_lead, :lead |
app/models/external_feed.rb
@@ -5,9 +5,9 @@ class ExternalFeed < ActiveRecord::Base | @@ -5,9 +5,9 @@ class ExternalFeed < ActiveRecord::Base | ||
5 | validates_presence_of :address, :if => lambda {|efeed| efeed.enabled} | 5 | validates_presence_of :address, :if => lambda {|efeed| efeed.enabled} |
6 | validates_uniqueness_of :blog_id | 6 | validates_uniqueness_of :blog_id |
7 | 7 | ||
8 | - scope :enabled, :conditions => { :enabled => true } | ||
9 | - scope :expired, lambda { | ||
10 | - { :conditions => ['(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] } | 8 | + scope :enabled, -> { where enabled: true } |
9 | + scope :expired, -> { | ||
10 | + where '(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval | ||
11 | } | 11 | } |
12 | 12 | ||
13 | attr_accessible :address, :enabled, :only_once | 13 | attr_accessible :address, :enabled, :only_once |
app/models/featured_products_block.rb
@@ -11,7 +11,7 @@ class FeaturedProductsBlock < Block | @@ -11,7 +11,7 @@ class FeaturedProductsBlock < Block | ||
11 | if block.owner.kind_of?(Environment) && block.product_ids.blank? | 11 | if block.owner.kind_of?(Environment) && block.product_ids.blank? |
12 | total = block.owner.products.count | 12 | total = block.owner.products.count |
13 | offset = rand([(total - block.groups_of * 3) + 1, 1].max) | 13 | offset = rand([(total - block.groups_of * 3) + 1, 1].max) |
14 | - block.product_ids = block.owner.highlighted_products_with_image(:offset => offset, :limit => block.groups_of * 3).map(&:id) | 14 | + block.product_ids = block.owner.highlighted_products_with_image.offset(offset).limit(block.groups_of * 3).map(&:id) |
15 | end | 15 | end |
16 | block.groups_of = block.groups_of.to_i | 16 | block.groups_of = block.groups_of.to_i |
17 | end | 17 | end |
@@ -20,6 +20,10 @@ class FeaturedProductsBlock < Block | @@ -20,6 +20,10 @@ class FeaturedProductsBlock < Block | ||
20 | _('Featured Products') | 20 | _('Featured Products') |
21 | end | 21 | end |
22 | 22 | ||
23 | + def self.pretty_name | ||
24 | + _('Featured Products') | ||
25 | + end | ||
26 | + | ||
23 | def products | 27 | def products |
24 | Product.find(self.product_ids) || [] | 28 | Product.find(self.product_ids) || [] |
25 | end | 29 | end |
app/models/feed_reader_block.rb
@@ -27,8 +27,8 @@ class FeedReaderBlock < Block | @@ -27,8 +27,8 @@ class FeedReaderBlock < Block | ||
27 | settings_items :update_errors, :type => :integer, :default => 0 | 27 | settings_items :update_errors, :type => :integer, :default => 0 |
28 | settings_items :error_message, :type => :string | 28 | settings_items :error_message, :type => :string |
29 | 29 | ||
30 | - scope :expired, lambda { | ||
31 | - { :conditions => [ '(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] } | 30 | + scope :expired, -> { |
31 | + where '(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval | ||
32 | } | 32 | } |
33 | 33 | ||
34 | before_create do |block| | 34 | before_create do |block| |
@@ -40,6 +40,10 @@ class FeedReaderBlock < Block | @@ -40,6 +40,10 @@ class FeedReaderBlock < Block | ||
40 | _('Feed reader') | 40 | _('Feed reader') |
41 | end | 41 | end |
42 | 42 | ||
43 | + def self.pretty_name | ||
44 | + _('Feed Reader') | ||
45 | + end | ||
46 | + | ||
43 | def help | 47 | def help |
44 | _('This block can be used to list the latest new from any site you want. You just need to inform the address of a RSS feed.') | 48 | _('This block can be used to list the latest new from any site you want. You just need to inform the address of a RSS feed.') |
45 | end | 49 | end |
app/models/folder.rb
@@ -56,10 +56,11 @@ class Folder < Article | @@ -56,10 +56,11 @@ class Folder < Article | ||
56 | profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) | 56 | profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) |
57 | end | 57 | end |
58 | 58 | ||
59 | - has_many :images, :class_name => 'Article', | ||
60 | - :foreign_key => 'parent_id', | ||
61 | - :order => 'articles.type, articles.name', | ||
62 | - :conditions => ["articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery')", UploadedFile.content_types] | 59 | + has_many :images, -> { |
60 | + order('articles.type, articles.name'). | ||
61 | + where("articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery')", UploadedFile.content_types) | ||
62 | + }, class_name: 'Article', foreign_key: 'parent_id' | ||
63 | + | ||
63 | 64 | ||
64 | def accept_uploads? | 65 | def accept_uploads? |
65 | !self.has_posts? || self.gallery? | 66 | !self.has_posts? || self.gallery? |
app/models/highlights_block.rb
app/models/image.rb
1 | class Image < ActiveRecord::Base | 1 | class Image < ActiveRecord::Base |
2 | 2 | ||
3 | + attr_accessible :uploaded_data, :label, :remove_image | ||
4 | + attr_accessor :remove_image | ||
5 | + | ||
3 | def self.max_size | 6 | def self.max_size |
4 | Image.attachment_options[:max_size] | 7 | Image.attachment_options[:max_size] |
5 | end | 8 | end |
6 | 9 | ||
7 | sanitize_filename | 10 | sanitize_filename |
8 | 11 | ||
9 | - has_attachment :content_type => :image, | ||
10 | - :storage => :file_system, | 12 | + has_attachment :content_type => :image, |
13 | + :storage => :file_system, | ||
11 | :path_prefix => 'public/image_uploads', | 14 | :path_prefix => 'public/image_uploads', |
12 | :resize_to => '800x600>', | 15 | :resize_to => '800x600>', |
13 | :thumbnails => { :big => '150x150', | 16 | :thumbnails => { :big => '150x150', |
@@ -15,7 +18,8 @@ class Image < ActiveRecord::Base | @@ -15,7 +18,8 @@ class Image < ActiveRecord::Base | ||
15 | :portrait => '64x64', | 18 | :portrait => '64x64', |
16 | :minor => '50x50>', | 19 | :minor => '50x50>', |
17 | :icon => '20x20!' }, | 20 | :icon => '20x20!' }, |
18 | - :max_size => 5.megabytes # remember to update validate message below | 21 | + :max_size => 5.megabytes, # remember to update validate message below |
22 | + processor: 'Rmagick' | ||
19 | 23 | ||
20 | validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of 5.0 MB").fix_i18n | 24 | validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of 5.0 MB").fix_i18n |
21 | 25 | ||
@@ -23,10 +27,8 @@ class Image < ActiveRecord::Base | @@ -23,10 +27,8 @@ class Image < ActiveRecord::Base | ||
23 | 27 | ||
24 | postgresql_attachment_fu | 28 | postgresql_attachment_fu |
25 | 29 | ||
26 | - attr_accessible :uploaded_data, :label, :remove_image | ||
27 | - attr_accessor :remove_image | ||
28 | - | ||
29 | def current_data | 30 | def current_data |
30 | File.file?(full_filename) ? File.read(full_filename) : nil | 31 | File.file?(full_filename) ? File.read(full_filename) : nil |
31 | end | 32 | end |
33 | + | ||
32 | end | 34 | end |
app/models/input.rb
@@ -13,7 +13,7 @@ class Input < ActiveRecord::Base | @@ -13,7 +13,7 @@ class Input < ActiveRecord::Base | ||
13 | 13 | ||
14 | belongs_to :unit | 14 | belongs_to :unit |
15 | 15 | ||
16 | - scope :relevant_to_price, :conditions => { :relevant_to_price => true } | 16 | + scope :relevant_to_price, -> { where relevant_to_price: true } |
17 | 17 | ||
18 | include FloatHelper | 18 | include FloatHelper |
19 | 19 |
app/models/invite_friend.rb
@@ -45,7 +45,7 @@ class InviteFriend < Invitation | @@ -45,7 +45,7 @@ class InviteFriend < Invitation | ||
45 | private | 45 | private |
46 | def check_for_invitation_existence | 46 | def check_for_invitation_existence |
47 | if friend | 47 | if friend |
48 | - friend.tasks.pending.of("InviteFriend").find(:all, :conditions => {:requestor_id => person.id, :target_id => friend.id}).blank? | 48 | + friend.tasks.pending.of("InviteFriend").where(requestor_id: person.id, target_id: friend.id).blank? |
49 | end | 49 | end |
50 | end | 50 | end |
51 | 51 |
app/models/invite_member.rb
@@ -65,7 +65,7 @@ class InviteMember < Invitation | @@ -65,7 +65,7 @@ class InviteMember < Invitation | ||
65 | private | 65 | private |
66 | def check_for_invitation_existence | 66 | def check_for_invitation_existence |
67 | if friend | 67 | if friend |
68 | - friend.tasks.pending.of("InviteMember").find(:all, :conditions => {:requestor_id => person.id}).select { |t| t.data[:community_id] == community_id }.blank? | 68 | + friend.tasks.pending.of("InviteMember").where(requestor_id: person.id).select{ |t| t.data[:community_id] == community_id }.blank? |
69 | end | 69 | end |
70 | end | 70 | end |
71 | 71 |
app/models/link_list_block.rb
@@ -41,7 +41,7 @@ class LinkListBlock < Block | @@ -41,7 +41,7 @@ class LinkListBlock < Block | ||
41 | [N_('New window'), '_new'], | 41 | [N_('New window'), '_new'], |
42 | ] | 42 | ] |
43 | 43 | ||
44 | - settings_items :links, Array, :default => [] | 44 | + settings_items :links, type: Array, :default => [] |
45 | 45 | ||
46 | before_save do |block| | 46 | before_save do |block| |
47 | block.links = block.links.delete_if {|i| i[:name].blank? and i[:address].blank?} | 47 | block.links = block.links.delete_if {|i| i[:name].blank? and i[:address].blank?} |
@@ -55,6 +55,10 @@ class LinkListBlock < Block | @@ -55,6 +55,10 @@ class LinkListBlock < Block | ||
55 | _('This block can be used to create a menu of links. You can add, remove and update the links as you wish.') | 55 | _('This block can be used to create a menu of links. You can add, remove and update the links as you wish.') |
56 | end | 56 | end |
57 | 57 | ||
58 | + def self.pretty_name | ||
59 | + _('Link list') | ||
60 | + end | ||
61 | + | ||
58 | def content(args={}) | 62 | def content(args={}) |
59 | block_title(title) + | 63 | block_title(title) + |
60 | content_tag('ul', | 64 | content_tag('ul', |
app/models/organization.rb
@@ -84,7 +84,7 @@ class Organization < Profile | @@ -84,7 +84,7 @@ class Organization < Profile | ||
84 | end | 84 | end |
85 | 85 | ||
86 | def find_pending_validation(code) | 86 | def find_pending_validation(code) |
87 | - validations.pending.find(:first, :conditions => {:code => code}) | 87 | + validations.pending.where(code: code).first |
88 | end | 88 | end |
89 | 89 | ||
90 | def processed_validations | 90 | def processed_validations |
@@ -92,7 +92,7 @@ class Organization < Profile | @@ -92,7 +92,7 @@ class Organization < Profile | ||
92 | end | 92 | end |
93 | 93 | ||
94 | def find_processed_validation(code) | 94 | def find_processed_validation(code) |
95 | - validations.finished.find(:first, :conditions => {:code => code}) | 95 | + validations.finished.where(code: code).first |
96 | end | 96 | end |
97 | 97 | ||
98 | def is_validation_entity? | 98 | def is_validation_entity? |
@@ -116,6 +116,7 @@ class Organization < Profile | @@ -116,6 +116,7 @@ class Organization < Profile | ||
116 | tag_list | 116 | tag_list |
117 | template_id | 117 | template_id |
118 | district | 118 | district |
119 | + address_line2 | ||
119 | address_reference | 120 | address_reference |
120 | ] | 121 | ] |
121 | 122 | ||
@@ -136,11 +137,11 @@ class Organization < Profile | @@ -136,11 +137,11 @@ class Organization < Profile | ||
136 | end | 137 | end |
137 | 138 | ||
138 | N_('Display name'); N_('Description'); N_('Contact person'); N_('Contact email'); N_('Acronym'); N_('Foundation year'); N_('Legal form'); N_('Economic activity'); N_('Management information'); N_('Tag list'); N_('District'); N_('Address reference') | 139 | N_('Display name'); N_('Description'); N_('Contact person'); N_('Contact email'); N_('Acronym'); N_('Foundation year'); N_('Legal form'); N_('Economic activity'); N_('Management information'); N_('Tag list'); N_('District'); N_('Address reference') |
139 | - settings_items :display_name, :description, :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :district, :address_reference | 140 | + settings_items :display_name, :description, :contact_person, :contact_email, :acronym, :foundation_year, :legal_form, :economic_activity, :management_information, :district, :address_line2, :address_reference |
140 | 141 | ||
141 | settings_items :zip_code, :city, :state, :country | 142 | settings_items :zip_code, :city, :state, :country |
142 | 143 | ||
143 | - validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT | 144 | + validates_numericality_of :foundation_year, only_integer: true, if: -> o { o.foundation_year.present? } |
144 | validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |org| !org.contact_email.blank? }) | 145 | validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |org| !org.contact_email.blank? }) |
145 | validates_as_cnpj :cnpj | 146 | validates_as_cnpj :cnpj |
146 | 147 | ||
@@ -190,7 +191,7 @@ class Organization < Profile | @@ -190,7 +191,7 @@ class Organization < Profile | ||
190 | end | 191 | end |
191 | 192 | ||
192 | def already_request_membership?(person) | 193 | def already_request_membership?(person) |
193 | - self.tasks.pending.find_by_requestor_id(person.id, :conditions => { :type => 'AddMember' }) | 194 | + self.tasks.pending.where(type: 'AddMember', requestor_id: person.id).first |
194 | end | 195 | end |
195 | 196 | ||
196 | def jid(options = {}) | 197 | def jid(options = {}) |
app/models/person.rb
@@ -16,27 +16,26 @@ class Person < Profile | @@ -16,27 +16,26 @@ class Person < Profile | ||
16 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} | 16 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} |
17 | acts_as_accessor | 17 | acts_as_accessor |
18 | 18 | ||
19 | - scope :members_of, lambda { |resources| | ||
20 | - resources = [resources] if !resources.kind_of?(Array) | 19 | + scope :members_of, -> resources { |
20 | + resources = Array(resources) | ||
21 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') | 21 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') |
22 | - { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => [conditions] } | 22 | + select('DISTINCT profiles.*').joins(:role_assignments).where([conditions]) |
23 | } | 23 | } |
24 | 24 | ||
25 | - scope :not_members_of, lambda { |resources| | ||
26 | - resources = [resources] if !resources.kind_of?(Array) | 25 | + scope :not_members_of, -> resources { |
26 | + resources = Array(resources) | ||
27 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') | 27 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') |
28 | - { :select => 'DISTINCT profiles.*', :conditions => ['"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "role_assignments" ON "role_assignments"."accessor_id" = "profiles"."id" AND "role_assignments"."accessor_type" = (\'Profile\') WHERE "profiles"."type" IN (\'Person\') AND (%s))' % conditions] } | 28 | + select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "role_assignments" ON "role_assignments"."accessor_id" = "profiles"."id" AND "role_assignments"."accessor_type" = (\'Profile\') WHERE "profiles"."type" IN (\'Person\') AND (%s))' % conditions) |
29 | } | 29 | } |
30 | 30 | ||
31 | - scope :by_role, lambda { |roles| | ||
32 | - roles = [roles] unless roles.kind_of?(Array) | ||
33 | - { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.role_id IN (?)', | ||
34 | -roles] } | 31 | + scope :by_role, -> roles { |
32 | + roles = Array(roles) | ||
33 | + select('DISTINCT profiles.*').joins(:role_assignments).where('role_assignments.role_id IN (?)', roles) | ||
35 | } | 34 | } |
36 | 35 | ||
37 | - scope :not_friends_of, lambda { |resources| | 36 | + scope :not_friends_of, -> resources { |
38 | resources = Array(resources) | 37 | resources = Array(resources) |
39 | - { :select => 'DISTINCT profiles.*', :conditions => ['"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "friendships" ON "friendships"."person_id" = "profiles"."id" WHERE "friendships"."friend_id" IN (%s))' % resources.map(&:id)] } | 38 | + select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "friendships" ON "friendships"."person_id" = "profiles"."id" WHERE "friendships"."friend_id" IN (%s))' % resources.map(&:id)) |
40 | } | 39 | } |
41 | 40 | ||
42 | scope :visible_for_person, lambda { |person| | 41 | scope :visible_for_person, lambda { |person| |
@@ -68,6 +67,9 @@ roles] } | @@ -68,6 +67,9 @@ roles] } | ||
68 | end | 67 | end |
69 | alias_method_chain :has_permission?, :plugins | 68 | alias_method_chain :has_permission?, :plugins |
70 | 69 | ||
70 | + # for eager loading | ||
71 | + has_many :memberships, through: :role_assignments, source: :resource, source_type: 'Profile' | ||
72 | + | ||
71 | def memberships | 73 | def memberships |
72 | scopes = [] | 74 | scopes = [] |
73 | plugins_scopes = plugins.dispatch_scopes(:person_memberships, self) | 75 | plugins_scopes = plugins.dispatch_scopes(:person_memberships, self) |
@@ -81,10 +83,14 @@ roles] } | @@ -81,10 +83,14 @@ roles] } | ||
81 | memberships.where('role_assignments.role_id = ?', role.id) | 83 | memberships.where('role_assignments.role_id = ?', role.id) |
82 | end | 84 | end |
83 | 85 | ||
86 | + has_many :comments, :foreign_key => :author_id | ||
87 | + | ||
84 | has_many :friendships, :dependent => :destroy | 88 | has_many :friendships, :dependent => :destroy |
85 | has_many :friends, :class_name => 'Person', :through => :friendships | 89 | has_many :friends, :class_name => 'Person', :through => :friendships |
86 | 90 | ||
87 | - scope :online, lambda { { :include => :user, :conditions => ["users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes] } } | 91 | + scope :online, -> { |
92 | + joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes) | ||
93 | + } | ||
88 | 94 | ||
89 | has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy | 95 | has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy |
90 | 96 | ||
@@ -100,21 +106,31 @@ roles] } | @@ -100,21 +106,31 @@ roles] } | ||
100 | has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' | 106 | has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' |
101 | has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' | 107 | has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' |
102 | 108 | ||
103 | - has_many :suggested_profiles, :class_name => 'ProfileSuggestion', :foreign_key => :person_id, :order => 'score DESC', :dependent => :destroy | ||
104 | - has_many :suggested_people, :through => :suggested_profiles, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true] | ||
105 | - has_many :suggested_communities, :through => :suggested_profiles, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true] | 109 | + has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy |
110 | + has_many :suggested_people, -> { | ||
111 | + where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true | ||
112 | + }, through: :suggested_profiles, source: :suggestion | ||
113 | + has_many :suggested_communities, -> { | ||
114 | + where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true | ||
115 | + }, through: :suggested_profiles, source: :suggestion | ||
106 | 116 | ||
107 | - scope :more_popular, :order => 'friends_count DESC' | 117 | + scope :more_popular, -> { order 'friends_count DESC' } |
108 | 118 | ||
109 | - scope :abusers, :joins => :abuse_complaints, :conditions => ['tasks.status = 3'], :select => 'DISTINCT profiles.*' | ||
110 | - scope :non_abusers, :joins => "LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'", :conditions => ["tasks.status != 3 OR tasks.id is NULL"], :select => "DISTINCT profiles.*" | 119 | + scope :abusers, -> { |
120 | + joins(:abuse_complaints).where('tasks.status = 3').select('DISTINCT profiles.*') | ||
121 | + } | ||
122 | + scope :non_abusers, -> { | ||
123 | + select("DISTINCT profiles.*"). | ||
124 | + joins("LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'"). | ||
125 | + where("tasks.status != 3 OR tasks.id is NULL") | ||
126 | + } | ||
111 | 127 | ||
112 | - scope :admins, :joins => [:role_assignments => :role], :conditions => ['roles.key = ?', 'environment_administrator' ] | ||
113 | - scope :activated, :joins => :user, :conditions => ['users.activation_code IS NULL AND users.activated_at IS NOT NULL'] | ||
114 | - scope :deactivated, :joins => :user, :conditions => ['NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)'] | 128 | + scope :admins, -> { joins(:role_assignments => :role).where('roles.key = ?', 'environment_administrator') } |
129 | + scope :activated, -> { joins(:user).where('users.activation_code IS NULL AND users.activated_at IS NOT NULL') } | ||
130 | + scope :deactivated, -> { joins(:user).where('NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)') } | ||
115 | 131 | ||
116 | after_destroy do |person| | 132 | after_destroy do |person| |
117 | - Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } | 133 | + Friendship.where(friend_id: person.id).each{ |friendship| friendship.destroy } |
118 | end | 134 | end |
119 | 135 | ||
120 | belongs_to :user, :dependent => :delete | 136 | belongs_to :user, :dependent => :delete |
@@ -177,7 +193,7 @@ roles] } | @@ -177,7 +193,7 @@ roles] } | ||
177 | end | 193 | end |
178 | 194 | ||
179 | def remove_friend(friend) | 195 | def remove_friend(friend) |
180 | - Friendship.find(:first, :conditions => {:friend_id => friend, :person_id => id}).destroy | 196 | + Friendship.where(friend_id: friend, person_id: id).first.destroy |
181 | end | 197 | end |
182 | 198 | ||
183 | FIELDS = %w[ | 199 | FIELDS = %w[ |
@@ -194,6 +210,7 @@ roles] } | @@ -194,6 +210,7 @@ roles] } | ||
194 | district | 210 | district |
195 | zip_code | 211 | zip_code |
196 | address | 212 | address |
213 | + address_line2 | ||
197 | address_reference | 214 | address_reference |
198 | cell_phone | 215 | cell_phone |
199 | comercial_phone | 216 | comercial_phone |
@@ -259,7 +276,7 @@ roles] } | @@ -259,7 +276,7 @@ roles] } | ||
259 | settings_items :formation, :custom_formation, :custom_area_of_study | 276 | settings_items :formation, :custom_formation, :custom_area_of_study |
260 | 277 | ||
261 | N_('Contact information'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code'); N_('District'); N_('Address reference') | 278 | N_('Contact information'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code'); N_('District'); N_('Address reference') |
262 | - settings_items :photo, :contact_information, :sex, :city, :state, :country, :zip_code, :district, :address_reference | 279 | + settings_items :photo, :contact_information, :sex, :city, :state, :country, :zip_code, :district, :address_line2, :address_reference |
263 | 280 | ||
264 | extend SetProfileRegionFromCityState::ClassMethods | 281 | extend SetProfileRegionFromCityState::ClassMethods |
265 | set_profile_region_from_city_state | 282 | set_profile_region_from_city_state |
@@ -288,7 +305,7 @@ roles] } | @@ -288,7 +305,7 @@ roles] } | ||
288 | end | 305 | end |
289 | 306 | ||
290 | validates_each :email, :on => :update do |record,attr,value| | 307 | validates_each :email, :on => :update do |record,attr,value| |
291 | - if User.find(:first, :conditions => ['email = ? and id != ? and environment_id = ?', value, record.user.id, record.environment.id]) | 308 | + if User.where('email = ? and id != ? and environment_id = ?', value, record.user.id, record.environment.id).first |
292 | record.errors.add(attr, _('{fn} is already used by other user').fix_i18n) | 309 | record.errors.add(attr, _('{fn} is already used by other user').fix_i18n) |
293 | end | 310 | end |
294 | end | 311 | end |
@@ -397,7 +414,7 @@ roles] } | @@ -397,7 +414,7 @@ roles] } | ||
397 | def ask_to_join?(community) | 414 | def ask_to_join?(community) |
398 | return false if !community.visible? | 415 | return false if !community.visible? |
399 | return false if memberships.include?(community) | 416 | return false if memberships.include?(community) |
400 | - return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id}) | 417 | + return false if AddMember.where(requestor_id: self.id, target_id: community.id).first |
401 | !refused_communities.include?(community) | 418 | !refused_communities.include?(community) |
402 | end | 419 | end |
403 | 420 |
app/models/person_notifier.rb
1 | +# FIXME needed by test/units/application_helper.rb | ||
2 | +require_dependency 'application_helper' | ||
3 | + | ||
1 | class PersonNotifier | 4 | class PersonNotifier |
2 | 5 | ||
3 | def initialize(person) | 6 | def initialize(person) |
@@ -28,7 +31,7 @@ class PersonNotifier | @@ -28,7 +31,7 @@ class PersonNotifier | ||
28 | 31 | ||
29 | def notify | 32 | def notify |
30 | if @person.notification_time && @person.notification_time > 0 | 33 | if @person.notification_time && @person.notification_time > 0 |
31 | - notifications = @person.tracked_notifications.find(:all, :conditions => ["created_at > ?", notify_from]) | 34 | + notifications = @person.tracked_notifications.where("created_at > ?", notify_from) |
32 | tasks = Task.to(@person).without_spam.pending.where("created_at > ?", notify_from).order_by('created_at', 'asc') | 35 | tasks = Task.to(@person).without_spam.pending.where("created_at > ?", notify_from).order_by('created_at', 'asc') |
33 | 36 | ||
34 | Noosfero.with_locale @person.environment.default_language do | 37 | Noosfero.with_locale @person.environment.default_language do |
@@ -74,9 +77,8 @@ class PersonNotifier | @@ -74,9 +77,8 @@ class PersonNotifier | ||
74 | 77 | ||
75 | end | 78 | end |
76 | 79 | ||
77 | - class Mailer < ActionMailer::Base | 80 | + class Mailer < ApplicationMailer |
78 | 81 | ||
79 | - helper ApplicationHelper | ||
80 | helper ActionTrackerHelper | 82 | helper ActionTrackerHelper |
81 | 83 | ||
82 | def session | 84 | def session |
@@ -85,8 +87,8 @@ class PersonNotifier | @@ -85,8 +87,8 @@ class PersonNotifier | ||
85 | 87 | ||
86 | def content_summary(person, notifications, tasks) | 88 | def content_summary(person, notifications, tasks) |
87 | if person.environment | 89 | if person.environment |
88 | - ActionMailer::Base.asset_host = person.environment.top_url | ||
89 | - ActionMailer::Base.default_url_options[:host] = person.environment.default_hostname | 90 | + ApplicationMailer.asset_host = person.environment.top_url |
91 | + ApplicationMailer.default_url_options[:host] = person.environment.default_hostname | ||
90 | end | 92 | end |
91 | 93 | ||
92 | @current_theme = 'default' | 94 | @current_theme = 'default' |
@@ -94,7 +96,7 @@ class PersonNotifier | @@ -94,7 +96,7 @@ class PersonNotifier | ||
94 | @recipient = @profile.nickname || @profile.name | 96 | @recipient = @profile.nickname || @profile.name |
95 | @notifications = notifications | 97 | @notifications = notifications |
96 | @tasks = tasks | 98 | @tasks = tasks |
97 | - @environment = @profile.environment.name | 99 | + @environment = @profile.environment |
98 | @url = @profile.environment.top_url | 100 | @url = @profile.environment.top_url |
99 | mail( | 101 | mail( |
100 | content_type: "text/html", | 102 | content_type: "text/html", |
app/models/product.rb
@@ -52,8 +52,8 @@ class Product < ActiveRecord::Base | @@ -52,8 +52,8 @@ class Product < ActiveRecord::Base | ||
52 | 52 | ||
53 | scope :more_recent, :order => "created_at DESC" | 53 | scope :more_recent, :order => "created_at DESC" |
54 | 54 | ||
55 | - scope :from_category, lambda { |category| | ||
56 | - {:joins => :product_category, :conditions => ['categories.path LIKE ?', "%#{category.slug}%"]} if category | 55 | + scope :from_category, -> category { |
56 | + joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category | ||
57 | } | 57 | } |
58 | 58 | ||
59 | scope :visible_for_person, lambda { |person| | 59 | scope :visible_for_person, lambda { |person| |
app/models/product_category.rb
@@ -6,19 +6,16 @@ class ProductCategory < Category | @@ -6,19 +6,16 @@ class ProductCategory < Category | ||
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, lambda { |enterprise| { | ||
10 | - :joins => :products, | ||
11 | - :conditions => ['products.profile_id = ?', enterprise.id] | ||
12 | - }} | ||
13 | - scope :by_environment, lambda { |environment| { | ||
14 | - :conditions => ['environment_id = ?', environment.id] | ||
15 | - }} | ||
16 | - scope :unique_by_level, lambda { |level| { | ||
17 | - :select => "DISTINCT ON (filtered_category) split_part(path, '/', #{level}) AS filtered_category, categories.*" | ||
18 | - }} | 9 | + scope :by_enterprise, -> enterprise { |
10 | + distinct.joins(:products). | ||
11 | + where('products.profile_id = ?', enterprise.id) | ||
12 | + } | ||
13 | + scope :by_environment, -> environment { | ||
14 | + where 'environment_id = ?', environment.id | ||
15 | + } | ||
19 | 16 | ||
20 | def all_products | 17 | def all_products |
21 | - Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) | 18 | + Product.where(product_category_id: (all_children << self).map(&:id)) |
22 | end | 19 | end |
23 | 20 | ||
24 | def self.menu_categories(top_category, env) | 21 | def self.menu_categories(top_category, env) |
app/models/products_block.rb
@@ -39,7 +39,7 @@ class ProductsBlock < Block | @@ -39,7 +39,7 @@ class ProductsBlock < Block | ||
39 | link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) | 39 | link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) |
40 | end | 40 | end |
41 | 41 | ||
42 | - settings_items :product_ids, Array | 42 | + settings_items :product_ids, type: Array |
43 | def product_ids=(array) | 43 | def product_ids=(array) |
44 | self.settings[:product_ids] = array | 44 | self.settings[:product_ids] = array |
45 | if self.settings[:product_ids] | 45 | if self.settings[:product_ids] |
app/models/profile.rb
@@ -50,7 +50,7 @@ class Profile < ActiveRecord::Base | @@ -50,7 +50,7 @@ class Profile < ActiveRecord::Base | ||
50 | all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?} | 50 | all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?} |
51 | end | 51 | end |
52 | def self.all_roles(env_id) | 52 | def self.all_roles(env_id) |
53 | - Role.all :conditions => { :environment_id => env_id } | 53 | + Role.where(environment_id: env_id) |
54 | end | 54 | end |
55 | def self.method_missing(m, *args, &block) | 55 | def self.method_missing(m, *args, &block) |
56 | role = find_role(m, args[0]) | 56 | role = find_role(m, args[0]) |
@@ -84,23 +84,32 @@ class Profile < ActiveRecord::Base | @@ -84,23 +84,32 @@ class Profile < ActiveRecord::Base | ||
84 | } | 84 | } |
85 | 85 | ||
86 | acts_as_accessible | 86 | acts_as_accessible |
87 | + acts_as_customizable | ||
87 | 88 | ||
88 | include Noosfero::Plugin::HotSpot | 89 | include Noosfero::Plugin::HotSpot |
89 | 90 | ||
90 | - scope :memberships_of, lambda { |person| { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id ] } } | 91 | + scope :memberships_of, -> person { |
92 | + select('DISTINCT profiles.*'). | ||
93 | + joins(:role_assignments). | ||
94 | + where('role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id) | ||
95 | + } | ||
91 | #FIXME: these will work only if the subclass is already loaded | 96 | #FIXME: these will work only if the subclass is already loaded |
92 | - scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | ||
93 | - scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | ||
94 | - scope :templates, lambda { |template_id = nil| | ||
95 | - conditions = {:conditions => {:is_template => true}} | ||
96 | - conditions[:conditions].merge!({:id => template_id}) unless template_id.nil? | ||
97 | - conditions | 97 | + scope :enterprises, -> { |
98 | + where((Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")) | ||
99 | + } | ||
100 | + scope :communities, -> { | ||
101 | + where((Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")) | ||
102 | + } | ||
103 | + scope :templates, -> template_id = nil { | ||
104 | + s = where is_template: true | ||
105 | + s = s.where id: template_id if template_id | ||
106 | + s | ||
98 | } | 107 | } |
99 | 108 | ||
100 | - scope :with_templates, lambda { |templates| | ||
101 | - {:conditions => {:template_id => templates}} | 109 | + scope :with_templates, -> templates { |
110 | + where template_id: templates | ||
102 | } | 111 | } |
103 | - scope :no_templates, {:conditions => {:is_template => false}} | 112 | + scope :no_templates, -> { where is_template: false } |
104 | 113 | ||
105 | # Returns a scoped object to select profiles in a given location or in a radius | 114 | # Returns a scoped object to select profiles in a given location or in a radius |
106 | # distance from the given location center. | 115 | # distance from the given location center. |
@@ -177,10 +186,10 @@ class Profile < ActiveRecord::Base | @@ -177,10 +186,10 @@ class Profile < ActiveRecord::Base | ||
177 | Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') | 186 | Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') |
178 | end | 187 | end |
179 | 188 | ||
180 | - scope :visible, :conditions => { :visible => true, :secret => false } | ||
181 | - scope :disabled, :conditions => { :visible => false } | ||
182 | - scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false } | ||
183 | - scope :enabled, :conditions => { :enabled => true } | 189 | + scope :visible, -> { where visible: true, secret: false } |
190 | + scope :disabled, -> { where visible: false } | ||
191 | + scope :is_public, -> { where visible: true, public_profile: true, secret: false } | ||
192 | + scope :enabled, -> { where enabled: true } | ||
184 | 193 | ||
185 | # Subclasses must override this method | 194 | # Subclasses must override this method |
186 | scope :more_popular | 195 | scope :more_popular |
@@ -229,7 +238,7 @@ class Profile < ActiveRecord::Base | @@ -229,7 +238,7 @@ class Profile < ActiveRecord::Base | ||
229 | validates_length_of :description, :maximum => 550, :allow_nil => true | 238 | validates_length_of :description, :maximum => 550, :allow_nil => true |
230 | 239 | ||
231 | # Valid identifiers must match this format. | 240 | # Valid identifiers must match this format. |
232 | - IDENTIFIER_FORMAT = /^#{Noosfero.identifier_format}$/ | 241 | + IDENTIFIER_FORMAT = /\A#{Noosfero.identifier_format}\Z/ |
233 | 242 | ||
234 | # These names cannot be used as identifiers for Profiles | 243 | # These names cannot be used as identifiers for Profiles |
235 | RESERVED_IDENTIFIERS = %w[ | 244 | RESERVED_IDENTIFIERS = %w[ |
@@ -281,7 +290,7 @@ class Profile < ActiveRecord::Base | @@ -281,7 +290,7 @@ class Profile < ActiveRecord::Base | ||
281 | end | 290 | end |
282 | end | 291 | end |
283 | 292 | ||
284 | - has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] | 293 | + has_many :profile_categorizations, -> { where 'categories_profiles.virtual = ?', false } |
285 | has_many :categories, :through => :profile_categorizations | 294 | has_many :categories, :through => :profile_categorizations |
286 | 295 | ||
287 | has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' | 296 | has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' |
@@ -508,14 +517,13 @@ class Profile < ActiveRecord::Base | @@ -508,14 +517,13 @@ class Profile < ActiveRecord::Base | ||
508 | self.articles.recent(limit, options, pagination) | 517 | self.articles.recent(limit, options, pagination) |
509 | end | 518 | end |
510 | 519 | ||
511 | - def last_articles(limit = 10, options = {}) | ||
512 | - options = { :limit => limit, | ||
513 | - :conditions => ["advertise = ? AND published = ? AND | ||
514 | - ((articles.type != ? and articles.type != ? and articles.type != ?) OR | ||
515 | - articles.type is NULL)", | ||
516 | - true, true, 'UploadedFile', 'RssFeed', 'Blog'], | ||
517 | - :order => 'articles.published_at desc, articles.id desc' }.merge(options) | ||
518 | - self.articles.find(:all, options) | 520 | + def last_articles limit = 10 |
521 | + self.articles.limit(limit).where( | ||
522 | + "advertise = ? AND published = ? AND | ||
523 | + ((articles.type != ? and articles.type != ? and articles.type != ?) OR | ||
524 | + articles.type is NULL)", | ||
525 | + true, true, 'UploadedFile', 'RssFeed', 'Blog' | ||
526 | + ).order('articles.published_at desc, articles.id desc') | ||
519 | end | 527 | end |
520 | 528 | ||
521 | class << self | 529 | class << self |
@@ -713,7 +721,7 @@ private :generate_url, :url_options | @@ -713,7 +721,7 @@ private :generate_url, :url_options | ||
713 | num = num + 1 | 721 | num = num + 1 |
714 | new_name = original_article.name + ' ' + num.to_s | 722 | new_name = original_article.name + ' ' + num.to_s |
715 | end | 723 | end |
716 | - original_article.update_attributes!(:name => new_name) | 724 | + original_article.update!(:name => new_name) |
717 | end | 725 | end |
718 | article_copy = article.copy(:profile => self, :parent => parent, :advertise => false) | 726 | article_copy = article.copy(:profile => self, :parent => parent, :advertise => false) |
719 | if article.profile.home_page == article | 727 | if article.profile.home_page == article |
app/models/profile_activity.rb
@@ -25,8 +25,8 @@ class ProfileActivity < ActiveRecord::Base | @@ -25,8 +25,8 @@ class ProfileActivity < ActiveRecord::Base | ||
25 | protected | 25 | protected |
26 | 26 | ||
27 | def copy_timestamps | 27 | def copy_timestamps |
28 | - self.created_at = self.activity.created_at | ||
29 | - self.updated_at = self.activity.updated_at | 28 | + self.created_at = self.activity.created_at if self.activity.created_at |
29 | + self.updated_at = self.activity.updated_at if self.activity.updated_at | ||
30 | end | 30 | end |
31 | 31 | ||
32 | end | 32 | end |
app/models/profile_categorization.rb
1 | class ProfileCategorization < ActiveRecord::Base | 1 | class ProfileCategorization < ActiveRecord::Base |
2 | - set_table_name :categories_profiles | 2 | + self.table_name = :categories_profiles |
3 | belongs_to :profile | 3 | belongs_to :profile |
4 | belongs_to :category | 4 | belongs_to :category |
5 | 5 | ||
@@ -13,7 +13,7 @@ class ProfileCategorization < ActiveRecord::Base | @@ -13,7 +13,7 @@ class ProfileCategorization < ActiveRecord::Base | ||
13 | end | 13 | end |
14 | 14 | ||
15 | def self.remove_region(profile) | 15 | def self.remove_region(profile) |
16 | - region = profile.categories.find(:first, :conditions => { :type => [Region, State, City].map(&:name) }) | 16 | + region = profile.categories.where(type: [Region, State, City].map(&:name)).first |
17 | if region | 17 | if region |
18 | ids = region.hierarchy.map(&:id) | 18 | ids = region.hierarchy.map(&:id) |
19 | self.delete_all(:profile_id => profile.id, :category_id => ids) | 19 | self.delete_all(:profile_id => profile.id, :category_id => ids) |
app/models/profile_info_block.rb
1 | class ProfileInfoBlock < Block | 1 | class ProfileInfoBlock < Block |
2 | 2 | ||
3 | def self.description | 3 | def self.description |
4 | - _('Profile information') | 4 | + _('Display profile image and links to access initial homepage, control panel and profile activities.') |
5 | + end | ||
6 | + | ||
7 | + def self.short_description | ||
8 | + _('Show profile information') | ||
9 | + end | ||
10 | + | ||
11 | + def self.pretty_name | ||
12 | + _('Profile Information') | ||
5 | end | 13 | end |
6 | 14 | ||
7 | def help | 15 | def help |
app/models/profile_list_block.rb
@@ -16,7 +16,7 @@ class ProfileListBlock < Block | @@ -16,7 +16,7 @@ class ProfileListBlock < Block | ||
16 | 16 | ||
17 | def profile_list | 17 | def profile_list |
18 | result = nil | 18 | result = nil |
19 | - public_profiles = profiles.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.all(: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 |
@@ -28,7 +28,7 @@ result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at | @@ -28,7 +28,7 @@ result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at | ||
28 | end | 28 | end |
29 | 29 | ||
30 | def profile_count | 30 | def profile_count |
31 | - profiles.public.length | 31 | + profiles.is_public.length |
32 | end | 32 | end |
33 | 33 | ||
34 | # the title of the block. Probably will be overriden in subclasses. | 34 | # the title of the block. Probably will be overriden in subclasses. |