-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): warn users and delete user accounts after period of in…
…activity (#2088) * feat(migrations): add last_active_at column to users table * feat(auth): update user authentication to track last active timestamp * feat(migrations): remove NOT NULL constraint from author_id in projects and update revert migration * feat(users): implement process for identifying and handling inactive users * Revert "feat(auth): update user authentication to track last active timestamp" This reverts commit 6441f36. * feat(users): update user retrieval to include last active timestamp tracking * feat(users): rename last_active_at to last_login_at for clarity * feat(auth): update user creation to set last_login_at on conflict * refactor(migration): rename file names from last active at to last login at * feat(migrations): add last_login_at column to users and remove null constraint from project author * revert: dbuser one method to not update last login at * refactor(user): uncomment super admin check for inactive user deletion --------- Signed-off-by: Anuj Gupta <84966248+Anuj-Gupta4@users.noreply.github.com>
- Loading branch information
1 parent
0b03b65
commit bb2fa96
Showing
7 changed files
with
196 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- ## Migration add some extra fields. | ||
-- * Add last_login_at to users. | ||
-- * Remove NOT NULL constraint from author_id in projects. | ||
|
||
-- Related issues: | ||
-- https://github.com/hotosm/fmtm/issues/1999 | ||
|
||
-- Start a transaction | ||
|
||
BEGIN; | ||
|
||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.columns | ||
WHERE table_name = 'users' | ||
AND column_name = 'last_login_at' | ||
) THEN | ||
ALTER TABLE users ADD COLUMN last_login_at TIMESTAMPTZ DEFAULT now(); | ||
END IF; | ||
END $$; | ||
|
||
DO $$ | ||
BEGIN | ||
IF EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.columns | ||
WHERE table_name = 'projects' | ||
AND column_name = 'author_id' | ||
AND is_nullable = 'NO' | ||
) THEN | ||
ALTER TABLE projects ALTER COLUMN author_id DROP NOT NULL; | ||
END IF; | ||
END $$; | ||
|
||
-- Commit the transaction | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/backend/migrations/revert/005-add-user-lastloginat.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- * Remove last_login_at from users. | ||
-- * Restore NOT NULL constraint on author_id in projects. | ||
|
||
-- Start a transaction | ||
BEGIN; | ||
|
||
-- Remove last_login_at column from users | ||
DO $$ | ||
BEGIN | ||
IF EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.columns | ||
WHERE table_name = 'users' | ||
AND column_name = 'last_login_at' | ||
) THEN | ||
ALTER TABLE users DROP COLUMN last_login_at; | ||
END IF; | ||
END $$; | ||
|
||
-- Restore NOT NULL constraint on author_id in projects | ||
DO $$ | ||
BEGIN | ||
IF EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.columns | ||
WHERE table_name = 'projects' | ||
AND column_name = 'author_id' | ||
AND is_nullable = 'YES' | ||
) THEN | ||
ALTER TABLE projects ALTER COLUMN author_id SET NOT NULL; | ||
END IF; | ||
END $$; | ||
|
||
-- Commit the transaction | ||
COMMIT; |