decidim-cleaner 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dda43559128f10de066d98d4ffc56eb53c6b46e3a49d4d49373cf62e054fcb3
4
- data.tar.gz: a22f580ae6fde675ca5c572005b224ac17d9546c861b343432ee919e67400420
3
+ metadata.gz: ac1fce1219b0b742c8b61a04692d5347c52143dbfdf68ad79bc7c482828327b9
4
+ data.tar.gz: 6d2f34f4cefa57d317ac26b025ddf74a86de35f59d0cd036c825644ffc7bdad7
5
5
  SHA512:
6
- metadata.gz: 746f6a5f4048779b2fa841a8911c7d8596c5a1c6363472f3bb0ede9b648d555f09d3069f22ee1fad1c514aef8409a5cf86447a7f25b6ab6684843dd9cf6b82c1
7
- data.tar.gz: 6a1fd5e673054d0ffad860b6bb1441c4d5a91986bff9f2611d7d45d24d0df0e8b1d68db0ca0024774e322f4e7fb7a1da35351e9cb4e07742a900d812c2264656
6
+ metadata.gz: ea06df0a3a5e974bb1d2ed5ddc9ec871a123b1bbedf7a1e096b4d5f18339c90123c0b6ded17e5320687277d711215c01d7db4cd488e86bd8956b4c1b1685c412
7
+ data.tar.gz: 6d286d5dae2c41de0a6f7e8d12c031c3b45c6a00bc25907e27c60e294b3dc23a32c4e29f24eab57dfb339f9ad667d856b444b6ecfafac008c59ed4177ef26547
data/README.md CHANGED
@@ -22,19 +22,6 @@ bundle exec rails decidim_cleaner:install:migrations
22
22
  bundle exec rails db:migrate
23
23
  ```
24
24
 
25
- You can then modify the default values of the cleaner in your .ENV with the following variables:
26
-
27
- ```bash
28
- # Delay until a user is considered inactive and receive a warning email (in days)
29
- DECIDIM_CLEANER_INACTIVE_USERS_MAIL=
30
-
31
- # Delay until a user is deleted after receiving an email (in days)
32
- DECIDIM_CLEANER_DELETE_INACTIVE_USERS=
33
-
34
- # Delay until an admin log is deleted (in days)
35
- DECIDIM_CLEANER_DELETE_ADMIN_LOGS=
36
- ```
37
-
38
25
  ### Sidekiq Scheduler
39
26
  [Further documentation](https://github.com/sidekiq-scheduler/sidekiq-scheduler)
40
27
 
@@ -9,17 +9,11 @@ module Decidim
9
9
  Decidim::Organization.find_each do |organization|
10
10
  next unless organization.delete_admin_logs?
11
11
 
12
- Decidim::ActionLog.where(organization: organization)
13
- .where("created_at < ?", delete_admin_logs_before_date(organization))
12
+ Decidim::ActionLog.where(organization:)
13
+ .where("created_at < ?", Time.zone.now - (organization.delete_admin_logs_after || 365).days)
14
14
  .delete_all
15
15
  end
16
16
  end
17
-
18
- private
19
-
20
- def delete_admin_logs_before_date(organization)
21
- Time.zone.now - (organization.delete_admin_logs_after || Decidim::Cleaner.delete_admin_logs_after).days
22
- end
23
17
  end
24
18
  end
25
19
  end
@@ -9,34 +9,28 @@ module Decidim
9
9
  Decidim::Organization.find_each do |organization|
10
10
  next unless organization.delete_inactive_users?
11
11
 
12
- send_warning(Decidim::User.where(organization: organization)
12
+ send_warning(Decidim::User.where(organization:)
13
13
  .not_deleted
14
14
  .where.not(email: "")
15
- .where("last_sign_in_at < ?", email_inactive_before_date(organization)))
16
- delete_user_and_send_email(Decidim::User.where(organization: organization)
15
+ .where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days)
16
+ .where("last_sign_in_at > ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days - 1.day))
17
+
18
+ delete_user_and_send_email(Decidim::User.where(organization:)
17
19
  .not_deleted
18
20
  .where.not(email: "")
19
- .where("warning_date < ?", delete_inactive_before_date(organization)))
21
+ .where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_after || 390).days))
20
22
  end
21
23
  end
22
24
 
23
25
  def send_warning(users)
24
26
  users.find_each do |user|
25
- next if user.warning_date.present?
26
-
27
- user.update!(warning_date: Time.zone.now) if InactiveUsersMailer.warning_inactive(user).deliver_now
27
+ InactiveUsersMailer.warning_inactive(user).deliver_now
28
28
  Rails.logger.info "Inactive warning sent to #{user.email}"
29
29
  end
30
30
  end
31
31
 
32
32
  def delete_user_and_send_email(users)
33
33
  users.find_each do |user|
34
- if user.last_sign_in_at > user.warning_date
35
- user.update!(warning_date: nil)
36
- Rails.logger.info "User with id #{user.id} has logged in again, warning date reset"
37
- next
38
- end
39
-
40
34
  InactiveUsersMailer.warning_deletion(user).deliver_now
41
35
  Rails.logger.info "Deletion warning sent to #{user.email}"
42
36
 
@@ -44,16 +38,6 @@ module Decidim
44
38
  Rails.logger.info "User with id #{user.id} destroyed"
45
39
  end
46
40
  end
47
-
48
- private
49
-
50
- def email_inactive_before_date(organization)
51
- Time.zone.now - (organization.delete_inactive_users_email_after || Decidim::Cleaner.delete_inactive_users_email_after).days
52
- end
53
-
54
- def delete_inactive_before_date(organization)
55
- Time.zone.now - (organization.delete_inactive_users_after || Decidim::Cleaner.delete_inactive_users_after).days
56
- end
57
41
  end
58
42
  end
59
43
  end
@@ -5,7 +5,6 @@ module Decidim
5
5
  # A custom mailer for Decidim so we can notify users
6
6
  # when their account was blocked
7
7
  class InactiveUsersMailer < Decidim::ApplicationMailer
8
- helper Decidim::Cleaner::DelaysHelper
9
8
  def warning_inactive(user)
10
9
  with_user(user) do
11
10
  @user = user
@@ -14,7 +13,7 @@ module Decidim
14
13
  "decidim.cleaner.inactive_users_mailer.warning_inactive.subject",
15
14
  organization_name: @organization.name
16
15
  )
17
- mail(to: user.email, subject: subject)
16
+ mail(to: user.email, subject:)
18
17
  end
19
18
  end
20
19
 
@@ -26,7 +25,7 @@ module Decidim
26
25
  "decidim.cleaner.inactive_users_mailer.warning_deletion.subject",
27
26
  organization_name: @organization.name
28
27
  )
29
- mail(to: user.email, subject: subject)
28
+ mail(to: user.email, subject:)
30
29
  end
31
30
  end
32
31
  end
@@ -1,6 +1,6 @@
1
1
  <p class="email-greeting"><%= t ".hello" %></p>
2
2
 
3
- <p class="email-instructions"><%= t(".body_1", organization_name: h(@organization.name), organization_url: decidim.root_url(host: @organization.host), days: email_inactive_after(@organization) + delete_inactive_after(@organization)).html_safe %></p>
3
+ <p class="email-instructions"><%= t(".body_1", organization_name: h(@organization.name), organization_url: decidim.root_url(host: @organization.host), days: @organization.delete_inactive_users_after||390).html_safe %></p>
4
4
 
5
5
  <p class="email-instructions"><%= t ".body_2" %></p>
6
6
 
@@ -1,7 +1,7 @@
1
1
  <p class="email-greeting"><%= t ".hello" %></p>
2
2
 
3
- <p class="email-instructions"><%= t ".body_1", organization_name: h(@organization.name), days: email_inactive_after(@organization) %></p>
3
+ <p class="email-instructions"><%= t ".body_1", organization_name: h(@organization.name), days: @organization.delete_inactive_users_email_after %></p>
4
4
 
5
- <p class="email-instructions"><%= t(".body_2", remaining_days: delete_inactive_after(@organization), organization_url: decidim.root_url(host: @organization.host)).html_safe %></p>
5
+ <p class="email-instructions"><%= t(".body_2", remaining_days: (@organization.delete_inactive_users_after||390) - (@organization.delete_inactive_users_email_after||365), organization_url: decidim.root_url(host: @organization.host)).html_safe %></p>
6
6
 
7
7
  <p class="email-closing"><%= t(".greetings", organization_name: h(@organization.name), organization_url: decidim.root_url(host: @organization.host)).html_safe %></p>
@@ -6,8 +6,7 @@ en:
6
6
  delete_admin_logs: Enable admin logs deletion
7
7
  delete_admin_logs_after: Delete admin logs after (days, default 365)
8
8
  delete_inactive_users: Enable inactive users deletion
9
- delete_inactive_users_after: Delete inactive users x days after the mail(days,
10
- default 30)
9
+ delete_inactive_users_after: Delete inactive users after (days, default 390)
11
10
  delete_inactive_users_email_after: Send email to inactive users before deletion
12
11
  (days, default 365)
13
12
  decidim:
@@ -7,8 +7,8 @@ fr:
7
7
  delete_admin_logs_after: Supprimer l'historique d'administration après (jours,
8
8
  par défaut 365)
9
9
  delete_inactive_users: Activer la suppression des utilisateurs inactifs
10
- delete_inactive_users_after: Supprimer les utilisateurs inactifs au bout de
11
- x jours après le courriel (jours, par défaut 30)
10
+ delete_inactive_users_after: Supprimer les utilisateurs inactifs après (jours,
11
+ par défaut 390)
12
12
  delete_inactive_users_email_after: Envoyer un courriel aux utilisateurs inactifs
13
13
  avant la suppression (jours, par défaut 365)
14
14
  decidim:
@@ -5,11 +5,11 @@ module Decidim
5
5
  # This holds the decidim-meetings version.
6
6
  module Cleaner
7
7
  def self.version
8
- "3.1.0"
8
+ "4.0.0"
9
9
  end
10
10
 
11
11
  def self.compatible_decidim_version
12
- "0.27.0"
12
+ "0.28.dev"
13
13
  end
14
14
  end
15
15
  end
@@ -7,18 +7,5 @@ require "decidim/cleaner/admin_engine"
7
7
  module Decidim
8
8
  # This namespace holds the logic of the `Cleaner` module.
9
9
  module Cleaner
10
- include ActiveSupport::Configurable
11
-
12
- config_accessor :delete_admin_logs_after do
13
- ENV.fetch("DECIDIM_CLEANER_DELETE_ADMIN_LOGS", "365").to_i
14
- end
15
-
16
- config_accessor :delete_inactive_users_after do
17
- ENV.fetch("DECIDIM_CLEANER_DELETE_INACTIVE_USERS", "30").to_i
18
- end
19
-
20
- config_accessor :delete_inactive_users_email_after do
21
- ENV.fetch("DECIDIM_CLEANER_INACTIVE_USERS_MAIL", "365").to_i
22
- end
23
10
  end
24
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quentinchampenois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-19 00:00:00.000000000 Z
11
+ date: 2023-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim-core
@@ -16,42 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.27.0
19
+ version: 0.28.dev
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.27.0
27
- - !ruby/object:Gem::Dependency
28
- name: decidim-dev
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.27.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.27.0
41
- - !ruby/object:Gem::Dependency
42
- name: rubocop-faker
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
26
+ version: 0.28.dev
55
27
  description: Clean outdated data in Decidim's database.
56
28
  email:
57
29
  - 26109239+Quentinchampenois@users.noreply.github.com
@@ -66,7 +38,6 @@ files:
66
38
  - app/controllers/decidim/cleaner/admin/application_controller.rb
67
39
  - app/controllers/decidim/cleaner/admin/organization_cleaner_controller.rb
68
40
  - app/forms/decidim/cleaner/admin/organization_cleaner_form.rb
69
- - app/helpers/decidim/cleaner/delays_helper.rb
70
41
  - app/jobs/decidim/cleaner/clean_admin_logs_job.rb
71
42
  - app/jobs/decidim/cleaner/clean_inactive_users_job.rb
72
43
  - app/mailers/decidim/cleaner/inactive_users_mailer.rb
@@ -81,7 +52,6 @@ files:
81
52
  - config/routes.rb
82
53
  - db/migrate/20230106105014_add_delete_admin_logs_to_organization.rb
83
54
  - db/migrate/20230110150032_add_delete_inactive_users_to_organization.rb
84
- - db/migrate/20230328094652_add_warning_date_to_users.rb
85
55
  - lib/decidim/cleaner.rb
86
56
  - lib/decidim/cleaner/admin.rb
87
57
  - lib/decidim/cleaner/admin_engine.rb
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Cleaner
5
- module DelaysHelper
6
- def email_inactive_after(organization)
7
- organization.delete_inactive_users_email_after || Decidim::Cleaner.delete_inactive_users_email_after
8
- end
9
-
10
- def delete_inactive_after(organization)
11
- organization.delete_inactive_users_after || Decidim::Cleaner.delete_inactive_users_after
12
- end
13
- end
14
- end
15
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddWarningDateToUsers < ActiveRecord::Migration[6.1]
4
- def change
5
- add_column :decidim_users, :warning_date, :datetime
6
- end
7
- end