From 92c56db362c108ce586dbf57de1662e5083b3a9c Mon Sep 17 00:00:00 2001 From: Armand Fardeau Date: Wed, 29 Mar 2023 11:50:49 +0200 Subject: [PATCH] Release (#20) * Fix rubocop * Improve installation instructions (#16) * Fix compat range (#17) * Fix compat range * Fix offenses * Fix lint * Fix tests * Fix/no email (#18) * Fix rubocop * Don't query deleted users * Don't query empty email users * Bump gem to prepare release --- .github/workflows/ci_cleaner.yml | 4 +- .rubocop.yml | 6 +- .rubocop_ruby.yml | 7 +- Gemfile.lock | 273 +++++++++--------- README.md | 14 + .../decidim/cleaner/clean_admin_logs_job.rb | 2 +- .../cleaner/clean_inactive_users_job.rb | 13 +- .../decidim/cleaner/inactive_users_mailer.rb | 4 +- decidim-cleaner.gemspec | 2 +- lib/decidim/cleaner/version.rb | 6 +- .../admin/update_organization_cleaner_spec.rb | 2 +- spec/factories.rb | 4 +- .../cleaner/clean_admin_logs_job_spec.rb | 12 +- .../cleaner/clean_inactive_users_job_spec.rb | 10 +- spec/lib/decidim/cleaner/version_spec.rb | 4 +- .../cleaner/inactive_users_mailer_spec.rb | 4 +- spec/permissions/admin/permissions_spec.rb | 6 +- ...dmin_manages_organization_cleaning_spec.rb | 4 +- 18 files changed, 198 insertions(+), 179 deletions(-) diff --git a/.github/workflows/ci_cleaner.yml b/.github/workflows/ci_cleaner.yml index 0f88c55..2d5ffe1 100644 --- a/.github/workflows/ci_cleaner.yml +++ b/.github/workflows/ci_cleaner.yml @@ -6,6 +6,8 @@ env: CODECOV: "true" RUBY_VERSION: 3.1.1 NODE_VERSION: 16.9.1 + WEBPACKER_RUNTIME_COMPILE: "false" + RAILS_ENV: test jobs: lint: @@ -91,7 +93,7 @@ jobs: path: ./spec/decidim_dummy_app/tmp/screenshots if-no-files-found: ignore release: - if: "github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'" + if: "github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release' )" needs: [tests, lint] runs-on: ubuntu-latest steps: diff --git a/.rubocop.yml b/.rubocop.yml index 32f2693..53ea2b4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,7 @@ inherit_from: - .rubocop_rails.yml AllCops: - TargetRubyVersion: 2.7.5 + TargetRubyVersion: 3.1 Include: - "**/*.rb" - "**/*.rake" @@ -16,3 +16,7 @@ AllCops: - "vendor/**/*" - "spec/decidim_dummy_app/**/*" - "development_app/**/*" + +RSpec/DescribeClass: + Exclude: + - spec/system/* \ No newline at end of file diff --git a/.rubocop_ruby.yml b/.rubocop_ruby.yml index 299a4ad..c5346f7 100644 --- a/.rubocop_ruby.yml +++ b/.rubocop_ruby.yml @@ -70,11 +70,6 @@ AllCops: # Otherwise we fallback to the oldest officially supported Ruby version (2.0). TargetRubyVersion: 2.7 - RSpec: - Patterns: - - "(?:^|/)spec/" - - "(?:^|/)test/" - # Indent private/protected/public as deep as method definitions Layout/AccessModifierIndentation: EnforcedStyle: indent @@ -257,7 +252,7 @@ Style/BlockDelimiters: - let! - subject - watch - IgnoredMethods: + AllowedMethods: # Methods that can be either procedural or functional and cannot be # categorised from their usage alone, e.g. # diff --git a/Gemfile.lock b/Gemfile.lock index 67937c2..696d40d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/decidim/decidim - revision: acb9a9d50c4e51d4f379d761a6d4e00e24c0e7d0 + revision: c782bb2fe0ce82b9f8b3502504a9a5573b51bc79 specs: decidim (0.28.0.dev) decidim-accountability (= 0.28.0.dev) @@ -71,7 +71,7 @@ GIT hashdiff (>= 0.4.0, < 2.0.0) invisible_captcha (~> 0.12) kaminari (~> 1.2, >= 1.2.1) - loofah (~> 2.3.1) + loofah (>= 2.19.1) mime-types (>= 1.16, < 4.0) mini_magick (~> 4.9) mustache (~> 1.1.0) @@ -85,10 +85,10 @@ GIT pg (~> 1.4.0, < 2) pg_search (~> 2.2) premailer-rails (~> 1.10) - psych (< 4) - rack (~> 2.2, >= 2.2.3) + psych (~> 4.0) + rack (~> 2.2, >= 2.2.6.3) rack-attack (~> 6.0) - rails (~> 6.1.0) + rails (~> 6.1.7) rails-i18n (~> 6.0) ransack (~> 3.2.1) redis (~> 4.1) @@ -96,10 +96,10 @@ GIT rubyXL (~> 3.4) rubyzip (~> 2.0) seven_zip_ruby (~> 1.3) + shakapacker (~> 6.6.0) turbo-rails (~> 1.3.0) valid_email2 (~> 4.0) - webpacker (= 6.0.0.rc.5) - webpush (~> 1.1) + web-push (~> 3.0) wisper (~> 2.0) decidim-debates (0.28.0.dev) decidim-comments (= 0.28.0.dev) @@ -121,7 +121,7 @@ GIT rspec-rails (~> 4.0) rspec-retry (~> 0.6.2) rspec_junit_formatter (~> 0.3.0) - rubocop (~> 1.28.0) + rubocop (~> 1.33.0) rubocop-faker (~> 1.1) rubocop-rails (~> 2.14) rubocop-rspec (~> 2.10) @@ -174,46 +174,46 @@ GIT PATH remote: . specs: - decidim-cleaner (1.0.1) - decidim-core (~> 0.26) + decidim-cleaner (4.0.0) + decidim-core (~> 0.28.dev) GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7) - actionpack (= 6.1.7) - activesupport (= 6.1.7) + actioncable (6.1.7.3) + actionpack (= 6.1.7.3) + activesupport (= 6.1.7.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7) - actionpack (= 6.1.7) - activejob (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + actionmailbox (6.1.7.3) + actionpack (= 6.1.7.3) + activejob (= 6.1.7.3) + activerecord (= 6.1.7.3) + activestorage (= 6.1.7.3) + activesupport (= 6.1.7.3) mail (>= 2.7.1) - actionmailer (6.1.7) - actionpack (= 6.1.7) - actionview (= 6.1.7) - activejob (= 6.1.7) - activesupport (= 6.1.7) + actionmailer (6.1.7.3) + actionpack (= 6.1.7.3) + actionview (= 6.1.7.3) + activejob (= 6.1.7.3) + activesupport (= 6.1.7.3) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.7) - actionview (= 6.1.7) - activesupport (= 6.1.7) + actionpack (6.1.7.3) + actionview (= 6.1.7.3) + activesupport (= 6.1.7.3) 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.1.7) - actionpack (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + actiontext (6.1.7.3) + actionpack (= 6.1.7.3) + activerecord (= 6.1.7.3) + activestorage (= 6.1.7.3) + activesupport (= 6.1.7.3) nokogiri (>= 1.8.5) - actionview (6.1.7) - activesupport (= 6.1.7) + actionview (6.1.7.3) + activesupport (= 6.1.7.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -221,28 +221,28 @@ GEM active_link_to (1.0.5) actionpack addressable - activejob (6.1.7) - activesupport (= 6.1.7) + activejob (6.1.7.3) + activesupport (= 6.1.7.3) globalid (>= 0.3.6) - activemodel (6.1.7) - activesupport (= 6.1.7) - activerecord (6.1.7) - activemodel (= 6.1.7) - activesupport (= 6.1.7) - activestorage (6.1.7) - actionpack (= 6.1.7) - activejob (= 6.1.7) - activerecord (= 6.1.7) - activesupport (= 6.1.7) + activemodel (6.1.7.3) + activesupport (= 6.1.7.3) + activerecord (6.1.7.3) + activemodel (= 6.1.7.3) + activesupport (= 6.1.7.3) + activestorage (6.1.7.3) + actionpack (= 6.1.7.3) + activejob (= 6.1.7.3) + activerecord (= 6.1.7.3) + activesupport (= 6.1.7.3) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.7) + activesupport (6.1.7.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - acts_as_list (1.0.4) + acts_as_list (1.1.0) activerecord (>= 4.2) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) @@ -258,7 +258,7 @@ GEM parser (>= 2.4) smart_properties bindex (0.8.1) - bootsnap (1.15.0) + bootsnap (1.16.0) msgpack (~> 1.2) browser (2.7.1) builder (3.2.4) @@ -293,12 +293,12 @@ GEM cells (>= 4.1.6, < 5.0.0) charlock_holmes (0.7.7) childprocess (4.1.0) - commonmarker (0.23.6) - concurrent-ruby (1.1.10) + commonmarker (0.23.8) + concurrent-ruby (1.2.2) crack (0.4.5) rexml crass (1.0.6) - css_parser (1.13.0) + css_parser (1.14.0) addressable date (3.3.3) date_validator (0.12.0) @@ -310,15 +310,15 @@ GEM declarative-builder (0.1.0) declarative-option (< 0.2.0) declarative-option (0.1.0) - devise (4.8.1) + devise (4.9.0) 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.7) actionmailer (>= 5.0) devise (>= 4.6) diff-lcs (1.5.0) @@ -327,7 +327,7 @@ GEM nokogiri (>= 1.13.2, < 1.14.0) rubyzip (~> 2.3.0) docile (1.4.0) - doorkeeper (5.6.2) + doorkeeper (5.6.5) railties (>= 5) doorkeeper-i18n (4.0.1) erb_lint (0.0.37) @@ -342,7 +342,7 @@ GEM temple erubi (1.12.0) escape_utils (1.3.0) - excon (0.95.0) + excon (0.99.0) extended-markdown-filter (0.7.0) html-pipeline (~> 2.9) factory_bot (4.11.1) @@ -352,7 +352,7 @@ GEM railties (>= 3.0.0) faker (2.23.0) i18n (>= 1.8.11, < 2) - faraday (2.7.2) + faraday (2.7.4) faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) faraday-net_http (3.0.2) @@ -375,7 +375,7 @@ GEM railties (>= 4.1, < 7.1) gemoji (3.0.1) geocoder (1.8.1) - globalid (1.0.0) + globalid (1.1.0) activesupport (>= 5.0) graphql (1.12.24) graphql-docs (2.1.0) @@ -389,7 +389,7 @@ GEM hashdiff (1.0.1) hashie (5.0.0) highline (2.1.0) - hkdf (0.3.0) + hkdf (1.0.0) html-pipeline (2.14.3) activesupport (>= 2) nokogiri (>= 1.4) @@ -416,7 +416,7 @@ GEM invisible_captcha (0.13.0) rails (>= 3.2.0) json (2.6.3) - jwt (2.6.0) + jwt (2.7.0) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -438,13 +438,13 @@ GEM letter_opener (~> 1.7) railties (>= 5.2) rexml - 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.8.0) + mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop @@ -454,12 +454,11 @@ GEM method_source (1.0.0) mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) + mime-types-data (3.2023.0218.1) mini_magick (4.12.0) mini_mime (1.1.2) - mini_portile2 (2.8.1) - minitest (5.17.0) - msgpack (1.6.0) + minitest (5.18.0) + msgpack (1.6.1) multi_xml (0.6.0) mustache (1.1.1) net-imap (0.3.4) @@ -472,8 +471,7 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.8) - nokogiri (1.13.10) - mini_portile2 (~> 2.8.0) + nokogiri (1.13.10-arm64-darwin) racc (~> 1.4) nokogiri (1.13.10-x86_64-darwin) racc (~> 1.4) @@ -492,7 +490,7 @@ GEM rack (>= 1.2, < 4) snaky_hash (~> 2.0) version_gem (~> 1.1) - omniauth (2.1.0) + omniauth (2.1.1) hashie (>= 3.4.6) rack (>= 2.2.3) rack-protection @@ -515,6 +513,7 @@ GEM omniauth-twitter (1.4.0) omniauth-oauth (~> 1.1) rack + openssl (3.1.0) orm_adapter (0.5.0) paper_trail (12.3.0) activerecord (>= 5.2) @@ -522,13 +521,13 @@ GEM parallel (1.22.1) parallel_tests (3.13.0) parallel - parser (3.2.0.0) + parser (3.2.1.1) ast (~> 2.4.1) - pg (1.4.5) + pg (1.4.6) pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) - premailer (1.18.0) + premailer (1.20.0) addressable css_parser (>= 1.12.0) htmlentities (>= 4.0.0) @@ -536,36 +535,37 @@ GEM actionmailer (>= 3) net-smtp premailer (~> 1.7, >= 1.7.9) - psych (3.3.4) + psych (4.0.6) + stringio public_suffix (5.0.1) puma (5.6.5) nio4r (~> 2.0) racc (1.6.2) - rack (2.2.5) + rack (2.2.6.4) rack-attack (6.6.1) rack (>= 1.0, < 3) rack-cors (1.1.1) rack (>= 2.0.0) rack-protection (3.0.5) rack - rack-proxy (0.7.4) + rack-proxy (0.7.6) rack - rack-test (2.0.2) + rack-test (2.1.0) rack (>= 1.3) - rails (6.1.7) - actioncable (= 6.1.7) - actionmailbox (= 6.1.7) - actionmailer (= 6.1.7) - actionpack (= 6.1.7) - actiontext (= 6.1.7) - actionview (= 6.1.7) - activejob (= 6.1.7) - activemodel (= 6.1.7) - activerecord (= 6.1.7) - activestorage (= 6.1.7) - activesupport (= 6.1.7) + rails (6.1.7.3) + actioncable (= 6.1.7.3) + actionmailbox (= 6.1.7.3) + actionmailer (= 6.1.7.3) + actionpack (= 6.1.7.3) + actiontext (= 6.1.7.3) + actionview (= 6.1.7.3) + activejob (= 6.1.7.3) + activemodel (= 6.1.7.3) + activerecord (= 6.1.7.3) + activestorage (= 6.1.7.3) + activesupport (= 6.1.7.3) bundler (>= 1.15.0) - railties (= 6.1.7) + railties (= 6.1.7.3) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -574,14 +574,14 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) 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.1.7) - actionpack (= 6.1.7) - activesupport (= 6.1.7) + railties (6.1.7.3) + actionpack (= 6.1.7.3) + activesupport (= 6.1.7.3) method_source rake (>= 12.2) thor (~> 1.0) @@ -594,14 +594,14 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - redcarpet (3.5.1) - redis (4.8.0) - regexp_parser (2.6.1) + redcarpet (3.6.0) + redis (4.8.1) + regexp_parser (2.7.0) request_store (1.5.1) rack (>= 1.4) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) + responders (3.1.0) + actionpack (>= 5.2) + railties (>= 5.2) rexml (3.2.5) rspec (3.12.0) rspec-core (~> 3.12.0) @@ -610,15 +610,15 @@ GEM rspec-cells (0.3.8) cells (>= 4.0.0, < 6.0.0) rspec-rails (>= 3.0.0, < 6.1.0) - rspec-core (3.12.0) + rspec-core (3.12.1) rspec-support (~> 3.12.0) - rspec-expectations (3.12.1) + rspec-expectations (3.12.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-html-matchers (0.9.4) nokogiri (~> 1) rspec (>= 3.0.0.a, < 4) - rspec-mocks (3.12.1) + rspec-mocks (3.12.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-rails (4.1.2) @@ -634,27 +634,28 @@ GEM rspec-support (3.12.0) rspec_junit_formatter (0.3.0) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (1.28.2) + rubocop (1.33.0) + json (~> 2.3) parallel (~> 1.10) parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.17.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.19.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) + rubocop-ast (1.27.0) + parser (>= 3.2.1.0) rubocop-faker (1.1.0) faker (>= 2.12.0) rubocop (>= 0.82.0) - rubocop-rails (2.15.2) + rubocop-rails (2.18.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-rspec (2.11.1) - rubocop (~> 1.19) - ruby-progressbar (1.11.0) + rubocop (>= 1.33.0, < 2.0) + rubocop-rspec (2.17.1) + rubocop (~> 1.33) + ruby-progressbar (1.13.0) ruby-vips (2.1.4) ffi (~> 1.12) ruby2_keywords (0.0.5) @@ -673,6 +674,11 @@ GEM rubyzip (>= 1.2.2) semantic_range (3.0.0) seven_zip_ruby (1.3.0) + shakapacker (6.6.0) + activesupport (>= 5.2) + rack-proxy (>= 0.6.1) + railties (>= 5.2) + semantic_range (>= 2.3.0) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -698,24 +704,25 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) ssrf_filter (1.1.1) - temple (0.9.1) + stringio (3.0.5) + temple (0.10.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) thor (1.2.1) - tilt (2.0.11) - timeout (0.3.1) - turbo-rails (1.3.2) + tilt (2.1.0) + timeout (0.3.2) + turbo-rails (1.3.3) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) - tzinfo (2.0.5) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unicode-display_width (2.4.0) - valid_email2 (4.0.4) + unicode-display_width (2.4.2) + valid_email2 (4.0.5) activemodel (>= 3.2) mail (~> 2.5) - version_gem (1.1.1) + version_gem (1.1.2) w3c_rspec_validators (0.3.0) rails rspec @@ -731,18 +738,14 @@ GEM activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) + web-push (3.0.0) + hkdf (~> 1.0) + jwt (~> 2.0) + openssl (~> 3.0) webmock (3.18.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webpacker (6.0.0.rc.5) - activesupport (>= 5.2) - rack-proxy (>= 0.6.1) - railties (>= 5.2) - semantic_range (>= 2.3.0) - webpush (1.1.0) - hkdf (~> 0.2) - jwt (~> 2.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -753,10 +756,10 @@ GEM wkhtmltopdf-binary (0.12.6.6) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.6) + zeitwerk (2.6.7) PLATFORMS - ruby + arm64-darwin-21 x86_64-darwin-21 x86_64-linux @@ -778,4 +781,4 @@ RUBY VERSION ruby 3.1.1p18 BUNDLED WITH - 2.3.22 + 2.4.6 diff --git a/README.md b/README.md index 2c6a42c..d850cf4 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,11 @@ bundle exec rails decidim_cleaner:install:migrations bundle exec rails db:migrate ``` +### Sidekiq Scheduler +[Further documentation](https://github.com/sidekiq-scheduler/sidekiq-scheduler) + +**Sidekiq scheduler uses a 6 columns format** + You can then add to your 'config/sidekiq.yml' file: ```yaml @@ -36,6 +41,15 @@ You can then add to your 'config/sidekiq.yml' file: queue: scheduled ``` +### Cronjob +``` +# Warns and deletes inactive users +0 9 * * * cd /home/user/decidim_application && RAILS_ENV=production bundle exec rake decidim_cleaner:clean_inactive_users + +# Deletes old admin logs +0 9 * * * cd /home/user/decidim_application && RAILS_ENV=production bundle exec rake decidim_cleaner:clean_admin_logs +``` + ## Available tasks - [ ] **Delete inactive users** diff --git a/app/jobs/decidim/cleaner/clean_admin_logs_job.rb b/app/jobs/decidim/cleaner/clean_admin_logs_job.rb index d06e54f..b31b63f 100644 --- a/app/jobs/decidim/cleaner/clean_admin_logs_job.rb +++ b/app/jobs/decidim/cleaner/clean_admin_logs_job.rb @@ -9,7 +9,7 @@ def perform Decidim::Organization.find_each do |organization| next unless organization.delete_admin_logs? - Decidim::ActionLog.where(organization: organization) + Decidim::ActionLog.where(organization:) .where("created_at < ?", Time.zone.now - (organization.delete_admin_logs_after || 365).days) .delete_all end diff --git a/app/jobs/decidim/cleaner/clean_inactive_users_job.rb b/app/jobs/decidim/cleaner/clean_inactive_users_job.rb index a66ff6e..7381bf6 100644 --- a/app/jobs/decidim/cleaner/clean_inactive_users_job.rb +++ b/app/jobs/decidim/cleaner/clean_inactive_users_job.rb @@ -9,18 +9,21 @@ def perform Decidim::Organization.find_each do |organization| next unless organization.delete_inactive_users? - send_warning(Decidim::User.where(organization: organization) + send_warning(Decidim::User.where(organization:) + .not_deleted + .where.not(email: "") .where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days) .where("last_sign_in_at > ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days - 1.day)) - delete_user_and_send_email(Decidim::User.where(organization: organization) + + delete_user_and_send_email(Decidim::User.where(organization:) + .not_deleted + .where.not(email: "") .where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_after || 390).days)) end end def send_warning(users) users.find_each do |user| - next if user.deleted? - InactiveUsersMailer.warning_inactive(user).deliver_now Rails.logger.info "Inactive warning sent to #{user.email}" end @@ -28,8 +31,6 @@ def send_warning(users) def delete_user_and_send_email(users) users.find_each do |user| - next if user.deleted? - InactiveUsersMailer.warning_deletion(user).deliver_now Rails.logger.info "Deletion warning sent to #{user.email}" diff --git a/app/mailers/decidim/cleaner/inactive_users_mailer.rb b/app/mailers/decidim/cleaner/inactive_users_mailer.rb index be05a52..b694eb9 100644 --- a/app/mailers/decidim/cleaner/inactive_users_mailer.rb +++ b/app/mailers/decidim/cleaner/inactive_users_mailer.rb @@ -13,7 +13,7 @@ def warning_inactive(user) "decidim.cleaner.inactive_users_mailer.warning_inactive.subject", organization_name: @organization.name ) - mail(to: user.email, subject: subject) + mail(to: user.email, subject:) end end @@ -25,7 +25,7 @@ def warning_deletion(user) "decidim.cleaner.inactive_users_mailer.warning_deletion.subject", organization_name: @organization.name ) - mail(to: user.email, subject: subject) + mail(to: user.email, subject:) end end end diff --git a/decidim-cleaner.gemspec b/decidim-cleaner.gemspec index 981523e..e67a5bf 100644 --- a/decidim-cleaner.gemspec +++ b/decidim-cleaner.gemspec @@ -25,5 +25,5 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "LICENSE-AGPLv3.txt", "Rakefile", "README.md"] - s.add_dependency "decidim-core", "~> #{Decidim::Cleaner.decidim_version}" + s.add_dependency "decidim-core", "~> #{Decidim::Cleaner.compatible_decidim_version}" end diff --git a/lib/decidim/cleaner/version.rb b/lib/decidim/cleaner/version.rb index ee585f9..c576c07 100644 --- a/lib/decidim/cleaner/version.rb +++ b/lib/decidim/cleaner/version.rb @@ -5,11 +5,11 @@ module Decidim # This holds the decidim-meetings version. module Cleaner def self.version - "1.0.1" + "4.0.0" end - def self.decidim_version - "0.26" + def self.compatible_decidim_version + "0.28.dev" end end end diff --git a/spec/commands/decidim/cleaner/admin/update_organization_cleaner_spec.rb b/spec/commands/decidim/cleaner/admin/update_organization_cleaner_spec.rb index bd49dff..15fec17 100644 --- a/spec/commands/decidim/cleaner/admin/update_organization_cleaner_spec.rb +++ b/spec/commands/decidim/cleaner/admin/update_organization_cleaner_spec.rb @@ -6,7 +6,7 @@ module Decidim::Cleaner::Admin describe UpdateOrganizationCleaner do describe "call" do let(:organization) { create(:organization) } - let(:user) { create(:user, organization: organization) } + let(:user) { create(:user, organization:) } let(:params) do { delete_admin_logs: true, diff --git a/spec/factories.rb b/spec/factories.rb index ec405e7..7b178e9 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -55,8 +55,8 @@ after(:create) do |organization, evaluator| if evaluator.create_static_pages - tos_page = Decidim::StaticPage.find_by(slug: "terms-and-conditions", organization: organization) - create(:static_page, :tos, organization: organization) if tos_page.nil? + tos_page = Decidim::StaticPage.find_by(slug: "terms-and-conditions", organization:) + create(:static_page, :tos, organization:) if tos_page.nil? end end end diff --git a/spec/jobs/decidim/cleaner/clean_admin_logs_job_spec.rb b/spec/jobs/decidim/cleaner/clean_admin_logs_job_spec.rb index 76130b9..a5ea42b 100644 --- a/spec/jobs/decidim/cleaner/clean_admin_logs_job_spec.rb +++ b/spec/jobs/decidim/cleaner/clean_admin_logs_job_spec.rb @@ -9,8 +9,8 @@ module Cleaner context "when the delay is specified" do let!(:organization) { create(:organization, delete_admin_logs: true, delete_admin_logs_after: 25) } - let!(:old_action_log) { create(:action_log, organization: organization, created_at: 50.days.ago) } - let!(:action_log) { create(:action_log, organization: organization) } + let!(:old_action_log) { create(:action_log, organization:, created_at: 50.days.ago) } + let!(:action_log) { create(:action_log, organization:) } it "enqueues job in queue 'cleaner'" do expect(subject.queue_name).to eq("scheduled") @@ -28,8 +28,8 @@ module Cleaner context "when the delay is not specified" do let!(:organization) { create(:organization, delete_admin_logs: true) } - let!(:old_action_log) { create(:action_log, organization: organization, created_at: 2.years.ago) } - let!(:action_log) { create(:action_log, organization: organization) } + let!(:old_action_log) { create(:action_log, organization:, created_at: 2.years.ago) } + let!(:action_log) { create(:action_log, organization:) } it "enqueues job in queue 'cleaner'" do expect(subject.queue_name).to eq("scheduled") @@ -47,8 +47,8 @@ module Cleaner context "when the cleaning is not enabled" do let!(:organization) { create(:organization, delete_admin_logs: false) } - let!(:old_action_log) { create(:action_log, organization: organization, created_at: 2.years.ago) } - let!(:action_log) { create(:action_log, organization: organization) } + let!(:old_action_log) { create(:action_log, organization:, created_at: 2.years.ago) } + let!(:action_log) { create(:action_log, organization:) } it "removes the admin logs that should be removed" do expect(Decidim::ActionLog.count).to eq(2) diff --git a/spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb b/spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb index 2f56112..9d27602 100644 --- a/spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb +++ b/spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb @@ -7,9 +7,9 @@ context "when the delay is specified" do let!(:organization) { create(:organization, delete_inactive_users: true, delete_inactive_users_email_after: 25, delete_inactive_users_after: 30) } - let!(:pending_user) { create(:user, organization: organization, last_sign_in_at: 25.days.ago - 1.hour) } - let!(:inactive_user) { create(:user, organization: organization, last_sign_in_at: 50.days.ago) } - let!(:user) { create(:user, organization: organization) } + let!(:pending_user) { create(:user, organization:, last_sign_in_at: 25.days.ago - 1.hour) } + let!(:inactive_user) { create(:user, organization:, last_sign_in_at: 50.days.ago) } + let!(:user) { create(:user, organization:) } it "enqueues job in queue 'cleaner'" do expect(subject.queue_name).to eq("scheduled") @@ -32,8 +32,8 @@ end context "when users have destroyed his/her account" do - let!(:pending_user) { create(:user, :deleted, organization: organization, last_sign_in_at: 25.days.ago - 1.hour) } - let!(:inactive_user) { create(:user, :deleted, organization: organization, last_sign_in_at: 50.days.ago) } + let!(:pending_user) { create(:user, :deleted, organization:, last_sign_in_at: 25.days.ago - 1.hour) } + let!(:inactive_user) { create(:user, :deleted, organization:, last_sign_in_at: 50.days.ago) } it "doesn't send email" do expect(Decidim::Cleaner::InactiveUsersMailer).not_to receive(:warning_inactive).with(pending_user).and_call_original diff --git a/spec/lib/decidim/cleaner/version_spec.rb b/spec/lib/decidim/cleaner/version_spec.rb index c7c2f1b..abdabeb 100644 --- a/spec/lib/decidim/cleaner/version_spec.rb +++ b/spec/lib/decidim/cleaner/version_spec.rb @@ -7,11 +7,11 @@ module Decidim subject { described_class } it "has version" do - expect(subject.version).to eq("1.0.1") + expect(subject.version).to eq("4.0.0") end it "has decidim version compatibility" do - expect(subject.decidim_version).to eq("0.26") + expect(subject.compatible_decidim_version).to eq("0.28.dev") end end end diff --git a/spec/mailers/decidim/cleaner/inactive_users_mailer_spec.rb b/spec/mailers/decidim/cleaner/inactive_users_mailer_spec.rb index 6a02cc6..2681ef9 100644 --- a/spec/mailers/decidim/cleaner/inactive_users_mailer_spec.rb +++ b/spec/mailers/decidim/cleaner/inactive_users_mailer_spec.rb @@ -3,8 +3,8 @@ require "spec_helper" module Decidim::Cleaner - describe InactiveUsersMailer, type: :mailer do - let(:user) { create(:user, :confirmed, organization: organization) } + describe InactiveUsersMailer do + let(:user) { create(:user, :confirmed, organization:) } let(:organization) { create(:organization, delete_inactive_users: true) } let(:organization_url) { "http://www.example.com" } let(:decidim) { Decidim::Core::Engine.routes.url_helpers } diff --git a/spec/permissions/admin/permissions_spec.rb b/spec/permissions/admin/permissions_spec.rb index a2ffe81..32f2443 100644 --- a/spec/permissions/admin/permissions_spec.rb +++ b/spec/permissions/admin/permissions_spec.rb @@ -6,7 +6,7 @@ module Decidim::Cleaner::Admin describe Permissions do subject { described_class.new(user, permission_action, context).permissions.allowed? } - let(:organization) { create :organization } + let(:organization) { create(:organization) } let(:context) do { current_organization: organization @@ -18,7 +18,7 @@ module Decidim::Cleaner::Admin let(:permission_action) { Decidim::PermissionAction.new(**action) } context "when user is admin" do - let(:user) { create :user, :admin, organization: organization } + let(:user) { create(:user, :admin, organization:) } it { is_expected.to be_truthy } @@ -32,7 +32,7 @@ module Decidim::Cleaner::Admin end context "when user is not admin" do - let(:user) { create :user, organization: organization } + let(:user) { create(:user, organization:) } it_behaves_like "permission is not set" end diff --git a/spec/system/admin_manages_organization_cleaning_spec.rb b/spec/system/admin_manages_organization_cleaning_spec.rb index 61ac487..262c972 100644 --- a/spec/system/admin_manages_organization_cleaning_spec.rb +++ b/spec/system/admin_manages_organization_cleaning_spec.rb @@ -2,9 +2,9 @@ require "spec_helper" -describe "Admin manages organization cleaning", type: :system do +describe "Admin manages organization cleaning" do let(:organization) { create(:organization) } - let(:user) { create(:user, :admin, :confirmed, organization: organization) } + let(:user) { create(:user, :admin, :confirmed, organization:) } before do switch_to_host(organization.host)