decidim-cleaner 2.1.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -14
- data/app/commands/decidim/cleaner/admin/update_organization_cleaner.rb +1 -1
- data/app/jobs/decidim/cleaner/clean_admin_logs_job.rb +1 -7
- data/app/jobs/decidim/cleaner/clean_inactive_users_job.rb +4 -21
- data/app/mailers/decidim/cleaner/inactive_users_mailer.rb +0 -1
- data/app/views/decidim/cleaner/inactive_users_mailer/warning_deletion.html.erb +1 -1
- data/app/views/decidim/cleaner/inactive_users_mailer/warning_inactive.html.erb +2 -2
- data/config/locales/en.yml +1 -2
- data/config/locales/fr.yml +2 -2
- data/db/migrate/20230106105014_add_delete_admin_logs_to_organization.rb +1 -1
- data/db/migrate/20230110150032_add_delete_inactive_users_to_organization.rb +1 -1
- data/lib/decidim/cleaner/version.rb +2 -2
- data/lib/decidim/cleaner.rb +0 -13
- metadata +32 -6
- data/app/helpers/decidim/cleaner/delays_helper.rb +0 -15
- data/db/migrate/20230328094652_add_warning_date_to_users.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b548444c799a42e64b8c0e6e382f98d51738eb48ba9b7d29bc25f637b65b0ad
|
4
|
+
data.tar.gz: 222adf9a1210f66f8521273aa5351b46fac2ca57393883c5eb817c30ce7130b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8118d7e5d0b4334fc7bbf82ca9ffe74283b611c5f47cdeccc543a277dad15d1b4ab21206e440f91cf61aa8246d2faea020bcc7cbebd62af58d045fe8464255d4
|
7
|
+
data.tar.gz: 607dd023747be3edfcb94cdc3888a6aec98d7b3ca84d3523f25fbceee00b1e6072ff12945f278a0019be232062aa36387773e271e25d2ef7d4953be33d27f370
|
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
|
|
@@ -66,7 +53,7 @@ You can then add to your 'config/sidekiq.yml' file:
|
|
66
53
|
## Available tasks
|
67
54
|
|
68
55
|
- [ ] **Delete inactive users**
|
69
|
-
- Cron task that checks for user accounts where `
|
56
|
+
- Cron task that checks for user accounts where `last_sign_in_at` is superior to environment variable `CLEANER_USER_INACTIVITY_LIMIT`. If true, deletes inactive user from the database.
|
70
57
|
|
71
58
|
- [ ] **Delete old admin logs**
|
72
59
|
- Cron task that checks for admin logs where `created_at` is anterior to the time you configured in the back office. If true, deletes old admin logs from the database.
|
@@ -5,7 +5,7 @@ module Decidim
|
|
5
5
|
module Admin
|
6
6
|
# A command with all the business logic for updating the current
|
7
7
|
# organization cleaner.
|
8
|
-
class UpdateOrganizationCleaner <
|
8
|
+
class UpdateOrganizationCleaner < Decidim::Command
|
9
9
|
# Public: Initializes the command.
|
10
10
|
#
|
11
11
|
# organization - The Organization that will be updated.
|
@@ -10,16 +10,10 @@ module Decidim
|
|
10
10
|
next unless organization.delete_admin_logs?
|
11
11
|
|
12
12
|
Decidim::ActionLog.where(organization: organization)
|
13
|
-
.where("created_at < ?",
|
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
|
@@ -12,32 +12,25 @@ module Decidim
|
|
12
12
|
send_warning(Decidim::User.where(organization: organization)
|
13
13
|
.not_deleted
|
14
14
|
.where.not(email: "")
|
15
|
-
.where("
|
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))
|
16
17
|
|
17
18
|
delete_user_and_send_email(Decidim::User.where(organization: organization)
|
18
19
|
.not_deleted
|
19
20
|
.where.not(email: "")
|
20
|
-
.where("
|
21
|
+
.where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_after || 390).days))
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def send_warning(users)
|
25
26
|
users.find_each do |user|
|
26
|
-
|
27
|
-
|
28
|
-
user.update!(warning_date: Time.zone.now) if InactiveUsersMailer.warning_inactive(user).deliver_now
|
27
|
+
InactiveUsersMailer.warning_inactive(user).deliver_now
|
29
28
|
Rails.logger.info "Inactive warning sent to #{user.email}"
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
def delete_user_and_send_email(users)
|
34
33
|
users.find_each do |user|
|
35
|
-
if user.current_sign_in_at > user.warning_date
|
36
|
-
user.update!(warning_date: nil)
|
37
|
-
Rails.logger.info "User with id #{user.id} has logged in again, warning date reset"
|
38
|
-
next
|
39
|
-
end
|
40
|
-
|
41
34
|
InactiveUsersMailer.warning_deletion(user).deliver_now
|
42
35
|
Rails.logger.info "Deletion warning sent to #{user.email}"
|
43
36
|
|
@@ -45,16 +38,6 @@ module Decidim
|
|
45
38
|
Rails.logger.info "User with id #{user.id} destroyed"
|
46
39
|
end
|
47
40
|
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def email_inactive_before_date(organization)
|
52
|
-
Time.zone.now - (organization.delete_inactive_users_email_after || Decidim::Cleaner.delete_inactive_users_email_after).days
|
53
|
-
end
|
54
|
-
|
55
|
-
def delete_inactive_before_date(organization)
|
56
|
-
Time.zone.now - (organization.delete_inactive_users_after || Decidim::Cleaner.delete_inactive_users_after).days
|
57
|
-
end
|
58
41
|
end
|
59
42
|
end
|
60
43
|
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:
|
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:
|
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:
|
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>
|
data/config/locales/en.yml
CHANGED
@@ -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
|
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:
|
data/config/locales/fr.yml
CHANGED
@@ -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
|
11
|
-
|
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:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class AddDeleteAdminLogsToOrganization < ActiveRecord::Migration[
|
3
|
+
class AddDeleteAdminLogsToOrganization < ActiveRecord::Migration[6.1]
|
4
4
|
def change
|
5
5
|
add_column :decidim_organizations, :delete_admin_logs, :boolean, default: false, null: false
|
6
6
|
add_column :decidim_organizations, :delete_admin_logs_after, :integer
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class AddDeleteInactiveUsersToOrganization < ActiveRecord::Migration[
|
3
|
+
class AddDeleteInactiveUsersToOrganization < ActiveRecord::Migration[6.1]
|
4
4
|
def change
|
5
5
|
add_column :decidim_organizations, :delete_inactive_users, :boolean, default: false, null: false
|
6
6
|
add_column :decidim_organizations, :delete_inactive_users_email_after, :integer
|
data/lib/decidim/cleaner.rb
CHANGED
@@ -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:
|
4
|
+
version: 3.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-
|
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,14 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.27.0
|
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.
|
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'
|
27
55
|
description: Clean outdated data in Decidim's database.
|
28
56
|
email:
|
29
57
|
- 26109239+Quentinchampenois@users.noreply.github.com
|
@@ -38,7 +66,6 @@ files:
|
|
38
66
|
- app/controllers/decidim/cleaner/admin/application_controller.rb
|
39
67
|
- app/controllers/decidim/cleaner/admin/organization_cleaner_controller.rb
|
40
68
|
- app/forms/decidim/cleaner/admin/organization_cleaner_form.rb
|
41
|
-
- app/helpers/decidim/cleaner/delays_helper.rb
|
42
69
|
- app/jobs/decidim/cleaner/clean_admin_logs_job.rb
|
43
70
|
- app/jobs/decidim/cleaner/clean_inactive_users_job.rb
|
44
71
|
- app/mailers/decidim/cleaner/inactive_users_mailer.rb
|
@@ -53,7 +80,6 @@ files:
|
|
53
80
|
- config/routes.rb
|
54
81
|
- db/migrate/20230106105014_add_delete_admin_logs_to_organization.rb
|
55
82
|
- db/migrate/20230110150032_add_delete_inactive_users_to_organization.rb
|
56
|
-
- db/migrate/20230328094652_add_warning_date_to_users.rb
|
57
83
|
- lib/decidim/cleaner.rb
|
58
84
|
- lib/decidim/cleaner/admin.rb
|
59
85
|
- 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
|