Commit 92fbfd944ae0d9f1f97a8d7ca7debcf293171a18
Exists in
theme-brasil-digital-from-staging
and in
4 other branches
Merge branch 'master_rails4' into staging
Conflicts: Gemfile Rakefile app/controllers/box_organizer_controller.rb app/controllers/my_profile/tasks_controller.rb app/controllers/public/profile_controller.rb app/mailers/user_mailer.rb app/models/article.rb app/models/person.rb app/models/product_category.rb app/models/task.rb config/application.rb config/routes.rb lib/acts_as_having_settings.rb lib/noosfero/api/entities.rb lib/noosfero/api/helpers.rb lib/noosfero/api/session.rb lib/noosfero/api/v1/articles.rb lib/noosfero/api/v1/contacts.rb lib/noosfero/api/v1/search.rb lib/noosfero/api/v1/users.rb test/functional/tasks_controller_test.rb test/unit/api/articles_test.rb test/unit/api/helpers_test.rb test/unit/api/people_test.rb test/unit/api/search_test.rb test/unit/api/session_test.rb test/unit/api/users_test.rb test/unit/person_notifier_test.rb test/unit/task_test.rb vendor/plugins/access_control/lib/acts_as_accessible.rb
Showing
1494 changed files
with
29787 additions
and
74185 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 1494 files displayed.
.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 |
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' | ||
13 | -#gem 'thin', '~> 1.3.1' | ||
14 | -gem 'nokogiri', '~> 1.6.0' | 18 | +gem 'daemons', '~> 1.1' |
15 | gem 'unicorn', '~> 4.8' | 19 | gem 'unicorn', '~> 4.8' |
16 | -#gem 'nokogiri', '~> 1.5.5' | 20 | +gem 'nokogiri', '~> 1.6.0' |
21 | +gem 'will_paginate' | ||
22 | +gem 'pothoven-attachment_fu', '~> 3.2.16' | ||
23 | +gem 'delayed_job' | ||
24 | +gem 'delayed_job_active_record' | ||
17 | gem 'rake', :require => false | 25 | gem 'rake', :require => false |
18 | -gem 'rest-client', '~> 1.6.7' | 26 | +gem 'rest-client', '~> 1.6' |
19 | gem 'exception_notification', '~> 4.0.1' | 27 | gem 'exception_notification', '~> 4.0.1' |
20 | -gem 'gettext', '~> 2.2.1', :require => false | ||
21 | -gem 'locale', '~> 2.0.5' | 28 | +gem 'gettext', '~> 3.1', :require => false |
29 | +gem 'locale', '~> 2.1' | ||
22 | gem 'whenever', :require => false | 30 | gem 'whenever', :require => false |
23 | -gem 'eita-jrails', '~> 0.9.5', require: 'jrails' | 31 | +gem 'eita-jrails', '~> 0.10.0', require: 'jrails' |
32 | +gem 'diffy', '~> 3.0' | ||
24 | 33 | ||
25 | # API dependencies | 34 | # API dependencies |
26 | gem 'grape', '~> 0.12' | 35 | gem 'grape', '~> 0.12' |
27 | gem 'grape-entity' | 36 | gem 'grape-entity' |
37 | +gem 'grape_logging' | ||
28 | gem 'grape-swagger' | 38 | gem 'grape-swagger' |
29 | gem 'swagger-ui_rails' | 39 | gem 'swagger-ui_rails' |
30 | gem 'kramdown' | 40 | gem 'kramdown' |
31 | - | ||
32 | -#FIXME Get the Grape Loggin from master yo solve this issue https://github.com/intridea/grape/issues/1059 | ||
33 | -#We have to remove this commit referenve code when update the next release of grape_logging. Actualy we are using (1.1.2) | ||
34 | -gem 'grape_logging', :git => 'https://github.com/aceunreal/grape_logging.git', :ref => 'f1755ae' | ||
35 | -#gem 'grape_logging' | ||
36 | gem 'rack-cors' | 41 | gem 'rack-cors' |
37 | gem 'rack-contrib' | 42 | gem 'rack-contrib' |
38 | gem 'liquid', '~> 3.0.3' | 43 | gem 'liquid', '~> 3.0.3' |
39 | -#gem 'grape-swagger-rails' | ||
40 | -gem 'rubyzip' | ||
41 | - | ||
42 | -gem 'execjs' | ||
43 | -gem 'therubyracer' | ||
44 | - | ||
45 | -# FIXME list here all actual dependencies (i.e. the ones in debian/control), | ||
46 | -# with their GEM names (not the Debian package names) | ||
47 | 44 | ||
48 | gem 'api-pagination', '~> 4.1.1' | 45 | gem 'api-pagination', '~> 4.1.1' |
49 | 46 | ||
50 | # asset pipeline | 47 | # asset pipeline |
51 | gem 'uglifier', '>= 1.0.3' | 48 | gem 'uglifier', '>= 1.0.3' |
52 | gem 'sass-rails' | 49 | gem 'sass-rails' |
53 | -gem 'sass', '~> 3.1.19' | 50 | + |
51 | +# gems to enable rails3 behaviour | ||
52 | +gem 'protected_attributes' | ||
53 | +gem 'rails-observers' | ||
54 | +gem 'actionpack-page_caching' | ||
55 | +gem 'actionpack-action_caching' | ||
56 | +gem 'activerecord-session_store' | ||
57 | +gem 'activerecord-deprecated_finders', require: 'active_record/deprecated_finders' | ||
54 | 58 | ||
55 | group :production do | 59 | group :production do |
56 | gem 'dalli', '~> 2.7.0' | 60 | gem 'dalli', '~> 2.7.0' |
57 | end | 61 | end |
58 | 62 | ||
63 | +group :development do | ||
64 | +end | ||
65 | + | ||
66 | +group :development, :test do | ||
67 | + gem 'spring' | ||
68 | +end | ||
69 | + | ||
59 | group :test do | 70 | group :test do |
60 | - gem 'rspec', '~> 2.14.0' | ||
61 | - gem 'rspec-rails', '~> 2.14.1' | 71 | + gem 'rspec', '~> 3.3', require: false |
72 | + gem 'rspec-rails', '~> 3.2', require: false | ||
62 | gem 'mocha', '~> 1.1.0', :require => false | 73 | gem 'mocha', '~> 1.1.0', :require => false |
74 | + gem 'test-unit' if RUBY_VERSION >= '2.2.0' | ||
75 | + gem 'minitest' | ||
76 | + gem 'minitest-reporters' | ||
63 | end | 77 | end |
64 | 78 | ||
65 | group :cucumber do | 79 | group :cucumber do |
66 | - gem 'cucumber-rails', '~> 1.0.6', :require => false | ||
67 | - gem 'capybara', '~> 2.1.0' | ||
68 | - gem 'cucumber', '~> 1.0.6' | ||
69 | - gem 'database_cleaner', '~> 1.2.0' | ||
70 | - gem 'selenium-webdriver', '~> 2.47.0' | 80 | + gem 'capybara', '~> 2.2' |
81 | + gem 'launchy' | ||
82 | + gem 'cucumber' | ||
83 | + gem 'cucumber-rails', '~> 1.4.2', :require => false | ||
84 | + gem 'database_cleaner', '~> 1.3' | ||
85 | + gem 'selenium-webdriver' | ||
71 | end | 86 | end |
72 | 87 | ||
73 | # Requires custom dependencies | 88 | # Requires custom dependencies |
74 | eval(File.read('config/Gemfile'), binding) rescue nil | 89 | eval(File.read('config/Gemfile'), binding) rescue nil |
75 | 90 | ||
91 | +vendor = Dir.glob('vendor/{,plugins/}*') - ['vendor/plugins'] | ||
92 | +vendor.each do |dir| | ||
93 | + plugin = File.basename dir | ||
94 | + version = if Dir.glob("#{dir}/*.gemspec").length > 0 then '> 0.0.0' else '0.0.0' end | ||
95 | + | ||
96 | + gem plugin, version, path: dir | ||
97 | +end | ||
98 | + | ||
76 | # include gemfiles from enabled plugins | 99 | # include gemfiles from enabled plugins |
77 | # plugins in baseplugins/ are not included on purpose. They should not have any | 100 | # plugins in baseplugins/ are not included on purpose. They should not have any |
78 | # dependencies. | 101 | # dependencies. |
Gemfile.lock
1 | -GIT | ||
2 | - remote: https://github.com/aceunreal/grape_logging.git | ||
3 | - revision: f1755ae4e1d897a65b20218d40681f59a9630f1b | ||
4 | - ref: f1755ae | 1 | +PATH |
2 | + remote: vendor/contacts | ||
5 | specs: | 3 | specs: |
6 | - grape_logging (1.1.2) | ||
7 | - grape | 4 | + contacts (1.2.0) |
5 | + gdata (>= 1.1.1) | ||
6 | + json (>= 1.1.1) | ||
7 | + | ||
8 | +PATH | ||
9 | + remote: vendor/ezcrypto | ||
10 | + specs: | ||
11 | + ezcrypto (0.0.0) | ||
12 | + | ||
13 | +PATH | ||
14 | + remote: vendor/gdata | ||
15 | + specs: | ||
16 | + gdata (1.1.1) | ||
17 | + | ||
18 | +PATH | ||
19 | + remote: vendor/plugins/access_control | ||
20 | + specs: | ||
21 | + access_control (0.0.0) | ||
22 | + | ||
23 | +PATH | ||
24 | + remote: vendor/plugins/action_tracker | ||
25 | + specs: | ||
26 | + action_tracker (0.0.1) | ||
27 | + | ||
28 | +PATH | ||
29 | + remote: vendor/plugins/action_tracker_has_comments | ||
30 | + specs: | ||
31 | + action_tracker_has_comments (0.0.0) | ||
32 | + | ||
33 | +PATH | ||
34 | + remote: vendor/plugins/acts_as_list | ||
35 | + specs: | ||
36 | + acts_as_list (0.0.0) | ||
37 | + | ||
38 | +PATH | ||
39 | + remote: vendor/plugins/acts_as_tree | ||
40 | + specs: | ||
41 | + acts_as_tree (0.0.0) | ||
42 | + | ||
43 | +PATH | ||
44 | + remote: vendor/plugins/acts_as_versioned | ||
45 | + specs: | ||
46 | + acts_as_versioned (3.2.1) | ||
47 | + activerecord | ||
48 | + | ||
49 | +PATH | ||
50 | + remote: vendor/plugins/honeypot | ||
51 | + specs: | ||
52 | + honeypot (0.0.0) | ||
53 | + | ||
54 | +PATH | ||
55 | + remote: vendor/plugins/i18n_deprecation | ||
56 | + specs: | ||
57 | + i18n_deprecation (0.0.0) | ||
58 | + | ||
59 | +PATH | ||
60 | + remote: vendor/plugins/kandadaboggu-vote_fu | ||
61 | + specs: | ||
62 | + kandadaboggu-vote_fu (0.0.15) | ||
63 | + | ||
64 | +PATH | ||
65 | + remote: vendor/plugins/monkey_patches | ||
66 | + specs: | ||
67 | + monkey_patches (0.0.0) | ||
68 | + | ||
69 | +PATH | ||
70 | + remote: vendor/plugins/noosfero_caching | ||
71 | + specs: | ||
72 | + noosfero_caching (0.0.0) | ||
73 | + | ||
74 | +PATH | ||
75 | + remote: vendor/plugins/rails_rcov | ||
76 | + specs: | ||
77 | + rails_rcov (0.0.0) | ||
78 | + | ||
79 | +PATH | ||
80 | + remote: vendor/plugins/recaptcha | ||
81 | + specs: | ||
82 | + recaptcha (0.3.2) | ||
83 | + i18n | ||
84 | + | ||
85 | +PATH | ||
86 | + remote: vendor/plugins/ruby_bosh | ||
87 | + specs: | ||
88 | + ruby_bosh (0.5.4) | ||
89 | + builder | ||
90 | + rest-client | ||
91 | + | ||
92 | +PATH | ||
93 | + remote: vendor/plugins/validates_as_cnpj | ||
94 | + specs: | ||
95 | + validates_as_cnpj (0.0.0) | ||
96 | + | ||
97 | +PATH | ||
98 | + remote: vendor/plugins/validates_multiparameter_assignments | ||
99 | + specs: | ||
100 | + validates_multiparameter_assignments (0.0.0) | ||
101 | + | ||
102 | +PATH | ||
103 | + remote: vendor/plugins/xss_terminate | ||
104 | + specs: | ||
105 | + xss_terminate (0.0.0) | ||
8 | 106 | ||
9 | GEM | 107 | GEM |
10 | remote: https://rubygems.org/ | 108 | remote: https://rubygems.org/ |
11 | specs: | 109 | specs: |
12 | RedCloth (4.2.9) | 110 | RedCloth (4.2.9) |
13 | - actionmailer (3.2.22) | ||
14 | - actionpack (= 3.2.22) | ||
15 | - mail (~> 2.5.4) | ||
16 | - actionpack (3.2.22) | ||
17 | - activemodel (= 3.2.22) | ||
18 | - activesupport (= 3.2.22) | ||
19 | - builder (~> 3.0.0) | 111 | + actionmailer (4.2.5) |
112 | + actionpack (= 4.2.5) | ||
113 | + actionview (= 4.2.5) | ||
114 | + activejob (= 4.2.5) | ||
115 | + mail (~> 2.5, >= 2.5.4) | ||
116 | + rails-dom-testing (~> 1.0, >= 1.0.5) | ||
117 | + actionpack (4.2.5) | ||
118 | + actionview (= 4.2.5) | ||
119 | + activesupport (= 4.2.5) | ||
120 | + rack (~> 1.6) | ||
121 | + rack-test (~> 0.6.2) | ||
122 | + rails-dom-testing (~> 1.0, >= 1.0.5) | ||
123 | + rails-html-sanitizer (~> 1.0, >= 1.0.2) | ||
124 | + actionpack-action_caching (1.1.1) | ||
125 | + actionpack (>= 4.0.0, < 5.0) | ||
126 | + actionpack-page_caching (1.0.2) | ||
127 | + actionpack (>= 4.0.0, < 5) | ||
128 | + actionview (4.2.5) | ||
129 | + activesupport (= 4.2.5) | ||
130 | + builder (~> 3.1) | ||
20 | erubis (~> 2.7.0) | 131 | erubis (~> 2.7.0) |
21 | - journey (~> 1.0.4) | ||
22 | - rack (~> 1.4.5) | ||
23 | - rack-cache (~> 1.2) | ||
24 | - rack-test (~> 0.6.1) | ||
25 | - sprockets (~> 2.2.1) | ||
26 | - activemodel (3.2.22) | ||
27 | - activesupport (= 3.2.22) | ||
28 | - builder (~> 3.0.0) | ||
29 | - activerecord (3.2.22) | ||
30 | - activemodel (= 3.2.22) | ||
31 | - activesupport (= 3.2.22) | ||
32 | - arel (~> 3.0.2) | ||
33 | - tzinfo (~> 0.3.29) | ||
34 | - activeresource (3.2.22) | ||
35 | - activemodel (= 3.2.22) | ||
36 | - activesupport (= 3.2.22) | ||
37 | - activesupport (3.2.22) | ||
38 | - i18n (~> 0.6, >= 0.6.4) | ||
39 | - multi_json (~> 1.0) | ||
40 | - acts-as-taggable-on (3.4.4) | 132 | + rails-dom-testing (~> 1.0, >= 1.0.5) |
133 | + rails-html-sanitizer (~> 1.0, >= 1.0.2) | ||
134 | + activejob (4.2.5) | ||
135 | + activesupport (= 4.2.5) | ||
136 | + globalid (>= 0.3.0) | ||
137 | + activemodel (4.2.5) | ||
138 | + activesupport (= 4.2.5) | ||
139 | + builder (~> 3.1) | ||
140 | + activerecord (4.2.5) | ||
141 | + activemodel (= 4.2.5) | ||
142 | + activesupport (= 4.2.5) | ||
143 | + arel (~> 6.0) | ||
144 | + activerecord-deprecated_finders (1.0.4) | ||
145 | + activerecord-session_store (0.1.2) | ||
146 | + actionpack (>= 4.0.0, < 5) | ||
147 | + activerecord (>= 4.0.0, < 5) | ||
148 | + railties (>= 4.0.0, < 5) | ||
149 | + activesupport (4.2.5) | ||
150 | + i18n (~> 0.7) | ||
151 | + json (~> 1.7, >= 1.7.7) | ||
152 | + minitest (~> 5.1) | ||
153 | + thread_safe (~> 0.3, >= 0.3.4) | ||
154 | + tzinfo (~> 1.1) | ||
155 | + acts-as-taggable-on (3.5.0) | ||
41 | activerecord (>= 3.2, < 5) | 156 | activerecord (>= 3.2, < 5) |
157 | + addressable (2.3.8) | ||
158 | + ansi (1.5.0) | ||
42 | api-pagination (4.1.1) | 159 | api-pagination (4.1.1) |
43 | - arel (3.0.3) | 160 | + arel (6.0.3) |
44 | axiom-types (0.1.1) | 161 | axiom-types (0.1.1) |
45 | descendants_tracker (~> 0.0.4) | 162 | descendants_tracker (~> 0.0.4) |
46 | ice_nine (~> 0.11.0) | 163 | ice_nine (~> 0.11.0) |
47 | thread_safe (~> 0.3, >= 0.3.1) | 164 | thread_safe (~> 0.3, >= 0.3.1) |
48 | - builder (3.0.4) | ||
49 | - capybara (2.1.0) | 165 | + builder (3.2.2) |
166 | + capybara (2.5.0) | ||
50 | mime-types (>= 1.16) | 167 | mime-types (>= 1.16) |
51 | nokogiri (>= 1.3.3) | 168 | nokogiri (>= 1.3.3) |
52 | rack (>= 1.0.0) | 169 | rack (>= 1.0.0) |
53 | rack-test (>= 0.5.4) | 170 | rack-test (>= 0.5.4) |
54 | xpath (~> 2.0) | 171 | xpath (~> 2.0) |
55 | - childprocess (0.5.6) | 172 | + childprocess (0.5.8) |
56 | ffi (~> 1.0, >= 1.0.11) | 173 | ffi (~> 1.0, >= 1.0.11) |
57 | chronic (0.10.2) | 174 | chronic (0.10.2) |
58 | coercible (1.0.0) | 175 | coercible (1.0.0) |
59 | descendants_tracker (~> 0.0.1) | 176 | descendants_tracker (~> 0.0.1) |
60 | - cucumber (1.0.6) | 177 | + cucumber (1.3.20) |
61 | builder (>= 2.1.2) | 178 | builder (>= 2.1.2) |
62 | - diff-lcs (>= 1.1.2) | ||
63 | - gherkin (~> 2.4.18) | ||
64 | - json (>= 1.4.6) | ||
65 | - term-ansicolor (>= 1.0.6) | ||
66 | - cucumber-rails (1.0.6) | ||
67 | - capybara (>= 1.1.1) | ||
68 | - cucumber (>= 1.0.6) | ||
69 | - nokogiri (>= 1.5.0) | ||
70 | - daemons (1.1.9) | 179 | + diff-lcs (>= 1.1.3) |
180 | + gherkin (~> 2.12) | ||
181 | + multi_json (>= 1.7.5, < 2.0) | ||
182 | + multi_test (>= 0.1.2) | ||
183 | + cucumber-rails (1.4.2) | ||
184 | + capybara (>= 1.1.2, < 3) | ||
185 | + cucumber (>= 1.3.8, < 2) | ||
186 | + mime-types (>= 1.16, < 3) | ||
187 | + nokogiri (~> 1.5) | ||
188 | + rails (>= 3, < 5) | ||
189 | + daemons (1.2.3) | ||
71 | dalli (2.7.4) | 190 | dalli (2.7.4) |
72 | - database_cleaner (1.2.0) | 191 | + database_cleaner (1.5.1) |
192 | + delayed_job (4.1.1) | ||
193 | + activesupport (>= 3.0, < 5.0) | ||
194 | + delayed_job_active_record (4.1.0) | ||
195 | + activerecord (>= 3.0, < 5) | ||
196 | + delayed_job (>= 3.0, < 5) | ||
73 | descendants_tracker (0.0.4) | 197 | descendants_tracker (0.0.4) |
74 | thread_safe (~> 0.3, >= 0.3.1) | 198 | thread_safe (~> 0.3, >= 0.3.1) |
75 | diff-lcs (1.2.5) | 199 | diff-lcs (1.2.5) |
76 | - eita-jrails (0.9.8) | 200 | + diffy (3.0.7) |
201 | + domain_name (0.5.25) | ||
202 | + unf (>= 0.0.5, < 1.0.0) | ||
203 | + eita-jrails (0.10.0) | ||
77 | actionpack (>= 3.1.0) | 204 | actionpack (>= 3.1.0) |
78 | activesupport (>= 3.0.0) | 205 | activesupport (>= 3.0.0) |
79 | equalizer (0.0.11) | 206 | equalizer (0.0.11) |
@@ -82,13 +209,16 @@ GEM | @@ -82,13 +209,16 @@ GEM | ||
82 | actionmailer (>= 3.0.4) | 209 | actionmailer (>= 3.0.4) |
83 | activesupport (>= 3.0.4) | 210 | activesupport (>= 3.0.4) |
84 | execjs (2.6.0) | 211 | execjs (2.6.0) |
85 | - fast_gettext (0.6.12) | 212 | + fast_gettext (0.9.2) |
86 | ffi (1.9.10) | 213 | ffi (1.9.10) |
87 | - gettext (2.2.1) | ||
88 | - locale | ||
89 | - gherkin (2.4.21) | ||
90 | - json (>= 1.4.6) | 214 | + gettext (3.1.7) |
215 | + locale (>= 2.0.5) | ||
216 | + text (>= 1.3.0) | ||
217 | + gherkin (2.12.2) | ||
218 | + multi_json (~> 1.3) | ||
91 | git-version-bump (0.15.1) | 219 | git-version-bump (0.15.1) |
220 | + globalid (0.3.6) | ||
221 | + activesupport (>= 4.1.0) | ||
92 | grape (0.13.0) | 222 | grape (0.13.0) |
93 | activesupport | 223 | activesupport |
94 | builder | 224 | builder |
@@ -105,125 +235,153 @@ GEM | @@ -105,125 +235,153 @@ GEM | ||
105 | grape-swagger (0.10.2) | 235 | grape-swagger (0.10.2) |
106 | grape (>= 0.8.0) | 236 | grape (>= 0.8.0) |
107 | grape-entity | 237 | grape-entity |
108 | - hashie (3.4.2) | ||
109 | - hike (1.2.3) | 238 | + grape_logging (1.1.2) |
239 | + grape | ||
240 | + hashie (3.4.3) | ||
241 | + http-cookie (1.0.2) | ||
242 | + domain_name (~> 0.5) | ||
110 | i18n (0.7.0) | 243 | i18n (0.7.0) |
111 | ice_nine (0.11.1) | 244 | ice_nine (0.11.1) |
112 | - journey (1.0.4) | ||
113 | json (1.8.3) | 245 | json (1.8.3) |
114 | kgio (2.10.0) | 246 | kgio (2.10.0) |
115 | kramdown (1.9.0) | 247 | kramdown (1.9.0) |
116 | - libv8 (3.16.14.11) | 248 | + launchy (2.4.3) |
249 | + addressable (~> 2.3) | ||
117 | liquid (3.0.6) | 250 | liquid (3.0.6) |
118 | - locale (2.0.9) | 251 | + locale (2.1.2) |
252 | + loofah (2.0.3) | ||
253 | + nokogiri (>= 1.5.9) | ||
119 | magic (0.2.9) | 254 | magic (0.2.9) |
120 | ffi (>= 0.6.3) | 255 | ffi (>= 0.6.3) |
121 | - mail (2.5.4) | ||
122 | - mime-types (~> 1.16) | ||
123 | - treetop (~> 1.4.8) | 256 | + mail (2.6.3) |
257 | + mime-types (>= 1.16, < 3) | ||
124 | metaclass (0.0.4) | 258 | metaclass (0.0.4) |
125 | - mime-types (1.25.1) | 259 | + mime-types (2.6.2) |
126 | mini_portile (0.6.2) | 260 | mini_portile (0.6.2) |
127 | - minitest (3.2.0) | 261 | + minitest (5.8.2) |
262 | + minitest-reporters (1.1.5) | ||
263 | + ansi | ||
264 | + builder | ||
265 | + minitest (>= 5.0) | ||
266 | + ruby-progressbar | ||
128 | mocha (1.1.0) | 267 | mocha (1.1.0) |
129 | metaclass (~> 0.0.1) | 268 | metaclass (~> 0.0.1) |
130 | multi_json (1.11.2) | 269 | multi_json (1.11.2) |
270 | + multi_test (0.1.2) | ||
131 | multi_xml (0.5.5) | 271 | multi_xml (0.5.5) |
272 | + netrc (0.11.0) | ||
132 | nokogiri (1.6.6.2) | 273 | nokogiri (1.6.6.2) |
133 | mini_portile (~> 0.6.0) | 274 | mini_portile (~> 0.6.0) |
134 | - pg (0.13.2) | ||
135 | - polyglot (0.3.5) | ||
136 | - rack (1.4.7) | 275 | + pg (0.18.4) |
276 | + pothoven-attachment_fu (3.2.16) | ||
277 | + power_assert (0.2.6) | ||
278 | + protected_attributes (1.1.3) | ||
279 | + activemodel (>= 4.0.1, < 5.0) | ||
280 | + rack (1.6.4) | ||
137 | rack-accept (0.4.5) | 281 | rack-accept (0.4.5) |
138 | rack (>= 0.4) | 282 | rack (>= 0.4) |
139 | - rack-cache (1.5.0) | ||
140 | - rack (>= 0.4) | ||
141 | rack-contrib (1.4.0) | 283 | rack-contrib (1.4.0) |
142 | git-version-bump (~> 0.15) | 284 | git-version-bump (~> 0.15) |
143 | rack (~> 1.4) | 285 | rack (~> 1.4) |
144 | rack-cors (0.4.0) | 286 | rack-cors (0.4.0) |
145 | rack-mount (0.8.3) | 287 | rack-mount (0.8.3) |
146 | rack (>= 1.0.0) | 288 | rack (>= 1.0.0) |
147 | - rack-ssl (1.3.4) | ||
148 | - rack | ||
149 | rack-test (0.6.3) | 289 | rack-test (0.6.3) |
150 | rack (>= 1.0) | 290 | rack (>= 1.0) |
151 | - rails (3.2.22) | ||
152 | - actionmailer (= 3.2.22) | ||
153 | - actionpack (= 3.2.22) | ||
154 | - activerecord (= 3.2.22) | ||
155 | - activeresource (= 3.2.22) | ||
156 | - activesupport (= 3.2.22) | ||
157 | - bundler (~> 1.0) | ||
158 | - railties (= 3.2.22) | 291 | + rails (4.2.5) |
292 | + actionmailer (= 4.2.5) | ||
293 | + actionpack (= 4.2.5) | ||
294 | + actionview (= 4.2.5) | ||
295 | + activejob (= 4.2.5) | ||
296 | + activemodel (= 4.2.5) | ||
297 | + activerecord (= 4.2.5) | ||
298 | + activesupport (= 4.2.5) | ||
299 | + bundler (>= 1.3.0, < 2.0) | ||
300 | + railties (= 4.2.5) | ||
301 | + sprockets-rails | ||
302 | + rails-deprecated_sanitizer (1.0.3) | ||
303 | + activesupport (>= 4.2.0.alpha) | ||
304 | + rails-dom-testing (1.0.7) | ||
305 | + activesupport (>= 4.2.0.beta, < 5.0) | ||
306 | + nokogiri (~> 1.6.0) | ||
307 | + rails-deprecated_sanitizer (>= 1.0.1) | ||
308 | + rails-html-sanitizer (1.0.2) | ||
309 | + loofah (~> 2.0) | ||
310 | + rails-observers (0.1.2) | ||
311 | + activemodel (~> 4.0) | ||
159 | rails_autolink (1.1.6) | 312 | rails_autolink (1.1.6) |
160 | rails (> 3.1) | 313 | rails (> 3.1) |
161 | - railties (3.2.22) | ||
162 | - actionpack (= 3.2.22) | ||
163 | - activesupport (= 3.2.22) | ||
164 | - rack-ssl (~> 1.3.2) | 314 | + railties (4.2.5) |
315 | + actionpack (= 4.2.5) | ||
316 | + activesupport (= 4.2.5) | ||
165 | rake (>= 0.8.7) | 317 | rake (>= 0.8.7) |
166 | - rdoc (~> 3.4) | ||
167 | - thor (>= 0.14.6, < 2.0) | 318 | + thor (>= 0.18.1, < 2.0) |
168 | raindrops (0.15.0) | 319 | raindrops (0.15.0) |
169 | rake (10.4.2) | 320 | rake (10.4.2) |
170 | - rdoc (3.12.2) | ||
171 | - json (~> 1.4) | ||
172 | - ref (2.0.0) | ||
173 | - rest-client (1.6.9) | ||
174 | - mime-types (~> 1.16) | ||
175 | - rmagick (2.13.4) | ||
176 | - rspec (2.14.1) | ||
177 | - rspec-core (~> 2.14.0) | ||
178 | - rspec-expectations (~> 2.14.0) | ||
179 | - rspec-mocks (~> 2.14.0) | ||
180 | - rspec-core (2.14.8) | ||
181 | - rspec-expectations (2.14.5) | ||
182 | - diff-lcs (>= 1.1.3, < 2.0) | ||
183 | - rspec-mocks (2.14.6) | ||
184 | - rspec-rails (2.14.2) | ||
185 | - actionpack (>= 3.0) | ||
186 | - activemodel (>= 3.0) | ||
187 | - activesupport (>= 3.0) | ||
188 | - railties (>= 3.0) | ||
189 | - rspec-core (~> 2.14.0) | ||
190 | - rspec-expectations (~> 2.14.0) | ||
191 | - rspec-mocks (~> 2.14.0) | 321 | + rest-client (1.8.0) |
322 | + http-cookie (>= 1.0.2, < 2.0) | ||
323 | + mime-types (>= 1.16, < 3.0) | ||
324 | + netrc (~> 0.7) | ||
325 | + rmagick (2.15.4) | ||
326 | + rspec (3.4.0) | ||
327 | + rspec-core (~> 3.4.0) | ||
328 | + rspec-expectations (~> 3.4.0) | ||
329 | + rspec-mocks (~> 3.4.0) | ||
330 | + rspec-core (3.4.0) | ||
331 | + rspec-support (~> 3.4.0) | ||
332 | + rspec-expectations (3.4.0) | ||
333 | + diff-lcs (>= 1.2.0, < 2.0) | ||
334 | + rspec-support (~> 3.4.0) | ||
335 | + rspec-mocks (3.4.0) | ||
336 | + diff-lcs (>= 1.2.0, < 2.0) | ||
337 | + rspec-support (~> 3.4.0) | ||
338 | + rspec-rails (3.4.0) | ||
339 | + actionpack (>= 3.0, < 4.3) | ||
340 | + activesupport (>= 3.0, < 4.3) | ||
341 | + railties (>= 3.0, < 4.3) | ||
342 | + rspec-core (~> 3.4.0) | ||
343 | + rspec-expectations (~> 3.4.0) | ||
344 | + rspec-mocks (~> 3.4.0) | ||
345 | + rspec-support (~> 3.4.0) | ||
346 | + rspec-support (3.4.0) | ||
192 | ruby-feedparser (0.9.3) | 347 | ruby-feedparser (0.9.3) |
193 | magic | 348 | magic |
349 | + ruby-progressbar (1.7.5) | ||
194 | rubyzip (1.1.7) | 350 | rubyzip (1.1.7) |
195 | - sass (3.1.21) | ||
196 | - sass-rails (3.2.6) | ||
197 | - railties (~> 3.2.0) | ||
198 | - sass (>= 3.1.10) | ||
199 | - tilt (~> 1.3) | ||
200 | - selenium-webdriver (2.47.1) | 351 | + sass (3.4.19) |
352 | + sass-rails (5.0.4) | ||
353 | + railties (>= 4.0.0, < 5.0) | ||
354 | + sass (~> 3.1) | ||
355 | + sprockets (>= 2.8, < 4.0) | ||
356 | + sprockets-rails (>= 2.0, < 4.0) | ||
357 | + tilt (>= 1.1, < 3) | ||
358 | + selenium-webdriver (2.48.1) | ||
201 | childprocess (~> 0.5) | 359 | childprocess (~> 0.5) |
202 | multi_json (~> 1.0) | 360 | multi_json (~> 1.0) |
203 | rubyzip (~> 1.0) | 361 | rubyzip (~> 1.0) |
204 | websocket (~> 1.0) | 362 | websocket (~> 1.0) |
205 | - sprockets (2.2.3) | ||
206 | - hike (~> 1.2) | ||
207 | - multi_json (~> 1.0) | ||
208 | - rack (~> 1.0) | ||
209 | - tilt (~> 1.1, != 1.3.0) | 363 | + spring (1.4.1) |
364 | + sprockets (3.4.0) | ||
365 | + rack (> 1, < 3) | ||
366 | + sprockets-rails (2.3.3) | ||
367 | + actionpack (>= 3.0) | ||
368 | + activesupport (>= 3.0) | ||
369 | + sprockets (>= 2.8, < 4.0) | ||
210 | swagger-ui_rails (0.1.7) | 370 | swagger-ui_rails (0.1.7) |
211 | - term-ansicolor (1.3.2) | ||
212 | - tins (~> 1.0) | ||
213 | - therubyracer (0.12.2) | ||
214 | - libv8 (~> 3.16.14.0) | ||
215 | - ref | 371 | + test-unit (3.1.5) |
372 | + power_assert | ||
373 | + text (1.3.1) | ||
216 | thor (0.19.1) | 374 | thor (0.19.1) |
217 | thread_safe (0.3.5) | 375 | thread_safe (0.3.5) |
218 | - tilt (1.4.1) | ||
219 | - tins (1.6.0) | ||
220 | - treetop (1.4.15) | ||
221 | - polyglot | ||
222 | - polyglot (>= 0.3.1) | ||
223 | - tzinfo (0.3.45) | 376 | + tilt (2.0.1) |
377 | + tzinfo (1.2.2) | ||
378 | + thread_safe (~> 0.1) | ||
224 | uglifier (2.7.2) | 379 | uglifier (2.7.2) |
225 | execjs (>= 0.3.0) | 380 | execjs (>= 0.3.0) |
226 | json (>= 1.8.0) | 381 | json (>= 1.8.0) |
382 | + unf (0.1.4) | ||
383 | + unf_ext | ||
384 | + unf_ext (0.0.7.1) | ||
227 | unicorn (4.9.0) | 385 | unicorn (4.9.0) |
228 | kgio (~> 2.6) | 386 | kgio (~> 2.6) |
229 | rack | 387 | rack |
@@ -244,48 +402,80 @@ PLATFORMS | @@ -244,48 +402,80 @@ PLATFORMS | ||
244 | ruby | 402 | ruby |
245 | 403 | ||
246 | DEPENDENCIES | 404 | DEPENDENCIES |
247 | - RedCloth (~> 4.2.9) | ||
248 | - acts-as-taggable-on (~> 3.4.2) | 405 | + RedCloth (~> 4.2) |
406 | + access_control (= 0.0.0)! | ||
407 | + action_tracker (> 0.0.0)! | ||
408 | + action_tracker_has_comments (= 0.0.0)! | ||
409 | + actionpack-action_caching | ||
410 | + actionpack-page_caching | ||
411 | + activerecord-deprecated_finders | ||
412 | + activerecord-jdbcpostgresql-adapter | ||
413 | + activerecord-session_store | ||
414 | + acts-as-taggable-on (~> 3.5) | ||
415 | + acts_as_list (= 0.0.0)! | ||
416 | + acts_as_tree (= 0.0.0)! | ||
417 | + acts_as_versioned (> 0.0.0)! | ||
249 | api-pagination (~> 4.1.1) | 418 | api-pagination (~> 4.1.1) |
250 | - capybara (~> 2.1.0) | ||
251 | - cucumber (~> 1.0.6) | ||
252 | - cucumber-rails (~> 1.0.6) | ||
253 | - daemons (~> 1.1.5) | 419 | + capybara (~> 2.2) |
420 | + contacts (> 0.0.0)! | ||
421 | + cucumber | ||
422 | + cucumber-rails (~> 1.4.2) | ||
423 | + daemons (~> 1.1) | ||
254 | dalli (~> 2.7.0) | 424 | dalli (~> 2.7.0) |
255 | - database_cleaner (~> 1.2.0) | ||
256 | - eita-jrails (~> 0.9.5) | 425 | + database_cleaner (~> 1.3) |
426 | + delayed_job | ||
427 | + delayed_job_active_record | ||
428 | + diffy (~> 3.0) | ||
429 | + eita-jrails (~> 0.10.0) | ||
257 | exception_notification (~> 4.0.1) | 430 | exception_notification (~> 4.0.1) |
258 | - execjs | ||
259 | - fast_gettext (~> 0.6.8) | ||
260 | - gettext (~> 2.2.1) | 431 | + ezcrypto (= 0.0.0)! |
432 | + fast_gettext (~> 0.9) | ||
433 | + gdata (> 0.0.0)! | ||
434 | + gettext (~> 3.1) | ||
261 | grape (~> 0.12) | 435 | grape (~> 0.12) |
262 | grape-entity | 436 | grape-entity |
263 | grape-swagger | 437 | grape-swagger |
264 | - grape_logging! | 438 | + grape_logging |
439 | + honeypot (= 0.0.0)! | ||
440 | + i18n_deprecation (= 0.0.0)! | ||
441 | + kandadaboggu-vote_fu (> 0.0.0)! | ||
265 | kramdown | 442 | kramdown |
443 | + launchy | ||
266 | liquid (~> 3.0.3) | 444 | liquid (~> 3.0.3) |
267 | - locale (~> 2.0.5) | ||
268 | - minitest (~> 3.2.0) | 445 | + locale (~> 2.1) |
446 | + minitest | ||
447 | + minitest-reporters | ||
269 | mocha (~> 1.1.0) | 448 | mocha (~> 1.1.0) |
449 | + monkey_patches (= 0.0.0)! | ||
270 | nokogiri (~> 1.6.0) | 450 | nokogiri (~> 1.6.0) |
271 | - pg (~> 0.13.2) | 451 | + noosfero_caching (= 0.0.0)! |
452 | + pg (~> 0.17) | ||
453 | + pothoven-attachment_fu (~> 3.2.16) | ||
454 | + protected_attributes | ||
272 | rack-contrib | 455 | rack-contrib |
273 | rack-cors | 456 | rack-cors |
274 | - rails (~> 3.2.22) | 457 | + rails (~> 4.2.4) |
458 | + rails-observers | ||
275 | rails_autolink (~> 1.1.5) | 459 | rails_autolink (~> 1.1.5) |
460 | + rails_rcov (= 0.0.0)! | ||
276 | rake | 461 | rake |
277 | - rest-client (~> 1.6.7) | ||
278 | - rmagick (~> 2.13.1) | ||
279 | - rspec (~> 2.14.0) | ||
280 | - rspec-rails (~> 2.14.1) | 462 | + recaptcha (> 0.0.0)! |
463 | + rest-client (~> 1.6) | ||
464 | + rmagick (~> 2.13) | ||
465 | + rmagick4j | ||
466 | + rspec (~> 3.3) | ||
467 | + rspec-rails (~> 3.2) | ||
281 | ruby-feedparser (~> 0.7) | 468 | ruby-feedparser (~> 0.7) |
282 | - rubyzip | ||
283 | - sass (~> 3.1.19) | 469 | + ruby_bosh (> 0.0.0)! |
284 | sass-rails | 470 | sass-rails |
285 | - selenium-webdriver (~> 2.47.0) | 471 | + selenium-webdriver |
472 | + spring | ||
286 | swagger-ui_rails | 473 | swagger-ui_rails |
287 | - therubyracer | 474 | + test-unit |
288 | uglifier (>= 1.0.3) | 475 | uglifier (>= 1.0.3) |
289 | unicorn (~> 4.8) | 476 | unicorn (~> 4.8) |
477 | + validates_as_cnpj (= 0.0.0)! | ||
478 | + validates_multiparameter_assignments (= 0.0.0)! | ||
290 | whenever | 479 | whenever |
291 | - will_paginate (~> 3.0.3) | 480 | + will_paginate |
481 | + xss_terminate (= 0.0.0)! |
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
@@ -36,7 +36,7 @@ class FeaturesController < AdminController | @@ -36,7 +36,7 @@ class FeaturesController < AdminController | ||
36 | 36 | ||
37 | post_only :update | 37 | post_only :update |
38 | def update | 38 | def update |
39 | - if @environment.update_attributes(params[:environment]) | 39 | + if @environment.update(params[:environment]) |
40 | session[:notice] = _('Features updated successfully.') | 40 | session[:notice] = _('Features updated successfully.') |
41 | redirect_to :action => 'index' | 41 | redirect_to :action => 'index' |
42 | else | 42 | else |
@@ -93,7 +93,7 @@ class FeaturesController < AdminController | @@ -93,7 +93,7 @@ class FeaturesController < AdminController | ||
93 | 93 | ||
94 | def search_members | 94 | def search_members |
95 | arg = params[:q].downcase | 95 | arg = params[:q].downcase |
96 | - result = environment.people.find(:all, :conditions => ['LOWER(name) LIKE ? OR identifier LIKE ?', "%#{arg}%", "%#{arg}%"]) | 96 | + result = environment.people.where('LOWER(name) LIKE ? OR identifier LIKE ?', "%#{arg}%", "%#{arg}%") |
97 | render :text => prepare_to_token_input(result).to_json | 97 | render :text => prepare_to_token_input(result).to_json |
98 | end | 98 | end |
99 | 99 |
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] |
@@ -50,7 +50,7 @@ class ApplicationController < ActionController::Base | @@ -50,7 +50,7 @@ class ApplicationController < ActionController::Base | ||
50 | include ApplicationHelper | 50 | include ApplicationHelper |
51 | layout :get_layout | 51 | layout :get_layout |
52 | def get_layout | 52 | def get_layout |
53 | - return nil if request.format == :js or request.xhr? | 53 | + return false if request.format == :js or request.xhr? |
54 | 54 | ||
55 | theme_layout = theme_option(:layout) | 55 | theme_layout = theme_option(:layout) |
56 | if theme_layout | 56 | if theme_layout |
@@ -74,15 +74,12 @@ class ApplicationController < ActionController::Base | @@ -74,15 +74,12 @@ class ApplicationController < ActionController::Base | ||
74 | helper :language | 74 | helper :language |
75 | 75 | ||
76 | include DesignHelper | 76 | include DesignHelper |
77 | - | ||
78 | - # Be sure to include AuthenticationSystem in Application Controller instead | ||
79 | - include AuthenticatedSystem | ||
80 | include PermissionCheck | 77 | include PermissionCheck |
81 | 78 | ||
82 | before_filter :set_locale | 79 | before_filter :set_locale |
83 | def set_locale | 80 | def set_locale |
84 | FastGettext.available_locales = environment.available_locales | 81 | FastGettext.available_locales = environment.available_locales |
85 | - FastGettext.default_locale = environment.default_locale | 82 | + FastGettext.default_locale = environment.default_locale || 'en' |
86 | FastGettext.locale = (params[:lang] || session[:lang] || environment.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') | 83 | FastGettext.locale = (params[:lang] || session[:lang] || environment.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') |
87 | I18n.locale = FastGettext.locale.to_s.gsub '_', '-' | 84 | I18n.locale = FastGettext.locale.to_s.gsub '_', '-' |
88 | I18n.default_locale = FastGettext.default_locale.to_s.gsub '_', '-' | 85 | I18n.default_locale = FastGettext.default_locale.to_s.gsub '_', '-' |
@@ -153,7 +150,7 @@ class ApplicationController < ActionController::Base | @@ -153,7 +150,7 @@ class ApplicationController < ActionController::Base | ||
153 | # Check if the requested profile belongs to another domain | 150 | # Check if the requested profile belongs to another domain |
154 | if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier | 151 | if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier |
155 | @profile = @environment.profiles.find_by_identifier params[:profile] | 152 | @profile = @environment.profiles.find_by_identifier params[:profile] |
156 | - redirect_to params.merge(:host => @profile.default_hostname) | 153 | + redirect_to url_for(params.merge host: @profile.default_hostname) |
157 | end | 154 | end |
158 | end | 155 | end |
159 | end | 156 | end |
@@ -168,7 +165,8 @@ class ApplicationController < ActionController::Base | @@ -168,7 +165,8 @@ class ApplicationController < ActionController::Base | ||
168 | def render_not_found(path = nil) | 165 | def render_not_found(path = nil) |
169 | @no_design_blocks = true | 166 | @no_design_blocks = true |
170 | @path ||= request.path | 167 | @path ||= request.path |
171 | - render :template => 'shared/not_found.html.erb', :status => 404, :layout => get_layout | 168 | + # force html template even if the browser asked for a image |
169 | + render template: 'shared/not_found', status: 404, layout: get_layout, formats: [:html] | ||
172 | end | 170 | end |
173 | alias :render_404 :render_not_found | 171 | alias :render_404 :render_not_found |
174 | 172 | ||
@@ -176,7 +174,8 @@ class ApplicationController < ActionController::Base | @@ -176,7 +174,8 @@ class ApplicationController < ActionController::Base | ||
176 | @no_design_blocks = true | 174 | @no_design_blocks = true |
177 | @message = message | 175 | @message = message |
178 | @title = title | 176 | @title = title |
179 | - render :template => 'shared/access_denied.html.erb', :status => 403 | 177 | + # force html template even if the browser asked for a image |
178 | + render template: 'shared/access_denied', status: 403, formats: [:html] | ||
180 | end | 179 | end |
181 | 180 | ||
182 | def load_category | 181 | def load_category |
@@ -190,13 +189,7 @@ class ApplicationController < ActionController::Base | @@ -190,13 +189,7 @@ class ApplicationController < ActionController::Base | ||
190 | end | 189 | end |
191 | 190 | ||
192 | include SearchTermHelper | 191 | include SearchTermHelper |
193 | - | ||
194 | - def find_by_contents(asset, context, scope, query, paginate_options={:page => 1}, options={}) | ||
195 | - scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank? | ||
196 | - search = plugins.dispatch_first(:find_by_contents, asset, scope, query, paginate_options, options) | ||
197 | - register_search_term(query, scope.count, search[:results].count, context, asset) | ||
198 | - search | ||
199 | - end | 192 | + include FindByContents |
200 | 193 | ||
201 | def find_suggestions(query, context, asset, options={}) | 194 | def find_suggestions(query, context, asset, options={}) |
202 | plugins.dispatch_first(:find_suggestions, query, context, asset, options) | 195 | plugins.dispatch_first(:find_suggestions, query, context, asset, options) |
@@ -209,7 +202,7 @@ class ApplicationController < ActionController::Base | @@ -209,7 +202,7 @@ class ApplicationController < ActionController::Base | ||
209 | def redirect_to_current_user | 202 | def redirect_to_current_user |
210 | if params[:profile] == '~' | 203 | if params[:profile] == '~' |
211 | if logged_in? | 204 | if logged_in? |
212 | - redirect_to params.merge(:profile => user.identifier) | 205 | + redirect_to url_for(params.merge profile: user.identifier) |
213 | else | 206 | else |
214 | render_not_found | 207 | render_not_found |
215 | end | 208 | end |
app/controllers/box_organizer_controller.rb
@@ -69,9 +69,9 @@ class BoxOrganizerController < ApplicationController | @@ -69,9 +69,9 @@ class BoxOrganizerController < ApplicationController | ||
69 | if request.xhr? and params[:query] | 69 | if request.xhr? and params[:query] |
70 | search = params[:query] | 70 | search = params[:query] |
71 | 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 |
72 | - 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 } |
73 | elsif boxes_holder.is_a?(Profile) | 73 | elsif boxes_holder.is_a?(Profile) |
74 | - 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 } |
75 | else | 75 | else |
76 | [] | 76 | [] |
77 | end | 77 | end |
@@ -86,7 +86,7 @@ class BoxOrganizerController < ApplicationController | @@ -86,7 +86,7 @@ class BoxOrganizerController < ApplicationController | ||
86 | if @block.kind_of?(RawHTMLBlock) && !user.is_admin?(environment) | 86 | if @block.kind_of?(RawHTMLBlock) && !user.is_admin?(environment) |
87 | render_access_denied | 87 | render_access_denied |
88 | else | 88 | else |
89 | - @block.update_attributes(params[:block]) | 89 | + @block.update(params[:block]) |
90 | redirect_to :action => 'index' | 90 | redirect_to :action => 'index' |
91 | end | 91 | end |
92 | end | 92 | 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
@@ -15,7 +15,7 @@ class MapsController < MyProfileController | @@ -15,7 +15,7 @@ class MapsController < MyProfileController | ||
15 | end | 15 | end |
16 | 16 | ||
17 | Profile.transaction do | 17 | Profile.transaction do |
18 | - if profile.update_attributes!(params[:profile_data]) | 18 | + if profile.update!(params[:profile_data]) |
19 | BlockSweeper.expire_blocks profile.blocks.select{ |b| b.class == LocationBlock } | 19 | BlockSweeper.expire_blocks profile.blocks.select{ |b| b.class == LocationBlock } |
20 | session[:notice] = _('Address was updated successfully!') | 20 | session[:notice] = _('Address was updated successfully!') |
21 | redirect_to :action => 'edit_location' | 21 | redirect_to :action => 'edit_location' |
app/controllers/my_profile/profile_editor_controller.rb
@@ -30,7 +30,7 @@ class ProfileEditorController < MyProfileController | @@ -30,7 +30,7 @@ class ProfileEditorController < MyProfileController | ||
30 | Image.transaction do | 30 | Image.transaction do |
31 | begin | 31 | begin |
32 | @plugins.dispatch(:profile_editor_transaction_extras) | 32 | @plugins.dispatch(:profile_editor_transaction_extras) |
33 | - @profile_data.update_attributes!(params[:profile_data]) | 33 | + @profile_data.update!(params[:profile_data]) |
34 | redirect_to :action => 'index', :profile => profile.identifier | 34 | redirect_to :action => 'index', :profile => profile.identifier |
35 | rescue Exception => ex | 35 | rescue Exception => ex |
36 | profile.identifier = params[:profile] if profile.identifier.blank? | 36 | profile.identifier = params[:profile] if profile.identifier.blank? |
@@ -86,7 +86,7 @@ class ProfileEditorController < MyProfileController | @@ -86,7 +86,7 @@ class ProfileEditorController < MyProfileController | ||
86 | if @profile.destroy | 86 | if @profile.destroy |
87 | session[:notice] = _('The profile was deleted.') | 87 | session[:notice] = _('The profile was deleted.') |
88 | if(params[:return_to]) | 88 | if(params[:return_to]) |
89 | - redirect_to params[:return_to] | 89 | + redirect_to url_for(params[:return_to]) |
90 | else | 90 | else |
91 | redirect_to :controller => 'home' | 91 | redirect_to :controller => 'home' |
92 | end | 92 | end |
@@ -100,7 +100,7 @@ class ProfileEditorController < MyProfileController | @@ -100,7 +100,7 @@ class ProfileEditorController < MyProfileController | ||
100 | @welcome_page = profile.welcome_page || TinyMceArticle.new(:name => 'Welcome Page', :profile => profile, :published => false) | 100 | @welcome_page = profile.welcome_page || TinyMceArticle.new(:name => 'Welcome Page', :profile => profile, :published => false) |
101 | if request.post? | 101 | if request.post? |
102 | begin | 102 | begin |
103 | - @welcome_page.update_attributes!(params[:welcome_page]) | 103 | + @welcome_page.update!(params[:welcome_page]) |
104 | profile.welcome_page = @welcome_page | 104 | profile.welcome_page = @welcome_page |
105 | profile.save! | 105 | profile.save! |
106 | session[:notice] = _('Welcome page saved successfully.') | 106 | 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
@@ -71,7 +71,7 @@ class TasksController < MyProfileController | @@ -71,7 +71,7 @@ class TasksController < MyProfileController | ||
71 | if VALID_DECISIONS.include?(decision) && id && decision != 'skip' | 71 | if VALID_DECISIONS.include?(decision) && id && decision != 'skip' |
72 | task ||= profile.find_in_all_tasks(id) | 72 | task ||= profile.find_in_all_tasks(id) |
73 | begin | 73 | begin |
74 | - task.update_attributes(value[:task]) | 74 | + task.update(value[:task]) |
75 | task.send(decision, current_person) | 75 | task.send(decision, current_person) |
76 | rescue Exception => ex | 76 | rescue Exception => ex |
77 | message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" | 77 | message = "#{task.title} (#{task.requestor ? task.requestor.name : task.author_name})" |
@@ -85,7 +85,6 @@ class TasksController < MyProfileController | @@ -85,7 +85,6 @@ class TasksController < MyProfileController | ||
85 | end | 85 | end |
86 | 86 | ||
87 | url = { :action => 'index' } | 87 | url = { :action => 'index' } |
88 | - | ||
89 | if failed.blank? | 88 | if failed.blank? |
90 | session[:notice] = _("All decisions were applied successfully.") | 89 | session[:notice] = _("All decisions were applied successfully.") |
91 | else | 90 | else |
@@ -113,7 +112,7 @@ class TasksController < MyProfileController | @@ -113,7 +112,7 @@ class TasksController < MyProfileController | ||
113 | end | 112 | end |
114 | 113 | ||
115 | def ticket_details | 114 | def ticket_details |
116 | - @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) | 115 | + @ticket = Ticket.where('(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]).first |
117 | end | 116 | end |
118 | 117 | ||
119 | def search_tasks | 118 | def search_tasks |
app/controllers/public/account_controller.rb
@@ -125,9 +125,9 @@ class AccountController < ApplicationController | @@ -125,9 +125,9 @@ class AccountController < ApplicationController | ||
125 | @user.signup! | 125 | @user.signup! |
126 | owner_role = Role.find_by_name('owner') | 126 | owner_role = Role.find_by_name('owner') |
127 | @user.person.affiliate(@user.person, [owner_role]) if owner_role | 127 | @user.person.affiliate(@user.person, [owner_role]) if owner_role |
128 | - invitation = Task.find_by_code(@invitation_code) | 128 | + invitation = Task.from_code(@invitation_code).first |
129 | if invitation | 129 | if invitation |
130 | - invitation.update_attributes!({:friend => @user.person}) | 130 | + invitation.update! friend: @user.person |
131 | invitation.finish | 131 | invitation.finish |
132 | end | 132 | end |
133 | 133 | ||
@@ -222,7 +222,7 @@ class AccountController < ApplicationController | @@ -222,7 +222,7 @@ class AccountController < ApplicationController | ||
222 | # | 222 | # |
223 | # Posts back. | 223 | # Posts back. |
224 | def new_password | 224 | def new_password |
225 | - @change_password = ChangePassword.find_by_code(params[:code]) | 225 | + @change_password = ChangePassword.from_code(params[:code]).first |
226 | 226 | ||
227 | unless @change_password | 227 | unless @change_password |
228 | render :action => 'invalid_change_password_code', :status => 403 | 228 | render :action => 'invalid_change_password_code', :status => 403 |
@@ -231,7 +231,7 @@ class AccountController < ApplicationController | @@ -231,7 +231,7 @@ class AccountController < ApplicationController | ||
231 | 231 | ||
232 | if request.post? | 232 | if request.post? |
233 | begin | 233 | begin |
234 | - @change_password.update_attributes!(params[:change_password]) | 234 | + @change_password.update!(params[:change_password]) |
235 | @change_password.finish | 235 | @change_password.finish |
236 | render :action => 'new_password_ok' | 236 | render :action => 'new_password_ok' |
237 | rescue ActiveRecord::RecordInvalid => e | 237 | rescue ActiveRecord::RecordInvalid => e |
@@ -415,7 +415,7 @@ class AccountController < ApplicationController | @@ -415,7 +415,7 @@ class AccountController < ApplicationController | ||
415 | end | 415 | end |
416 | 416 | ||
417 | def load_enterprise_activation | 417 | def load_enterprise_activation |
418 | - @enterprise_activation ||= EnterpriseActivation.find_by_code(params[:enterprise_code]) | 418 | + @enterprise_activation ||= EnterpriseActivation.from_code(params[:enterprise_code]).first |
419 | end | 419 | end |
420 | 420 | ||
421 | def load_enterprise | 421 | def load_enterprise |
@@ -439,7 +439,7 @@ class AccountController < ApplicationController | @@ -439,7 +439,7 @@ class AccountController < ApplicationController | ||
439 | 439 | ||
440 | def go_to_initial_page | 440 | def go_to_initial_page |
441 | if params[:return_to] | 441 | if params[:return_to] |
442 | - redirect_to params[:return_to] | 442 | + redirect_to url_for(params[:return_to]) |
443 | elsif environment.enabled?('allow_change_of_redirection_after_login') | 443 | elsif environment.enabled?('allow_change_of_redirection_after_login') |
444 | check_redirection_options(user, user.preferred_login_redirection, user.admin_url) | 444 | check_redirection_options(user, user.preferred_login_redirection, user.admin_url) |
445 | else | 445 | else |
@@ -500,7 +500,7 @@ class AccountController < ApplicationController | @@ -500,7 +500,7 @@ class AccountController < ApplicationController | ||
500 | def check_redirection | 500 | def check_redirection |
501 | unless params[:redirection].blank? | 501 | unless params[:redirection].blank? |
502 | session[:return_to] = @user.return_to | 502 | session[:return_to] = @user.return_to |
503 | - @user.update_attributes(:return_to => nil) | 503 | + @user.update(:return_to => nil) |
504 | end | 504 | end |
505 | end | 505 | end |
506 | 506 |
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
@@ -37,7 +37,7 @@ class ProfileController < PublicController | @@ -37,7 +37,7 @@ class ProfileController < PublicController | ||
37 | 37 | ||
38 | def tag_feed | 38 | def tag_feed |
39 | @tag = params[:id] | 39 | @tag = params[:id] |
40 | - tagged = profile.articles.paginate(:per_page => 20, :page => 1, :order => 'published_at DESC', :include => :tags, :conditions => ['tags.name LIKE ?', @tag]) | 40 | + 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 | 41 | feed_writer = FeedWriter.new |
42 | data = feed_writer.write( | 42 | data = feed_writer.write( |
43 | tagged, | 43 | tagged, |
@@ -228,7 +228,7 @@ class ProfileController < PublicController | @@ -228,7 +228,7 @@ class ProfileController < PublicController | ||
228 | end | 228 | end |
229 | 229 | ||
230 | def more_replies | 230 | def more_replies |
231 | - activity = Scrap.find(:first, :conditions => {:id => params[:activity], :receiver_id => @profile, :scrap_id => nil}) | 231 | + activity = Scrap.where(:id => params[:activity], :receiver_id => @profile, :scrap_id => nil).first |
232 | comments_count = activity.replies.count | 232 | comments_count = activity.replies.count |
233 | comment_page = (params[:comment_page] || 1).to_i | 233 | comment_page = (params[:comment_page] || 1).to_i |
234 | comments_per_page = 5 | 234 | comments_per_page = 5 |
@@ -275,7 +275,7 @@ class ProfileController < PublicController | @@ -275,7 +275,7 @@ class ProfileController < PublicController | ||
275 | def remove_notification | 275 | def remove_notification |
276 | begin | 276 | begin |
277 | raise if !can_edit_profile | 277 | raise if !can_edit_profile |
278 | - notification = ActionTrackerNotification.find(:first, :conditions => {:profile_id => profile.id, :action_tracker_id => params[:activity_id]}) | 278 | + notification = ActionTrackerNotification.where(profile_id: profile.id, action_tracker_id: params[:activity_id]).first |
279 | notification.destroy | 279 | notification.destroy |
280 | render :text => _('Notification successfully removed.') | 280 | render :text => _('Notification successfully removed.') |
281 | rescue | 281 | rescue |
app/controllers/public/search_controller.rb
@@ -17,7 +17,7 @@ class SearchController < PublicController | @@ -17,7 +17,7 @@ class SearchController < PublicController | ||
17 | # Backwards compatibility with old URLs | 17 | # Backwards compatibility with old URLs |
18 | def redirect_asset_param | 18 | def redirect_asset_param |
19 | return unless params.has_key?(:asset) | 19 | return unless params.has_key?(:asset) |
20 | - redirect_to params.merge(:action => params.delete(:asset)) | 20 | + redirect_to url_for(params.merge action: params.delete(:asset)) |
21 | end | 21 | end |
22 | 22 | ||
23 | no_design_blocks | 23 | no_design_blocks |
@@ -65,12 +65,12 @@ class SearchController < PublicController | @@ -65,12 +65,12 @@ class SearchController < PublicController | ||
65 | end | 65 | end |
66 | 66 | ||
67 | def articles | 67 | def articles |
68 | - @scope = @environment.articles.public | 68 | + @scope = @environment.articles.is_public |
69 | full_text_search | 69 | full_text_search |
70 | end | 70 | end |
71 | 71 | ||
72 | def contents | 72 | def contents |
73 | - redirect_to params.merge(:action => :articles) | 73 | + redirect_to url_for(params.merge action: :articles) |
74 | end | 74 | end |
75 | 75 | ||
76 | def people | 76 | def people |
@@ -125,7 +125,7 @@ class SearchController < PublicController | @@ -125,7 +125,7 @@ class SearchController < PublicController | ||
125 | # keep old URLs workings | 125 | # keep old URLs workings |
126 | def assets | 126 | def assets |
127 | params[:action] = params[:asset].is_a?(Array) ? :index : params.delete(:asset) | 127 | params[:action] = params[:asset].is_a?(Array) ? :index : params.delete(:asset) |
128 | - redirect_to params | 128 | + redirect_to url_for(params) |
129 | end | 129 | end |
130 | 130 | ||
131 | def tags | 131 | def tags |
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 |
@@ -283,36 +287,6 @@ module ApplicationHelper | @@ -283,36 +287,6 @@ module ApplicationHelper | ||
283 | concat(content_tag('div', capture(&block).to_s + tag('br', :style => 'clear: left;'), options)) | 287 | concat(content_tag('div', capture(&block).to_s + tag('br', :style => 'clear: left;'), options)) |
284 | end | 288 | end |
285 | 289 | ||
286 | - | ||
287 | - def partial_for_class_in_view_path(klass, view_path, prefix = nil, suffix = nil) | ||
288 | - return nil if klass.nil? | ||
289 | - name = [prefix, klass.name.underscore, suffix].compact.map(&:to_s).join('_') | ||
290 | - | ||
291 | - search_name = String.new(name) | ||
292 | - if search_name.include?("/") | ||
293 | - search_name.gsub!(/(\/)([^\/]*)$/,'\1_\2') | ||
294 | - name = File.join(params[:controller], name) if defined?(params) && params[:controller] | ||
295 | - else | ||
296 | - search_name = "_" + search_name | ||
297 | - end | ||
298 | - | ||
299 | - path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name + '.html.erb') : File.join(view_path, search_name + '.html.erb') | ||
300 | - return name if File.exists?(File.join(path)) | ||
301 | - | ||
302 | - partial_for_class_in_view_path(klass.superclass, view_path, prefix, suffix) | ||
303 | - end | ||
304 | - | ||
305 | - def partial_for_class(klass, prefix=nil, suffix=nil) | ||
306 | - raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? | ||
307 | - name = klass.name.underscore | ||
308 | - controller.view_paths.each do |view_path| | ||
309 | - partial = partial_for_class_in_view_path(klass, view_path, prefix, suffix) | ||
310 | - return partial if partial | ||
311 | - end | ||
312 | - | ||
313 | - raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' | ||
314 | - end | ||
315 | - | ||
316 | def render_profile_actions klass | 290 | def render_profile_actions klass |
317 | name = klass.to_s.underscore | 291 | name = klass.to_s.underscore |
318 | begin | 292 | begin |
@@ -909,8 +883,14 @@ module ApplicationHelper | @@ -909,8 +883,14 @@ module ApplicationHelper | ||
909 | end | 883 | end |
910 | alias :top_url :base_url | 884 | alias :top_url :base_url |
911 | 885 | ||
886 | + class View < ActionView::Base | ||
887 | + def url_for *args | ||
888 | + self.controller.url_for *args | ||
889 | + end | ||
890 | + end | ||
891 | + | ||
912 | def helper_for_article(article) | 892 | def helper_for_article(article) |
913 | - article_helper = ActionView::Base.new | 893 | + article_helper = View.new |
914 | article_helper.controller = controller | 894 | article_helper.controller = controller |
915 | article_helper.extend ArticleHelper | 895 | article_helper.extend ArticleHelper |
916 | article_helper.extend Rails.application.routes.url_helpers | 896 | article_helper.extend Rails.application.routes.url_helpers |
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/boxes_helper.rb
@@ -255,7 +255,7 @@ module BoxesHelper | @@ -255,7 +255,7 @@ module BoxesHelper | ||
255 | end | 255 | end |
256 | 256 | ||
257 | if movable?(block) && !block.main? | 257 | if movable?(block) && !block.main? |
258 | - 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?')}) |
259 | 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' }) |
260 | end | 260 | end |
261 | 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 |
app/helpers/events_helper.rb
@@ -24,7 +24,7 @@ module EventsHelper | @@ -24,7 +24,7 @@ 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 | + events = events.reject{ |event| !event.display_to? user } |
28 | calendar = Event.date_range(selected_date.year, selected_date.month).map do |date| | 28 | calendar = Event.date_range(selected_date.year, selected_date.month).map do |date| |
29 | [ | 29 | [ |
30 | # the day itself | 30 | # 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)')) |
@@ -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 | include EmailTemplateHelper | 3 | include EmailTemplateHelper |
4 | 4 | ||
5 | def target_notification(task, message) | 5 | def target_notification(task, message) |
6 | + self.environment = task.environment | ||
7 | + | ||
6 | @message = extract_message(message) | 8 | @message = extract_message(message) |
7 | @target = task.target.name | 9 | @target = task.target.name |
8 | - @environment = task.environment.name | ||
9 | @url = generate_environment_url(task, :controller => 'home') | 10 | @url = generate_environment_url(task, :controller => 'home') |
10 | url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url.merge(:script_name => Noosfero.root('/'))) | 11 | url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url.merge(:script_name => Noosfero.root('/'))) |
11 | @tasks_url = url_for_tasks_list | 12 | @tasks_url = url_for_tasks_list |
@@ -18,6 +19,8 @@ class TaskMailer < ActionMailer::Base | @@ -18,6 +19,8 @@ class TaskMailer < ActionMailer::Base | ||
18 | end | 19 | end |
19 | 20 | ||
20 | def invitation_notification(task) | 21 | def invitation_notification(task) |
22 | + self.environment = task.requestor.environment | ||
23 | + | ||
21 | msg = task.expanded_message | 24 | msg = task.expanded_message |
22 | @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code) | 25 | @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code) |
23 | 26 | ||
@@ -29,11 +32,12 @@ class TaskMailer < ActionMailer::Base | @@ -29,11 +32,12 @@ class TaskMailer < ActionMailer::Base | ||
29 | end | 32 | end |
30 | 33 | ||
31 | def generic_message(name, task) | 34 | def generic_message(name, task) |
35 | + self.environment = task.requestor.environment | ||
36 | + | ||
32 | return if !task.respond_to?("#{name}_message") | 37 | return if !task.respond_to?("#{name}_message") |
33 | 38 | ||
34 | @message = extract_message(task.send("#{name}_message")) | 39 | @message = extract_message(task.send("#{name}_message")) |
35 | @requestor = task.requestor.name | 40 | @requestor = task.requestor.name |
36 | - @environment = task.requestor.environment.name | ||
37 | @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home') | 41 | @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home') |
38 | 42 | ||
39 | mail_with_template( | 43 | mail_with_template( |
app/mailers/user_mailer.rb
1 | -class UserMailer < ActionMailer::Base | 1 | +class UserMailer < ApplicationMailer |
2 | 2 | ||
3 | include EmailTemplateHelper | 3 | include EmailTemplateHelper |
4 | 4 | ||
5 | def activation_email_notify(user) | 5 | def activation_email_notify(user) |
6 | + self.environment = user.environment | ||
7 | + | ||
6 | user_email = "#{user.login}@#{user.email_domain}" | 8 | user_email = "#{user.login}@#{user.email_domain}" |
7 | @name = user.name | 9 | @name = user.name |
8 | @email = user_email | 10 | @email = user_email |
9 | @webmail = MailConf.webmail_url(user.login, user.email_domain) | 11 | @webmail = MailConf.webmail_url(user.login, user.email_domain) |
10 | - @environment = user.environment.name | ||
11 | @url = url_for(:host => user.environment.default_hostname, :controller => 'home') | 12 | @url = url_for(:host => user.environment.default_hostname, :controller => 'home') |
12 | 13 | ||
13 | mail( | 14 | mail( |
@@ -18,9 +19,10 @@ class UserMailer < ActionMailer::Base | @@ -18,9 +19,10 @@ class UserMailer < ActionMailer::Base | ||
18 | end | 19 | end |
19 | 20 | ||
20 | def activation_code(user) | 21 | def activation_code(user) |
22 | + self.environment = user.environment | ||
23 | + | ||
21 | @recipient = user.name | 24 | @recipient = user.name |
22 | @activation_code = user.activation_code | 25 | @activation_code = user.activation_code |
23 | - @environment = user.environment.name | ||
24 | @url = user.environment.top_url | 26 | @url = user.environment.top_url |
25 | @redirection = (true if user.return_to) | 27 | @redirection = (true if user.return_to) |
26 | @join = (user.community_to_join if user.community_to_join) | 28 | @join = (user.community_to_join if user.community_to_join) |
@@ -35,6 +37,8 @@ class UserMailer < ActionMailer::Base | @@ -35,6 +37,8 @@ class UserMailer < ActionMailer::Base | ||
35 | end | 37 | end |
36 | 38 | ||
37 | def signup_welcome_email(user) | 39 | def signup_welcome_email(user) |
40 | + self.environment = user.environment | ||
41 | + | ||
38 | @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) | 42 | @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name) |
39 | email_subject = user.environment.signup_welcome_text_subject | 43 | email_subject = user.environment.signup_welcome_text_subject |
40 | mail( | 44 | mail( |
@@ -47,8 +51,9 @@ class UserMailer < ActionMailer::Base | @@ -47,8 +51,9 @@ class UserMailer < ActionMailer::Base | ||
47 | end | 51 | end |
48 | 52 | ||
49 | def profiles_suggestions_email(user) | 53 | def profiles_suggestions_email(user) |
54 | + self.environment = user.environment | ||
55 | + | ||
50 | @recipient = user.name | 56 | @recipient = user.name |
51 | - @environment = user.environment.name | ||
52 | @url = user.environment.top_url | 57 | @url = user.environment.top_url |
53 | @people_suggestions_url = user.people_suggestions_url | 58 | @people_suggestions_url = user.people_suggestions_url |
54 | @people_suggestions = user.suggested_people.sample(3) | 59 | @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_article.rb
@@ -138,9 +138,4 @@ class ApproveArticle < Task | @@ -138,9 +138,4 @@ class ApproveArticle < Task | ||
138 | message | 138 | message |
139 | end | 139 | end |
140 | 140 | ||
141 | - def request_is_member_of_target | ||
142 | - unless requestor.is_member_of?(target) | ||
143 | - errors.add(:approve_article, N_('Requestor must be a member of target.')) | ||
144 | - end | ||
145 | - end | ||
146 | end | 141 | end |
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
1 | + | ||
1 | class Article < ActiveRecord::Base | 2 | class Article < ActiveRecord::Base |
2 | 3 | ||
3 | attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, | 4 | attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, |
@@ -28,9 +29,14 @@ class Article < ActiveRecord::Base | @@ -28,9 +29,14 @@ class Article < ActiveRecord::Base | ||
28 | def initialize(*params) | 29 | def initialize(*params) |
29 | super | 30 | super |
30 | 31 | ||
31 | - if !params.blank? && params.first.has_key?(:profile) && !params.first[:profile].blank? | ||
32 | - profile = params.first[:profile] | ||
33 | - self.published = false unless profile.public? | 32 | + if !params.blank? |
33 | + if params.first.has_key?(:profile) && !params.first[:profile].blank? | ||
34 | + profile = params.first[:profile] | ||
35 | + self.published = false unless profile.public_profile | ||
36 | + end | ||
37 | + | ||
38 | + self.published = params.first["published"] if params.first.has_key?("published") | ||
39 | + self.published = params.first[:published] if params.first.has_key?(:published) | ||
34 | end | 40 | end |
35 | 41 | ||
36 | end | 42 | end |
@@ -77,7 +83,7 @@ class Article < ActiveRecord::Base | @@ -77,7 +83,7 @@ class Article < ActiveRecord::Base | ||
77 | 83 | ||
78 | has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' | 84 | has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' |
79 | 85 | ||
80 | - has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] | 86 | + has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false } |
81 | has_many :categories, :through => :article_categorizations | 87 | has_many :categories, :through => :article_categorizations |
82 | 88 | ||
83 | has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' | 89 | has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' |
@@ -129,17 +135,15 @@ class Article < ActiveRecord::Base | @@ -129,17 +135,15 @@ class Article < ActiveRecord::Base | ||
129 | 135 | ||
130 | xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' | 136 | xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' |
131 | 137 | ||
132 | - scope :in_category, lambda { |category| | ||
133 | - {:include => 'categories_including_virtual', :conditions => { 'categories.id' => category.id }} | 138 | + scope :in_category, -> category { |
139 | + includes('categories_including_virtual').where('categories.id' => category.id) | ||
134 | } | 140 | } |
135 | 141 | ||
136 | include TimeScopes | 142 | include TimeScopes |
137 | 143 | ||
138 | - scope :by_range, lambda { |range| { | ||
139 | - :conditions => [ | ||
140 | - 'articles.published_at BETWEEN :start_date AND :end_date', { :start_date => range.first, :end_date => range.last } | ||
141 | - ] | ||
142 | - }} | 144 | + scope :by_range, -> range { |
145 | + where 'articles.published_at BETWEEN :start_date AND :end_date', { start_date: range.first, end_date: range.last } | ||
146 | + } | ||
143 | 147 | ||
144 | URL_FORMAT = /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\Z/ix | 148 | URL_FORMAT = /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\Z/ix |
145 | 149 | ||
@@ -261,19 +265,21 @@ class Article < ActiveRecord::Base | @@ -261,19 +265,21 @@ class Article < ActiveRecord::Base | ||
261 | 265 | ||
262 | # retrieves all articles belonging to the given +profile+ that are not | 266 | # retrieves all articles belonging to the given +profile+ that are not |
263 | # sub-articles of any other article. | 267 | # sub-articles of any other article. |
264 | - scope :top_level_for, lambda { |profile| | ||
265 | - {: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 | ||
266 | } | 270 | } |
267 | 271 | ||
268 | - scope :public, | ||
269 | - :conditions => [ "articles.advertise = ? AND articles.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 | + } | ||
270 | 276 | ||
271 | - scope :more_recent, | ||
272 | - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND | ||
273 | - ((articles.type != ?) OR articles.type is NULL)", | ||
274 | - true, true, true, true, 'RssFeed' | ||
275 | - ], | ||
276 | - :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 | + } | ||
277 | 283 | ||
278 | # retrives the most commented articles, sorted by the comment count (largest | 284 | # retrives the most commented articles, sorted by the comment count (largest |
279 | # first) | 285 | # first) |
@@ -281,12 +287,14 @@ class Article < ActiveRecord::Base | @@ -281,12 +287,14 @@ class Article < ActiveRecord::Base | ||
281 | paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) | 287 | paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) |
282 | end | 288 | end |
283 | 289 | ||
284 | - scope :more_popular, :order => 'hits DESC' | ||
285 | - 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 | + } | ||
286 | 294 | ||
287 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) | 295 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) |
288 | result = scoped({:conditions => extra_conditions}). | 296 | result = scoped({:conditions => extra_conditions}). |
289 | - public. | 297 | + is_public. |
290 | relevant_as_recent. | 298 | relevant_as_recent. |
291 | limit(limit). | 299 | limit(limit). |
292 | order(['articles.published_at desc', 'articles.id desc']) | 300 | order(['articles.published_at desc', 'articles.id desc']) |
@@ -411,7 +419,7 @@ class Article < ActiveRecord::Base | @@ -411,7 +419,7 @@ class Article < ActiveRecord::Base | ||
411 | self.translations.map(&:language) | 419 | self.translations.map(&:language) |
412 | end | 420 | end |
413 | 421 | ||
414 | - scope :native_translations, :conditions => { :translation_of_id => nil } | 422 | + scope :native_translations, -> { where :translation_of_id => nil } |
415 | 423 | ||
416 | def translatable? | 424 | def translatable? |
417 | false | 425 | false |
@@ -453,7 +461,7 @@ class Article < ActiveRecord::Base | @@ -453,7 +461,7 @@ class Article < ActiveRecord::Base | ||
453 | 461 | ||
454 | def rotate_translations | 462 | def rotate_translations |
455 | unless self.translations.empty? | 463 | unless self.translations.empty? |
456 | - rotate = self.translations | 464 | + rotate = self.translations.all |
457 | root = rotate.shift | 465 | root = rotate.shift |
458 | root.update_attribute(:translation_of_id, nil) | 466 | root.update_attribute(:translation_of_id, nil) |
459 | root.translations = rotate | 467 | root.translations = rotate |
@@ -466,7 +474,7 @@ class Article < ActiveRecord::Base | @@ -466,7 +474,7 @@ class Article < ActiveRecord::Base | ||
466 | elsif self.native_translation.language == locale | 474 | elsif self.native_translation.language == locale |
467 | self.native_translation | 475 | self.native_translation |
468 | else | 476 | else |
469 | - self.native_translation.translations.first(:conditions => { :language => locale }) | 477 | + self.native_translation.translations.where(:language => locale).first |
470 | end | 478 | end |
471 | end | 479 | end |
472 | 480 | ||
@@ -490,19 +498,19 @@ class Article < ActiveRecord::Base | @@ -490,19 +498,19 @@ class Article < ActiveRecord::Base | ||
490 | ['TextArticle', 'TextileArticle', 'TinyMceArticle'] | 498 | ['TextArticle', 'TextileArticle', 'TinyMceArticle'] |
491 | end | 499 | end |
492 | 500 | ||
493 | - scope :published, :conditions => ['articles.published = ?', true] | ||
494 | - scope :folders, lambda {|profile|{:conditions => ['articles.type IN (?)', profile.folder_types] }} | ||
495 | - scope :no_folders, lambda {|profile|{:conditions => ['articles.type NOT IN (?)', profile.folder_types]}} | ||
496 | - scope :galleries, :conditions => [ "articles.type IN ('Gallery')" ] | ||
497 | - scope :images, :conditions => { :is_image => true } | ||
498 | - scope :no_images, :conditions => { :is_image => false } | ||
499 | - scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] | ||
500 | - scope :files, :conditions => { :type => 'UploadedFile' } | ||
501 | - scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } | 501 | + scope :published, -> { where 'articles.published = ?', true } |
502 | + scope :folders, -> profile { where 'articles.type IN (?)', profile.folder_types } | ||
503 | + scope :no_folders, -> profile { where 'articles.type NOT IN (?)', profile.folder_types } | ||
504 | + scope :galleries, -> { where "articles.type IN ('Gallery')" } | ||
505 | + scope :images, -> { where :is_image => true } | ||
506 | + scope :no_images, -> { where :is_image => false } | ||
507 | + scope :text_articles, -> { where 'articles.type IN (?)', text_article_types } | ||
508 | + scope :files, -> { where :type => 'UploadedFile' } | ||
509 | + scope :with_types, -> types { where 'articles.type IN (?)', types } | ||
502 | 510 | ||
503 | - scope :more_popular, :order => 'hits DESC' | ||
504 | - scope :more_comments, :order => "comments_count DESC" | ||
505 | - scope :more_recent, :order => "created_at DESC" | 511 | + scope :more_popular, -> { order 'hits DESC' } |
512 | + scope :more_comments, -> { order "comments_count DESC" } | ||
513 | + scope :more_recent, -> { order "created_at DESC" } | ||
506 | 514 | ||
507 | scope :display_filter, lambda {|user, profile| | 515 | scope :display_filter, lambda {|user, profile| |
508 | return published if (user.nil? && profile && profile.public?) | 516 | return published if (user.nil? && profile && profile.public?) |
@@ -624,7 +632,7 @@ class Article < ActiveRecord::Base | @@ -624,7 +632,7 @@ class Article < ActiveRecord::Base | ||
624 | ] | 632 | ] |
625 | 633 | ||
626 | def self.find_by_old_path(old_path) | 634 | def self.find_by_old_path(old_path) |
627 | - find(:first, :include => :versions, :conditions => ['article_versions.path = ?', old_path], :order => 'article_versions.id desc') | 635 | + self.includes(:versions).where('article_versions.path = ?', old_path).order('article_versions.id DESC').first |
628 | end | 636 | end |
629 | 637 | ||
630 | def hit | 638 | def hit |
@@ -702,11 +710,11 @@ class Article < ActiveRecord::Base | @@ -702,11 +710,11 @@ class Article < ActiveRecord::Base | ||
702 | end | 710 | end |
703 | 711 | ||
704 | def get_version(version_number = nil) | 712 | def get_version(version_number = nil) |
705 | - version_number ? versions.find(:first, :order => 'version', :offset => version_number - 1) : versions.earliest | 713 | + if version_number then self.versions.order('version').offset(version_number - 1).first else self.versions.earliest end |
706 | end | 714 | end |
707 | 715 | ||
708 | def author_by_version(version_number = nil) | 716 | def author_by_version(version_number = nil) |
709 | - version_number ? profile.environment.people.find_by_id(get_version(version_number).author_id) : author | 717 | + if version_number then profile.environment.people.where(id: get_version(version_number).author_id).first else author end |
710 | end | 718 | end |
711 | 719 | ||
712 | def author_name(version_number = nil) | 720 | def author_name(version_number = nil) |
@@ -802,7 +810,7 @@ class Article < ActiveRecord::Base | @@ -802,7 +810,7 @@ class Article < ActiveRecord::Base | ||
802 | end | 810 | end |
803 | 811 | ||
804 | def activity | 812 | def activity |
805 | - ActionTracker::Record.find_by_target_type_and_target_id 'Article', self.id | 813 | + ActionTracker::Record.where(target_type: 'Article', target_id: self.id).first |
806 | end | 814 | end |
807 | 815 | ||
808 | def create_activity | 816 | def create_activity |
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? |
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/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 |
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
@@ -71,7 +71,7 @@ class Enterprise < Organization | @@ -71,7 +71,7 @@ class Enterprise < Organization | ||
71 | end | 71 | end |
72 | 72 | ||
73 | def highlighted_products_with_image(options = {}) | 73 | def highlighted_products_with_image(options = {}) |
74 | - Product.find(:all, {:conditions => {:highlighted => true}, :joins => :image}.merge(options)) | 74 | + Product.where(:highlighted => true).joins(:image) |
75 | end | 75 | end |
76 | 76 | ||
77 | def required_fields | 77 | def required_fields |
app/models/environment.rb
@@ -17,7 +17,10 @@ class Environment < ActiveRecord::Base | @@ -17,7 +17,10 @@ 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 |
@@ -110,7 +113,7 @@ class Environment < ActiveRecord::Base | @@ -110,7 +113,7 @@ class Environment < ActiveRecord::Base | ||
110 | def admins | 113 | def admins |
111 | admin_role = Environment::Roles.admin(self) | 114 | admin_role = Environment::Roles.admin(self) |
112 | return [] if admin_role.blank? | 115 | return [] if admin_role.blank? |
113 | - Person.members_of(self).all(:conditions => ['role_assignments.role_id = ?', admin_role.id]) | 116 | + Person.members_of(self).where 'role_assignments.role_id = ?', admin_role.id |
114 | end | 117 | end |
115 | 118 | ||
116 | # returns the available features for a Environment, in the form of a | 119 | # returns the available features for a Environment, in the form of a |
@@ -225,9 +228,11 @@ class Environment < ActiveRecord::Base | @@ -225,9 +228,11 @@ class Environment < ActiveRecord::Base | ||
225 | has_many :licenses | 228 | has_many :licenses |
226 | 229 | ||
227 | has_many :categories | 230 | has_many :categories |
228 | - has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' | 231 | + has_many :display_categories, -> { |
232 | + order('display_color').where('display_color is not null and parent_id is null') | ||
233 | + }, class_name: 'Category' | ||
229 | 234 | ||
230 | - has_many :product_categories, :conditions => { :type => 'ProductCategory'} | 235 | + has_many :product_categories, -> { where type: 'ProductCategory'} |
231 | has_many :regions | 236 | has_many :regions |
232 | has_many :states | 237 | has_many :states |
233 | has_many :cities | 238 | has_many :cities |
@@ -349,7 +354,7 @@ class Environment < ActiveRecord::Base | @@ -349,7 +354,7 @@ class Environment < ActiveRecord::Base | ||
349 | settings_items :signup_welcome_screen_body, :type => String | 354 | settings_items :signup_welcome_screen_body, :type => String |
350 | 355 | ||
351 | #Captcha settings | 356 | #Captcha settings |
352 | - settings_items :api_captcha_settings, :type => ActiveSupport::HashWithIndifferentAccess, :default => {} | 357 | + settings_items :api_captcha_settings, :default => {} |
353 | 358 | ||
354 | def has_custom_welcome_screen? | 359 | def has_custom_welcome_screen? |
355 | settings[:signup_welcome_screen_body].present? | 360 | settings[:signup_welcome_screen_body].present? |
@@ -696,7 +701,7 @@ class Environment < ActiveRecord::Base | @@ -696,7 +701,7 @@ class Environment < ActiveRecord::Base | ||
696 | 701 | ||
697 | # the default Environment. | 702 | # the default Environment. |
698 | def self.default | 703 | def self.default |
699 | - self.find(:first, :conditions => [ 'is_default = ?', true ] ) | 704 | + self.where('is_default = ?', true).first |
700 | end | 705 | end |
701 | 706 | ||
702 | # returns an array with the top level categories for this environment. | 707 | # returns an array with the top level categories for this environment. |
@@ -877,7 +882,7 @@ class Environment < ActiveRecord::Base | @@ -877,7 +882,7 @@ class Environment < ActiveRecord::Base | ||
877 | end | 882 | end |
878 | 883 | ||
879 | def portal_folders | 884 | def portal_folders |
880 | - (settings[:portal_folders] || []).map{|fid| portal_community.articles.find(:first, :conditions => { :id => fid }) }.compact | 885 | + (settings[:portal_folders] || []).map{|fid| portal_community.articles.where(id: fid).first }.compact |
881 | end | 886 | end |
882 | 887 | ||
883 | def portal_folders=(folders) | 888 | def portal_folders=(folders) |
@@ -964,7 +969,7 @@ class Environment < ActiveRecord::Base | @@ -964,7 +969,7 @@ class Environment < ActiveRecord::Base | ||
964 | end | 969 | end |
965 | 970 | ||
966 | def highlighted_products_with_image(options = {}) | 971 | def highlighted_products_with_image(options = {}) |
967 | - Product.find(:all, {:conditions => {:highlighted => true, :profile_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) | 972 | + self.products.where(highlighted: true).joins(:image).order('created_at ASC') |
968 | end | 973 | end |
969 | 974 | ||
970 | settings_items :home_cache_in_minutes, :type => :integer, :default => 5 | 975 | settings_items :home_cache_in_minutes, :type => :integer, :default => 5 |
app/models/event.rb
@@ -13,14 +13,14 @@ class Event < Article | @@ -13,14 +13,14 @@ class Event < Article | ||
13 | settings_items :presenter, :type => :string | 13 | settings_items :presenter, :type => :string |
14 | 14 | ||
15 | def link=(value) | 15 | def link=(value) |
16 | - self.setting[:link] = maybe_add_http(value) | 16 | + self.setting[:link] = maybe_add_http(URI.escape value.to_s) |
17 | end | 17 | end |
18 | 18 | ||
19 | def link | 19 | def link |
20 | maybe_add_http(self.setting[:link]) | 20 | maybe_add_http(self.setting[:link]) |
21 | end | 21 | end |
22 | 22 | ||
23 | - xss_terminate :only => [ :name, :body, :link, :address ], :with => 'white_list', :on => 'validation' | 23 | + xss_terminate :only => [ :name, :body, :address ], :with => 'white_list', :on => 'validation' |
24 | 24 | ||
25 | def initialize(*args) | 25 | def initialize(*args) |
26 | super(*args) | 26 | super(*args) |
@@ -35,23 +35,21 @@ class Event < Article | @@ -35,23 +35,21 @@ class Event < Article | ||
35 | end | 35 | end |
36 | end | 36 | end |
37 | 37 | ||
38 | - scope :by_day, lambda { |date| | ||
39 | - { :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}], | ||
40 | - :order => 'start_date ASC' | ||
41 | - } | 38 | + scope :by_day, -> date { |
39 | + 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)', | ||
40 | + start_date: date.beginning_of_day, end_date: date.end_of_day). | ||
41 | + order('start_date ASC') | ||
42 | } | 42 | } |
43 | 43 | ||
44 | - scope :next_events_from_month, lambda { |date| | 44 | + scope :next_events_from_month, -> date { |
45 | date_temp = date.strftime("%Y-%m-%d") | 45 | date_temp = date.strftime("%Y-%m-%d") |
46 | - { :conditions => ["start_date >= ?","#{date_temp}"], | ||
47 | - :order => 'start_date ASC' | ||
48 | - } | 46 | + order('start_date ASC') |
47 | + .where("start_date >= ?","#{date_temp}") | ||
49 | } | 48 | } |
50 | 49 | ||
51 | - scope :by_month, lambda { |date| | ||
52 | - { :conditions => ["EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?",date.year,date.month], | ||
53 | - :order => 'start_date ASC' | ||
54 | - } | 50 | + scope :by_month, -> date { |
51 | + order('start_date ASC') | ||
52 | + .where("EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?", date.year, date.month) | ||
55 | } | 53 | } |
56 | 54 | ||
57 | include WhiteListFilter | 55 | include WhiteListFilter |
@@ -72,12 +70,10 @@ class Event < Article | @@ -72,12 +70,10 @@ class Event < Article | ||
72 | 'event' | 70 | 'event' |
73 | end | 71 | end |
74 | 72 | ||
75 | - scope :by_range, lambda { |range| { | ||
76 | - :conditions => [ | ||
77 | - 'start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day', | ||
78 | - { :start_day => range.first, :end_day => range.last } | ||
79 | - ] | ||
80 | - }} | 73 | + scope :by_range, -> range { |
74 | + where('start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day', | ||
75 | + {:start_day => range.first, :end_day => range.last}) | ||
76 | + } | ||
81 | 77 | ||
82 | def self.date_range(year, month) | 78 | def self.date_range(year, month) |
83 | if year.nil? || month.nil? | 79 | if year.nil? || month.nil? |
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 |
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| |
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/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?} |
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? |
@@ -140,7 +140,7 @@ class Organization < Profile | @@ -140,7 +140,7 @@ class Organization < Profile | ||
140 | 140 | ||
141 | settings_items :zip_code, :city, :state, :country | 141 | settings_items :zip_code, :city, :state, :country |
142 | 142 | ||
143 | - validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT | 143 | + 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? }) | 144 | validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |org| !org.contact_email.blank? }) |
145 | validates_as_cnpj :cnpj | 145 | validates_as_cnpj :cnpj |
146 | 146 | ||
@@ -194,7 +194,7 @@ class Organization < Profile | @@ -194,7 +194,7 @@ class Organization < Profile | ||
194 | end | 194 | end |
195 | 195 | ||
196 | def already_request_membership?(person) | 196 | def already_request_membership?(person) |
197 | - self.tasks.pending.find_by_requestor_id(person.id, :conditions => { :type => 'AddMember' }) | 197 | + self.tasks.pending.where(type: 'AddMember', requestor_id: person.id).first |
198 | end | 198 | end |
199 | 199 | ||
200 | def jid(options = {}) | 200 | def jid(options = {}) |
app/models/person.rb
@@ -19,45 +19,41 @@ class Person < Profile | @@ -19,45 +19,41 @@ class Person < Profile | ||
19 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} | 19 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} |
20 | acts_as_accessor | 20 | acts_as_accessor |
21 | 21 | ||
22 | - | ||
23 | - scope :members_of, lambda { |resources, extra_joins = nil| | ||
24 | - resources = [resources] if !resources.kind_of?(Array) | 22 | + scope :members_of, -> resources { |
23 | + resources = Array(resources) | ||
25 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') | 24 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') |
26 | - joins = [:role_assignments] | ||
27 | - joins += extra_joins if extra_joins.is_a? Array | ||
28 | - { :select => 'DISTINCT profiles.*', :joins => joins, :conditions => [conditions] } | 25 | + select('DISTINCT profiles.*').joins(:role_assignments).where([conditions]) |
29 | } | 26 | } |
30 | 27 | ||
31 | - scope :not_members_of, lambda { |resources| | ||
32 | - resources = [resources] if !resources.kind_of?(Array) | 28 | + scope :not_members_of, -> resources { |
29 | + resources = Array(resources) | ||
33 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') | 30 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') |
34 | - { :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] } | 31 | + 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) |
35 | } | 32 | } |
36 | 33 | ||
37 | - scope :by_role, lambda { |roles, extra_joins = nil| | ||
38 | - roles = [roles] unless roles.kind_of?(Array) | ||
39 | - joins = [:role_assignments] | ||
40 | - joins += extra_joins if extra_joins.is_a? Array | ||
41 | - { :select => 'DISTINCT profiles.*', :joins => joins, :conditions => ['role_assignments.role_id IN (?)',roles] } | 34 | + scope :by_role, -> roles { |
35 | + roles = Array(roles) | ||
36 | + select('DISTINCT profiles.*').joins(:role_assignments).where('role_assignments.role_id IN (?)', roles) | ||
42 | } | 37 | } |
43 | 38 | ||
44 | - scope :not_friends_of, lambda { |resources| | 39 | + scope :not_friends_of, -> resources { |
45 | resources = Array(resources) | 40 | resources = Array(resources) |
46 | - { :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)] } | 41 | + 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)) |
47 | } | 42 | } |
48 | 43 | ||
49 | scope :visible_for_person, lambda { |person| | 44 | scope :visible_for_person, lambda { |person| |
50 | - joins('LEFT JOIN "role_assignments" ON | ||
51 | - "role_assignments"."resource_id" = "profiles"."environment_id" AND | ||
52 | - "role_assignments"."resource_type" = \'Environment\'') | ||
53 | - .joins('LEFT JOIN "roles" ON "role_assignments"."role_id" = "roles"."id"') | ||
54 | - .joins('LEFT JOIN "friendships" ON "friendships"."friend_id" = "profiles"."id"') | ||
55 | - .where( | ||
56 | - ['( roles.key = ? AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR ( | ||
57 | - ( ( friendships.person_id = ? ) OR (profiles.public_profile = ?)) AND (profiles.visible = ?) )', 'environment_administrator', Profile.name, person.id, person.id, true, true] | ||
58 | - ).uniq | 45 | + joins('LEFT JOIN "role_assignments" ON |
46 | + "role_assignments"."resource_id" = "profiles"."environment_id" AND | ||
47 | + "role_assignments"."resource_type" = \'Environment\'') | ||
48 | + .joins('LEFT JOIN "roles" ON "role_assignments"."role_id" = "roles"."id"') | ||
49 | + .joins('LEFT JOIN "friendships" ON "friendships"."friend_id" = "profiles"."id"') | ||
50 | + .where( | ||
51 | + ['( roles.key = ? AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR ( | ||
52 | + ( ( friendships.person_id = ? ) OR (profiles.public_profile = ?)) AND (profiles.visible = ?) )', 'environment_administrator', Profile.name, person.id, person.id, true, true] | ||
53 | + ).uniq | ||
59 | } | 54 | } |
60 | 55 | ||
56 | + | ||
61 | def has_permission_with_admin?(permission, resource) | 57 | def has_permission_with_admin?(permission, resource) |
62 | return true if resource.blank? || resource.admins.include?(self) | 58 | return true if resource.blank? || resource.admins.include?(self) |
63 | return true if resource.kind_of?(Profile) && resource.environment.admins.include?(self) | 59 | return true if resource.kind_of?(Profile) && resource.environment.admins.include?(self) |
@@ -74,6 +70,9 @@ class Person < Profile | @@ -74,6 +70,9 @@ class Person < Profile | ||
74 | end | 70 | end |
75 | alias_method_chain :has_permission?, :plugins | 71 | alias_method_chain :has_permission?, :plugins |
76 | 72 | ||
73 | + # for eager loading | ||
74 | + has_many :memberships, through: :role_assignments, source: :resource, source_type: 'Profile' | ||
75 | + | ||
77 | def memberships | 76 | def memberships |
78 | scopes = [] | 77 | scopes = [] |
79 | plugins_scopes = plugins.dispatch_scopes(:person_memberships, self) | 78 | plugins_scopes = plugins.dispatch_scopes(:person_memberships, self) |
@@ -95,7 +94,9 @@ class Person < Profile | @@ -95,7 +94,9 @@ class Person < Profile | ||
95 | has_many :friendships, :dependent => :destroy | 94 | has_many :friendships, :dependent => :destroy |
96 | has_many :friends, :class_name => 'Person', :through => :friendships | 95 | has_many :friends, :class_name => 'Person', :through => :friendships |
97 | 96 | ||
98 | - scope :online, lambda { { :include => :user, :conditions => ["users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes] } } | 97 | + scope :online, -> { |
98 | + joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes) | ||
99 | + } | ||
99 | 100 | ||
100 | has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy | 101 | has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy |
101 | 102 | ||
@@ -111,21 +112,31 @@ class Person < Profile | @@ -111,21 +112,31 @@ class Person < Profile | ||
111 | has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' | 112 | has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' |
112 | has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' | 113 | has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' |
113 | 114 | ||
114 | - has_many :suggested_profiles, :class_name => 'ProfileSuggestion', :foreign_key => :person_id, :order => 'score DESC', :dependent => :destroy | ||
115 | - has_many :suggested_people, :through => :suggested_profiles, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true] | ||
116 | - has_many :suggested_communities, :through => :suggested_profiles, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true] | 115 | + has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy |
116 | + has_many :suggested_people, -> { | ||
117 | + where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true | ||
118 | + }, through: :suggested_profiles, source: :suggestion | ||
119 | + has_many :suggested_communities, -> { | ||
120 | + where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true | ||
121 | + }, through: :suggested_profiles, source: :suggestion | ||
117 | 122 | ||
118 | - scope :more_popular, :order => 'friends_count DESC' | 123 | + scope :more_popular, -> { order 'friends_count DESC' } |
119 | 124 | ||
120 | - scope :abusers, :joins => :abuse_complaints, :conditions => ['tasks.status = 3'], :select => 'DISTINCT profiles.*' | ||
121 | - 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.*" | 125 | + scope :abusers, -> { |
126 | + joins(:abuse_complaints).where('tasks.status = 3').select('DISTINCT profiles.*') | ||
127 | + } | ||
128 | + scope :non_abusers, -> { | ||
129 | + select("DISTINCT profiles.*"). | ||
130 | + joins("LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'"). | ||
131 | + where("tasks.status != 3 OR tasks.id is NULL") | ||
132 | + } | ||
122 | 133 | ||
123 | - scope :admins, :joins => [:role_assignments => :role], :conditions => ['roles.key = ?', 'environment_administrator' ] | ||
124 | - scope :activated, :joins => :user, :conditions => ['users.activation_code IS NULL AND users.activated_at IS NOT NULL'] | ||
125 | - scope :deactivated, :joins => :user, :conditions => ['NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)'] | 134 | + scope :admins, -> { joins(:role_assignments => :role).where('roles.key = ?', 'environment_administrator') } |
135 | + scope :activated, -> { joins(:user).where('users.activation_code IS NULL AND users.activated_at IS NOT NULL') } | ||
136 | + scope :deactivated, -> { joins(:user).where('NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)') } | ||
126 | 137 | ||
127 | after_destroy do |person| | 138 | after_destroy do |person| |
128 | - Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } | 139 | + Friendship.where(friend_id: person.id).each{ |friendship| friendship.destroy } |
129 | end | 140 | end |
130 | 141 | ||
131 | belongs_to :user, :dependent => :delete | 142 | belongs_to :user, :dependent => :delete |
@@ -188,7 +199,7 @@ class Person < Profile | @@ -188,7 +199,7 @@ class Person < Profile | ||
188 | end | 199 | end |
189 | 200 | ||
190 | def remove_friend(friend) | 201 | def remove_friend(friend) |
191 | - Friendship.find(:first, :conditions => {:friend_id => friend, :person_id => id}).destroy | 202 | + Friendship.where(friend_id: friend, person_id: id).first.destroy |
192 | end | 203 | end |
193 | 204 | ||
194 | FIELDS = %w[ | 205 | FIELDS = %w[ |
@@ -219,7 +230,7 @@ class Person < Profile | @@ -219,7 +230,7 @@ class Person < Profile | ||
219 | organization | 230 | organization |
220 | organization_website | 231 | organization_website |
221 | contact_phone | 232 | contact_phone |
222 | - contact_informatioin | 233 | + contact_information |
223 | ] | 234 | ] |
224 | 235 | ||
225 | xss_terminate :only => [ :custom_footer, :custom_header, :description, :nickname, :sex, :nationality, :country, :district, :zip_code, :address, :address_reference, :cell_phone, :comercial_phone, :personal_website, :jabber_id, :schooling, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization, :organization_website, :contact_phone, :contact_information ], :with => 'white_list' | 236 | xss_terminate :only => [ :custom_footer, :custom_header, :description, :nickname, :sex, :nationality, :country, :district, :zip_code, :address, :address_reference, :cell_phone, :comercial_phone, :personal_website, :jabber_id, :schooling, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization, :organization_website, :contact_phone, :contact_information ], :with => 'white_list' |
@@ -301,7 +312,7 @@ class Person < Profile | @@ -301,7 +312,7 @@ class Person < Profile | ||
301 | end | 312 | end |
302 | 313 | ||
303 | validates_each :email, :on => :update do |record,attr,value| | 314 | validates_each :email, :on => :update do |record,attr,value| |
304 | - if User.find(:first, :conditions => ['email = ? and id != ? and environment_id = ?', value, record.user.id, record.environment.id]) | 315 | + if User.where('email = ? and id != ? and environment_id = ?', value, record.user.id, record.environment.id).first |
305 | record.errors.add(attr, _('{fn} is already used by other user').fix_i18n) | 316 | record.errors.add(attr, _('{fn} is already used by other user').fix_i18n) |
306 | end | 317 | end |
307 | end | 318 | end |
@@ -410,7 +421,7 @@ class Person < Profile | @@ -410,7 +421,7 @@ class Person < Profile | ||
410 | def ask_to_join?(community) | 421 | def ask_to_join?(community) |
411 | return false if !community.visible? | 422 | return false if !community.visible? |
412 | return false if memberships.include?(community) | 423 | return false if memberships.include?(community) |
413 | - return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id}) | 424 | + return false if AddMember.where(requestor_id: self.id, target_id: community.id).first |
414 | !refused_communities.include?(community) | 425 | !refused_communities.include?(community) |
415 | end | 426 | end |
416 | 427 |
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,22 +6,19 @@ class ProductCategory < Category | @@ -6,22 +6,19 @@ 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 | - | ||
17 | - # updated scope method to avoid sql injection vunerabillity (http://brakemanscanner.org/docs/warning_types/sql_injection/) | ||
18 | - # explicited to_i on level argument | ||
19 | - scope :unique_by_level, lambda { |level| { | ||
20 | - :select => "DISTINCT ON (filtered_category) split_part(path, '/', #{level.to_i}) AS filtered_category, categories.*" | ||
21 | - }} | 9 | + scope :by_enterprise, -> enterprise { |
10 | + joins(:products). | ||
11 | + where('products.profile_id = ?', enterprise.id) | ||
12 | + } | ||
13 | + scope :by_environment, -> environment { | ||
14 | + where 'environment_id = ?', environment.id | ||
15 | + } | ||
16 | + scope :unique_by_level, -> level { | ||
17 | + select "DISTINCT ON (filtered_category) split_part(path, '/', #{level}) AS filtered_category, categories.*" | ||
18 | + } | ||
22 | 19 | ||
23 | def all_products | 20 | def all_products |
24 | - Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) | 21 | + Product.where(product_category_id: (all_children << self).map(&:id)) |
25 | end | 22 | end |
26 | 23 | ||
27 | def self.menu_categories(top_category, env) | 24 | 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
@@ -79,7 +79,7 @@ class Profile < ActiveRecord::Base | @@ -79,7 +79,7 @@ class Profile < ActiveRecord::Base | ||
79 | all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?} | 79 | all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?} |
80 | end | 80 | end |
81 | def self.all_roles(env_id) | 81 | def self.all_roles(env_id) |
82 | - Role.all :conditions => { :environment_id => env_id } | 82 | + Role.where(environment_id: env_id) |
83 | end | 83 | end |
84 | def self.method_missing(m, *args, &block) | 84 | def self.method_missing(m, *args, &block) |
85 | role = find_role(m, args[0]) | 85 | role = find_role(m, args[0]) |
@@ -117,20 +117,28 @@ class Profile < ActiveRecord::Base | @@ -117,20 +117,28 @@ class Profile < ActiveRecord::Base | ||
117 | 117 | ||
118 | include Noosfero::Plugin::HotSpot | 118 | include Noosfero::Plugin::HotSpot |
119 | 119 | ||
120 | - 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 ] } } | 120 | + scope :memberships_of, -> person { |
121 | + select('DISTINCT profiles.*'). | ||
122 | + joins(:role_assignments). | ||
123 | + where('role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id) | ||
124 | + } | ||
121 | #FIXME: these will work only if the subclass is already loaded | 125 | #FIXME: these will work only if the subclass is already loaded |
122 | - scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | ||
123 | - scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | ||
124 | - scope :templates, lambda { |template_id = nil| | ||
125 | - conditions = {:conditions => {:is_template => true}} | ||
126 | - conditions[:conditions].merge!({:id => template_id}) unless template_id.nil? | ||
127 | - conditions | 126 | + scope :enterprises, -> { |
127 | + where((Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")) | ||
128 | + } | ||
129 | + scope :communities, -> { | ||
130 | + where((Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")) | ||
131 | + } | ||
132 | + scope :templates, -> template_id = nil { | ||
133 | + s = where is_template: true | ||
134 | + s = s.where id: template_id if template_id | ||
135 | + s | ||
128 | } | 136 | } |
129 | 137 | ||
130 | - scope :with_templates, lambda { |templates| | ||
131 | - {:conditions => {:template_id => templates}} | 138 | + scope :with_templates, -> templates { |
139 | + where template_id: templates | ||
132 | } | 140 | } |
133 | - scope :no_templates, {:conditions => {:is_template => false}} | 141 | + scope :no_templates, -> { where is_template: false } |
134 | 142 | ||
135 | # Returns a scoped object to select profiles in a given location or in a radius | 143 | # Returns a scoped object to select profiles in a given location or in a radius |
136 | # distance from the given location center. | 144 | # distance from the given location center. |
@@ -195,8 +203,8 @@ class Profile < ActiveRecord::Base | @@ -195,8 +203,8 @@ class Profile < ActiveRecord::Base | ||
195 | alias_method_chain :count, :distinct | 203 | alias_method_chain :count, :distinct |
196 | end | 204 | end |
197 | 205 | ||
198 | - def members_by_role(roles, with_entities = nil) | ||
199 | - Person.members_of(self, with_entities).by_role(roles, with_entities) | 206 | + def members_by_role(roles) |
207 | + Person.members_of(self).by_role(roles) | ||
200 | end | 208 | end |
201 | 209 | ||
202 | acts_as_having_boxes | 210 | acts_as_having_boxes |
@@ -207,10 +215,10 @@ class Profile < ActiveRecord::Base | @@ -207,10 +215,10 @@ class Profile < ActiveRecord::Base | ||
207 | Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') | 215 | Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') |
208 | end | 216 | end |
209 | 217 | ||
210 | - scope :visible, :conditions => { :visible => true, :secret => false } | ||
211 | - scope :disabled, :conditions => { :visible => false } | ||
212 | - scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false } | ||
213 | - scope :enabled, :conditions => { :enabled => true } | 218 | + scope :visible, -> { where visible: true, secret: false } |
219 | + scope :disabled, -> { where visible: false } | ||
220 | + scope :is_public, -> { where visible: true, public_profile: true, secret: false } | ||
221 | + scope :enabled, -> { where enabled: true } | ||
214 | 222 | ||
215 | # Subclasses must override this method | 223 | # Subclasses must override this method |
216 | scope :more_popular | 224 | scope :more_popular |
@@ -262,7 +270,7 @@ class Profile < ActiveRecord::Base | @@ -262,7 +270,7 @@ class Profile < ActiveRecord::Base | ||
262 | validates_length_of :description, :maximum => 550, :allow_nil => true | 270 | validates_length_of :description, :maximum => 550, :allow_nil => true |
263 | 271 | ||
264 | # Valid identifiers must match this format. | 272 | # Valid identifiers must match this format. |
265 | - IDENTIFIER_FORMAT = /^#{Noosfero.identifier_format}$/ | 273 | + IDENTIFIER_FORMAT = /\A#{Noosfero.identifier_format}\Z/ |
266 | 274 | ||
267 | # These names cannot be used as identifiers for Profiles | 275 | # These names cannot be used as identifiers for Profiles |
268 | RESERVED_IDENTIFIERS = %w[ | 276 | RESERVED_IDENTIFIERS = %w[ |
@@ -314,7 +322,7 @@ class Profile < ActiveRecord::Base | @@ -314,7 +322,7 @@ class Profile < ActiveRecord::Base | ||
314 | end | 322 | end |
315 | end | 323 | end |
316 | 324 | ||
317 | - has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] | 325 | + has_many :profile_categorizations, -> { where 'categories_profiles.virtual = ?', false } |
318 | has_many :categories, :through => :profile_categorizations | 326 | has_many :categories, :through => :profile_categorizations |
319 | 327 | ||
320 | has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' | 328 | has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' |
@@ -541,14 +549,13 @@ class Profile < ActiveRecord::Base | @@ -541,14 +549,13 @@ class Profile < ActiveRecord::Base | ||
541 | self.articles.recent(limit, options, pagination) | 549 | self.articles.recent(limit, options, pagination) |
542 | end | 550 | end |
543 | 551 | ||
544 | - def last_articles(limit = 10, options = {}) | ||
545 | - options = { :limit => limit, | ||
546 | - :conditions => ["advertise = ? AND published = ? AND | ||
547 | - ((articles.type != ? and articles.type != ? and articles.type != ?) OR | ||
548 | - articles.type is NULL)", | ||
549 | - true, true, 'UploadedFile', 'RssFeed', 'Blog'], | ||
550 | - :order => 'articles.published_at desc, articles.id desc' }.merge(options) | ||
551 | - self.articles.find(:all, options) | 552 | + def last_articles limit = 10 |
553 | + self.articles.limit(limit).where( | ||
554 | + "advertise = ? AND published = ? AND | ||
555 | + ((articles.type != ? and articles.type != ? and articles.type != ?) OR | ||
556 | + articles.type is NULL)", | ||
557 | + true, true, 'UploadedFile', 'RssFeed', 'Blog' | ||
558 | + ).order('articles.published_at desc, articles.id desc') | ||
552 | end | 559 | end |
553 | 560 | ||
554 | def to_liquid | 561 | def to_liquid |
@@ -752,7 +759,7 @@ private :generate_url, :url_options | @@ -752,7 +759,7 @@ private :generate_url, :url_options | ||
752 | num = num + 1 | 759 | num = num + 1 |
753 | new_name = original_article.name + ' ' + num.to_s | 760 | new_name = original_article.name + ' ' + num.to_s |
754 | end | 761 | end |
755 | - original_article.update_attributes!(:name => new_name) | 762 | + original_article.update!(:name => new_name) |
756 | end | 763 | end |
757 | article_copy = article.copy(:profile => self, :parent => parent, :advertise => false) | 764 | article_copy = article.copy(:profile => self, :parent => parent, :advertise => false) |
758 | if article.profile.home_page == article | 765 | if article.profile.home_page == article |
@@ -942,11 +949,11 @@ private :generate_url, :url_options | @@ -942,11 +949,11 @@ private :generate_url, :url_options | ||
942 | self.forums.count.nonzero? | 949 | self.forums.count.nonzero? |
943 | end | 950 | end |
944 | 951 | ||
945 | - def admins(with_entities = nil) | 952 | + def admins |
946 | return [] if environment.blank? | 953 | return [] if environment.blank? |
947 | admin_role = Profile::Roles.admin(environment.id) | 954 | admin_role = Profile::Roles.admin(environment.id) |
948 | return [] if admin_role.blank? | 955 | return [] if admin_role.blank? |
949 | - self.members_by_role(admin_role, with_entities) | 956 | + self.members_by_role(admin_role) |
950 | end | 957 | end |
951 | 958 | ||
952 | def enable_contact? | 959 | def enable_contact? |
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_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. |
app/models/profile_suggestion.rb
@@ -26,9 +26,9 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -26,9 +26,9 @@ class ProfileSuggestion < ActiveRecord::Base | ||
26 | end | 26 | end |
27 | 27 | ||
28 | validates_uniqueness_of :suggestion_id, :scope => [ :person_id ] | 28 | validates_uniqueness_of :suggestion_id, :scope => [ :person_id ] |
29 | - scope :of_person, :conditions => { :suggestion_type => 'Person' } | ||
30 | - scope :of_community, :conditions => { :suggestion_type => 'Community' } | ||
31 | - scope :enabled, :conditions => { :enabled => true } | 29 | + scope :of_person, -> { where suggestion_type: 'Person' } |
30 | + scope :of_community, -> { where suggestion_type: 'Community' } | ||
31 | + scope :enabled, -> { where enabled: true } | ||
32 | 32 | ||
33 | # {:category_type => ['category-icon', 'category-label']} | 33 | # {:category_type => ['category-icon', 'category-label']} |
34 | CATEGORIES = { | 34 | CATEGORIES = { |
@@ -55,13 +55,13 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -55,13 +55,13 @@ class ProfileSuggestion < ActiveRecord::Base | ||
55 | :threshold => 2, :weight => 1, :connection => 'Profile' | 55 | :threshold => 2, :weight => 1, :connection => 'Profile' |
56 | }, | 56 | }, |
57 | :people_with_common_tags => { | 57 | :people_with_common_tags => { |
58 | - :threshold => 2, :weight => 1, :connection => 'ActsAsTaggableOn::Tag' | 58 | + :threshold => 2, :weight => 1, :connection => 'Tag' |
59 | }, | 59 | }, |
60 | :communities_with_common_friends => { | 60 | :communities_with_common_friends => { |
61 | :threshold => 2, :weight => 1, :connection => 'Profile' | 61 | :threshold => 2, :weight => 1, :connection => 'Profile' |
62 | }, | 62 | }, |
63 | :communities_with_common_tags => { | 63 | :communities_with_common_tags => { |
64 | - :threshold => 2, :weight => 1, :connection => 'ActsAsTaggableOn::Tag' | 64 | + :threshold => 2, :weight => 1, :connection => 'Tag' |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
@@ -127,17 +127,15 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -127,17 +127,15 @@ class ProfileSuggestion < ActiveRecord::Base | ||
127 | rescue NoMethodError | 127 | rescue NoMethodError |
128 | next | 128 | next |
129 | end | 129 | end |
130 | - connections = suggested_profile.send("#{rule}_connections") | ||
131 | - if connections.present? | ||
132 | - connections = connections[1..-2].split(',') | ||
133 | - else | ||
134 | - connections = [] | ||
135 | - end | ||
136 | - suggestion.send("#{rule}=", value) | 130 | + |
131 | + connections = suggested_profile.send("#{rule}_connections") || [] | ||
132 | + connections = connections[1..-2] if connections.present? | ||
137 | connections.each do |connection_id| | 133 | connections.each do |connection_id| |
138 | next if SuggestionConnection.where(:suggestion_id => suggestion.id, :connection_id => connection_id, :connection_type => options[:connection]).present? | 134 | next if SuggestionConnection.where(:suggestion_id => suggestion.id, :connection_id => connection_id, :connection_type => options[:connection]).present? |
139 | - SuggestionConnection.create!(:suggestion => suggestion, :connection_id => connection_id, :connection_type => options[:connection]) | 135 | + SuggestionConnection.create!(:suggestion => suggestion, :connection_id => connection_id, :connection_type => options[:connection]) |
140 | end | 136 | end |
137 | + | ||
138 | + suggestion.send("#{rule}=", value) | ||
141 | suggestion.score += value * options[:weight] | 139 | suggestion.score += value * options[:weight] |
142 | end | 140 | end |
143 | suggestion.save! | 141 | suggestion.save! |
app/models/reported_image.rb
@@ -5,6 +5,7 @@ class ReportedImage < ActiveRecord::Base | @@ -5,6 +5,7 @@ class ReportedImage < ActiveRecord::Base | ||
5 | 5 | ||
6 | has_attachment :content_type => :image, | 6 | has_attachment :content_type => :image, |
7 | :storage => :file_system, | 7 | :storage => :file_system, |
8 | - :max_size => 5.megabytes | 8 | + :max_size => 5.megabytes, |
9 | + processor: 'Rmagick' | ||
9 | 10 | ||
10 | end | 11 | end |
app/models/rss_feed.rb
@@ -14,7 +14,7 @@ class RssFeed < Article | @@ -14,7 +14,7 @@ class RssFeed < Article | ||
14 | 14 | ||
15 | # store setting in body | 15 | # store setting in body |
16 | serialize :body, Hash | 16 | serialize :body, Hash |
17 | - | 17 | + |
18 | def body | 18 | def body |
19 | self[:body] ||= {} | 19 | self[:body] ||= {} |
20 | end | 20 | end |
@@ -40,7 +40,7 @@ class RssFeed < Article | @@ -40,7 +40,7 @@ class RssFeed < Article | ||
40 | 40 | ||
41 | # FIXME this should be validates_numericality_of, but Rails 2.0.2 does not | 41 | # FIXME this should be validates_numericality_of, but Rails 2.0.2 does not |
42 | # support validates_numericality_of with virtual attributes | 42 | # support validates_numericality_of with virtual attributes |
43 | - validates_format_of :limit, :with => /^\d+$/, :if => :limit | 43 | + validates_format_of :limit, :with => /\d+/, :if => :limit |
44 | 44 | ||
45 | # determinates what to include in the feed. Possible values are +:all+ | 45 | # determinates what to include in the feed. Possible values are +:all+ |
46 | # (include everything from the profile) and :parent_and_children (include | 46 | # (include everything from the profile) and :parent_and_children (include |
@@ -69,7 +69,7 @@ class RssFeed < Article | @@ -69,7 +69,7 @@ class RssFeed < Article | ||
69 | def fetch_articles | 69 | def fetch_articles |
70 | if parent && parent.has_posts? | 70 | if parent && parent.has_posts? |
71 | language = self.language.blank? ? {} : { :language => self.language } | 71 | language = self.language.blank? ? {} : { :language => self.language } |
72 | - return parent.posts.find(:all, :conditions => { :published => true }.merge(language), :limit => self.limit, :order => 'id desc') | 72 | + return parent.posts.where({published: true}.merge language).limit(self.limit).order('id desc') |
73 | end | 73 | end |
74 | 74 | ||
75 | articles = | 75 | articles = |
@@ -89,6 +89,14 @@ class RssFeed < Article | @@ -89,6 +89,14 @@ class RssFeed < Article | ||
89 | ) | 89 | ) |
90 | end | 90 | end |
91 | 91 | ||
92 | + def published? | ||
93 | + if self.parent | ||
94 | + self.parent.published? | ||
95 | + else | ||
96 | + self.published | ||
97 | + end | ||
98 | + end | ||
99 | + | ||
92 | def self.short_description | 100 | def self.short_description |
93 | _('RSS Feed') | 101 | _('RSS Feed') |
94 | end | 102 | end |
app/models/scrap.rb
@@ -18,9 +18,9 @@ class Scrap < ActiveRecord::Base | @@ -18,9 +18,9 @@ class Scrap < ActiveRecord::Base | ||
18 | after_create :create_activity | 18 | after_create :create_activity |
19 | after_update :update_activity | 19 | after_update :update_activity |
20 | 20 | ||
21 | - scope :all_scraps, lambda {|profile| {:conditions => ["receiver_id = ? OR sender_id = ?", profile, profile], :limit => 30}} | 21 | + scope :all_scraps, -> profile { limit(30).where("receiver_id = ? OR sender_id = ?", profile, profile) } |
22 | 22 | ||
23 | - scope :not_replies, :conditions => {:scrap_id => nil} | 23 | + scope :not_replies, -> { where scrap_id: nil } |
24 | 24 | ||
25 | track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.sender != s.receiver && s.sender != s.top_root.receiver}, :custom_target => :action_tracker_target, :custom_user => :sender | 25 | track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.sender != s.receiver && s.sender != s.top_root.receiver}, :custom_target => :action_tracker_target, :custom_user => :sender |
26 | 26 |
app/models/search_term_occurrence.rb
1 | class SearchTermOccurrence < ActiveRecord::Base | 1 | class SearchTermOccurrence < ActiveRecord::Base |
2 | + | ||
2 | belongs_to :search_term | 3 | belongs_to :search_term |
3 | validates_presence_of :search_term | 4 | validates_presence_of :search_term |
4 | attr_accessible :search_term, :created_at, :total, :indexed | 5 | attr_accessible :search_term, :created_at, :total, :indexed |
5 | 6 | ||
6 | EXPIRATION_TIME = 1.year | 7 | EXPIRATION_TIME = 1.year |
7 | 8 | ||
8 | - scope :valid, :conditions => ["search_term_occurrences.created_at > ?", DateTime.now - EXPIRATION_TIME] | 9 | + scope :valid, -> { where "search_term_occurrences.created_at > ?", DateTime.now - EXPIRATION_TIME } |
10 | + | ||
9 | end | 11 | end |
app/models/slideshow_block.rb
@@ -13,7 +13,7 @@ class SlideshowBlock < Block | @@ -13,7 +13,7 @@ class SlideshowBlock < Block | ||
13 | end | 13 | end |
14 | 14 | ||
15 | def gallery | 15 | def gallery |
16 | - gallery_id ? Gallery.find(:first, :conditions => { :id => gallery_id }) : nil | 16 | + if gallery_id then Gallery.where(id: gallery_id).first else nil end |
17 | end | 17 | end |
18 | 18 | ||
19 | def public_filename_for(image) | 19 | def public_filename_for(image) |
app/models/suggestion_connection.rb
1 | class SuggestionConnection < ActiveRecord::Base | 1 | class SuggestionConnection < ActiveRecord::Base |
2 | - attr_accessible :suggestion, :connection_type, :connection_id | 2 | + attr_accessible :suggestion, :suggestion_id, :connection_type, :connection_id |
3 | 3 | ||
4 | belongs_to :suggestion, :class_name => 'ProfileSuggestion', :foreign_key => 'suggestion_id' | 4 | belongs_to :suggestion, :class_name => 'ProfileSuggestion', :foreign_key => 'suggestion_id' |
5 | belongs_to :connection, :polymorphic => true | 5 | belongs_to :connection, :polymorphic => true |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +Tag = ActsAsTaggableOn::Tag | ||
2 | +class Tag | ||
3 | + | ||
4 | + attr_accessible :name, :parent_id, :pending | ||
5 | + | ||
6 | + has_many :children, class_name: 'Tag', foreign_key: 'parent_id', dependent: :destroy | ||
7 | + | ||
8 | + @@original_find = self.method(:find) | ||
9 | + # Rename the find method to find_with_pendings that includes all tags in the search regardless if its pending or not | ||
10 | + def self.find_with_pendings(*args) | ||
11 | + @@original_find.call(*args) | ||
12 | + end | ||
13 | + | ||
14 | + # Redefine the find method to exclude the pending tags from the search not allowing to tag something with an unapproved tag | ||
15 | + def self.find(*args) | ||
16 | + self.where(pending: false).find_with_pendings(*args) | ||
17 | + end | ||
18 | + | ||
19 | + # Return all the tags that were suggested but not yet approved | ||
20 | + def self.find_pendings | ||
21 | + self.where(pending: true) | ||
22 | + end | ||
23 | + | ||
24 | + # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops | ||
25 | + def parent_candidates | ||
26 | + ActsAsTaggableOn::Tag.all - descendents - [self] | ||
27 | + end | ||
28 | + | ||
29 | + # All tags that have this tag as its one of its ancestors | ||
30 | + def descendents | ||
31 | + children.to_a.sum([], &:descendents) + children | ||
32 | + end | ||
33 | + | ||
34 | +end |
app/models/task.rb
@@ -53,7 +53,7 @@ class Task < ActiveRecord::Base | @@ -53,7 +53,7 @@ class Task < ActiveRecord::Base | ||
53 | before_validation(:on => :create) do |task| | 53 | before_validation(:on => :create) do |task| |
54 | if task.code.nil? | 54 | if task.code.nil? |
55 | task.code = Task.generate_code(task.code_length) | 55 | task.code = Task.generate_code(task.code_length) |
56 | - while (Task.find_by_code(task.code)) | 56 | + while Task.from_code(task.code).first |
57 | task.code = Task.generate_code(task.code_length) | 57 | task.code = Task.generate_code(task.code_length) |
58 | end | 58 | end |
59 | end | 59 | end |
@@ -74,7 +74,7 @@ class Task < ActiveRecord::Base | @@ -74,7 +74,7 @@ class Task < ActiveRecord::Base | ||
74 | TaskMailer.target_notification(task, target_msg).deliver | 74 | TaskMailer.target_notification(task, target_msg).deliver |
75 | end | 75 | end |
76 | end | 76 | end |
77 | - rescue Exception => ex | 77 | + rescue NotImplementedError => ex |
78 | Rails.logger.info ex.to_s | 78 | Rails.logger.info ex.to_s |
79 | end | 79 | end |
80 | end | 80 | end |
@@ -310,58 +310,29 @@ class Task < ActiveRecord::Base | @@ -310,58 +310,29 @@ class Task < ActiveRecord::Base | ||
310 | }) | 310 | }) |
311 | end | 311 | end |
312 | 312 | ||
313 | - scope :pending, :conditions => { :status => Task::Status::ACTIVE } | ||
314 | - scope :hidden, :conditions => { :status => Task::Status::HIDDEN } | ||
315 | - scope :finished, :conditions => { :status => Task::Status::FINISHED } | ||
316 | - scope :canceled, :conditions => { :status => Task::Status::CANCELLED } | ||
317 | - scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] } | ||
318 | - scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } | ||
319 | - | ||
320 | - # # updated scope method to avoid sql injection vunerabillity (http://brakemanscanner.org/docs/warning_types/sql_injection/) | ||
321 | - # def self.of type | ||
322 | - # if type | ||
323 | - # where "type LIKE ?", type | ||
324 | - # else | ||
325 | - # all | ||
326 | - # end | ||
327 | - # end | ||
328 | - # | ||
329 | - # # updated scope method to avoid sql injection vunerabillity (http://brakemanscanner.org/docs/warning_types/sql_injection/) | ||
330 | - # def self.order_by attribute_name, sort_order | ||
331 | - # if Task.column_names.include? attribute_name | ||
332 | - # # TODO future versions of rails accepts a hash as param to order method | ||
333 | - # # which helps to prevent sql injection in an shorter way | ||
334 | - # sort_order_filtered = ("ASC".eql? "#{sort_order}".upcase) ? 'asc' : 'desc' | ||
335 | - # sort_expression = Task.column_names.collect {|column_name| "#{column_name} #{sort_order_filtered}" if column_name.eql? attribute_name} | ||
336 | - # order(sort_expression.join) unless sort_expression.join.empty? | ||
337 | - # end | ||
338 | - # end | ||
339 | - # | ||
340 | - # # updated scope method to avoid sql injection vunerabillity (http://brakemanscanner.org/docs/warning_types/sql_injection/) | ||
341 | - # def self.like field, value | ||
342 | - # if value and Tasks.column_names.include? field | ||
343 | - # where("LOWER(?) LIKE ?", "#{field}", "%#{value.downcase}%") | ||
344 | - # end | ||
345 | - # end | ||
346 | - | ||
347 | - scope :of, lambda { |type| conditions = type ? "tasks.type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } | ||
348 | - scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } | ||
349 | - scope :like, lambda { |field, value| where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value} | ||
350 | - | ||
351 | - scope :pending_all, lambda { |profile, filter_type, filter_text| | 313 | + scope :pending, -> { where status: Task::Status::ACTIVE } |
314 | + scope :hidden, -> { where status: Task::Status::HIDDEN } | ||
315 | + scope :finished, -> { where status: Task::Status::FINISHED } | ||
316 | + scope :canceled, -> { where status: Task::Status::CANCELLED } | ||
317 | + scope :closed, -> { where status: [Task::Status::CANCELLED, Task::Status::FINISHED] } | ||
318 | + scope :opened, -> { where status: [Task::Status::ACTIVE, Task::Status::HIDDEN] } | ||
319 | + scope :of, -> type { where "type LIKE ?", type if type } | ||
320 | + scope :order_by, -> attribute, ord { order "#{attribute} #{ord}" } | ||
321 | + scope :like, -> field, value { where "LOWER(#{field}) LIKE ?", "%#{value.downcase}%" if value } | ||
322 | + scope :pending_all, -> profile, filter_type, filter_text { | ||
352 | self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text) | 323 | self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text) |
353 | } | 324 | } |
354 | 325 | ||
355 | scope :to, lambda { |profile| | 326 | scope :to, lambda { |profile| |
356 | environment_condition = nil | 327 | environment_condition = nil |
357 | if profile.person? | 328 | if profile.person? |
358 | - envs_ids = Environment.find(:all).select{ |env| profile.is_admin?(env) }.map { |env| "target_id = #{env.id}"}.join(' OR ') | 329 | + envs_ids = Environment.all.select{ |env| profile.is_admin?(env) }.map{ |env| "target_id = #{env.id}"}.join(' OR ') |
359 | environment_condition = envs_ids.blank? ? nil : "(target_type = 'Environment' AND (#{envs_ids}))" | 330 | environment_condition = envs_ids.blank? ? nil : "(target_type = 'Environment' AND (#{envs_ids}))" |
360 | end | 331 | end |
361 | profile_condition = "(target_type = 'Profile' AND target_id = #{profile.id})" | 332 | profile_condition = "(target_type = 'Profile' AND target_id = #{profile.id})" |
362 | - { :conditions => [environment_condition, profile_condition].compact.join(' OR ') } | ||
363 | - } | ||
364 | 333 | ||
334 | + where [environment_condition, profile_condition].compact.join(' OR ') | ||
335 | + } | ||
365 | 336 | ||
366 | def self.pending_types_for(profile) | 337 | def self.pending_types_for(profile) |
367 | Task.to(profile).pending.select('distinct type').map { |t| [t.class.name, t.title] } | 338 | Task.to(profile).pending.select('distinct type').map { |t| [t.class.name, t.title] } |
@@ -422,6 +393,12 @@ class Task < ActiveRecord::Base | @@ -422,6 +393,12 @@ class Task < ActiveRecord::Base | ||
422 | end | 393 | end |
423 | end | 394 | end |
424 | 395 | ||
396 | + # finds a task by its (generated) code. Only returns a task with the | ||
397 | + # specified code AND with status = Task::Status::ACTIVE. | ||
398 | + # | ||
399 | + # Can be used in subclasses to find only their instances. | ||
400 | + scope :from_code, -> code { where code: code, status: Task::Status::ACTIVE } | ||
401 | + | ||
425 | class << self | 402 | class << self |
426 | 403 | ||
427 | # generates a random code string consisting of length characters (or 36 by | 404 | # generates a random code string consisting of length characters (or 36 by |
app/models/thumbnail.rb
1 | class Thumbnail < ActiveRecord::Base | 1 | class Thumbnail < ActiveRecord::Base |
2 | + | ||
3 | + attr_accessible :uploaded_data | ||
4 | + # mass assigned by attachment_fu | ||
5 | + attr_accessible :content_type, :filename, :thumbnail_resize_options, :thumbnail, :parent_id | ||
6 | + | ||
2 | has_attachment :storage => :file_system, | 7 | has_attachment :storage => :file_system, |
3 | - :content_type => :image, :max_size => 5.megabytes | 8 | + :content_type => :image, :max_size => 5.megabytes, processor: 'Rmagick' |
4 | validates_as_attachment | 9 | validates_as_attachment |
5 | 10 | ||
6 | sanitize_filename | 11 | sanitize_filename |
7 | 12 | ||
8 | postgresql_attachment_fu | 13 | postgresql_attachment_fu |
9 | 14 | ||
10 | - attr_accessible :uploaded_data | ||
11 | end | 15 | end |
app/models/tiny_mce_article.rb
@@ -9,7 +9,7 @@ class TinyMceArticle < TextArticle | @@ -9,7 +9,7 @@ class TinyMceArticle < TextArticle | ||
9 | def self.description | 9 | def self.description |
10 | _('Not accessible for visually impaired users.') | 10 | _('Not accessible for visually impaired users.') |
11 | end | 11 | end |
12 | - | 12 | + |
13 | xss_terminate :only => [ ] | 13 | xss_terminate :only => [ ] |
14 | 14 | ||
15 | xss_terminate :only => [ :name, :abstract, :body ], :with => 'white_list', :on => 'validation' | 15 | xss_terminate :only => [ :name, :abstract, :body ], :with => 'white_list', :on => 'validation' |
app/models/uploaded_file.rb
@@ -63,7 +63,8 @@ class UploadedFile < Article | @@ -63,7 +63,8 @@ class UploadedFile < Article | ||
63 | has_attachment :storage => :file_system, | 63 | has_attachment :storage => :file_system, |
64 | :thumbnails => { :icon => [24,24], :bigicon => [50,50], :thumb => '130x130>', :slideshow => '320x240>', :display => '640X480>' }, | 64 | :thumbnails => { :icon => [24,24], :bigicon => [50,50], :thumb => '130x130>', :slideshow => '320x240>', :display => '640X480>' }, |
65 | :thumbnail_class => Thumbnail, | 65 | :thumbnail_class => Thumbnail, |
66 | - :max_size => self.max_size | 66 | + :max_size => self.max_size, |
67 | + processor: 'Rmagick' | ||
67 | 68 | ||
68 | validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of %{size}").sub('%{size}', self.max_size.to_humanreadable).fix_i18n | 69 | validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of %{size}").sub('%{size}', self.max_size.to_humanreadable).fix_i18n |
69 | 70 |
app/models/user.rb
@@ -102,7 +102,8 @@ class User < ActiveRecord::Base | @@ -102,7 +102,8 @@ class User < ActiveRecord::Base | ||
102 | end | 102 | end |
103 | end | 103 | end |
104 | 104 | ||
105 | - has_one :person, :dependent => :destroy | 105 | + # set autosave to false as we do manually when needed and Person syncs with us |
106 | + has_one :person, dependent: :destroy, autosave: false | ||
106 | belongs_to :environment | 107 | belongs_to :environment |
107 | 108 | ||
108 | has_many :sessions, dependent: :destroy | 109 | has_many :sessions, dependent: :destroy |
@@ -358,12 +359,12 @@ class User < ActiveRecord::Base | @@ -358,12 +359,12 @@ class User < ActiveRecord::Base | ||
358 | end | 359 | end |
359 | 360 | ||
360 | def name | 361 | def name |
361 | - name = (self[:name] || login) | 362 | + name = (@name || login) |
362 | person.nil? ? name : (person.name || name) | 363 | person.nil? ? name : (person.name || name) |
363 | end | 364 | end |
364 | 365 | ||
365 | def name= name | 366 | def name= name |
366 | - self[:name] = name | 367 | + @name = name |
367 | end | 368 | end |
368 | 369 | ||
369 | def enable_email! | 370 | def enable_email! |
app/views/categories/_category.html.erb
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | <div> | 15 | <div> |
16 | <%= link_to _('Add subcategory'), :action => 'new', :parent_id => category %> | 16 | <%= link_to _('Add subcategory'), :action => 'new', :parent_id => category %> |
17 | <%= link_to _('Edit'), :action => 'edit', :id => category %> | 17 | <%= link_to _('Edit'), :action => 'edit', :id => category %> |
18 | - <%= link_to _('Remove'), { :action => 'remove', :id => category, }, :method => 'post', :confirm => (category.children.empty? ? (_('Are you sure you want to remove "%s"?') % category.name) : (_('Are you sure you want to remove "%s" and all its subcategories?') % category.name) ) %> | 18 | + <%= link_to _('Remove'), { action: 'remove', id: category, }, method: 'post', data: {confirm: if category.children.empty? then _('Are you sure you want to remove "%s"?') % category.name else _('Are you sure you want to remove "%s" and all its subcategories?') % category.name end} %> |
19 | </div> | 19 | </div> |
20 | </div> | 20 | </div> |
21 | 21 |
app/views/cms/edit.html.erb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | 9 | ||
10 | <%= hidden_field_tag('success_back_to', @success_back_to) %> | 10 | <%= hidden_field_tag('success_back_to', @success_back_to) %> |
11 | 11 | ||
12 | - <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> | 12 | + <%= render_partial_for_class @article.class, f: f %> |
13 | 13 | ||
14 | <% if environment.is_portal_community?(profile) %> | 14 | <% if environment.is_portal_community?(profile) %> |
15 | <div> | 15 | <div> |
@@ -58,7 +58,7 @@ | @@ -58,7 +58,7 @@ | ||
58 | 58 | ||
59 | <% unless @article.new_record? %> | 59 | <% unless @article.new_record? %> |
60 | <%= button :delete, _('Delete'), {:controller => :cms, :action => :destroy, :id => @article}, | 60 | <%= button :delete, _('Delete'), {:controller => :cms, :action => :destroy, :id => @article}, |
61 | - :method => :post, :confirm => delete_article_message(@article) %> | 61 | + :method => :post, data: {confirm: delete_article_message(@article)} %> |
62 | <% end %> | 62 | <% end %> |
63 | <% end %> | 63 | <% end %> |
64 | <% end %> | 64 | <% end %> |