-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add User Status Log #372
base: main
Are you sure you want to change the base?
Add User Status Log #372
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,40 @@ def __repr__(self): | |
return f"<Role({self.id}, {self.name!r})>" | ||
|
||
|
||
class UserStatusLog(AmbudaUserMixin, Base): | ||
"""Tracks changes to user statuses.""" | ||
|
||
__tablename__ = "user_status_log" | ||
|
||
#: Primary key. | ||
id = pk() | ||
|
||
#: The user whose status was changed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. state changes should also indicate the user who made the change (or perhaps |
||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False) | ||
|
||
#: Timestamp at which this status change occured. | ||
timestamp = Column(DateTime, default=datetime.utcnow, nullable=False) | ||
|
||
#: Describes the status change that occurred. | ||
change_description = Column(String, nullable=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#: When should this status change expire/revert, defaults to never. | ||
expiry = Column(DateTime, default=None, nullable=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the semantics here are all in |
||
|
||
@property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's wait on these until we know how to use them |
||
def is_expired(self) -> bool: | ||
"""Check if the action has expired.""" | ||
return self.expiry and self.expiry < datetime.utcnow() | ||
|
||
@property | ||
def is_temporary(self) -> bool: | ||
""" | ||
Check if the action has an expiry and will be reverted | ||
in the future. | ||
""" | ||
return self.expiry | ||
|
||
|
||
class UserRoles(Base): | ||
|
||
"""Secondary table for users and roles.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Create user status log table | ||
|
||
Revision ID: e4c982111325 | ||
Revises: 99379162619e | ||
Create Date: 2022-09-24 19:04:16.240264 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy import orm | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'e4c982111325' | ||
down_revision = '99379162619e' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"user_status_log", | ||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=False), | ||
sa.Column("timestamp", sa.DateTime(), nullable=False), | ||
sa.Column("change_description", sa.String(), nullable=False), | ||
sa.Column("expiry", sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("user_status_log") | ||
# ### end Alembic commands ### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
UserMixin
here as this is not a user