Merge pull request #3414 from consul/upgrade_to_rails_5

Upgrade to rails 5
This commit is contained in:
Raimond Garcia
2019-04-23 16:26:14 +02:00
committed by GitHub
593 changed files with 1542 additions and 1309 deletions

16
Gemfile
View File

@@ -1,6 +1,6 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "rails", "4.2.11.1" gem "rails", "5.0.7.2"
gem "acts-as-taggable-on", "~> 5.0.0" gem "acts-as-taggable-on", "~> 5.0.0"
gem "acts_as_votable", "~> 0.11.1" gem "acts_as_votable", "~> 0.11.1"
@@ -15,11 +15,13 @@ gem "coffee-rails", "~> 4.2.2"
gem "daemons", "~> 1.2.4" gem "daemons", "~> 1.2.4"
gem "dalli", "~> 2.7.6" gem "dalli", "~> 2.7.6"
gem "delayed_job_active_record", "~> 4.1.3" gem "delayed_job_active_record", "~> 4.1.3"
gem "devise", "~> 3.5.7" gem "devise", "~> 4.6.0"
gem "devise-async", "~> 0.10.2" gem "devise-async", "~> 1.0.0"
gem "devise_security_extension", "~> 0.10.0" gem "devise_security_extension", git: "https://github.com/phatworx/devise_security_extension.git" #, "~> 0.10"
gem "foundation-rails", "~> 6.4.3.0" gem "foundation-rails", "~> 6.4.3.0"
gem "foundation_rails_helper", "~> 2.0.0" gem "foundation_rails_helper", "~> 2.0.0"
gem "globalize", "~> 5.2.0"
gem "globalize-accessors", "~> 0.2.1"
gem "graphiql-rails", "~> 1.4.1" gem "graphiql-rails", "~> 1.4.1"
gem "graphql", "~> 1.7.8" gem "graphql", "~> 1.7.8"
gem "groupdate", "~> 3.2.0" gem "groupdate", "~> 3.2.0"
@@ -38,6 +40,7 @@ gem "paperclip", "~> 5.2.1"
gem "paranoia", "~> 2.4.1" gem "paranoia", "~> 2.4.1"
gem "pg", "~> 0.21.0" gem "pg", "~> 0.21.0"
gem "pg_search", "~> 2.0.1" gem "pg_search", "~> 2.0.1"
gem "record_tag_helper", "~> 1.0"
gem "redcarpet", "~> 3.4.0" gem "redcarpet", "~> 3.4.0"
gem "responders", "~> 2.4.0" gem "responders", "~> 2.4.0"
gem "rinku", "~> 2.0.2", require: "rails_rinku" gem "rinku", "~> 2.0.2", require: "rails_rinku"
@@ -52,8 +55,6 @@ gem "turnout", "~> 2.4.0"
gem "uglifier", "~> 4.1.19" gem "uglifier", "~> 4.1.19"
gem "unicorn", "~> 5.4.1" gem "unicorn", "~> 5.4.1"
gem "whenever", "~> 0.10.0", require: false gem "whenever", "~> 0.10.0", require: false
gem "globalize", "~> 5.0.0"
gem "globalize-accessors", "~> 0.2.1"
gem "recipient_interceptor", "~> 0.2.0" gem "recipient_interceptor", "~> 0.2.0"
source "https://rails-assets.org" do source "https://rails-assets.org" do
@@ -70,7 +71,6 @@ group :development, :test do
gem "knapsack_pro", "~> 1.1.0" gem "knapsack_pro", "~> 1.1.0"
gem "launchy", "~> 2.4.3" gem "launchy", "~> 2.4.3"
gem "letter_opener_web", "~> 1.3.4" gem "letter_opener_web", "~> 1.3.4"
gem "quiet_assets", "~> 1.1.0"
gem "spring", "~> 2.0.1" gem "spring", "~> 2.0.1"
gem "spring-commands-rspec", "~> 1.0.4" gem "spring-commands-rspec", "~> 1.0.4"
end end
@@ -81,7 +81,7 @@ group :test do
gem "database_cleaner", "~> 1.7.0" gem "database_cleaner", "~> 1.7.0"
gem "email_spec", "~> 2.1.0" gem "email_spec", "~> 2.1.0"
gem "rspec-rails", "~> 3.8" gem "rspec-rails", "~> 3.8"
gem "selenium-webdriver", "~> 3.10" gem "selenium-webdriver", "~> 3.141"
end end
group :development do group :development do

View File

@@ -1,40 +1,51 @@
GIT
remote: https://github.com/phatworx/devise_security_extension.git
revision: b2ee978af7d49f0fb0e7271c6ac074dfb4d39353
specs:
devise_security_extension (0.10.0)
devise (>= 3.0.0, < 5.0)
railties (>= 3.2.6, < 6.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
remote: https://rails-assets.org/ remote: https://rails-assets.org/
specs: specs:
actionmailer (4.2.11.1) actioncable (5.0.7.2)
actionpack (= 4.2.11.1) actionpack (= 5.0.7.2)
actionview (= 4.2.11.1) nio4r (>= 1.2, < 3.0)
activejob (= 4.2.11.1) websocket-driver (~> 0.6.1)
actionmailer (5.0.7.2)
actionpack (= 5.0.7.2)
actionview (= 5.0.7.2)
activejob (= 5.0.7.2)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 2.0)
actionpack (4.2.11.1) actionpack (5.0.7.2)
actionview (= 4.2.11.1) actionview (= 5.0.7.2)
activesupport (= 4.2.11.1) activesupport (= 5.0.7.2)
rack (~> 1.6) rack (~> 2.0)
rack-test (~> 0.6.2) rack-test (~> 0.6.3)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.11.1) actionview (5.0.7.2)
activesupport (= 4.2.11.1) activesupport (= 5.0.7.2)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (4.2.11.1) activejob (5.0.7.2)
activesupport (= 4.2.11.1) activesupport (= 5.0.7.2)
globalid (>= 0.3.0) globalid (>= 0.3.6)
activemodel (4.2.11.1) activemodel (5.0.7.2)
activesupport (= 4.2.11.1) activesupport (= 5.0.7.2)
builder (~> 3.1) activerecord (5.0.7.2)
activerecord (4.2.11.1) activemodel (= 5.0.7.2)
activemodel (= 4.2.11.1) activesupport (= 5.0.7.2)
activesupport (= 4.2.11.1) arel (~> 7.0)
arel (~> 6.0) activesupport (5.0.7.2)
activesupport (4.2.11.1) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
acts-as-taggable-on (5.0.0) acts-as-taggable-on (5.0.0)
activerecord (>= 4.2.8) activerecord (>= 4.2.8)
@@ -59,7 +70,7 @@ GEM
nokogiri nokogiri
ancestry (3.0.2) ancestry (3.0.2)
activerecord (>= 3.2.0) activerecord (>= 3.2.0)
arel (6.0.4) arel (7.1.4)
ast (2.4.0) ast (2.4.0)
autoprefixer-rails (8.2.0) autoprefixer-rails (8.2.0)
execjs execjs
@@ -67,7 +78,7 @@ GEM
babel-transpiler (0.7.0) babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6) babel-source (>= 4.0, < 6)
execjs (~> 2.0) execjs (~> 2.0)
bcrypt (3.1.11) bcrypt (3.1.12)
better_html (1.0.13) better_html (1.0.13)
actionview (>= 4.0) actionview (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
@@ -104,7 +115,7 @@ GEM
rack (>= 1.0.0) rack (>= 1.0.0)
rack-test (>= 0.5.4) rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0) xpath (>= 2.0, < 4.0)
childprocess (0.8.0) childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11) ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2) chronic (0.10.2)
ckeditor (4.2.4) ckeditor (4.2.4)
@@ -138,18 +149,15 @@ GEM
delayed_job_active_record (4.1.3) delayed_job_active_record (4.1.3)
activerecord (>= 3.0, < 5.3) activerecord (>= 3.0, < 5.3)
delayed_job (>= 3.0, < 5) delayed_job (>= 3.0, < 5)
devise (3.5.10) devise (4.6.2)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5) railties (>= 4.1.0, < 6.0)
responders responders
thread_safe (~> 0.1)
warden (~> 1.2.3) warden (~> 1.2.3)
devise-async (0.10.2) devise-async (1.0.0)
devise (>= 3.2, < 4.0) activejob (>= 5.0)
devise_security_extension (0.10.0) devise (>= 4.0)
devise (>= 3.0.0, < 4.0)
railties (>= 3.2.6, < 5.0)
diff-lcs (1.3) diff-lcs (1.3)
docile (1.3.1) docile (1.3.1)
email_spec (2.1.1) email_spec (2.1.1)
@@ -174,9 +182,9 @@ GEM
railties (>= 3.0.0) railties (>= 3.0.0)
faker (1.8.7) faker (1.8.7)
i18n (>= 0.7) i18n (>= 0.7)
faraday (0.12.1) faraday (0.12.2)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
ffi (1.9.25) ffi (1.10.0)
foundation-rails (6.4.3.0) foundation-rails (6.4.3.0)
railties (>= 3.1.0) railties (>= 3.1.0)
sass (>= 3.3.0, < 3.5) sass (>= 3.3.0, < 3.5)
@@ -187,12 +195,13 @@ GEM
activesupport (>= 4.1) activesupport (>= 4.1)
railties (>= 4.1) railties (>= 4.1)
tzinfo (~> 1.2, >= 1.2.2) tzinfo (~> 1.2, >= 1.2.2)
geocoder (1.4.4) geocoder (1.4.5)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
globalize (5.0.1) globalize (5.2.0)
activemodel (>= 4.2.0, < 4.3) activemodel (>= 4.2, < 5.3)
activerecord (>= 4.2.0, < 4.3) activerecord (>= 4.2, < 5.3)
request_store (~> 1.0)
globalize-accessors (0.2.1) globalize-accessors (0.2.1)
globalize (~> 5.0, >= 5.0.0) globalize (~> 5.0, >= 5.0.0)
graphiql-rails (1.4.8) graphiql-rails (1.4.8)
@@ -269,6 +278,7 @@ GEM
kramdown (~> 1.12, >= 1.12.0) kramdown (~> 1.12, >= 1.12.0)
mixlib-cli (~> 1.7, >= 1.7.0) mixlib-cli (~> 1.7, >= 1.7.0)
mixlib-config (~> 2.2, >= 2.2.1) mixlib-config (~> 2.2, >= 2.2.1)
method_source (0.9.2)
mime-types (3.1) mime-types (3.1)
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521) mime-types-data (3.2016.0521)
@@ -286,10 +296,11 @@ GEM
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
net-ssh (5.0.2) net-ssh (5.0.2)
newrelic_rpm (4.1.0.333) newrelic_rpm (4.1.0.333)
nokogiri (1.10.1) nio4r (2.3.1)
nokogiri (1.10.2)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
nori (2.6.0) nori (2.6.0)
oauth (0.5.3) oauth (0.5.4)
oauth2 (1.4.0) oauth2 (1.4.0)
faraday (>= 0.8, < 0.13) faraday (>= 0.8, < 0.13)
jwt (~> 1.0) jwt (~> 1.0)
@@ -309,8 +320,8 @@ GEM
omniauth-oauth (1.1.0) omniauth-oauth (1.1.0)
oauth oauth
omniauth (~> 1.0) omniauth (~> 1.0)
omniauth-oauth2 (1.4.0) omniauth-oauth2 (1.5.0)
oauth2 (~> 1.0) oauth2 (~> 1.1)
omniauth (~> 1.2) omniauth (~> 1.2)
omniauth-twitter (1.4.0) omniauth-twitter (1.4.0)
omniauth-oauth (~> 1.1) omniauth-oauth (~> 1.1)
@@ -334,39 +345,36 @@ GEM
arel (>= 6) arel (>= 6)
powerpack (0.1.2) powerpack (0.1.2)
public_suffix (3.0.3) public_suffix (3.0.3)
quiet_assets (1.1.0) rack (2.0.6)
railties (>= 3.1, < 5.0)
rack (1.6.11)
rack-accept (0.4.5) rack-accept (0.4.5)
rack (>= 0.4) rack (>= 0.4)
rack-attack (5.0.1) rack-attack (5.0.1)
rack rack
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (4.2.11.1) rails (5.0.7.2)
actionmailer (= 4.2.11.1) actioncable (= 5.0.7.2)
actionpack (= 4.2.11.1) actionmailer (= 5.0.7.2)
actionview (= 4.2.11.1) actionpack (= 5.0.7.2)
activejob (= 4.2.11.1) actionview (= 5.0.7.2)
activemodel (= 4.2.11.1) activejob (= 5.0.7.2)
activerecord (= 4.2.11.1) activemodel (= 5.0.7.2)
activesupport (= 4.2.11.1) activerecord (= 5.0.7.2)
bundler (>= 1.3.0, < 2.0) activesupport (= 5.0.7.2)
railties (= 4.2.11.1) bundler (>= 1.3.0)
sprockets-rails railties (= 5.0.7.2)
rails-assets-leaflet (1.1.0) sprockets-rails (>= 2.0.0)
rails-assets-leaflet (1.2.0)
rails-assets-markdown-it (8.2.2) rails-assets-markdown-it (8.2.2)
rails-deprecated_sanitizer (1.0.3) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0.alpha) activesupport (>= 4.2.0)
rails-dom-testing (1.0.9) nokogiri (>= 1.6)
activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.4) rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2) loofah (~> 2.2, >= 2.2.2)
railties (4.2.11.1) railties (5.0.7.2)
actionpack (= 4.2.11.1) actionpack (= 5.0.7.2)
activesupport (= 4.2.11.1) activesupport (= 5.0.7.2)
method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (3.0.0) rainbow (3.0.0)
@@ -374,12 +382,15 @@ GEM
rake (12.3.2) rake (12.3.2)
recipient_interceptor (0.2.0) recipient_interceptor (0.2.0)
mail mail
record_tag_helper (1.0.0)
actionview (~> 5.x)
redcarpet (3.4.0) redcarpet (3.4.0)
referer-parser (0.3.0) referer-parser (0.3.0)
request_store (1.3.2) request_store (1.4.0)
responders (2.4.0) rack (>= 1.4)
actionpack (>= 4.2.0, < 5.3) responders (2.4.1)
railties (>= 4.2.0, < 5.3) actionpack (>= 4.2.0, < 6.0)
railties (>= 4.2.0, < 6.0)
rinku (2.0.4) rinku (2.0.4)
rollbar (2.18.0) rollbar (2.18.0)
multi_json multi_json
@@ -391,7 +402,7 @@ GEM
rspec-mocks (3.8.0) rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0) rspec-support (~> 3.8.0)
rspec-rails (3.8.1) rspec-rails (3.8.2)
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
railties (>= 3.0) railties (>= 3.0)
@@ -434,9 +445,9 @@ GEM
scss_lint (0.55.0) scss_lint (0.55.0)
rake (>= 0.9, < 13) rake (>= 0.9, < 13)
sass (~> 3.4.20) sass (~> 3.4.20)
selenium-webdriver (3.10.0) selenium-webdriver (3.141.0)
childprocess (~> 0.5) childprocess (~> 0.5)
rubyzip (~> 1.2) rubyzip (~> 1.2, >= 1.2.2)
simplecov (0.16.1) simplecov (0.16.1)
docile (~> 1.1) docile (~> 1.1)
json (>= 1.8, < 3) json (>= 1.8, < 3)
@@ -475,9 +486,9 @@ GEM
tilt (2.0.8) tilt (2.0.8)
tins (1.16.3) tins (1.16.3)
tomlrb (1.2.7) tomlrb (1.2.7)
turbolinks (2.5.3) turbolinks (2.5.4)
coffee-rails coffee-rails
turnout (2.4.0) turnout (2.4.1)
i18n (~> 0.7) i18n (~> 0.7)
rack (>= 1.3, < 3) rack (>= 1.3, < 3)
rack-accept (~> 0.4) rack-accept (~> 0.4)
@@ -491,10 +502,10 @@ GEM
kgio (~> 2.6) kgio (~> 2.6)
raindrops (~> 0.7) raindrops (~> 0.7)
uniform_notifier (1.11.0) uniform_notifier (1.11.0)
user_agent_parser (2.3.1) user_agent_parser (2.4.1)
uuidtools (2.1.5) uuidtools (2.1.5)
warden (1.2.7) warden (1.2.8)
rack (>= 1.0) rack (>= 2.0.6)
wasabi (3.5.0) wasabi (3.5.0)
httpi (~> 2.0) httpi (~> 2.0)
nokogiri (>= 1.4.2) nokogiri (>= 1.4.2)
@@ -502,6 +513,9 @@ GEM
activemodel (>= 4.2) activemodel (>= 4.2)
debug_inspector debug_inspector
railties (>= 4.2) railties (>= 4.2)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
whenever (0.10.0) whenever (0.10.0)
chronic (>= 0.6.3) chronic (>= 0.6.3)
xpath (3.0.0) xpath (3.0.0)
@@ -533,16 +547,16 @@ DEPENDENCIES
dalli (~> 2.7.6) dalli (~> 2.7.6)
database_cleaner (~> 1.7.0) database_cleaner (~> 1.7.0)
delayed_job_active_record (~> 4.1.3) delayed_job_active_record (~> 4.1.3)
devise (~> 3.5.7) devise (~> 4.6.0)
devise-async (~> 0.10.2) devise-async (~> 1.0.0)
devise_security_extension (~> 0.10.0) devise_security_extension!
email_spec (~> 2.1.0) email_spec (~> 2.1.0)
erb_lint erb_lint
factory_bot_rails (~> 4.8.2) factory_bot_rails (~> 4.8.2)
faker (~> 1.8.7) faker (~> 1.8.7)
foundation-rails (~> 6.4.3.0) foundation-rails (~> 6.4.3.0)
foundation_rails_helper (~> 2.0.0) foundation_rails_helper (~> 2.0.0)
globalize (~> 5.0.0) globalize (~> 5.2.0)
globalize-accessors (~> 0.2.1) globalize-accessors (~> 0.2.1)
graphiql-rails (~> 1.4.1) graphiql-rails (~> 1.4.1)
graphql (~> 1.7.8) graphql (~> 1.7.8)
@@ -567,11 +581,11 @@ DEPENDENCIES
paranoia (~> 2.4.1) paranoia (~> 2.4.1)
pg (~> 0.21.0) pg (~> 0.21.0)
pg_search (~> 2.0.1) pg_search (~> 2.0.1)
quiet_assets (~> 1.1.0) rails (= 5.0.7.2)
rails (= 4.2.11.1)
rails-assets-leaflet! rails-assets-leaflet!
rails-assets-markdown-it (~> 8.2.1)! rails-assets-markdown-it (~> 8.2.1)!
recipient_interceptor (~> 0.2.0) recipient_interceptor (~> 0.2.0)
record_tag_helper (~> 1.0)
redcarpet (~> 3.4.0) redcarpet (~> 3.4.0)
responders (~> 2.4.0) responders (~> 2.4.0)
rinku (~> 2.0.2) rinku (~> 2.0.2)
@@ -583,7 +597,7 @@ DEPENDENCIES
sass-rails (~> 5.0, >= 5.0.4) sass-rails (~> 5.0, >= 5.0.4)
savon (~> 2.12.0) savon (~> 2.12.0)
scss_lint (~> 0.55.0) scss_lint (~> 0.55.0)
selenium-webdriver (~> 3.10) selenium-webdriver (~> 3.141)
sitemap_generator (~> 6.0.1) sitemap_generator (~> 6.0.1)
social-share-button (~> 1.1) social-share-button (~> 1.1)
spring (~> 2.0.1) spring (~> 2.0.1)

View File

@@ -39,7 +39,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
if @investment.update(budget_investment_params) if @investment.update(budget_investment_params)
redirect_to admin_budget_budget_investment_path(@budget, redirect_to admin_budget_budget_investment_path(@budget,
@investment, @investment,
Budget::Investment.filter_params(params)), Budget::Investment.filter_params(params).to_h),
notice: t("flash.actions.update.budget_investment") notice: t("flash.actions.update.budget_investment")
else else
load_admins load_admins
@@ -69,7 +69,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end end
def resource_name def resource_name
resource_model.parameterize("_") resource_model.parameterize(separator: "_")
end end
def load_investments def load_investments
@@ -107,7 +107,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end end
def load_tags def load_tags
@tags = Budget::Investment.tags_on(:valuation).order(:name).uniq @tags = Budget::Investment.tags_on(:valuation).order(:name).distinct
end end
def load_ballot def load_ballot

View File

@@ -9,7 +9,8 @@ class Admin::Legislation::HomepagesController < Admin::Legislation::BaseControll
def update def update
if @process.update(process_params) if @process.update(process_params)
link = legislation_process_path(@process).html_safe link = legislation_process_path(@process).html_safe
redirect_to :back, notice: t("admin.legislation.processes.update.notice", link: link) redirect_back(fallback_location: (request.referrer || root_path),
notice: t("admin.legislation.processes.update.notice", link: link))
else else
flash.now[:error] = t("admin.legislation.processes.update.error") flash.now[:error] = t("admin.legislation.processes.update.error")
render :edit render :edit

View File

@@ -27,7 +27,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
set_tag_list set_tag_list
link = legislation_process_path(@process).html_safe link = legislation_process_path(@process).html_safe
redirect_to :back, notice: t("admin.legislation.processes.update.notice", link: link) redirect_back(fallback_location: (request.referrer || root_path),
notice: t("admin.legislation.processes.update.notice", link: link))
else else
flash.now[:error] = t("admin.legislation.processes.update.error") flash.now[:error] = t("admin.legislation.processes.update.error")
render :edit render :edit

View File

@@ -11,9 +11,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
end end
def show def show
@poll = Poll.includes(:questions). @poll = Poll.find(params[:id])
order("poll_questions.title").
find(params[:id])
end end
def new def new
@@ -67,6 +65,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
end end
def poll_params def poll_params
image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled, attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled,
:stats_enabled, :budget_id, geozone_ids: [], :stats_enabled, :budget_id, geozone_ids: [],
image_attributes: image_attributes] image_attributes: image_attributes]

View File

@@ -38,7 +38,7 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr
else else
t("flash.actions.destroy.error") t("flash.actions.destroy.error")
end end
redirect_to :back, notice: notice redirect_back(fallback_location: (request.referrer || root_path), notice: notice)
end end
private private

View File

@@ -46,7 +46,7 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
.keys .keys
languages_to_delete.each do |locale| languages_to_delete.each do |locale|
I18nContentTranslation.destroy_all(locale: locale) I18nContentTranslation.where(locale: locale).destroy_all
end end
end end

View File

@@ -1,5 +1,6 @@
class Admin::SpendingProposalsController < Admin::BaseController class Admin::SpendingProposalsController < Admin::BaseController
include FeatureFlags include FeatureFlags
before_action :load_filter_params
feature_flag :spending_proposals feature_flag :spending_proposals
has_filters %w{valuation_open without_admin managed valuating valuation_finished all}, only: :index has_filters %w{valuation_open without_admin managed valuating valuation_finished all}, only: :index
@@ -7,7 +8,7 @@ class Admin::SpendingProposalsController < Admin::BaseController
load_and_authorize_resource load_and_authorize_resource
def index def index
@spending_proposals = SpendingProposal.scoped_filter(params, @current_filter) @spending_proposals = SpendingProposal.scoped_filter(filter_params, @current_filter)
.order(cached_votes_up: :desc, created_at: :desc) .order(cached_votes_up: :desc, created_at: :desc)
.page(params[:page]) .page(params[:page])
end end
@@ -23,7 +24,7 @@ class Admin::SpendingProposalsController < Admin::BaseController
def update def update
if @spending_proposal.update(spending_proposal_params) if @spending_proposal.update(spending_proposal_params)
redirect_to admin_spending_proposal_path(@spending_proposal, SpendingProposal.filter_params(params)), redirect_to admin_spending_proposal_path(@spending_proposal, filter_params),
notice: t("flash.actions.update.spending_proposal") notice: t("flash.actions.update.spending_proposal")
else else
load_admins load_admins
@@ -46,6 +47,14 @@ class Admin::SpendingProposalsController < Admin::BaseController
:administrator_id, :tag_list, valuator_ids: []) :administrator_id, :tag_list, valuator_ids: [])
end end
def filter_params
params.permit(:geozone_id, :administrator_id, :tag_name, :valuator_id)
end
def load_filter_params
@filter_params ||= filter_params
end
def load_admins def load_admins
@admins = Administrator.includes(:user).all @admins = Administrator.includes(:user).all
end end

View File

@@ -4,7 +4,7 @@ class Admin::Widget::FeedsController < Admin::BaseController
@feed = ::Widget::Feed.find(params[:id]) @feed = ::Widget::Feed.find(params[:id])
@feed.update(feed_params) @feed.update(feed_params)
render nothing: true head :ok
end end
private private

View File

@@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
before_action :set_locale before_action :set_locale
before_action :track_email_campaign before_action :track_email_campaign
before_action :set_return_url before_action :set_return_url
before_action :set_fallbacks_to_all_available_locales
check_authorization unless: :devise_controller? check_authorization unless: :devise_controller?
self.responder = ApplicationResponder self.responder = ApplicationResponder
@@ -128,4 +129,8 @@ class ApplicationController < ActionController::Base
def current_budget def current_budget
Budget.current Budget.current
end end
def set_fallbacks_to_all_available_locales
Globalize.set_fallbacks_to_all_available_locales
end
end end

View File

@@ -19,7 +19,7 @@ module Budgets
.group_by(&:heading) .group_by(&:heading)
else else
@budget.investments.winners @budget.investments.winners
.joins(:milestones).includes(:milestones) .joins(milestones: :translations)
.distinct.group_by(&:heading) .distinct.group_by(&:heading)
end end
end end

View File

@@ -22,7 +22,7 @@ class FollowsController < ApplicationController
end end
def followable_translation_key(followable) def followable_translation_key(followable)
followable.class.name.parameterize("_") followable.class.name.parameterize(separator: "_")
end end
end end

View File

@@ -1,4 +1,4 @@
class Legislation::AnnotationsController < ApplicationController class Legislation::AnnotationsController < Legislation::BaseController
skip_before_action :verify_authenticity_token skip_before_action :verify_authenticity_token
before_action :authenticate_user!, only: [:create, :new_comment] before_action :authenticate_user!, only: [:create, :new_comment]

View File

@@ -16,7 +16,7 @@ class Management::DocumentVerificationsController < Management::BaseController
elsif @document_verification.user? elsif @document_verification.user?
render :new render :new
elsif @document_verification.in_census? elsif @document_verification.in_census?
redirect_to new_management_email_verification_path(email_verification: document_verification_params) redirect_to new_management_email_verification_path(email_verification: document_verification_params.to_h)
else else
render :invalid_document render :invalid_document
end end

View File

@@ -17,7 +17,7 @@ class Management::UsersController < Management::BaseController
@user.residence_verified_at = Time.current @user.residence_verified_at = Time.current
@user.verified_at = Time.current @user.verified_at = Time.current
if @user.save then if @user.save
render :show render :show
else else
render :new render :new

View File

@@ -11,7 +11,7 @@ class PollsController < ApplicationController
::Poll::Answer # trigger autoload ::Poll::Answer # trigger autoload
def index def index
@polls = @polls.not_budget.send(@current_filter).includes(:geozones).sort_for_list.page(params[:page]) @polls = @polls.not_budget.send(@current_filter).sort_for_list.page(params[:page])
end end
def show def show

View File

@@ -25,7 +25,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def sign_in_with(feature, provider) def sign_in_with(feature, provider)
raise ActionController::RoutingError.new("Not Found") unless Setting["feature.#{feature}"] raise ActionController::RoutingError.new("Not Found") unless Setting["feature.#{feature}"]
auth = env["omniauth.auth"] auth = request.env["omniauth.auth"]
identity = Identity.first_or_create_from_oauth(auth) identity = Identity.first_or_create_from_oauth(auth)
@user = current_user || identity.user || User.first_or_initialize_for_oauth(auth) @user = current_user || identity.user || User.first_or_initialize_for_oauth(auth)

View File

@@ -1,6 +1,6 @@
class Users::RegistrationsController < Devise::RegistrationsController class Users::RegistrationsController < Devise::RegistrationsController
prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy, :finish_signup, :do_finish_signup] prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy, :finish_signup, :do_finish_signup]
before_filter :configure_permitted_parameters before_action :configure_permitted_parameters
invisible_captcha only: [:create], honeypot: :address, scope: :user invisible_captcha only: [:create], honeypot: :address, scope: :user
@@ -66,7 +66,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
end end
def configure_permitted_parameters def configure_permitted_parameters
devise_parameter_sanitizer.for(:account_update).push(:email) devise_parameter_sanitizer.permit(:account_update, keys: [:email])
end end
def erase_params def erase_params

View File

@@ -61,7 +61,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
end end
def resource_name def resource_name
resource_model.parameterize("_") resource_model.parameterize(separator: "_")
end end
def load_budget def load_budget
@@ -97,8 +97,8 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
end end
def params_for_current_valuator def params_for_current_valuator
Budget::Investment.filter_params(params).merge(valuator_id: current_user.valuator.id, Budget::Investment.filter_params(params).to_h.merge({ valuator_id: current_user.valuator.id,
budget_id: @budget.id) budget_id: @budget.id })
end end
def valuation_params def valuation_params

View File

@@ -12,7 +12,8 @@ module BudgetsHelper
end end
def csv_params def csv_params
csv_params = params.clone.merge(format: :csv).symbolize_keys csv_params = params.clone.merge(format: :csv)
csv_params = csv_params.to_unsafe_h.map { |k, v| [k.to_sym, v] }.to_h
csv_params.delete(:page) csv_params.delete(:page)
csv_params csv_params
end end

View File

@@ -1,7 +1,7 @@
module DocumentablesHelper module DocumentablesHelper
def documentable_class(documentable) def documentable_class(documentable)
documentable.class.name.parameterize("_") documentable.class.name.parameterize(separator: "_")
end end
def max_documents_allowed(documentable) def max_documents_allowed(documentable)

View File

@@ -22,7 +22,7 @@ module FollowablesHelper
end end
def followable_class_name(followable) def followable_class_name(followable)
followable.class.to_s.parameterize("_") followable.class.to_s.parameterize(separator: "_")
end end
def find_or_build_follow(user, followable) def find_or_build_follow(user, followable)

View File

@@ -12,7 +12,7 @@ module GlobalizeHelper
def display_translation?(resource, locale) def display_translation?(resource, locale)
if !resource || resource.translations.blank? || if !resource || resource.translations.blank? ||
resource.translations.map(&:locale).include?(I18n.locale) resource.locales_not_marked_for_destruction.include?(I18n.locale)
locale == I18n.locale locale == I18n.locale
else else
locale == resource.translations.first.locale locale == resource.translations.first.locale

View File

@@ -5,7 +5,7 @@ module ImageablesHelper
end end
def imageable_class(imageable) def imageable_class(imageable)
imageable.class.name.parameterize("_") imageable.class.name.parameterize(separator: "_")
end end
def imageable_max_file_size def imageable_max_file_size

View File

@@ -6,7 +6,13 @@ module TranslatableFormHelper
end end
class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder
attr_accessor :translations
def translatable_fields(&block) def translatable_fields(&block)
@translations = {}
@object.globalize_locales.map do |locale|
@translations[locale] = translation_for(locale)
end
@object.globalize_locales.map do |locale| @object.globalize_locales.map do |locale|
Globalize.with_locale(locale) { fields_for_locale(locale, &block) } Globalize.with_locale(locale) { fields_for_locale(locale, &block) }
end.join.html_safe end.join.html_safe
@@ -15,7 +21,7 @@ module TranslatableFormHelper
private private
def fields_for_locale(locale, &block) def fields_for_locale(locale, &block)
fields_for_translation(translation_for(locale)) do |translations_form| fields_for_translation(@translations[locale]) do |translations_form|
@template.content_tag :div, translations_options(translations_form.object, locale) do @template.content_tag :div, translations_options(translations_form.object, locale) do
@template.concat translations_form.hidden_field( @template.concat translations_form.hidden_field(
:_destroy, :_destroy,

View File

@@ -1,4 +1,4 @@
class ActivePoll < ActiveRecord::Base class ActivePoll < ApplicationRecord
include Measurable include Measurable
translates :description, touch: true translates :description, touch: true

View File

@@ -1,4 +1,4 @@
class Activity < ActiveRecord::Base class Activity < ApplicationRecord
belongs_to :actionable, -> { with_hidden }, polymorphic: true belongs_to :actionable, -> { with_hidden }, polymorphic: true
belongs_to :user, -> { with_hidden } belongs_to :user, -> { with_hidden }

View File

@@ -1,4 +1,4 @@
class AdminNotification < ActiveRecord::Base class AdminNotification < ApplicationRecord
include Notifiable include Notifiable
translates :title, touch: true translates :title, touch: true

View File

@@ -1,4 +1,4 @@
class Administrator < ActiveRecord::Base class Administrator < ApplicationRecord
belongs_to :user, touch: true belongs_to :user, touch: true
delegate :name, :email, :name_and_email, to: :user delegate :name, :email, :name_and_email, to: :user

View File

@@ -1,5 +1,5 @@
module Ahoy module Ahoy
class Event < ActiveRecord::Base class Event < ApplicationRecord
self.table_name = "ahoy_events" self.table_name = "ahoy_events"
belongs_to :visit belongs_to :visit

View File

@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

@@ -1,4 +1,4 @@
class Banner < ActiveRecord::Base class Banner < ApplicationRecord
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases include ActsAsParanoidAliases

View File

@@ -1,4 +1,4 @@
class Banner::Section < ActiveRecord::Base class Banner::Section < ApplicationRecord
belongs_to :banner belongs_to :banner
belongs_to :web_section belongs_to :web_section
end end

View File

@@ -1,4 +1,4 @@
class Budget < ActiveRecord::Base class Budget < ApplicationRecord
include Measurable include Measurable
include Sluggable include Sluggable
@@ -6,6 +6,18 @@ class Budget < ActiveRecord::Base
translates :name, touch: true translates :name, touch: true
include Globalizable include Globalizable
class Translation
validate :name_uniqueness_by_budget
def name_uniqueness_by_budget
if Budget.joins(:translations)
.where(name: name)
.where.not("budget_translations.budget_id": budget_id).any?
errors.add(:name, I18n.t("errors.messages.taken"))
end
end
end
CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze
before_validation :assign_model_to_translations before_validation :assign_model_to_translations

View File

@@ -1,13 +1,13 @@
class Budget class Budget
class Ballot < ActiveRecord::Base class Ballot < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :budget belongs_to :budget
belongs_to :poll_ballot, class_name: "Poll::Ballot" belongs_to :poll_ballot, class_name: "Poll::Ballot"
has_many :lines, dependent: :destroy has_many :lines, dependent: :destroy
has_many :investments, through: :lines has_many :investments, through: :lines
has_many :groups, -> { uniq }, through: :lines has_many :groups, -> { distinct }, through: :lines
has_many :headings, -> { uniq }, through: :groups has_many :headings, -> { distinct }, through: :groups
def add_investment(investment) def add_investment(investment)
lines.create(investment: investment).persisted? lines.create(investment: investment).persisted?

View File

@@ -1,6 +1,6 @@
class Budget class Budget
class Ballot class Ballot
class Line < ActiveRecord::Base class Line < ApplicationRecord
belongs_to :ballot belongs_to :ballot
belongs_to :investment, counter_cache: :ballot_lines_count belongs_to :investment, counter_cache: :ballot_lines_count
belongs_to :heading belongs_to :heading

View File

@@ -1,5 +1,5 @@
class Budget class Budget
class ContentBlock < ActiveRecord::Base class ContentBlock < ApplicationRecord
validates :locale, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) } validates :locale, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) }
validates :heading, presence: true validates :heading, presence: true
validates_uniqueness_of :heading, scope: :locale validates_uniqueness_of :heading, scope: :locale

View File

@@ -1,9 +1,22 @@
class Budget class Budget
class Group < ActiveRecord::Base class Group < ApplicationRecord
include Sluggable include Sluggable
translates :name, touch: true translates :name, touch: true
include Globalizable include Globalizable
translation_class_delegate :budget
class Translation
validate :name_uniqueness_by_budget
def name_uniqueness_by_budget
if budget.groups.joins(:translations)
.where(name: name)
.where.not("budget_group_translations.budget_group_id": budget_group_id).any?
errors.add(:name, I18n.t("errors.messages.taken"))
end
end
end
belongs_to :budget belongs_to :budget
@@ -15,7 +28,7 @@ class Budget
validates :budget_id, presence: true validates :budget_id, presence: true
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/ validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
scope :sort_by_name, -> { includes(:translations).order(:name) } scope :sort_by_name, -> { joins(:translations).order(:name) }
def single_heading_group? def single_heading_group?
headings.count == 1 headings.count == 1

View File

@@ -1,13 +0,0 @@
class Budget::Group::Translation < Globalize::ActiveRecord::Translation
delegate :budget, to: :globalized_model
validate :name_uniqueness_by_budget
def name_uniqueness_by_budget
if budget.groups.joins(:translations)
.where(name: name)
.where.not("budget_group_translations.budget_group_id": budget_group_id).any?
errors.add(:name, I18n.t("errors.messages.taken"))
end
end
end

View File

@@ -1,11 +1,25 @@
class Budget class Budget
class Heading < ActiveRecord::Base class Heading < ApplicationRecord
OSM_DISTRICT_LEVEL_ZOOM = 12.freeze OSM_DISTRICT_LEVEL_ZOOM = 12.freeze
include Sluggable include Sluggable
translates :name, touch: true translates :name, touch: true
include Globalizable include Globalizable
translation_class_delegate :budget
class Translation
validate :name_uniqueness_by_budget
def name_uniqueness_by_budget
if budget.headings
.joins(:translations)
.where(name: name)
.where.not("budget_heading_translations.budget_heading_id": budget_heading_id).any?
errors.add(:name, I18n.t("errors.messages.taken"))
end
end
end
belongs_to :group belongs_to :group
@@ -26,8 +40,8 @@ class Budget
delegate :budget, :budget_id, to: :group, allow_nil: true delegate :budget, :budget_id, to: :group, allow_nil: true
scope :i18n, -> { includes(:translations) } scope :i18n, -> { joins(:translations) }
scope :allow_custom_content, -> { i18n.where(allow_custom_content: true).order(:name) } scope :allow_custom_content, -> { i18n.where(allow_custom_content: true).order("budget_heading_translations.name") }
def self.sort_by_name def self.sort_by_name
all.sort do |heading, other_heading| all.sort do |heading, other_heading|

View File

@@ -1,14 +0,0 @@
class Budget::Heading::Translation < Globalize::ActiveRecord::Translation
delegate :budget, to: :globalized_model
validate :name_uniqueness_by_budget
def name_uniqueness_by_budget
if budget.headings
.joins(:translations)
.where(name: name)
.where.not("budget_heading_translations.budget_heading_id": budget_heading_id).any?
errors.add(:name, I18n.t("errors.messages.taken"))
end
end
end

View File

@@ -1,5 +1,5 @@
class Budget class Budget
class Investment < ActiveRecord::Base class Investment < ApplicationRecord
SORTING_OPTIONS = {id: "id", title: "title", supports: "cached_votes_up"}.freeze SORTING_OPTIONS = {id: "id", title: "title", supports: "cached_votes_up"}.freeze
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
@@ -109,7 +109,7 @@ class Budget
end end
def self.filter_params(params) def self.filter_params(params)
params.select{ |x, _| %w{heading_id group_id administrator_id tag_name valuator_id}.include?(x.to_s) } params.permit(%i[heading_id group_id administrator_id tag_name valuator_id])
end end
def self.scoped_filter(params, current_filter) def self.scoped_filter(params, current_filter)
@@ -368,7 +368,7 @@ class Budget
end end
def self.with_milestone_status_id(status_id) def self.with_milestone_status_id(status_id)
joins(:milestones).includes(:milestones).select do |investment| includes(milestones: :translations).select do |investment|
investment.milestone_status_id == status_id.to_i investment.milestone_status_id == status_id.to_i
end end
end end

View File

@@ -1,5 +1,5 @@
class Budget class Budget
class Phase < ActiveRecord::Base class Phase < ApplicationRecord
PHASE_KINDS = %w(drafting informing accepting reviewing selecting valuating publishing_prices balloting PHASE_KINDS = %w(drafting informing accepting reviewing selecting valuating publishing_prices balloting
reviewing_ballots finished).freeze reviewing_ballots finished).freeze
PUBLISHED_PRICES_PHASES = %w(publishing_prices balloting reviewing_ballots finished).freeze PUBLISHED_PRICES_PHASES = %w(publishing_prices balloting reviewing_ballots finished).freeze
@@ -9,6 +9,7 @@ class Budget
translates :summary, touch: true translates :summary, touch: true
translates :description, touch: true translates :description, touch: true
include Globalizable include Globalizable
include Sanitizable
belongs_to :budget belongs_to :budget
belongs_to :next_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id belongs_to :next_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id

View File

@@ -1,9 +0,0 @@
class Budget::Phase::Translation < Globalize::ActiveRecord::Translation
before_validation :sanitize_description
private
def sanitize_description
self.description = WYSIWYGSanitizer.new.sanitize(description)
end
end

View File

@@ -1,5 +1,5 @@
class Budget class Budget
class ReclassifiedVote < ActiveRecord::Base class ReclassifiedVote < ApplicationRecord
REASONS = %w(heading_changed unfeasible) REASONS = %w(heading_changed unfeasible)
belongs_to :user belongs_to :user

View File

@@ -1,11 +0,0 @@
class Budget::Translation < Globalize::ActiveRecord::Translation
validate :name_uniqueness_by_budget
def name_uniqueness_by_budget
if Budget.joins(:translations)
.where(name: name)
.where.not("budget_translations.budget_id": budget_id).any?
errors.add(:name, I18n.t("errors.messages.taken"))
end
end
end

View File

@@ -1,5 +1,5 @@
class Budget class Budget
class ValuatorAssignment < ActiveRecord::Base class ValuatorAssignment < ApplicationRecord
belongs_to :valuator, counter_cache: :budget_investments_count belongs_to :valuator, counter_cache: :budget_investments_count
belongs_to :investment, counter_cache: true belongs_to :investment, counter_cache: true
end end

View File

@@ -1,5 +1,5 @@
class Budget class Budget
class ValuatorGroupAssignment < ActiveRecord::Base class ValuatorGroupAssignment < ApplicationRecord
belongs_to :valuator_group, counter_cache: :budget_investments_count belongs_to :valuator_group, counter_cache: :budget_investments_count
belongs_to :investment, counter_cache: true belongs_to :investment, counter_cache: true
end end

View File

@@ -1,2 +1,2 @@
class Campaign < ActiveRecord::Base class Campaign < ApplicationRecord
end end

View File

@@ -1,4 +1,4 @@
class Ckeditor::Asset < ActiveRecord::Base class Ckeditor::Asset < ApplicationRecord
include Ckeditor::Orm::ActiveRecord::AssetBase include Ckeditor::Orm::ActiveRecord::AssetBase
include Ckeditor::Backend::Paperclip include Ckeditor::Backend::Paperclip
end end

View File

@@ -1,4 +1,4 @@
class Comment < ActiveRecord::Base class Comment < ApplicationRecord
include Flaggable include Flaggable
include HasPublicAuthor include HasPublicAuthor
include Graphqlable include Graphqlable
@@ -22,7 +22,7 @@ class Comment < ActiveRecord::Base
validate :validate_body_length validate :validate_body_length
validate :comment_valuation, if: -> { valuation } validate :comment_valuation, if: -> { valuation }
belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true, touch: true
belongs_to :user, -> { with_hidden } belongs_to :user, -> { with_hidden }
before_save :calculate_confidence_score before_save :calculate_confidence_score

View File

@@ -1,4 +1,4 @@
class Community < ActiveRecord::Base class Community < ApplicationRecord
has_one :proposal has_one :proposal
has_one :investment, class_name: Budget::Investment has_one :investment, class_name: Budget::Investment
has_many :topics has_many :topics

View File

@@ -6,7 +6,7 @@ module Galleryable
accepts_nested_attributes_for :images, allow_destroy: true, update_only: true accepts_nested_attributes_for :images, allow_destroy: true, update_only: true
def image_url(style) def image_url(style)
image.attachment.url(style) if image && image.attachment.exists? image&.attachment&.url(style) || ""
end end
end end
end end

View File

@@ -12,6 +12,10 @@ module Globalizable
def assign_model_to_translations def assign_model_to_translations
translations.each { |translation| translation.globalized_model = self } translations.each { |translation| translation.globalized_model = self }
end end
def description
self.read_attribute(:description).try :html_safe
end
end end
class_methods do class_methods do
@@ -19,5 +23,9 @@ module Globalizable
validates(method, options.merge(if: lambda { |resource| resource.translations.blank? })) validates(method, options.merge(if: lambda { |resource| resource.translations.blank? }))
translation_class.instance_eval { validates method, options } translation_class.instance_eval { validates method, options }
end end
def translation_class_delegate(method)
translation_class.instance_eval { delegate method, to: :globalized_model }
end
end end
end end

View File

@@ -6,7 +6,7 @@ module Imageable
accepts_nested_attributes_for :image, allow_destroy: true, update_only: true accepts_nested_attributes_for :image, allow_destroy: true, update_only: true
def image_url(style) def image_url(style)
image.attachment.url(style) if image && image.attachment.exists? image&.attachment&.url(style) || ""
end end
end end
end end

View File

@@ -4,20 +4,47 @@ module Sanitizable
included do included do
before_validation :sanitize_description before_validation :sanitize_description
before_validation :sanitize_tag_list before_validation :sanitize_tag_list
end
unless included_modules.include? Globalizable
def description def description
super.try :html_safe super.try :html_safe
end end
end
end
protected protected
def sanitize_description def sanitize_description
if translatable_description?
sanitize_description_translations
else
self.description = WYSIWYGSanitizer.new.sanitize(description) self.description = WYSIWYGSanitizer.new.sanitize(description)
end end
end
def sanitize_tag_list def sanitize_tag_list
self.tag_list = TagSanitizer.new.sanitize_tag_list(tag_list) if self.class.taggable? self.tag_list = TagSanitizer.new.sanitize_tag_list(tag_list) if self.class.taggable?
end end
def translatable_description?
self.class.included_modules.include?(Globalizable) &&
self.class.translated_attribute_names.include?(:description)
end
def sanitize_description_translations
# Sanitize description when using attribute accessor in place of nested translations.
# This is because Globalize gem create translations on after save callback
# https://github.com/globalize/globalize/blob/e37c471775d196cd4318e61954572c300c015467/lib/globalize/active_record/act_macro.rb#L105
if translations.empty?
Globalize.with_locale(I18n.locale) do
self.description = WYSIWYGSanitizer.new.sanitize(description)
end
end
translations.reject(&:_destroy).each do |translation|
Globalize.with_locale(translation.locale) do
self.description = WYSIWYGSanitizer.new.sanitize(description)
end
end
end
end end

View File

@@ -1,5 +1,5 @@
require "numeric" require "numeric"
class Debate < ActiveRecord::Base class Debate < ApplicationRecord
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
include Flaggable include Flaggable
include Taggable include Taggable

View File

@@ -1,4 +1,4 @@
class DirectMessage < ActiveRecord::Base class DirectMessage < ApplicationRecord
belongs_to :sender, class_name: "User", foreign_key: "sender_id" belongs_to :sender, class_name: "User", foreign_key: "sender_id"
belongs_to :receiver, class_name: "User", foreign_key: "receiver_id" belongs_to :receiver, class_name: "User", foreign_key: "receiver_id"

View File

@@ -51,7 +51,7 @@ class DirectUpload
@relation.valid? @relation.valid?
if @relation.errors.key? :attachment if @relation.errors.key? :attachment
errors[:attachment] = @relation.errors[:attachment] errors.add(:attachment, @relation.errors.full_messages_for(:attachment))
end end
end end

View File

@@ -1,4 +1,4 @@
class Document < ActiveRecord::Base class Document < ApplicationRecord
include DocumentsHelper include DocumentsHelper
include DocumentablesHelper include DocumentablesHelper
has_attached_file :attachment, url: "/system/:class/:prefix/:style/:hash.:extension", has_attached_file :attachment, url: "/system/:class/:prefix/:style/:hash.:extension",
@@ -80,24 +80,26 @@ class Document < ActiveRecord::Base
def validate_attachment_size def validate_attachment_size
if documentable_class.present? && if documentable_class.present? &&
attachment_file_size > documentable_class.max_file_size attachment_file_size > documentable_class.max_file_size
errors[:attachment] = I18n.t("documents.errors.messages.in_between", errors.add(:attachment, I18n.t("documents.errors.messages.in_between",
min: "0 Bytes", min: "0 Bytes",
max: "#{max_file_size(documentable_class)} MB") max: "#{max_file_size(documentable_class)} MB"))
end end
end end
def validate_attachment_content_type def validate_attachment_content_type
if documentable_class && if documentable_class &&
!accepted_content_types(documentable_class).include?(attachment_content_type) !accepted_content_types(documentable_class).include?(attachment_content_type)
errors[:attachment] = I18n.t("documents.errors.messages.wrong_content_type", accepted_content_types = documentable_humanized_accepted_content_types(documentable_class)
message = I18n.t("documents.errors.messages.wrong_content_type",
content_type: attachment_content_type, content_type: attachment_content_type,
accepted_content_types: documentable_humanized_accepted_content_types(documentable_class)) accepted_content_types: accepted_content_types)
errors.add(:attachment, message)
end end
end end
def attachment_presence def attachment_presence
if attachment.blank? && cached_attachment.blank? if attachment.blank? && cached_attachment.blank?
errors[:attachment] = I18n.t("errors.messages.blank") errors.add(:attachment, I18n.t("errors.messages.blank"))
end end
end end

View File

@@ -1,4 +1,4 @@
class FailedCensusCall < ActiveRecord::Base class FailedCensusCall < ApplicationRecord
belongs_to :user, counter_cache: true belongs_to :user, counter_cache: true
belongs_to :poll_officer, class_name: "Poll::Officer", counter_cache: true belongs_to :poll_officer, class_name: "Poll::Officer", counter_cache: true
end end

View File

@@ -1,4 +1,4 @@
class Flag < ActiveRecord::Base class Flag < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :flaggable, polymorphic: true, counter_cache: true, touch: true belongs_to :flaggable, polymorphic: true, counter_cache: true, touch: true

View File

@@ -1,4 +1,4 @@
class Follow < ActiveRecord::Base class Follow < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :followable, polymorphic: true belongs_to :followable, polymorphic: true

View File

@@ -1,4 +1,4 @@
class Geozone < ActiveRecord::Base class Geozone < ApplicationRecord
include Graphqlable include Graphqlable

View File

@@ -1,4 +1,4 @@
class I18nContent < ActiveRecord::Base class I18nContent < ApplicationRecord
scope :by_key, ->(key) { where(key: key) } scope :by_key, ->(key) { where(key: key) }
scope :begins_with_key, ->(key) { where("key ILIKE ?", "#{key}%") } scope :begins_with_key, ->(key) { where("key ILIKE ?", "#{key}%") }

View File

@@ -1,5 +1,5 @@
class I18nContentTranslation < ActiveRecord::Base class I18nContentTranslation < ApplicationRecord
def self.existing_languages def self.existing_languages
self.select(:locale).uniq.map{ |l| l.locale.to_sym }.to_a self.select(:locale).distinct.map { |l| l.locale.to_sym }.to_a
end end
end end

View File

@@ -1,4 +1,4 @@
class Identity < ActiveRecord::Base class Identity < ApplicationRecord
belongs_to :user belongs_to :user
validates :provider, presence: true validates :provider, presence: true

View File

@@ -1,4 +1,4 @@
class Image < ActiveRecord::Base class Image < ApplicationRecord
include ImagesHelper include ImagesHelper
include ImageablesHelper include ImageablesHelper
@@ -79,23 +79,24 @@ class Image < ActiveRecord::Base
def validate_attachment_size def validate_attachment_size
if imageable_class && if imageable_class &&
attachment_file_size > 1.megabytes attachment_file_size > 1.megabytes
errors[:attachment] = I18n.t("images.errors.messages.in_between", errors.add(:attachment, I18n.t("images.errors.messages.in_between",
min: "0 Bytes", min: "0 Bytes",
max: "#{imageable_max_file_size} MB") max: "#{imageable_max_file_size} MB"))
end end
end end
def validate_attachment_content_type def validate_attachment_content_type
if imageable_class && !attachment_of_valid_content_type? if imageable_class && !attachment_of_valid_content_type?
errors[:attachment] = I18n.t("images.errors.messages.wrong_content_type", message = I18n.t("images.errors.messages.wrong_content_type",
content_type: attachment_content_type, content_type: attachment_content_type,
accepted_content_types: imageable_humanized_accepted_content_types) accepted_content_types: imageable_humanized_accepted_content_types)
errors.add(:attachment, message)
end end
end end
def attachment_presence def attachment_presence
if attachment.blank? && cached_attachment.blank? if attachment.blank? && cached_attachment.blank?
errors[:attachment] = I18n.t("errors.messages.blank") errors.add(:attachment, I18n.t("errors.messages.blank"))
end end
end end

View File

@@ -1,4 +1,4 @@
class Legislation::Annotation < ActiveRecord::Base class Legislation::Annotation < ApplicationRecord
COMMENTS_PAGE_SIZE = 5 COMMENTS_PAGE_SIZE = 5
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases include ActsAsParanoidAliases

View File

@@ -1,4 +1,4 @@
class Legislation::Answer < ActiveRecord::Base class Legislation::Answer < ApplicationRecord
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases include ActsAsParanoidAliases

View File

@@ -1,4 +1,4 @@
class Legislation::DraftVersion < ActiveRecord::Base class Legislation::DraftVersion < ApplicationRecord
VALID_STATUSES = %w(draft published) VALID_STATUSES = %w(draft published)
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at

View File

@@ -1,4 +1,4 @@
class Legislation::Process < ActiveRecord::Base class Legislation::Process < ApplicationRecord
include ActsAsParanoidAliases include ActsAsParanoidAliases
include Taggable include Taggable
include Milestoneable include Milestoneable

View File

@@ -1,4 +1,4 @@
class Legislation::Proposal < ActiveRecord::Base class Legislation::Proposal < ApplicationRecord
include ActsAsParanoidAliases include ActsAsParanoidAliases
include Flaggable include Flaggable
include Taggable include Taggable

View File

@@ -1,4 +1,4 @@
class Legislation::Question < ActiveRecord::Base class Legislation::Question < ApplicationRecord
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases include ActsAsParanoidAliases
include Notifiable include Notifiable

View File

@@ -1,4 +1,4 @@
class Legislation::QuestionOption < ActiveRecord::Base class Legislation::QuestionOption < ApplicationRecord
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases include ActsAsParanoidAliases

View File

@@ -1,4 +1,4 @@
class LocalCensusRecord < ActiveRecord::Base class LocalCensusRecord < ApplicationRecord
validates :document_number, presence: true validates :document_number, presence: true
validates :document_type, presence: true validates :document_type, presence: true
validates :date_of_birth, presence: true validates :date_of_birth, presence: true

View File

@@ -1,4 +1,4 @@
class Lock < ActiveRecord::Base class Lock < ApplicationRecord
belongs_to :user belongs_to :user
before_save :set_locked_until before_save :set_locked_until
@@ -21,7 +21,7 @@ class Lock < ActiveRecord::Base
end end
def self.increase_tries(user) def self.increase_tries(user)
Lock.find_or_create_by(user: user).increment!(:tries) Lock.find_or_create_by(user: user).increment!(:tries).save
end end
def self.max_tries def self.max_tries

View File

@@ -1,4 +1,4 @@
class Manager < ActiveRecord::Base class Manager < ApplicationRecord
belongs_to :user, touch: true belongs_to :user, touch: true
delegate :name, :email, :name_and_email, to: :user delegate :name, :email, :name_and_email, to: :user

View File

@@ -1,4 +1,4 @@
class MapLocation < ActiveRecord::Base class MapLocation < ApplicationRecord
belongs_to :proposal, touch: true belongs_to :proposal, touch: true
belongs_to :investment, class_name: Budget::Investment, touch: true belongs_to :investment, class_name: Budget::Investment, touch: true

View File

@@ -1,4 +1,4 @@
class Milestone < ActiveRecord::Base class Milestone < ApplicationRecord
include Imageable include Imageable
include Documentable include Documentable
documentable max_documents_allowed: 3, documentable max_documents_allowed: 3,
@@ -7,6 +7,7 @@ class Milestone < ActiveRecord::Base
translates :title, :description, touch: true translates :title, :description, touch: true
include Globalizable include Globalizable
translation_class_delegate :status_id
belongs_to :milestoneable, polymorphic: true belongs_to :milestoneable, polymorphic: true
belongs_to :status belongs_to :status

View File

@@ -1,4 +1,4 @@
class Milestone::Status < ActiveRecord::Base class Milestone::Status < ApplicationRecord
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
has_many :milestones has_many :milestones

View File

@@ -1,3 +0,0 @@
class Milestone::Translation < Globalize::ActiveRecord::Translation
delegate :status_id, to: :globalized_model
end

View File

@@ -1,4 +1,4 @@
class Moderator < ActiveRecord::Base class Moderator < ApplicationRecord
belongs_to :user, touch: true belongs_to :user, touch: true
delegate :name, :email, to: :user delegate :name, :email, to: :user

View File

@@ -1,4 +1,4 @@
class Newsletter < ActiveRecord::Base class Newsletter < ApplicationRecord
has_many :activities, as: :actionable has_many :activities, as: :actionable
validates :subject, presence: true validates :subject, presence: true

View File

@@ -1,4 +1,4 @@
class Notification < ActiveRecord::Base class Notification < ApplicationRecord
belongs_to :user, counter_cache: true belongs_to :user, counter_cache: true
belongs_to :notifiable, polymorphic: true belongs_to :notifiable, polymorphic: true

View File

@@ -1,4 +1,4 @@
class Organization < ActiveRecord::Base class Organization < ApplicationRecord
include Graphqlable include Graphqlable

View File

@@ -1,4 +1,4 @@
class Poll < ActiveRecord::Base class Poll < ApplicationRecord
include Imageable include Imageable
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases include ActsAsParanoidAliases
@@ -37,7 +37,7 @@ class Poll < ActiveRecord::Base
scope :public_for_api, -> { all } scope :public_for_api, -> { all }
scope :not_budget, -> { where(budget_id: nil) } scope :not_budget, -> { where(budget_id: nil) }
scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) } scope :sort_for_list, -> { joins(:translations).order(:geozone_restricted, :starts_at, "poll_translations.name") }
def title def title
name name

View File

@@ -1,4 +1,4 @@
class Poll::Answer < ActiveRecord::Base class Poll::Answer < ApplicationRecord
belongs_to :question, -> { with_hidden } belongs_to :question, -> { with_hidden }
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"

View File

@@ -1,5 +1,5 @@
class Poll class Poll
class Booth < ActiveRecord::Base class Booth < ApplicationRecord
has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booth_assignments, class_name: "Poll::BoothAssignment"
has_many :polls, through: :booth_assignments has_many :polls, through: :booth_assignments
has_many :shifts has_many :shifts
@@ -12,7 +12,7 @@ class Poll
end end
def self.available def self.available
where(polls: { id: Poll.current_or_recounting }).includes(:polls) where(polls: { id: Poll.current_or_recounting }).joins(polls: :translations)
end end
def assignment_on_poll(poll) def assignment_on_poll(poll)

View File

@@ -1,5 +1,5 @@
class Poll class Poll
class BoothAssignment < ActiveRecord::Base class BoothAssignment < ApplicationRecord
belongs_to :booth belongs_to :booth
belongs_to :poll belongs_to :poll

View File

@@ -1,5 +1,5 @@
class Poll class Poll
class Officer < ActiveRecord::Base class Officer < ApplicationRecord
belongs_to :user belongs_to :user
has_many :officer_assignments, class_name: "Poll::OfficerAssignment" has_many :officer_assignments, class_name: "Poll::OfficerAssignment"
has_many :shifts, class_name: "Poll::Shift" has_many :shifts, class_name: "Poll::Shift"

View File

@@ -1,5 +1,5 @@
class Poll class Poll
class OfficerAssignment < ActiveRecord::Base class OfficerAssignment < ApplicationRecord
belongs_to :officer belongs_to :officer
belongs_to :booth_assignment belongs_to :booth_assignment
has_many :ballot_sheets has_many :ballot_sheets

View File

@@ -1,4 +1,4 @@
class Poll::PartialResult < ActiveRecord::Base class Poll::PartialResult < ApplicationRecord
VALID_ORIGINS = %w{web booth} VALID_ORIGINS = %w{web booth}

View File

@@ -1,4 +1,4 @@
class Poll::Question < ActiveRecord::Base class Poll::Question < ApplicationRecord
include Measurable include Measurable
include Searchable include Searchable

View File

@@ -1,4 +1,4 @@
class Poll::Question::Answer < ActiveRecord::Base class Poll::Question::Answer < ApplicationRecord
include Galleryable include Galleryable
include Documentable include Documentable

View File

@@ -1,4 +1,4 @@
class Poll::Question::Answer::Video < ActiveRecord::Base class Poll::Question::Answer::Video < ApplicationRecord
belongs_to :answer, class_name: "Poll::Question::Answer", foreign_key: "answer_id" belongs_to :answer, class_name: "Poll::Question::Answer", foreign_key: "answer_id"
VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/

View File

@@ -1,4 +1,4 @@
class Poll::Recount < ActiveRecord::Base class Poll::Recount < ApplicationRecord
VALID_ORIGINS = %w{web booth letter}.freeze VALID_ORIGINS = %w{web booth letter}.freeze

View File

@@ -1,5 +1,5 @@
class Poll class Poll
class Shift < ActiveRecord::Base class Shift < ApplicationRecord
belongs_to :booth belongs_to :booth
belongs_to :officer belongs_to :officer

View File

@@ -1,5 +1,5 @@
class Poll class Poll
class Voter < ActiveRecord::Base class Voter < ApplicationRecord
VALID_ORIGINS = %w{web booth}.freeze VALID_ORIGINS = %w{web booth}.freeze

Some files were not shown because too many files have changed in this diff Show More