diff --git a/.github/workflows/challenges_system_tests.yml b/.github/workflows/challenges_system_tests.yml index 575d1421..0d002c73 100644 --- a/.github/workflows/challenges_system_tests.yml +++ b/.github/workflows/challenges_system_tests.yml @@ -9,7 +9,7 @@ on: pull_request: env: - RUBY_VERSION: 2.7.5 + RUBY_VERSION: 3.0.6 jobs: test-report: diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 4b509301..ea6c5e8c 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -9,7 +9,7 @@ on: pull_request: env: - RUBY_VERSION: 2.7.5 + RUBY_VERSION: 3.0.6 jobs: test-report: diff --git a/.github/workflows/problems_system_tests.yml b/.github/workflows/problems_system_tests.yml index 97ac60b9..9fb1940c 100644 --- a/.github/workflows/problems_system_tests.yml +++ b/.github/workflows/problems_system_tests.yml @@ -9,7 +9,7 @@ on: pull_request: env: - RUBY_VERSION: 2.7.5 + RUBY_VERSION: 3.0.6 jobs: test-report: diff --git a/.github/workflows/sgds_system_tests.yml b/.github/workflows/sgds_system_tests.yml index 048acdfc..dd87b005 100644 --- a/.github/workflows/sgds_system_tests.yml +++ b/.github/workflows/sgds_system_tests.yml @@ -9,7 +9,7 @@ on: pull_request: env: - RUBY_VERSION: 2.7.5 + RUBY_VERSION: 3.0.6 jobs: test-report: diff --git a/.github/workflows/solutions_system_tests.yml b/.github/workflows/solutions_system_tests.yml index 923de54c..67b7fdbc 100644 --- a/.github/workflows/solutions_system_tests.yml +++ b/.github/workflows/solutions_system_tests.yml @@ -9,7 +9,7 @@ on: pull_request: env: - RUBY_VERSION: 2.7.5 + RUBY_VERSION: 3.0.6 jobs: test-report: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b7c5038a..4d1b0944 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ on: pull_request: env: - RUBY_VERSION: 2.7.5 + RUBY_VERSION: 3.0.6 jobs: test-report: diff --git a/.node-version b/.node-version new file mode 100644 index 00000000..06e75159 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +16.9.1 diff --git a/.rubocop.yml b/.rubocop.yml index 2da637b0..a59ac14c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -65,12 +65,12 @@ AllCops: # If a value is specified for TargetRubyVersion then it is used. # Else if .ruby-version exists and it contains an MRI version it is used. # Otherwise we fallback to the oldest officially supported Ruby version (2.0). - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.0 - RSpec: - Patterns: - - "(?:^|/)spec/" - - "(?:^|/)test/" +RSpec: + Include: + - "(?:^|/)spec/" + - "(?:^|/)test/" # Indent private/protected/public as deep as method definitions Layout/AccessModifierIndentation: diff --git a/.ruby-version b/.ruby-version index a603bb50..818bd47a 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.5 +3.0.6 diff --git a/CHANGELOG.md b/CHANGELOG.md index 07372ab9..7308f32f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ Following Semantic Versioning 2. ## next version: +## Version 0.3.0 (MINOR) +- Increase minimum Decidim version to 0.27.4 +- Refactor scope, category and SDG filters with Ransack +- Fix when save challenge in CRUD solutions when there is a associated problem. + +## Version 0.2.1 (MINOR) +- Upgrade module's Ruby to 3.0.6 + ## Version 0.2.0 (MINOR) - Increase minimum Decidim version to 0.26.2 diff --git a/Gemfile b/Gemfile index eab6ea47..30c9f0a5 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" ruby RUBY_VERSION -DECIDIM_VERSION = { git: "https://github.com/decidim/decidim", branch: "release/0.26-stable" }.freeze +DECIDIM_VERSION = { git: "https://github.com/decidim/decidim", branch: "release/0.27-stable" }.freeze gem "decidim", DECIDIM_VERSION gem "decidim-challenges", path: "." @@ -16,6 +16,9 @@ gem "uglifier", "~> 4.1" # More exactly in comments in the homepage and in processes cards in the processes listing gem "nokogiri", "1.13.3" +# temporal solution while gems embrace new psych 4 (the default in Ruby 3.1) behavior. +gem "psych", "< 4" + group :development, :test do gem "byebug", ">= 11.1.3" gem "decidim-dev", DECIDIM_VERSION @@ -28,7 +31,7 @@ group :development do gem "faker" gem "letter_opener_web", "~> 1.3" gem "listen", "~> 3.1" - gem "spring", "~> 2.0" - gem "spring-watcher-listen", "~> 2.0" + gem "spring" + gem "spring-watcher-listen" gem "web-console", "~> 3.5" end diff --git a/Gemfile.lock b/Gemfile.lock index e65f9218..c9fe97b7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,55 +1,55 @@ GIT remote: https://github.com/decidim/decidim - revision: 5043f94d3d98ae81f52c2138a3ad1217286aed18 - branch: release/0.26-stable + revision: f25fd77687c92f7458dbb006db32b2718e4bd765 + branch: release/0.27-stable specs: - decidim (0.26.2) - decidim-accountability (= 0.26.2) - decidim-admin (= 0.26.2) - decidim-api (= 0.26.2) - decidim-assemblies (= 0.26.2) - decidim-blogs (= 0.26.2) - decidim-budgets (= 0.26.2) - decidim-comments (= 0.26.2) - decidim-core (= 0.26.2) - decidim-debates (= 0.26.2) - decidim-forms (= 0.26.2) - decidim-generators (= 0.26.2) - decidim-meetings (= 0.26.2) - decidim-pages (= 0.26.2) - decidim-participatory_processes (= 0.26.2) - decidim-proposals (= 0.26.2) - decidim-sortitions (= 0.26.2) - decidim-surveys (= 0.26.2) - decidim-system (= 0.26.2) - decidim-templates (= 0.26.2) - decidim-verifications (= 0.26.2) - decidim-accountability (0.26.2) - decidim-comments (= 0.26.2) - decidim-core (= 0.26.2) - decidim-admin (0.26.2) + decidim (0.27.4) + decidim-accountability (= 0.27.4) + decidim-admin (= 0.27.4) + decidim-api (= 0.27.4) + decidim-assemblies (= 0.27.4) + decidim-blogs (= 0.27.4) + decidim-budgets (= 0.27.4) + decidim-comments (= 0.27.4) + decidim-core (= 0.27.4) + decidim-debates (= 0.27.4) + decidim-forms (= 0.27.4) + decidim-generators (= 0.27.4) + decidim-meetings (= 0.27.4) + decidim-pages (= 0.27.4) + decidim-participatory_processes (= 0.27.4) + decidim-proposals (= 0.27.4) + decidim-sortitions (= 0.27.4) + decidim-surveys (= 0.27.4) + decidim-system (= 0.27.4) + decidim-templates (= 0.27.4) + decidim-verifications (= 0.27.4) + decidim-accountability (0.27.4) + decidim-comments (= 0.27.4) + decidim-core (= 0.27.4) + decidim-admin (0.27.4) active_link_to (~> 1.0) - decidim-core (= 0.26.2) + decidim-core (= 0.27.4) devise (~> 4.7) devise-i18n (~> 1.2) devise_invitable (~> 2.0) - decidim-api (0.26.2) + decidim-api (0.27.4) graphql (~> 1.12, < 1.13) + graphql-docs (~> 2.1.0) rack-cors (~> 1.0) + decidim-assemblies (0.27.4) + decidim-core (= 0.27.4) + decidim-blogs (0.27.4) + decidim-admin (= 0.27.4) + decidim-comments (= 0.27.4) + decidim-core (= 0.27.4) + decidim-budgets (0.27.4) + decidim-comments (= 0.27.4) + decidim-core (= 0.27.4) + decidim-comments (0.27.4) + decidim-core (= 0.27.4) redcarpet (~> 3.5, >= 3.5.1) - decidim-assemblies (0.26.2) - decidim-core (= 0.26.2) - decidim-blogs (0.26.2) - decidim-admin (= 0.26.2) - decidim-comments (= 0.26.2) - decidim-core (= 0.26.2) - decidim-budgets (0.26.2) - decidim-comments (= 0.26.2) - decidim-core (= 0.26.2) - decidim-comments (0.26.2) - decidim-core (= 0.26.2) - redcarpet (~> 3.5, >= 3.5.1) - decidim-core (0.26.2) + decidim-core (0.27.4) active_link_to (~> 1.0) acts_as_list (~> 0.9) batch-loader (~> 1.2) @@ -58,21 +58,21 @@ GIT cells-erb (~> 0.1.0) cells-rails (~> 0.1.3) charlock_holmes (~> 0.7) - date_validator (~> 0.9.0) - decidim-api (= 0.26.2) + date_validator (~> 0.12.0) + decidim-api (= 0.27.4) devise (~> 4.7) devise-i18n (~> 1.2) diffy (~> 3.3) doorkeeper (~> 5.1) doorkeeper-i18n (~> 4.0) - file_validators (~> 2.1) + file_validators (~> 3.0) fog-local (~> 0.6) - foundation_rails_helper - geocoder (~> 1.7.5) + foundation_rails_helper (~> 4.0) + geocoder (~> 1.8) hashdiff (>= 0.4.0, < 2.0.0) invisible_captcha (~> 0.12) kaminari (~> 1.2, >= 1.2.1) - loofah (~> 2.3.1) + loofah (~> 2.19.0) mime-types (>= 1.16, < 4.0) mini_magick (~> 4.9) mustache (~> 1.1.0) @@ -87,132 +87,133 @@ GIT premailer-rails (~> 1.10) rack (~> 2.2, >= 2.2.3) rack-attack (~> 6.0) - rails (~> 6.0.4) + rails (~> 6.1.0) rails-i18n (~> 6.0) ransack (~> 2.4.1) - rectify (~> 0.13.0) redis (~> 4.1) request_store (~> 1.5.0) rubyXL (~> 3.4) rubyzip (~> 2.0) - searchlight (~> 4.1) seven_zip_ruby (~> 1.3) social-share-button (~> 1.2, >= 1.2.1) valid_email2 (~> 2.1) webpacker (= 6.0.0.rc.5) + webpush (~> 1.1) wisper (~> 2.0) - decidim-debates (0.26.2) - decidim-comments (= 0.26.2) - decidim-core (= 0.26.2) - decidim-dev (0.26.2) + decidim-debates (0.27.4) + decidim-comments (= 0.27.4) + decidim-core (= 0.27.4) + decidim-dev (0.27.4) axe-core-rspec (~> 4.1.0) byebug (~> 11.0) capybara (~> 3.24) db-query-matchers (~> 0.10.0) - decidim (= 0.26.2) + decidim (= 0.27.4) erb_lint (~> 0.0.35) factory_bot_rails (~> 4.8) i18n-tasks (~> 0.9.18) mdl (~> 0.5) - nokogiri (~> 1.12) + nokogiri (~> 1.13) + parallel_tests (~> 3.7) puma (~> 5.0) rails-controller-testing (~> 1.0) - rspec-cells (~> 0.3.4) + rspec-cells (~> 0.3.7) rspec-html-matchers (~> 0.9.1) rspec-rails (~> 4.0) rspec-retry (~> 0.6.2) rspec_junit_formatter (~> 0.3.0) - rubocop (~> 0.92.0) - rubocop-rails (~> 2.8) - rubocop-rspec (= 1.43.2) - selenium-webdriver (~> 3.142) - simplecov (~> 0.19.0) - simplecov-cobertura (~> 1.3.1) - system_test_html_screenshots (~> 0.2) + rubocop (~> 1.28.0) + rubocop-rails (~> 2.14) + rubocop-rspec (~> 2.10) + selenium-webdriver (~> 4.1.0) + simplecov (~> 0.21.0) + simplecov-cobertura (~> 2.1.0) w3c_rspec_validators (~> 0.3.0) webmock (~> 3.6) wisper-rspec (~> 1.0) - decidim-forms (0.26.2) - decidim-core (= 0.26.2) + decidim-forms (0.27.4) + decidim-core (= 0.27.4) wicked_pdf (~> 2.1) wkhtmltopdf-binary (~> 0.12) - decidim-generators (0.26.2) - decidim-core (= 0.26.2) - decidim-meetings (0.26.2) - decidim-core (= 0.26.2) - decidim-forms (= 0.26.2) + decidim-generators (0.27.4) + decidim-core (= 0.27.4) + decidim-meetings (0.27.4) + decidim-core (= 0.27.4) + decidim-forms (= 0.27.4) icalendar (~> 2.5) - decidim-pages (0.26.2) - decidim-core (= 0.26.2) - decidim-participatory_processes (0.26.2) - decidim-core (= 0.26.2) - decidim-proposals (0.26.2) - decidim-comments (= 0.26.2) - decidim-core (= 0.26.2) - doc2text (~> 0.4.4) + decidim-pages (0.27.4) + decidim-core (= 0.27.4) + decidim-participatory_processes (0.27.4) + decidim-core (= 0.27.4) + decidim-proposals (0.27.4) + decidim-comments (= 0.27.4) + decidim-core (= 0.27.4) + doc2text (~> 0.4.5) redcarpet (~> 3.5, >= 3.5.1) - decidim-sortitions (0.26.2) - decidim-admin (= 0.26.2) - decidim-comments (= 0.26.2) - decidim-core (= 0.26.2) - decidim-proposals (= 0.26.2) - decidim-surveys (0.26.2) - decidim-core (= 0.26.2) - decidim-forms (= 0.26.2) - decidim-templates (= 0.26.2) - decidim-system (0.26.2) + decidim-sortitions (0.27.4) + decidim-admin (= 0.27.4) + decidim-comments (= 0.27.4) + decidim-core (= 0.27.4) + decidim-proposals (= 0.27.4) + decidim-surveys (0.27.4) + decidim-core (= 0.27.4) + decidim-forms (= 0.27.4) + decidim-templates (= 0.27.4) + decidim-system (0.27.4) active_link_to (~> 1.0) - decidim-core (= 0.26.2) + decidim-core (= 0.27.4) devise (~> 4.7) devise-i18n (~> 1.2) devise_invitable (~> 2.0) - decidim-templates (0.26.2) - decidim-core (= 0.26.2) - decidim-forms (= 0.26.2) - decidim-verifications (0.26.2) - decidim-core (= 0.26.2) + decidim-templates (0.27.4) + decidim-core (= 0.27.4) + decidim-forms (= 0.27.4) + decidim-verifications (0.27.4) + decidim-core (= 0.27.4) PATH remote: . specs: - decidim-challenges (0.2.0) - decidim-core (~> 0.26.2) + decidim-challenges (0.3.0) + decidim-core (~> 0.27) GEM remote: https://rubygems.org/ specs: - actioncable (6.0.5.1) - actionpack (= 6.0.5.1) + actioncable (6.1.7.6) + actionpack (= 6.1.7.6) + activesupport (= 6.1.7.6) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.0.5.1) - actionpack (= 6.0.5.1) - activejob (= 6.0.5.1) - activerecord (= 6.0.5.1) - activestorage (= 6.0.5.1) - activesupport (= 6.0.5.1) + actionmailbox (6.1.7.6) + actionpack (= 6.1.7.6) + activejob (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) mail (>= 2.7.1) - actionmailer (6.0.5.1) - actionpack (= 6.0.5.1) - actionview (= 6.0.5.1) - activejob (= 6.0.5.1) + actionmailer (6.1.7.6) + actionpack (= 6.1.7.6) + actionview (= 6.1.7.6) + activejob (= 6.1.7.6) + activesupport (= 6.1.7.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.5.1) - actionview (= 6.0.5.1) - activesupport (= 6.0.5.1) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.7.6) + actionview (= 6.1.7.6) + activesupport (= 6.1.7.6) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.5.1) - actionpack (= 6.0.5.1) - activerecord (= 6.0.5.1) - activestorage (= 6.0.5.1) - activesupport (= 6.0.5.1) + actiontext (6.1.7.6) + actionpack (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) nokogiri (>= 1.8.5) - actionview (6.0.5.1) - activesupport (= 6.0.5.1) + actionview (6.1.7.6) + activesupport (= 6.1.7.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -220,31 +221,33 @@ GEM active_link_to (1.0.5) actionpack addressable - activejob (6.0.5.1) - activesupport (= 6.0.5.1) + activejob (6.1.7.6) + activesupport (= 6.1.7.6) globalid (>= 0.3.6) - activemodel (6.0.5.1) - activesupport (= 6.0.5.1) - activerecord (6.0.5.1) - activemodel (= 6.0.5.1) - activesupport (= 6.0.5.1) - activestorage (6.0.5.1) - actionpack (= 6.0.5.1) - activejob (= 6.0.5.1) - activerecord (= 6.0.5.1) + activemodel (6.1.7.6) + activesupport (= 6.1.7.6) + activerecord (6.1.7.6) + activemodel (= 6.1.7.6) + activesupport (= 6.1.7.6) + activestorage (6.1.7.6) + actionpack (= 6.1.7.6) + activejob (= 6.1.7.6) + activerecord (= 6.1.7.6) + activesupport (= 6.1.7.6) marcel (~> 1.0) - activesupport (6.0.5.1) + mini_mime (>= 1.1.0) + activesupport (6.1.7.6) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) acts_as_list (0.9.19) activerecord (>= 3.0) - addressable (2.8.1) + addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) ast (2.4.2) - axe-core-api (4.4.1) + axe-core-api (4.8.0) dumb_delegator virtus axe-core-rspec (4.1.0) @@ -255,8 +258,9 @@ GEM descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) + base64 (0.1.1) batch-loader (1.5.0) - bcrypt (3.1.18) + bcrypt (3.1.19) better_html (1.0.16) actionview (>= 4.0) activesupport (>= 4.0) @@ -266,12 +270,12 @@ GEM parser (>= 2.4) smart_properties bindex (0.8.1) - bootsnap (1.13.0) + bootsnap (1.16.0) msgpack (~> 1.2) browser (2.7.1) builder (3.2.4) byebug (11.1.3) - capybara (3.37.1) + capybara (3.39.2) addressable matrix mini_mime (>= 0.1.3) @@ -280,7 +284,7 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - carrierwave (2.2.2) + carrierwave (2.2.4) activemodel (>= 5.0.0) activesupport (>= 5.0.0) addressable (~> 2.6) @@ -300,9 +304,9 @@ GEM actionpack (>= 5.0) cells (>= 4.1.6, < 5.0.0) charlock_holmes (0.7.7) - chef-utils (17.10.0) + chef-utils (18.3.0) concurrent-ruby - childprocess (3.0.0) + childprocess (4.1.0) coercible (1.0.0) descendants_tracker (~> 0.0.1) coffee-rails (5.0.0) @@ -312,15 +316,17 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.10) + commonmarker (0.23.10) + concurrent-ruby (1.2.2) crack (0.4.5) rexml crass (1.0.6) - css_parser (1.11.0) + css_parser (1.16.0) addressable - date_validator (0.9.0) - activemodel - activesupport + date (3.3.3) + date_validator (0.12.0) + activemodel (>= 3) + activesupport (>= 3) db-query-matchers (0.10.0) activesupport (>= 4.0, < 7) rspec (~> 3.0) @@ -329,28 +335,27 @@ GEM declarative-option (0.1.0) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) - devise (4.8.1) + devise (4.9.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - devise-i18n (1.10.2) - devise (>= 4.8.0) - devise_invitable (2.0.6) + devise-i18n (1.11.0) + devise (>= 4.9.0) + devise_invitable (2.0.8) actionmailer (>= 5.0) devise (>= 4.6) diff-lcs (1.5.0) diffy (3.4.2) - doc2text (0.4.5) - nokogiri (>= 1.13.2, < 1.14.0) + doc2text (0.4.6) + nokogiri (>= 1.13.2, < 1.15.0) rubyzip (~> 2.3.0) docile (1.4.0) - doorkeeper (5.5.4) + doorkeeper (5.6.6) railties (>= 5) doorkeeper-i18n (4.0.1) dumb_delegator (1.0.0) - equalizer (0.0.11) erb_lint (0.0.37) activesupport better_html (~> 1.0.7) @@ -361,22 +366,26 @@ GEM smart_properties erbse (0.1.4) temple - erubi (1.11.0) - excon (0.92.4) - execjs (2.8.1) + erubi (1.12.0) + escape_utils (1.3.0) + excon (0.103.0) + execjs (2.9.1) + extended-markdown-filter (0.7.0) + html-pipeline (~> 2.9) factory_bot (4.11.1) activesupport (>= 3.0.0) factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faker (2.22.0) + faker (3.2.1) i18n (>= 1.8.11, < 2) - faraday (2.5.2) + faraday (2.7.11) + base64 faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) - faraday-net_http (3.0.0) - ffi (1.15.5) - file_validators (2.3.0) + faraday-net_http (3.0.2) + ffi (1.16.2) + file_validators (3.0.0) activemodel (>= 3.2) mime-types (>= 1.0) fog-core (2.3.0) @@ -392,16 +401,29 @@ GEM activemodel (>= 4.1, < 7.1) activesupport (>= 4.1, < 7.1) railties (>= 4.1, < 7.1) - geocoder (1.7.5) - globalid (1.0.0) - activesupport (>= 5.0) + gemoji (3.0.1) + geocoder (1.8.2) + globalid (1.2.1) + activesupport (>= 6.1) graphql (1.12.24) + graphql-docs (2.1.0) + commonmarker (~> 0.16) + escape_utils (~> 1.2) + extended-markdown-filter (~> 0.4) + gemoji (~> 3.0) + graphql (~> 1.12) + html-pipeline (~> 2.9) + sass (~> 3.4) hashdiff (1.0.1) hashie (5.0.0) - highline (2.0.3) + highline (2.1.0) + hkdf (0.3.0) + html-pipeline (2.14.3) + activesupport (>= 2) + nokogiri (>= 1.4) html_tokenizer (0.0.7) htmlentities (4.3.4) - i18n (1.12.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) i18n-tasks (0.9.37) activesupport (>= 4.0.2) @@ -413,7 +435,7 @@ GEM rails-i18n rainbow (>= 2.2.2, < 4.0) terminal-table (>= 1.5.1) - icalendar (2.8.0) + icalendar (2.9.0) ice_cube (~> 0.16) ice_cube (0.16.4) ice_nine (0.11.2) @@ -422,8 +444,8 @@ GEM ruby-vips (>= 2.0.17, < 3) invisible_captcha (0.13.0) rails (>= 3.2.0) - json (2.6.2) - jwt (2.4.1) + json (2.6.3) + jwt (2.7.1) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -440,77 +462,90 @@ GEM rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) - launchy (2.5.0) - addressable (~> 2.7) + launchy (2.5.2) + addressable (~> 2.8) letter_opener (1.8.1) launchy (>= 2.2, < 3) letter_opener_web (1.4.1) actionmailer (>= 3.2) letter_opener (~> 1.0) railties (>= 3.2) - listen (3.7.1) + listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.3.1) + loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.1) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (1.0.2) matrix (0.4.2) - mdl (0.11.0) + mdl (0.13.0) kramdown (~> 2.3) kramdown-parser-gfm (~> 1.1) mixlib-cli (~> 2.1, >= 2.1.1) mixlib-config (>= 2.2.1, < 4) mixlib-shellout method_source (1.0.0) - mime-types (3.4.1) + mime-types (3.5.1) mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) - mini_magick (4.11.0) - mini_mime (1.1.2) - mini_portile2 (2.8.0) - minitest (5.16.3) + mime-types-data (3.2023.0808) + mini_magick (4.12.0) + mini_mime (1.1.5) + minitest (5.20.0) mixlib-cli (2.1.8) mixlib-config (3.0.27) tomlrb mixlib-shellout (3.2.7) chef-utils - msgpack (1.5.5) - multi_json (1.15.0) + msgpack (1.7.2) multi_xml (0.6.0) mustache (1.1.1) - nio4r (2.5.8) - nokogiri (1.13.3) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) + net-imap (0.3.7) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.4.0) + net-protocol + nio4r (2.5.9) nokogiri (1.13.3-x86_64-linux) racc (~> 1.4) - oauth (0.5.10) - oauth2 (1.4.10) + oauth (1.1.0) + oauth-tty (~> 1.0, >= 1.0.1) + snaky_hash (~> 2.0) + version_gem (~> 1.1) + oauth-tty (1.0.5) + version_gem (~> 1.1, >= 1.1.1) + oauth2 (2.0.9) faraday (>= 0.17.3, < 3.0) jwt (>= 1.0, < 3.0) - multi_json (~> 1.3) multi_xml (~> 0.5) - rack (>= 1.2, < 3) - omniauth (2.1.0) + rack (>= 1.2, < 4) + snaky_hash (~> 2.0) + version_gem (~> 1.1) + omniauth (2.1.1) hashie (>= 3.4.6) rack (>= 2.2.3) rack-protection omniauth-facebook (5.0.0) omniauth-oauth2 (~> 1.2) - omniauth-google-oauth2 (1.0.1) + omniauth-google-oauth2 (1.1.1) jwt (>= 2.0) - oauth2 (~> 1.1) + oauth2 (~> 2.0.6) omniauth (~> 2.0) - omniauth-oauth2 (~> 1.7.1) + omniauth-oauth2 (~> 1.8.0) omniauth-oauth (1.2.0) oauth omniauth (>= 1.0, < 3) - omniauth-oauth2 (1.7.3) + omniauth-oauth2 (1.8.0) oauth2 (>= 1.4, < 3) - omniauth (>= 1.9, < 3) + omniauth (~> 2.0) omniauth-rails_csrf_protection (1.0.1) actionpack (>= 4.2) omniauth (~> 2.0) @@ -521,110 +556,110 @@ GEM paper_trail (12.3.0) activerecord (>= 5.2) request_store (~> 1.1) - parallel (1.22.1) - parser (3.1.2.1) + parallel (1.23.0) + parallel_tests (3.13.0) + parallel + parser (3.2.2.3) ast (~> 2.4.1) + racc pg (1.1.4) pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) - premailer (1.16.0) + premailer (1.21.0) addressable - css_parser (>= 1.6.0) + css_parser (>= 1.12.0) htmlentities (>= 4.0.0) - premailer-rails (1.11.1) + premailer-rails (1.12.0) actionmailer (>= 3) + net-smtp premailer (~> 1.7, >= 1.7.9) - public_suffix (5.0.0) - puma (5.6.5) + psych (3.3.4) + public_suffix (5.0.3) + puma (5.6.7) nio4r (~> 2.0) - racc (1.6.0) - rack (2.2.4) - rack-attack (6.6.1) - rack (>= 1.0, < 3) + racc (1.7.1) + rack (2.2.8) + rack-attack (6.7.0) + rack (>= 1.0, < 4) rack-cors (1.1.1) rack (>= 2.0.0) - rack-protection (2.2.2) - rack - rack-proxy (0.7.2) + rack-protection (3.1.0) + rack (~> 2.2, >= 2.2.4) + rack-proxy (0.7.7) rack - rack-test (2.0.2) + rack-test (2.1.0) rack (>= 1.3) - rails (6.0.5.1) - actioncable (= 6.0.5.1) - actionmailbox (= 6.0.5.1) - actionmailer (= 6.0.5.1) - actionpack (= 6.0.5.1) - actiontext (= 6.0.5.1) - actionview (= 6.0.5.1) - activejob (= 6.0.5.1) - activemodel (= 6.0.5.1) - activerecord (= 6.0.5.1) - activestorage (= 6.0.5.1) - activesupport (= 6.0.5.1) - bundler (>= 1.3.0) - railties (= 6.0.5.1) + rails (6.1.7.6) + actioncable (= 6.1.7.6) + actionmailbox (= 6.1.7.6) + actionmailer (= 6.1.7.6) + actionpack (= 6.1.7.6) + actiontext (= 6.1.7.6) + actionview (= 6.1.7.6) + activejob (= 6.1.7.6) + activemodel (= 6.1.7.6) + activerecord (= 6.1.7.6) + activestorage (= 6.1.7.6) + activesupport (= 6.1.7.6) + bundler (>= 1.15.0) + railties (= 6.1.7.6) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.4.3) - loofah (~> 2.3) + rails-html-sanitizer (1.5.0) + loofah (~> 2.19, >= 2.19.1) rails-i18n (6.0.0) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 7) - railties (6.0.5.1) - actionpack (= 6.0.5.1) - activesupport (= 6.0.5.1) + railties (6.1.7.6) + actionpack (= 6.1.7.6) + activesupport (= 6.1.7.6) method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) + rake (>= 12.2) + thor (~> 1.0) rainbow (3.1.1) rake (13.0.6) ransack (2.4.2) activerecord (>= 5.2.4) activesupport (>= 5.2.4) i18n - rb-fsevent (0.11.1) + rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rectify (0.13.0) - activemodel (>= 4.1.0) - activerecord (>= 4.1.0) - activesupport (>= 4.1.0) - virtus (~> 1.0.5) - wisper (>= 1.6.1) - redcarpet (3.5.1) - redis (4.8.0) - regexp_parser (2.5.0) + redcarpet (3.6.0) + redis (4.8.1) + regexp_parser (2.8.1) request_store (1.5.1) rack (>= 1.4) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) - rexml (3.2.5) - rspec (3.11.0) - rspec-core (~> 3.11.0) - rspec-expectations (~> 3.11.0) - rspec-mocks (~> 3.11.0) - rspec-cells (0.3.7) + responders (3.1.0) + actionpack (>= 5.2) + railties (>= 5.2) + rexml (3.2.6) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-cells (0.3.8) cells (>= 4.0.0, < 6.0.0) - rspec-rails (< 6.0) - rspec-core (3.11.0) - rspec-support (~> 3.11.0) - rspec-expectations (3.11.0) + rspec-rails (>= 3.0.0, < 6.1.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) + rspec-support (~> 3.12.0) rspec-html-matchers (0.9.4) nokogiri (~> 1) rspec (>= 3.0.0.a, < 4) - rspec-mocks (3.11.1) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) + rspec-support (~> 3.12.0) rspec-rails (4.1.2) actionpack (>= 4.2) activesupport (>= 4.2) @@ -635,27 +670,27 @@ GEM rspec-support (~> 3.10) rspec-retry (0.6.2) rspec-core (> 3.3) - rspec-support (3.11.0) + rspec-support (3.12.1) rspec_junit_formatter (0.3.0) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (0.92.0) + rubocop (1.28.2) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 0.5.0) + rubocop-ast (>= 1.17.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.21.0) - parser (>= 3.1.1.0) - rubocop-rails (2.9.1) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.29.0) + parser (>= 3.2.1.0) + rubocop-rails (2.15.2) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.90.0, < 2.0) - rubocop-rspec (1.43.2) - rubocop (~> 0.87) - ruby-progressbar (1.11.0) + rubocop (>= 1.7.0, < 2.0) + rubocop-rspec (2.11.1) + rubocop (~> 1.19) + ruby-progressbar (1.13.0) ruby-vips (2.1.4) ffi (~> 1.12) ruby2_keywords (0.0.5) @@ -663,56 +698,66 @@ GEM nokogiri (>= 1.10.8) rubyzip (>= 1.3.0) rubyzip (2.3.2) - searchlight (4.1.0) - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) + sass (3.7.4) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + selenium-webdriver (4.1.0) + childprocess (>= 0.5, < 5.0) + rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2) semantic_range (3.0.0) seven_zip_ruby (1.3.0) - simplecov (0.19.1) + simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) - simplecov-cobertura (1.3.1) - simplecov (~> 0.8) + simplecov_json_formatter (~> 0.1) + simplecov-cobertura (2.1.0) + rexml + simplecov (~> 0.19) simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) smart_properties (1.17.0) + snaky_hash (2.0.1) + hashie + version_gem (~> 1.1, >= 1.1.1) social-share-button (1.2.4) coffee-rails - spring (2.1.1) - spring-watcher-listen (2.0.1) + spring (4.1.1) + spring-watcher-listen (2.1.0) listen (>= 2.7, < 4.0) - spring (>= 1.2, < 3.0) - sprockets (4.1.1) + spring (>= 4) + sprockets (4.2.1) concurrent-ruby (~> 1.0) - rack (> 1, < 3) + rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - ssrf_filter (1.0.8) - system_test_html_screenshots (0.2.0) - actionpack (>= 5.2, < 6.1.a) - temple (0.8.2) + ssrf_filter (1.1.2) + temple (0.10.2) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) - thor (1.2.1) + thor (1.2.2) thread_safe (0.3.6) - tilt (2.0.11) + tilt (2.3.0) + timeout (0.4.0) tomlrb (2.0.3) - tzinfo (1.2.10) - thread_safe (~> 0.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) uber (0.1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) - unicode-display_width (1.8.0) + unicode-display_width (2.4.2) valid_email2 (2.3.1) activemodel (>= 3.2) mail (~> 2.5) - virtus (1.0.5) + version_gem (1.1.3) + virtus (2.0.0) axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) - equalizer (~> 0.0, >= 0.0.9) w3c_rspec_validators (0.3.0) rails rspec @@ -728,7 +773,7 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - webmock (3.18.1) + webmock (3.19.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -737,20 +782,22 @@ GEM rack-proxy (>= 0.6.1) railties (>= 5.2) semantic_range (>= 2.3.0) - websocket-driver (0.7.5) + webpush (1.1.0) + hkdf (~> 0.2) + jwt (~> 2.0) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - wicked_pdf (2.6.3) + wicked_pdf (2.7.0) activesupport wisper (2.0.1) wisper-rspec (1.1.0) - wkhtmltopdf-binary (0.12.6.5) + wkhtmltopdf-binary (0.12.6.6) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.0) + zeitwerk (2.6.12) PLATFORMS - ruby x86_64-linux DEPENDENCIES @@ -763,17 +810,18 @@ DEPENDENCIES letter_opener_web (~> 1.3) listen (~> 3.1) nokogiri (= 1.13.3) + psych (< 4) puma (>= 4.3) rubocop rubocop-rails rubocop-rspec - spring (~> 2.0) - spring-watcher-listen (~> 2.0) + spring + spring-watcher-listen uglifier (~> 4.1) web-console (~> 3.5) RUBY VERSION - ruby 2.7.5p203 + ruby 3.0.6p216 BUNDLED WITH - 2.3.4 + 2.2.33 diff --git a/app/commands/decidim/challenges/admin/create_challenge.rb b/app/commands/decidim/challenges/admin/create_challenge.rb index e7c052f1..37600f65 100644 --- a/app/commands/decidim/challenges/admin/create_challenge.rb +++ b/app/commands/decidim/challenges/admin/create_challenge.rb @@ -4,7 +4,7 @@ module Decidim module Challenges module Admin # A command with all the business logic when a user creates a new challenge. - class CreateChallenge < Rectify::Command + class CreateChallenge < Decidim::Command # Public: Initializes the command. # # form - A form object with the params. diff --git a/app/commands/decidim/challenges/admin/destroy_challenge.rb b/app/commands/decidim/challenges/admin/destroy_challenge.rb index 9b684f4a..ec6dd44c 100644 --- a/app/commands/decidim/challenges/admin/destroy_challenge.rb +++ b/app/commands/decidim/challenges/admin/destroy_challenge.rb @@ -4,7 +4,7 @@ module Decidim module Challenges module Admin # This command deals with destroying a Challenge from the admin panel. - class DestroyChallenge < Rectify::Command + class DestroyChallenge < Decidim::Command # Public: Initializes the command. # # page - The Challenge to be destroyed. diff --git a/app/commands/decidim/challenges/admin/export_challenge_surveys.rb b/app/commands/decidim/challenges/admin/export_challenge_surveys.rb index f2bc3520..2a466e2f 100644 --- a/app/commands/decidim/challenges/admin/export_challenge_surveys.rb +++ b/app/commands/decidim/challenges/admin/export_challenge_surveys.rb @@ -5,7 +5,7 @@ module Challenges module Admin # This command is executed when the user exports the registrations of # a Meeting from the admin panel. - class ExportChallengeSurveys < Rectify::Command + class ExportChallengeSurveys < Decidim::Command # challenge - The current instance of the page to be closed. # format - a string representing the export format # current_user - the user performing the action diff --git a/app/commands/decidim/challenges/admin/publish_challenge.rb b/app/commands/decidim/challenges/admin/publish_challenge.rb index 4255a5dd..b4807af9 100644 --- a/app/commands/decidim/challenges/admin/publish_challenge.rb +++ b/app/commands/decidim/challenges/admin/publish_challenge.rb @@ -4,7 +4,7 @@ module Decidim module Challenges module Admin # A command that sets a challenge as published. - class PublishChallenge < Rectify::Command + class PublishChallenge < Decidim::Command # Public: Initializes the command. # # challenge - A Challenge that will be published diff --git a/app/commands/decidim/challenges/admin/unpublish_challenge.rb b/app/commands/decidim/challenges/admin/unpublish_challenge.rb index eddeca6e..55ecce27 100644 --- a/app/commands/decidim/challenges/admin/unpublish_challenge.rb +++ b/app/commands/decidim/challenges/admin/unpublish_challenge.rb @@ -4,7 +4,7 @@ module Decidim module Challenges module Admin # A command that sets a challenge as unpublished. - class UnpublishChallenge < Rectify::Command + class UnpublishChallenge < Decidim::Command # Public: Initializes the command. # # challenge - A Challenge that will be published diff --git a/app/commands/decidim/challenges/admin/update_challenge.rb b/app/commands/decidim/challenges/admin/update_challenge.rb index 38b77d48..a2039aa9 100644 --- a/app/commands/decidim/challenges/admin/update_challenge.rb +++ b/app/commands/decidim/challenges/admin/update_challenge.rb @@ -4,7 +4,7 @@ module Decidim module Challenges module Admin # A command with all the business logic when a user updates a challenge. - class UpdateChallenge < Rectify::Command + class UpdateChallenge < Decidim::Command # Public: Initializes the command. # # form - A form object with the params. diff --git a/app/commands/decidim/challenges/admin/update_surveys.rb b/app/commands/decidim/challenges/admin/update_surveys.rb index a9eadc6c..a20b9597 100644 --- a/app/commands/decidim/challenges/admin/update_surveys.rb +++ b/app/commands/decidim/challenges/admin/update_surveys.rb @@ -4,7 +4,7 @@ module Decidim module Challenges module Admin # This command is executed when the user updates the challenge survey, - class UpdateSurveys < Rectify::Command + class UpdateSurveys < Decidim::Command # Initializes a UpdateSurveys Command. # # form - The form from which to get the data. @@ -19,9 +19,9 @@ def initialize(form, challenge) # # Broadcasts :ok if successful, :invalid otherwise. def call - challenge.with_lock do - return broadcast(:invalid) if form.invalid? + return broadcast(:invalid) if form.invalid? + challenge.with_lock do update_challenge_surveys end diff --git a/app/commands/decidim/challenges/survey_challenge.rb b/app/commands/decidim/challenges/survey_challenge.rb index fa590e27..925000a3 100644 --- a/app/commands/decidim/challenges/survey_challenge.rb +++ b/app/commands/decidim/challenges/survey_challenge.rb @@ -3,7 +3,7 @@ module Decidim module Challenges # This command is executed when the user answer a survey. - class SurveyChallenge < Rectify::Command + class SurveyChallenge < Decidim::Command # Initializes a SurveyChallenge Command. # # challenge - The current instance of the challenge to be answer the survey. @@ -20,15 +20,18 @@ def initialize(challenge, user, survey_form) # # Broadcasts :ok if successful, :invalid otherwise. def call - challenge.with_lock do - return broadcast(:invalid) unless can_answer_survey? - return broadcast(:invalid_form) unless survey_form.valid? - - return broadcast(:invalid) if answer_questionnaire == :invalid + return broadcast(:invalid) unless can_answer_survey? + return broadcast(:invalid_form) unless survey_form.valid? + challenge.with_lock do + answer_questionnaire create_survey end + broadcast(:ok) + rescue ActiveRecord::Rollback + form.errors.add(:base, :invalid) + broadcast(:invalid) end private @@ -39,12 +42,8 @@ def answer_questionnaire return unless questionnaire? Decidim::Forms::AnswerQuestionnaire.call(survey_form, user, challenge.questionnaire) do - on(:ok) do - return :valid - end - on(:invalid) do - return :invalid + raise ActiveRecord::Rollback end end end @@ -57,7 +56,7 @@ def create_survey end def questionnaire? - survey_form.model_name == "Questionnaire" + survey_form.model_name.human == "Questionnaire" end def can_answer_survey? diff --git a/app/commands/decidim/command_utils.rb b/app/commands/decidim/command_utils.rb new file mode 100644 index 00000000..a62b863e --- /dev/null +++ b/app/commands/decidim/command_utils.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Decidim + module CommandUtils + def parsed_attribute(attribute) + Decidim::ContentProcessor.parse_with_processor(:hashtag, form.send(attribute), current_organization: form.current_organization).rewrite + end + + def challenge_id + challenge = form.decidim_challenges_challenge_id + problem = Decidim::Problems::Problem.find_by(id: form.decidim_problems_problem_id) + + if challenge.present? + Decidim::Challenges::Challenge.find(form.decidim_challenges_challenge_id).id + else + problem&.decidim_challenges_challenge_id.presence + end + end + end +end diff --git a/app/commands/decidim/problems/admin/create_problem.rb b/app/commands/decidim/problems/admin/create_problem.rb index 874079bb..d2e10898 100644 --- a/app/commands/decidim/problems/admin/create_problem.rb +++ b/app/commands/decidim/problems/admin/create_problem.rb @@ -4,7 +4,7 @@ module Decidim module Problems module Admin # A command with all the business logic when a user creates a new problem. - class CreateProblem < Rectify::Command + class CreateProblem < Decidim::Command # Public: Initializes the command. # # form - A form object with the params. diff --git a/app/commands/decidim/problems/admin/destroy_problem.rb b/app/commands/decidim/problems/admin/destroy_problem.rb index 166b8382..dd6940ee 100644 --- a/app/commands/decidim/problems/admin/destroy_problem.rb +++ b/app/commands/decidim/problems/admin/destroy_problem.rb @@ -4,7 +4,7 @@ module Decidim module Problems module Admin # This command deals with destroying a Problem from the admin panel. - class DestroyProblem < Rectify::Command + class DestroyProblem < Decidim::Command # Public: Initializes the command. # # page - The Problem to be destroyed. diff --git a/app/commands/decidim/problems/admin/publish_problem.rb b/app/commands/decidim/problems/admin/publish_problem.rb index ac007eb7..202a55f1 100644 --- a/app/commands/decidim/problems/admin/publish_problem.rb +++ b/app/commands/decidim/problems/admin/publish_problem.rb @@ -4,7 +4,7 @@ module Decidim module Problems module Admin # A command that sets a problem as published. - class PublishProblem < Rectify::Command + class PublishProblem < Decidim::Command # Public: Initializes the command. # # problem - A Problem that will be published diff --git a/app/commands/decidim/problems/admin/unpublish_problem.rb b/app/commands/decidim/problems/admin/unpublish_problem.rb index 56bc7511..83523cb0 100644 --- a/app/commands/decidim/problems/admin/unpublish_problem.rb +++ b/app/commands/decidim/problems/admin/unpublish_problem.rb @@ -4,7 +4,7 @@ module Decidim module Problems module Admin # A command that sets a problem as unpublished. - class UnpublishProblem < Rectify::Command + class UnpublishProblem < Decidim::Command # Public: Initializes the command. # # problem - A Problem that will be published diff --git a/app/commands/decidim/problems/admin/update_problem.rb b/app/commands/decidim/problems/admin/update_problem.rb index 88010230..c22d8406 100644 --- a/app/commands/decidim/problems/admin/update_problem.rb +++ b/app/commands/decidim/problems/admin/update_problem.rb @@ -4,7 +4,7 @@ module Decidim module Problems module Admin # A command with all the business logic when a user updates a Problem. - class UpdateProblem < Rectify::Command + class UpdateProblem < Decidim::Command # Public: Initializes the command. # # form - A form object with the params. diff --git a/app/commands/decidim/solutions/admin/create_solution.rb b/app/commands/decidim/solutions/admin/create_solution.rb index ebb58e79..75fb9e75 100644 --- a/app/commands/decidim/solutions/admin/create_solution.rb +++ b/app/commands/decidim/solutions/admin/create_solution.rb @@ -4,7 +4,10 @@ module Decidim module Solutions module Admin # A command with all the business logic when a user creates a new solution. - class CreateSolution < Rectify::Command + class CreateSolution < Decidim::Command + include Decidim::Challenges + include Decidim::CommandUtils + # Public: Initializes the command. # # form - A form object with the params. @@ -34,25 +37,18 @@ def call attr_reader :form, :solution def create_solution! - parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite - parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite - parsed_objectives = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.objectives, current_organization: form.current_organization).rewrite - parsed_indicators = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.indicators, current_organization: form.current_organization).rewrite - parsed_beneficiaries = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.beneficiaries, current_organization: form.current_organization).rewrite - parsed_requirements = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.requirements, current_organization: form.current_organization).rewrite - parsed_financing_type = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.financing_type, current_organization: form.current_organization).rewrite params = { - title: parsed_title, - description: parsed_description, + title: parsed_attribute(:title), + description: parsed_attribute(:description), component: form.current_component, decidim_problems_problem_id: form.decidim_problems_problem_id, - decidim_challenges_challenge_id: form.decidim_challenges_challenge_id, + decidim_challenges_challenge_id: challenge_id, tags: form.tags, - objectives: parsed_objectives, - indicators: parsed_indicators, - beneficiaries: parsed_beneficiaries, - requirements: parsed_requirements, - financing_type: parsed_financing_type, + objectives: parsed_attribute(:objectives), + indicators: parsed_attribute(:indicators), + beneficiaries: parsed_attribute(:beneficiaries), + requirements: parsed_attribute(:requirements), + financing_type: parsed_attribute(:financing_type), } @solution = Decidim.traceability.create!( diff --git a/app/commands/decidim/solutions/admin/destroy_solution.rb b/app/commands/decidim/solutions/admin/destroy_solution.rb index 66156356..b071dd61 100644 --- a/app/commands/decidim/solutions/admin/destroy_solution.rb +++ b/app/commands/decidim/solutions/admin/destroy_solution.rb @@ -4,7 +4,7 @@ module Decidim module Solutions module Admin # This command deals with destroying a Solution from the admin panel. - class DestroySolution < Rectify::Command + class DestroySolution < Decidim::Command # Public: Initializes the command. # # page - The Solution to be destroyed. diff --git a/app/commands/decidim/solutions/admin/publish_solution.rb b/app/commands/decidim/solutions/admin/publish_solution.rb index 7c7cee45..c0b249f0 100644 --- a/app/commands/decidim/solutions/admin/publish_solution.rb +++ b/app/commands/decidim/solutions/admin/publish_solution.rb @@ -4,7 +4,7 @@ module Decidim module Solutions module Admin # A command that sets a solution as published. - class PublishSolution < Rectify::Command + class PublishSolution < Decidim::Command # Public: Initializes the command. # # solution - A Solution that will be published diff --git a/app/commands/decidim/solutions/admin/unpublish_solution.rb b/app/commands/decidim/solutions/admin/unpublish_solution.rb index f07c0d4e..66f276d4 100644 --- a/app/commands/decidim/solutions/admin/unpublish_solution.rb +++ b/app/commands/decidim/solutions/admin/unpublish_solution.rb @@ -4,7 +4,7 @@ module Decidim module Solutions module Admin # A command that sets a solution as unpublished. - class UnpublishSolution < Rectify::Command + class UnpublishSolution < Decidim::Command # Public: Initializes the command. # # solution - A Solution that will be published diff --git a/app/commands/decidim/solutions/admin/update_solution.rb b/app/commands/decidim/solutions/admin/update_solution.rb index 8bf77391..9134e99d 100644 --- a/app/commands/decidim/solutions/admin/update_solution.rb +++ b/app/commands/decidim/solutions/admin/update_solution.rb @@ -4,7 +4,10 @@ module Decidim module Solutions module Admin # A command with all the business logic when a user updates a Solution. - class UpdateSolution < Rectify::Command + class UpdateSolution < Decidim::Command + include Decidim::Challenges + include Decidim::CommandUtils + # Public: Initializes the command. # # form - A form object with the params. @@ -44,25 +47,18 @@ def update_solution end def attributes - parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite - parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite - parsed_objectives = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.objectives, current_organization: form.current_organization).rewrite - parsed_indicators = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.indicators, current_organization: form.current_organization).rewrite - parsed_beneficiaries = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.beneficiaries, current_organization: form.current_organization).rewrite - parsed_requirements = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.requirements, current_organization: form.current_organization).rewrite - parsed_financing_type = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.financing_type, current_organization: form.current_organization).rewrite { - title: parsed_title, - description: parsed_description, + title: parsed_attribute(:title), + description: parsed_attribute(:description), component: form.current_component, decidim_problems_problem_id: form.decidim_problems_problem_id, - decidim_challenges_challenge_id: form.decidim_challenges_challenge_id, + decidim_challenges_challenge_id: challenge_id, tags: form.tags, - objectives: parsed_objectives, - indicators: parsed_indicators, - beneficiaries: parsed_beneficiaries, - requirements: parsed_requirements, - financing_type: parsed_financing_type, + objectives: parsed_attribute(:objectives), + indicators: parsed_attribute(:indicators), + beneficiaries: parsed_attribute(:beneficiaries), + requirements: parsed_attribute(:requirements), + financing_type: parsed_attribute(:financing_type), } end end diff --git a/app/controllers/decidim/challenges/challenges_controller.rb b/app/controllers/decidim/challenges/challenges_controller.rb index 0a3bbe96..d959ecc0 100644 --- a/app/controllers/decidim/challenges/challenges_controller.rb +++ b/app/controllers/decidim/challenges/challenges_controller.rb @@ -20,7 +20,9 @@ class ChallengesController < Decidim::Challenges::ApplicationController helper_method :challenges def index - @challenges = reorder(challenges) + @challenges = search.result + @challenges = reorder(@challenges) + @challenges = paginate(@challenges) end def show @@ -38,37 +40,21 @@ def challenge_scope def default_filter_params { - search_text: "", - category_id: default_filter_category_params, - state: %w(proposal execution finished), - scope_id: default_filter_scope_params, - related_to: "", - sdgs_codes: [], + search_text_cont: "", + with_any_category: default_filter_category_params, + with_any_state: %w(proposal execution finished), + with_any_scope: default_filter_scope_params, + with_related_to: "", + with_any_sdgs_codes: [], } end - def default_filter_category_params - return "all" unless current_component.participatory_space.categories.any? - - ["all"] + current_component.participatory_space.categories.map { |category| category.id.to_s } - end - - def default_filter_scope_params - return "all" unless current_component.participatory_space.scopes.any? - - if current_component.participatory_space.scope - ["all", current_component.participatory_space.scope.id] + current_component.participatory_space.scope.children.map { |scope| scope.id.to_s } - else - %w(all global) + current_component.participatory_space.scopes.map { |scope| scope.id.to_s } - end - end - def challenges - @challenges ||= paginate(search.results.published) + @challenges ||= reorder(paginate(search.result)) end - def search_klass - Decidim::Challenges::ChallengeSearch + def search_collection + ::Decidim::Challenges::Challenge.published end end end diff --git a/app/controllers/decidim/problems/problems_controller.rb b/app/controllers/decidim/problems/problems_controller.rb index c45de3ed..72bcf246 100644 --- a/app/controllers/decidim/problems/problems_controller.rb +++ b/app/controllers/decidim/problems/problems_controller.rb @@ -20,7 +20,9 @@ class ProblemsController < Decidim::Problems::ApplicationController helper_method :problems def index - @problems = reorder(problems) + @problems = search.result + @problems = reorder(@problems) + @problems = paginate(@problems) end def show @@ -36,23 +38,17 @@ def challenge_scope def default_filter_params { - search_text: "", - category_id: default_filter_category_params, - state: %w(proposal execution finished), - sectorial_scope_id: default_filter_scope_params, - technological_scope_id: default_filter_scope_params, - territorial_scope_id: default_filter_scope_params, - related_to: "", - sdgs_codes: [], + search_text_cont: "", + with_any_category: default_filter_category_params, + with_any_state: %w(proposal execution finished), + with_any_sectorial_scope_id: default_filter_scope_params, + with_any_technological_scope_id: default_filter_scope_params, + with_any_territorial_scope_id: default_filter_scope_params, + with_related_to: "", + with_any_sdgs_codes: [], } end - def default_filter_category_params - return "all" unless current_component.participatory_space.categories.any? - - ["all"] + current_component.participatory_space.categories.map { |category| category.id.to_s } - end - def default_filter_scope_params return "all" unless current_component.participatory_space.scopes.any? @@ -64,11 +60,11 @@ def default_filter_scope_params end def problems - @problems ||= paginate(search.results.published) + @problems ||= order(paginate(search.result)) end - def search_klass - Decidim::Problems::ProblemSearch + def search_collection + ::Decidim::Problems::Problem.published end end end diff --git a/app/controllers/decidim/solutions/solutions_controller.rb b/app/controllers/decidim/solutions/solutions_controller.rb index bd3880f4..ca650852 100644 --- a/app/controllers/decidim/solutions/solutions_controller.rb +++ b/app/controllers/decidim/solutions/solutions_controller.rb @@ -19,7 +19,9 @@ class SolutionsController < Decidim::Solutions::ApplicationController helper_method :solutions def index + @solutions = search.result @solutions = reorder(solutions) + @solutions = paginate(solutions) end def show @@ -36,20 +38,14 @@ def show def default_filter_params { - search_text: "", - category_id: default_filter_category_params, - territorial_scope_id: default_filter_scope_params, - related_to: "", - sdgs_codes: [], + search_text_cont: "", + with_any_category: default_filter_category_params, + with_any_territorial_scope_id: default_filter_scope_params, + with_related_to: "", + with_any_sdgs_codes: [], } end - def default_filter_category_params - return "all" unless current_component.participatory_space.categories.any? - - ["all"] + current_component.participatory_space.categories.map { |category| category.id.to_s } - end - def default_filter_scope_params return "all" unless current_component.participatory_space.scopes.any? @@ -61,7 +57,7 @@ def default_filter_scope_params end def solutions - @solutions ||= paginate(search.results.published) + @solutions ||= paginate(search.result) end def solution @@ -89,8 +85,8 @@ def technological_scope @technological_scope ||= current_organization.scopes.find_by(id: @solution.problem.decidim_technological_scope_id) end - def search_klass - Decidim::Solutions::SolutionSearch + def search_collection + ::Decidim::Solutions::Solution.published end end end diff --git a/app/forms/decidim/solutions/admin/solutions_form.rb b/app/forms/decidim/solutions/admin/solutions_form.rb index 19b98aa4..4c451e69 100644 --- a/app/forms/decidim/solutions/admin/solutions_form.rb +++ b/app/forms/decidim/solutions/admin/solutions_form.rb @@ -52,14 +52,14 @@ def select_challenge_collection # # Returns a Decidim::Problems::Problem def problem - @problem ||= @decidim_problems_problem_id.present? ? Decidim::Problems::Problem.find(@decidim_problems_problem_id) : false + @problem ||= decidim_problems_problem_id.present? ? Decidim::Problems::Problem.find(decidim_problems_problem_id) : false end # Finds the Challenge from the given decidim_challenges_challenge_id # # Returns a Decidim::Challenges::Challenge def challenge - @challenge ||= @decidim_challenges_challenge_id.present? ? Decidim::Challenges::Challenge.find(@decidim_challenges_challenge_id) : false + @challenge ||= @problem.present? ? Decidim::Challenges::Challenge.find(@problem.challenge.id) : false end def map_model(model); end diff --git a/app/models/decidim/challenges/challenge.rb b/app/models/decidim/challenges/challenge.rb index 5cdfa7cd..2307082c 100644 --- a/app/models/decidim/challenges/challenge.rb +++ b/app/models/decidim/challenges/challenge.rb @@ -5,6 +5,9 @@ module Challenges # The data store for a Challenge in the Decidim::Challenges component. class Challenge < Decidim::ApplicationRecord include Decidim::HasComponent + include Decidim::FilterableResource + include Decidim::ScopableResource + include Decidim::HasCategory include Decidim::Loggable include Decidim::Publicable include Decidim::Resourceable @@ -42,6 +45,22 @@ class Challenge < Decidim::ApplicationRecord scope :in_execution, -> { where(state: VALID_STATES.index(:execution)) } scope :in_finished, -> { where(state: VALID_STATES.index(:finished)) } + scope :with_any_state, lambda { |*values| + where(state: Array(values).map(&:to_sym) & VALID_STATES) + } + + scope :search_text_cont, lambda { |search_text| + where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%") + } + + scope :with_any_sdgs_codes, lambda { |*values| + where(sdg_code: Array(values).map(&:to_sym)) + } + + def self.ransackable_scopes(_auth_object = nil) + [:with_any_state, :search_text_cont, :with_any_sdgs_codes, :with_any_scope, :with_any_category] + end + searchable_fields({ scope_id: :decidim_scope_id, participatory_space: :itself, diff --git a/app/models/decidim/challenges/survey.rb b/app/models/decidim/challenges/survey.rb index ea6d1234..4a8344f9 100644 --- a/app/models/decidim/challenges/survey.rb +++ b/app/models/decidim/challenges/survey.rb @@ -4,7 +4,7 @@ module Decidim module Challenges # The data store for a Survey in the Decidim::Challenges component. class Survey < Decidim::ApplicationRecord - include Decidim::DataPortability + include Decidim::DownloadYourData belongs_to :challenge, foreign_key: "decidim_challenge_id", class_name: "Decidim::Challenges::Challenge" belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User" @@ -12,7 +12,7 @@ class Survey < Decidim::ApplicationRecord validates :user, uniqueness: { scope: :challenge } def self.export_serializer - Decidim::Challenges::DataPortabilitySurveySerializer + Decidim::Challenges::DownloadYourDataSurveySerializer end end end diff --git a/app/models/decidim/problems/problem.rb b/app/models/decidim/problems/problem.rb index 7a629731..dc18890e 100644 --- a/app/models/decidim/problems/problem.rb +++ b/app/models/decidim/problems/problem.rb @@ -5,6 +5,9 @@ module Problems # The data store for a Problem in the Decidim::Problems component. class Problem < Decidim::ApplicationRecord include Decidim::HasComponent + include Decidim::FilterableResource + include Decidim::ScopableResource + include Decidim::HasCategory include Decidim::Loggable include Decidim::Publicable include Decidim::Resourceable @@ -37,6 +40,65 @@ class Problem < Decidim::ApplicationRecord scope :in_execution, -> { where(state: VALID_STATES.index(:execution)) } scope :in_finished, -> { where(state: VALID_STATES.index(:finished)) } + scope :with_any_state, lambda { |*values| + where(state: Array(values).map(&:to_sym) & VALID_STATES) + } + + scope :search_text_cont, lambda { |search_text| + where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%") + } + + scope :with_any_sdgs_codes, lambda { |*values| + joins(:challenge).where("decidim_challenges_challenges" => { sdg_code: Array(values).map(&:to_sym) }) + } + + scope :with_any_sectorial_scope_id, lambda { |*sectorial_scope_id| + if sectorial_scope_id.include?("all") + all + else + clean_scope_ids = sectorial_scope_id + + conditions = [] + conditions << "#{model_name.plural}.decidim_sectorial_scope_id IS NULL" if clean_scope_ids.delete("global") + conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any? + + includes(:sectorial_scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i)) + end + } + + scope :with_any_technological_scope_id, lambda { |*technological_scope_id| + if technological_scope_id.include?("all") + all + else + clean_scope_ids = technological_scope_id + + conditions = [] + conditions << "#{model_name.plural}.decidim_technological_scope_id IS NULL" if clean_scope_ids.delete("global") + conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any? + + includes(:technological_scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i)) + end + } + + scope :with_any_territorial_scope_id, lambda { |*territorial_scope_id| + if territorial_scope_id.include?("all") + all + else + clean_scope_ids = territorial_scope_id + + conditions = [] + conditions << "decidim_challenges_challenges.decidim_scope_id IS NULL" if clean_scope_ids.delete("global") + conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any? + + includes(challenge: :scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i)) + end + } + + def self.ransackable_scopes(_auth_object = nil) + [:with_any_state, :search_text_cont, :with_any_sdgs_codes, :with_any_category, + :with_any_sectorial_scope_id, :with_any_technological_scope_id, :with_any_territorial_scope_id] + end + searchable_fields({ scope_id: "decidim_sectorial_scope_id", participatory_space: :itself, diff --git a/app/models/decidim/solutions/solution.rb b/app/models/decidim/solutions/solution.rb index a924dd41..d9d7dbc2 100644 --- a/app/models/decidim/solutions/solution.rb +++ b/app/models/decidim/solutions/solution.rb @@ -5,6 +5,8 @@ module Solutions # The data store for a Solution in the Decidim::Solutions component. class Solution < Solutions::ApplicationRecord include Decidim::HasComponent + include Decidim::FilterableResource + include Decidim::HasCategory include Decidim::Loggable include Decidim::Publicable include Decidim::Resourceable @@ -20,6 +22,32 @@ class Solution < Solutions::ApplicationRecord scope :published, -> { where.not(published_at: nil) } + scope :search_text_cont, lambda { |search_text| + where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%") + } + + scope :with_any_sdgs_codes, lambda { |*values| + joins(:challenge).where("decidim_challenges_challenges" => { sdg_code: Array(values).map(&:to_sym) }) + } + + scope :with_any_territorial_scope_id, lambda { |*territorial_scope_id| + if territorial_scope_id.include?("all") + all + else + clean_scope_ids = territorial_scope_id + + conditions = [] + conditions << "decidim_challenges_challenges.decidim_scope_id IS NULL" if clean_scope_ids.delete("global") + conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any? + + includes(problem: { challenge: :scope }).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i)) + end + } + + def self.ransackable_scopes(_auth_object = nil) + [:search_text_cont, :with_any_category, :with_any_sdgs_codes, :with_any_territorial_scope_id] + end + searchable_fields({ participatory_space: :itself, A: :title, diff --git a/app/packs/entrypoints/decidim_sdgs.js b/app/packs/entrypoints/decidim_sdgs.js index b49b57d5..8036984b 100644 --- a/app/packs/entrypoints/decidim_sdgs.js +++ b/app/packs/entrypoints/decidim_sdgs.js @@ -2,3 +2,5 @@ require.context("../images", true) import "entrypoints/decidim_sdgs.scss"; + +import "src/decidim/sdgs/filter.js"; diff --git a/app/packs/src/decidim/sdgs/filter.js b/app/packs/src/decidim/sdgs/filter.js new file mode 100644 index 00000000..803d3cc2 --- /dev/null +++ b/app/packs/src/decidim/sdgs/filter.js @@ -0,0 +1,65 @@ +const border_style_selected= "3px solid #555" +const border_style_unselected= "3px" + +function toggleSdgFilterCellSelect(cell, selected) { + if(selected) { + cell.css("border", border_style_selected); + } else { + cell.css("border", border_style_unselected); + } +} + +$( document ).ready(function() { + /** + * Setup Sdgs selector + */ + $('div.sdgs-filter input[type=hidden]').each(function () { + const input= $(this); + const current_value= input.val() + + // initial activation + if (current_value != "" && (typeof current_value == "string")) { + const cell= $('#sdgs-modal .sdg-cell[data-value=' + current_value + ']') + toggleSdgFilterCellSelect(cell, true) + } + }) + + /** + * Configure click event + */ + $('#sdgs-modal .sdg-cell').each(function (idx) { + const cell= $(this) + const current_value= cell.attr("data-value") + + cell.click(function () { + let selected= false + + // toggle inputs + const inputs= $('div.sdgs-filter input[type=hidden][data-value=' + current_value + ']') + inputs.each(function () { + const input= $(this) + if(input.val() == "") { + input.val(current_value) + selected= true + } else { + input.val("") + } + }) + + // update cell + toggleSdgFilterCellSelect(cell, selected) + }); + }); + + /** + * Send the filter form when done + */ + let sdgs_opener= null; + $('.sdgs-filter').click(function() { + sdgs_opener= $(this) + }); + $('#sdgs-modal .reveal__footer a.button').click(function() { + sdgs_opener.parent("form").submit() + sdgs_opener= null + }); +}) diff --git a/app/services/decidim/challenges/challenge_search.rb b/app/services/decidim/challenges/challenge_search.rb deleted file mode 100644 index 37249b45..00000000 --- a/app/services/decidim/challenges/challenge_search.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Challenges - # A service to encapsualte all the logic when searching and filtering - # challenges in a participatory process. - class ChallengeSearch < ResourceSearch - # text_search_fields :title - - # Public: Initializes the service. - # component - A Decidim::Component to get the challenges from. - # page - The page number to paginate the results. - # per_page - The number of challenges to return per page. - def initialize(options = {}) - super(Challenge.published.all, options) - end - - # Handle the search_text filter - def search_search_text - query.where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%") - end - - # Handle the state filter - def search_state - in_proposal = state.include?("proposal") ? query.in_proposal : nil - in_execution = state.member?("execution") ? query.in_execution : nil - in_finished = state.member?("finished") ? query.in_finished : nil - - query - .where(id: in_proposal) - .or(query.where(id: in_execution)) - .or(query.where(id: in_finished)) - end - - def search_sdgs_codes - query.where(sdg_code: sdgs_codes) - end - end - end -end diff --git a/app/services/decidim/problems/problem_search.rb b/app/services/decidim/problems/problem_search.rb deleted file mode 100644 index ce3e4038..00000000 --- a/app/services/decidim/problems/problem_search.rb +++ /dev/null @@ -1,97 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Problems - # A service to encapsualte all the logic when searching and filtering - # Problems in a participatory process. - class ProblemSearch < ResourceSearch - # text_search_fields :title - - # Public: Initializes the service. - # component - A Decidim::Component to get the problems from. - # page - The page number to paginate the results. - # per_page - The number of problems to return per page. - def initialize(options = {}) - super(Problem.published.all, options) - end - - # Handle the search_text filter - def search_search_text - query.where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%") - end - - # Handle the state filter - def search_state - in_proposal = state.include?("proposal") ? query.in_proposal : nil - in_execution = state.member?("execution") ? query.in_execution : nil - in_finished = state.member?("finished") ? query.in_finished : nil - - query - .where(id: in_proposal) - .or(query.where(id: in_execution)) - .or(query.where(id: in_finished)) - end - - # Handles the sectorial_scope_id filter. When we want to show only those that do not - # have a sectorial_scope_id set, we cannot pass an empty String or nil because Searchlight - # will automatically filter out these params, so the method will not be used. - # Instead, we need to pass a fake ID and then convert it inside. In this case, - # in order to select those elements that do not have a sectorial_scope_id set we use - # `"global"` as parameter, and in the method we do the needed changes to search - # properly. - def search_sectorial_scope_id - return query if sectorial_scope_id.include?("all") - - clean_scope_ids = sectorial_scope_id - - conditions = [] - conditions << "#{query.model_name.plural}.decidim_sectorial_scope_id IS NULL" if clean_scope_ids.delete("global") - conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any? - - query.includes(:sectorial_scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i)) - end - - # Handles the technological_scope_id filter. When we want to show only those that do not - # have a technological_scope_id set, we cannot pass an empty String or nil because Searchlight - # will automatically filter out these params, so the method will not be used. - # Instead, we need to pass a fake ID and then convert it inside. In this case, - # in order to select those elements that do not have a technological_scope_id set we use - # `"global"` as parameter, and in the method we do the needed changes to search - # properly. - def search_technological_scope_id - return query if technological_scope_id.include?("all") - - clean_scope_ids = technological_scope_id - - conditions = [] - conditions << "#{query.model_name.plural}.decidim_technological_scope_id IS NULL" if clean_scope_ids.delete("global") - conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any? - - query.includes(:technological_scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i)) - end - - # Handles the territorial challenge.scope_id filter. When we want to show only those that do not - # have a scope_id set, we cannot pass an empty String or nil because Searchlight - # will automatically filter out these params, so the method will not be used. - # Instead, we need to pass a fake ID and then convert it inside. In this case, - # in order to select those elements that do not have a scope_id set we use - # `"global"` as parameter, and in the method we do the needed changes to search - # properly. - def search_territorial_scope_id - return query if territorial_scope_id.include?("all") - - clean_scope_ids = territorial_scope_id - - conditions = [] - conditions << "decidim_challenges_challenges.decidim_scope_id IS NULL" if clean_scope_ids.delete("global") - conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any? - - query.includes(challenge: :scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i)) - end - - def search_sdgs_codes - query.joins(:challenge).where("decidim_challenges_challenges" => { sdg_code: sdgs_codes }) - end - end - end -end diff --git a/app/services/decidim/solutions/solution_search.rb b/app/services/decidim/solutions/solution_search.rb deleted file mode 100644 index 42b40a05..00000000 --- a/app/services/decidim/solutions/solution_search.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Solutions - # A service to encapsualte all the logic when searching and filtering - # Solutions in a participatory process. - class SolutionSearch < ResourceSearch - # text_search_fields :title - - # Public: Initializes the service. - # component - A Decidim::Component to get the solutions from. - # page - The page number to paginate the results. - # per_page - The number of solutions to return per page. - def initialize(options = {}) - super(Solution.published.all, options) - end - - # Handle the search_text filter - def search_search_text - query.where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%") - end - - # Handles the territorial challenge.scope_id filter. When we want to show only those that do not - # have a scope_id set, we cannot pass an empty String or nil because Searchlight - # will automatically filter out these params, so the method will not be used. - # Instead, we need to pass a fake ID and then convert it inside. In this case, - # in order to select those elements that do not have a scope_id set we use - # `"global"` as parameter, and in the method we do the needed changes to search - # properly. - def search_territorial_scope_id - return query if territorial_scope_id.include?("all") - - clean_scope_ids = territorial_scope_id - - conditions = [] - conditions << "decidim_challenges_challenges.decidim_scope_id IS NULL" if clean_scope_ids.delete("global") - conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any? - - query.includes(problem: { challenge: :scope }).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i)) - end - - def search_sdgs_codes - query.joins(problem: :challenge).where("decidim_challenges_challenges.sdg_code" => sdgs_codes) - end - end - end -end diff --git a/app/views/decidim/challenges/challenges/_count.html.erb b/app/views/decidim/challenges/challenges/_count.html.erb index c0b00cbc..5905bc92 100644 --- a/app/views/decidim/challenges/challenges/_count.html.erb +++ b/app/views/decidim/challenges/challenges/_count.html.erb @@ -1 +1 @@ -<%= t(".challenges_count", count: challenges.total_count) %> +<%= t(".challenges_count", count: challenges.count) %> diff --git a/app/views/decidim/challenges/challenges/_filters.html.erb b/app/views/decidim/challenges/challenges/_filters.html.erb index e632e95d..07ce772b 100644 --- a/app/views/decidim/challenges/challenges/_filters.html.erb +++ b/app/views/decidim/challenges/challenges/_filters.html.erb @@ -2,7 +2,7 @@
- +<%= javascript_pack_tag "decidim_sdgs" %> diff --git a/app/views/decidim/solutions/solutions/_count.html.erb b/app/views/decidim/solutions/solutions/_count.html.erb index 598e48b5..f0e040ec 100644 --- a/app/views/decidim/solutions/solutions/_count.html.erb +++ b/app/views/decidim/solutions/solutions/_count.html.erb @@ -1 +1 @@ -<%= t(".solutions_count", count: solutions.total_count) %> +<%= t(".solutions_count", count: solutions.count) %> diff --git a/app/views/decidim/solutions/solutions/_filters.html.erb b/app/views/decidim/solutions/solutions/_filters.html.erb index ab700ceb..f0106aaf 100644 --- a/app/views/decidim/solutions/solutions/_filters.html.erb +++ b/app/views/decidim/solutions/solutions/_filters.html.erb @@ -2,7 +2,7 @@