-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add patron resettable uuid. * Add api call to reset patron activity history * Pass patron to analytics event collection when possible.
- Loading branch information
1 parent
91609a2
commit 2e8316b
Showing
16 changed files
with
271 additions
and
67 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
alembic/versions/20241030_272da5f400de_add_uuid_to_patron_table.py
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,49 @@ | ||
"""Add UUID to patron table | ||
Revision ID: 272da5f400de | ||
Revises: 3faa5bba3ddf | ||
Create Date: 2024-10-30 17:41:28.151677+00:00 | ||
""" | ||
|
||
import uuid | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects.postgresql import UUID | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "272da5f400de" | ||
down_revision = "3faa5bba3ddf" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column( | ||
"patrons", | ||
sa.Column("uuid", UUID(as_uuid=True), nullable=True, default=uuid.uuid4), | ||
) | ||
|
||
conn = op.get_bind() | ||
rows = conn.execute("SELECT id from patrons").all() | ||
|
||
for row in rows: | ||
uid = str(uuid.uuid4()) | ||
conn.execute( | ||
"UPDATE patrons SET uuid = ? WHERE id = ?", | ||
( | ||
uid, | ||
row.id, | ||
), | ||
) | ||
|
||
op.alter_column( | ||
table_name="patrons", | ||
column_name="uuid", | ||
nullable=False, | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("patrons", "uuid") |
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
18 changes: 18 additions & 0 deletions
18
src/palace/manager/api/controller/patron_activity_history.py
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,18 @@ | ||
from __future__ import annotations | ||
|
||
import uuid | ||
|
||
import flask | ||
from flask import Response | ||
|
||
from palace.manager.sqlalchemy.model.patron import Patron | ||
|
||
|
||
class PatronActivityHistoryController: | ||
|
||
def reset_statistics_uuid(self) -> Response: | ||
"""Resets the patron's the statistics UUID that links the patron to past activity thus effectively erasing the | ||
link between activity history and patron.""" | ||
patron: Patron = flask.request.patron # type: ignore [attr-defined] | ||
patron.uuid = uuid.uuid4() | ||
return Response("UUID reset", 200) |
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
Oops, something went wrong.