Skip to content

Commit f7a3212

Browse files
committed
store date when account is last seen
This date will be used to drop personal user data if the account is inactive for a certain period. The automatic personal user data clean up has been announced here: https://linuxfr.org/news/regles-de-perennite-des-comptes-linuxfr-org-et-donnees-a-caractere-personnel This commit only add a column on Account and do not add scheduled jobs to apply deletion. To avoid to update database too often and to avoid to keep too accurate user personal information, only the date will be saved on database. Suivi request to add this information into database: https://linuxfr.org/suivi/pouvoir-determiner-si-un-compte-a-eu-de-l-activite-recemment
1 parent 75fe527 commit f7a3212

File tree

5 files changed

+579
-2
lines changed

5 files changed

+579
-2
lines changed

app/controllers/application_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
55
protect_from_forgery with: :reset_session, prepend: true
66
before_action :seo_filter
77
before_action :configure_permitted_parameters, if: :devise_controller?
8+
before_action :set_account_last_seen, if: :account_signed_in?
89
helper_method :url_for_content, :path_for_content, :current_user, :current_stylesheet
910
rescue_from Canable::Transgression, with: :error_403
1011

@@ -44,6 +45,15 @@ def seo_filter
4445
@dont_index = params.has_key?(:order) || (request.headers["User-Agent"] =~ /AppEngine-Google/i)
4546
end
4647

48+
def set_account_last_seen
49+
# Update last seen only once a day to avoid too many database update
50+
if Date.today - current_account.last_seen_on >= 1
51+
# Use update_columns to ensure updated_at value is not changed with this
52+
# automatic update
53+
current_account.update_columns(last_seen_on: Date.today);
54+
end
55+
end
56+
4757
def dont_index?
4858
!!@dont_index
4959
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class AddLastSeenOnToAccounts < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :accounts, :last_seen_on, :date
4+
5+
reversible do |set_last_seen_on|
6+
set_last_seen_on.up do
7+
# Set default value only for confirmed accounts
8+
execute <<-SQL
9+
UPDATE accounts
10+
SET last_seen_on =
11+
CASE
12+
WHEN confirmed_at is NULL
13+
THEN NULL
14+
WHEN login in ("Anonyme", "Collectif")
15+
THEN NULL
16+
ELSE
17+
CURRENT_DATE()
18+
END
19+
SQL
20+
end
21+
set_last_seen_on.down do
22+
# Column will be dropped nothing to do
23+
end
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)