mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 08:58:30 +01:00
feat: preserve user id on alias deleted (#2304)
This commit is contained in:
parent
7f01dec491
commit
31c8a766be
4 changed files with 40 additions and 2 deletions
|
@ -362,7 +362,9 @@ def delete_alias(
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if not DeletedAlias.get_by(email=alias.email):
|
if not DeletedAlias.get_by(email=alias.email):
|
||||||
deleted_alias = DeletedAlias(email=alias.email, reason=reason)
|
deleted_alias = DeletedAlias(
|
||||||
|
email=alias.email, reason=reason, user_id=user.id
|
||||||
|
)
|
||||||
Session.add(deleted_alias)
|
Session.add(deleted_alias)
|
||||||
Session.commit()
|
Session.commit()
|
||||||
LOG.i(f"Moving {alias} to global trash {deleted_alias}")
|
LOG.i(f"Moving {alias} to global trash {deleted_alias}")
|
||||||
|
|
|
@ -2306,6 +2306,12 @@ class DeletedAlias(Base, ModelMixin):
|
||||||
server_default=str(AliasDeleteReason.Unspecified.value),
|
server_default=str(AliasDeleteReason.Unspecified.value),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
user_id = sa.Column(sa.Integer, nullable=True, default=None, server_default=None)
|
||||||
|
|
||||||
|
__table_args__ = (
|
||||||
|
sa.Index("ix_deleted_alias_user_id_created_at", "user_id", "created_at"),
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, **kw):
|
def create(cls, **kw):
|
||||||
raise Exception("should use delete_alias(alias,user) instead")
|
raise Exception("should use delete_alias(alias,user) instead")
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
"""Preserve user id on alias delete
|
||||||
|
|
||||||
|
Revision ID: 4882cc49dde9
|
||||||
|
Revises: 32f25cbf12f6
|
||||||
|
Create Date: 2024-11-06 10:10:40.235991
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '4882cc49dde9'
|
||||||
|
down_revision = '32f25cbf12f6'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('deleted_alias', sa.Column('user_id', sa.Integer(), server_default=None, nullable=True))
|
||||||
|
with op.get_context().autocommit_block():
|
||||||
|
op.create_index('ix_deleted_alias_user_id_created_at', 'deleted_alias', ['user_id', 'created_at'], unique=False, postgresql_concurrently=True)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
with op.get_context().autocommit_block():
|
||||||
|
op.drop_index('ix_deleted_alias_user_id_created_at', table_name='deleted_alias')
|
||||||
|
op.drop_column('deleted_alias', 'user_id')
|
|
@ -31,7 +31,9 @@ def test_delete_alias(flask_client):
|
||||||
|
|
||||||
delete_alias(alias, user)
|
delete_alias(alias, user)
|
||||||
assert Alias.get_by(email=alias.email) is None
|
assert Alias.get_by(email=alias.email) is None
|
||||||
assert DeletedAlias.get_by(email=alias.email)
|
deleted_alias = DeletedAlias.get_by(email=alias.email)
|
||||||
|
assert deleted_alias is not None
|
||||||
|
assert deleted_alias.user_id == user.id
|
||||||
|
|
||||||
|
|
||||||
def test_delete_alias_already_in_trash(flask_client):
|
def test_delete_alias_already_in_trash(flask_client):
|
||||||
|
|
Loading…
Reference in a new issue