decidim-cleaner 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9fd35840bd986218c10726232aa523b811331ec05cb78d6ae52b0352e434862
4
- data.tar.gz: 2edf1e583c38516e4d7eefd51f4116cb883e4f823643c605df4f40ae4718684f
3
+ metadata.gz: f54787d174b568ded865927e72ec935eda6e9133b7f0852bc9e00e7aa1a3d7ca
4
+ data.tar.gz: 948c3bf4816c2ce34ce80d3d57196a5712c8fb286343662bfec2bfd3b4e3729a
5
5
  SHA512:
6
- metadata.gz: e0c59579a5fe21080c697d6553b2983b21f242d62687c7fb7e700e86c5a01617762cdd8019a0b9258719d1534f5be29a00faa0580208ae92c31dc6fedb6d536f
7
- data.tar.gz: aca024679460c2a7fd0896e426c3b2de5f6aee923595b572bdfae1f2cb419090ae5a5dba6d898d4e38a744b67a0caff17b2ed2eb583bd883156cad4c063df912
6
+ metadata.gz: a6eac33bbda665f50c8e2e0ac84e7b5c7ee143e6adce9c624a31e9cb89ab9d2c31cb57c92cad167ee84420bf176ccf236a6a055bc288556cdfcc76cda940dcf5
7
+ data.tar.gz: bac945ce0b0830278a2536242d0397e6bf8f78d448de866bf4ff23ebb047726c7c3d74cacd43e35b570ed469d39dcf189a6f025efc1dc36770c242d3bbd4a116
data/README.md CHANGED
@@ -22,6 +22,11 @@ bundle exec rails decidim_cleaner:install:migrations
22
22
  bundle exec rails db:migrate
23
23
  ```
24
24
 
25
+ ### Sidekiq Scheduler
26
+ [Further documentation](https://github.com/sidekiq-scheduler/sidekiq-scheduler)
27
+
28
+ **Sidekiq scheduler uses a 6 columns format**
29
+
25
30
  You can then add to your 'config/sidekiq.yml' file:
26
31
 
27
32
  ```yaml
@@ -36,6 +41,15 @@ You can then add to your 'config/sidekiq.yml' file:
36
41
  queue: scheduled
37
42
  ```
38
43
 
44
+ ### Cronjob
45
+ ```
46
+ # Warns and deletes inactive users
47
+ 0 9 * * * cd /home/user/decidim_application && RAILS_ENV=production bundle exec rake decidim_cleaner:clean_inactive_users
48
+
49
+ # Deletes old admin logs
50
+ 0 9 * * * cd /home/user/decidim_application && RAILS_ENV=production bundle exec rake decidim_cleaner:clean_admin_logs
51
+ ```
52
+
39
53
  ## Available tasks
40
54
 
41
55
  - [ ] **Delete inactive users**
@@ -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 < Decidim::Command
8
+ class UpdateOrganizationCleaner < Rectify::Command
9
9
  # Public: Initializes the command.
10
10
  #
11
11
  # organization - The Organization that will be updated.
@@ -10,17 +10,20 @@ module Decidim
10
10
  next unless organization.delete_inactive_users?
11
11
 
12
12
  send_warning(Decidim::User.where(organization: organization)
13
+ .not_deleted
14
+ .where.not(email: "")
13
15
  .where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days)
14
16
  .where("last_sign_in_at > ?", Time.zone.now - (organization.delete_inactive_users_email_after || 365).days - 1.day))
17
+
15
18
  delete_user_and_send_email(Decidim::User.where(organization: organization)
19
+ .not_deleted
20
+ .where.not(email: "")
16
21
  .where("last_sign_in_at < ?", Time.zone.now - (organization.delete_inactive_users_after || 390).days))
17
22
  end
18
23
  end
19
24
 
20
25
  def send_warning(users)
21
26
  users.find_each do |user|
22
- next if user.deleted?
23
-
24
27
  InactiveUsersMailer.warning_inactive(user).deliver_now
25
28
  Rails.logger.info "Inactive warning sent to #{user.email}"
26
29
  end
@@ -28,8 +31,6 @@ module Decidim
28
31
 
29
32
  def delete_user_and_send_email(users)
30
33
  users.find_each do |user|
31
- next if user.deleted?
32
-
33
34
  InactiveUsersMailer.warning_deletion(user).deliver_now
34
35
  Rails.logger.info "Deletion warning sent to #{user.email}"
35
36
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddDeleteAdminLogsToOrganization < ActiveRecord::Migration[6.1]
3
+ class AddDeleteAdminLogsToOrganization < ActiveRecord::Migration[5.2]
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[6.1]
3
+ class AddDeleteInactiveUsersToOrganization < ActiveRecord::Migration[5.2]
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
@@ -5,11 +5,11 @@ module Decidim
5
5
  # This holds the decidim-meetings version.
6
6
  module Cleaner
7
7
  def self.version
8
- "1.0.1"
8
+ "2.0.0"
9
9
  end
10
10
 
11
- def self.decidim_version
12
- "0.26"
11
+ def self.compatible_decidim_version
12
+ "0.26.0"
13
13
  end
14
14
  end
15
15
  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: 1.0.1
4
+ version: 2.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-03-09 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,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.26'
19
+ version: 0.26.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'
26
+ version: 0.26.0
27
27
  description: Clean outdated data in Decidim's database.
28
28
  email:
29
29
  - 26109239+Quentinchampenois@users.noreply.github.com