mirror of https://gitlab.com/tildes/tildes.git
Browse Source
Add ability to (manually) delete user accounts
Add ability to (manually) delete user accounts
Until now, if people want their account deleted, I've just been banning it. This will let me do it properly, but some additional cleanup should be added in the future once I think through what's safe to get rid of from deleted accounts.merge-requests/53/head
Deimos
6 years ago
7 changed files with 159 additions and 53 deletions
-
54tildes/alembic/versions/a0e0b6206146_users_add_is_deleted_deleted_time.py
-
17tildes/sql/init/triggers/users/users.sql
-
19tildes/tests/test_user.py
-
5tildes/tildes/auth.py
-
14tildes/tildes/models/user/user.py
-
2tildes/tildes/resources/user.py
-
19tildes/tildes/templates/user.jinja2
@ -0,0 +1,54 @@ |
|||||
|
"""Users: Add is_deleted/deleted_time |
||||
|
|
||||
|
Revision ID: a0e0b6206146 |
||||
|
Revises: 53567981cdf4 |
||||
|
Create Date: 2018-11-13 23:49:20.764289 |
||||
|
|
||||
|
""" |
||||
|
from alembic import op |
||||
|
import sqlalchemy as sa |
||||
|
|
||||
|
|
||||
|
# revision identifiers, used by Alembic. |
||||
|
revision = "a0e0b6206146" |
||||
|
down_revision = "53567981cdf4" |
||||
|
branch_labels = None |
||||
|
depends_on = None |
||||
|
|
||||
|
|
||||
|
def upgrade(): |
||||
|
op.add_column( |
||||
|
"users", sa.Column("deleted_time", sa.TIMESTAMP(timezone=True), nullable=True) |
||||
|
) |
||||
|
op.add_column( |
||||
|
"users", |
||||
|
sa.Column("is_deleted", sa.Boolean(), server_default="false", nullable=False), |
||||
|
) |
||||
|
op.create_index(op.f("ix_users_is_deleted"), "users", ["is_deleted"], unique=False) |
||||
|
|
||||
|
op.execute( |
||||
|
""" |
||||
|
CREATE OR REPLACE FUNCTION set_user_deleted_time() RETURNS TRIGGER AS $$ |
||||
|
BEGIN |
||||
|
NEW.deleted_time := current_timestamp; |
||||
|
|
||||
|
RETURN NEW; |
||||
|
END; |
||||
|
$$ LANGUAGE plpgsql; |
||||
|
|
||||
|
CREATE TRIGGER delete_user_set_deleted_time_update |
||||
|
BEFORE UPDATE ON users |
||||
|
FOR EACH ROW |
||||
|
WHEN (OLD.is_deleted = false AND NEW.is_deleted = true) |
||||
|
EXECUTE PROCEDURE set_user_deleted_time(); |
||||
|
""" |
||||
|
) |
||||
|
|
||||
|
|
||||
|
def downgrade(): |
||||
|
op.execute("DROP TRIGGER delete_user_set_deleted_time_update ON users") |
||||
|
op.execute("DROP FUNCTION set_user_deleted_time") |
||||
|
|
||||
|
op.drop_index(op.f("ix_users_is_deleted"), table_name="users") |
||||
|
op.drop_column("users", "is_deleted") |
||||
|
op.drop_column("users", "deleted_time") |
@ -0,0 +1,17 @@ |
|||||
|
-- Copyright (c) 2018 Tildes contributors <code@tildes.net> |
||||
|
-- SPDX-License-Identifier: AGPL-3.0-or-later |
||||
|
|
||||
|
-- set user.deleted_time when it's deleted |
||||
|
CREATE OR REPLACE FUNCTION set_user_deleted_time() RETURNS TRIGGER AS $$ |
||||
|
BEGIN |
||||
|
NEW.deleted_time := current_timestamp; |
||||
|
|
||||
|
RETURN NEW; |
||||
|
END; |
||||
|
$$ LANGUAGE plpgsql; |
||||
|
|
||||
|
CREATE TRIGGER delete_user_set_deleted_time_update |
||||
|
BEFORE UPDATE ON users |
||||
|
FOR EACH ROW |
||||
|
WHEN (OLD.is_deleted = false AND NEW.is_deleted = true) |
||||
|
EXECUTE PROCEDURE set_user_deleted_time(); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue