Skip to content

Commit

Permalink
Use current sign in at (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandfardeau authored May 26, 2023
1 parent a7486b0 commit 6a396a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ You can then add to your 'config/sidekiq.yml' file:
## Available tasks

- [ ] **Delete inactive users**
- 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.
- Cron task that checks for user accounts where `current_sign_in_at` is superior to environment variable `CLEANER_USER_INACTIVITY_LIMIT`. If true, deletes inactive user from the database.

- [ ] **Delete old admin logs**
- 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.
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/decidim/cleaner/clean_inactive_users_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def perform
send_warning(Decidim::User.where(organization:)
.not_deleted
.where.not(email: "")
.where("last_sign_in_at < ?", email_inactive_before_date(organization)))
.where("current_sign_in_at < ?", email_inactive_before_date(organization)))
delete_user_and_send_email(Decidim::User.where(organization:)
.not_deleted
.where.not(email: "")
Expand All @@ -31,7 +31,7 @@ def send_warning(users)

def delete_user_and_send_email(users)
users.find_each do |user|
if user.last_sign_in_at > user.warning_date
if user.current_sign_in_at > user.warning_date
user.update!(warning_date: nil)
Rails.logger.info "User with id #{user.id} has logged in again, warning date reset"
next
Expand Down
10 changes: 5 additions & 5 deletions spec/jobs/decidim/cleaner/clean_inactive_users_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

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: 5) }
let!(:pending_user) { create(:user, organization:, last_sign_in_at: 27.days.ago) }
let!(:inactive_user) { create(:user, organization:, last_sign_in_at: 35.days.ago, warning_date: 10.days.ago) }
let!(:pending_user) { create(:user, organization:, current_sign_in_at: 27.days.ago) }
let!(:inactive_user) { create(:user, organization:, current_sign_in_at: 35.days.ago, warning_date: 10.days.ago) }
let!(:user) { create(:user, organization:) }

it "enqueues job in queue 'cleaner'" do
Expand All @@ -32,8 +32,8 @@
end

context "when users have destroyed his/her account" do
let!(:pending_user) { create(:user, :deleted, organization:, last_sign_in_at: 27.days.ago) }
let!(:inactive_user) { create(:user, :deleted, organization:, last_sign_in_at: 35.days.ago, warning_date: 10.days.ago) }
let!(:pending_user) { create(:user, :deleted, organization:, current_sign_in_at: 27.days.ago) }
let!(:inactive_user) { create(:user, :deleted, organization:, current_sign_in_at: 35.days.ago, warning_date: 10.days.ago) }

it "doesn't send email" do
expect(Decidim::Cleaner::InactiveUsersMailer).not_to receive(:warning_inactive).with(pending_user).and_call_original
Expand All @@ -53,7 +53,7 @@
end

context "when user reconnect after warning" do
let!(:inactive_user) { create(:user, organization:, last_sign_in_at: 7.days.ago, warning_date: 10.days.ago) }
let!(:inactive_user) { create(:user, organization:, current_sign_in_at: 7.days.ago, warning_date: 10.days.ago) }

it "doesn't send email" do
expect(Decidim::Cleaner::InactiveUsersMailer).not_to receive(:warning_deletion).with(inactive_user).and_call_original
Expand Down

0 comments on commit 6a396a6

Please sign in to comment.