Skip to content
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

Finish audit fields for users table #1129

Merged
merged 49 commits into from
Oct 24, 2024
Merged

Conversation

michplunkett
Copy link
Collaborator

@michplunkett michplunkett commented Oct 9, 2024

Fixes issue

#1004

Description of Changes

Added disabled_by, disabled_at, approved_at, approved_by, and confirmed_at, and confirmed_by fields to the users table so that we could keep track of users actions on the platform at a more granular level. I also removed the previously mentioned columns corresponding boolean columns.

Tests and Linting

  • This branch is up-to-date with the develop branch.
  • pytest passes on my local development environment.
  • pre-commit passes on my local development environment.
  • The flask db upgrade and flask db downgrade functions work for both migrations.
I have no name!@c38d30934aa7:/usr/src/app$ %
(env) michaelp@MacBook-Air-18 OpenOversight % docker exec -it openoversight-web-1 bash
I have no name!@5027495d31c0:/usr/src/app$ flask db downgrade
...
INFO  [alembic.runtime.migration] Running downgrade 99c50fc8d294 -> bf254c0961ca, complete audit field addition to users
I have no name!@5027495d31c0:/usr/src/app$ flask db downgrade
...
INFO  [alembic.runtime.migration] Running downgrade bf254c0961ca -> 5865f488470c, add remaining audit fields for users table
I have no name!@5027495d31c0:/usr/src/app$ flask db downgrade
...
INFO  [alembic.runtime.migration] Running downgrade 5865f488470c -> 939ea0f2b26d, change salary column types
I have no name!@5027495d31c0:/usr/src/app$ flask db upgrade
...
INFO  [alembic.runtime.migration] Running upgrade 939ea0f2b26d -> 5865f488470c, change salary column types
INFO  [alembic.runtime.migration] Running upgrade 5865f488470c -> bf254c0961ca, add remaining audit fields for users table
INFO  [alembic.runtime.migration] Running upgrade bf254c0961ca -> 99c50fc8d294, complete audit field addition to users
I have no name!@5027495d31c0:/usr/src/app$

@michplunkett michplunkett self-assigned this Oct 9, 2024
@michplunkett michplunkett linked an issue Oct 9, 2024 that may be closed by this pull request
@@ -14,6 +14,7 @@

# Config Key Constants
KEY_ALLOWED_EXTENSIONS = "ALLOWED_EXTENSIONS"
KEY_APPROVE_REGISTRATIONS = "APPROVE_REGISTRATIONS"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this as a constant because it was being used throughout the tests.

@michplunkett michplunkett marked this pull request as ready for review October 11, 2024 22:08
@michplunkett michplunkett changed the title Finish adding audit fields to users table Finish audit fields for users table Oct 11, 2024
Comment on lines -163 to +166
assert not user.is_disabled
assert user.disabled_at is None
assert user.disabled_by is None
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the same statements, but they feel more intuitive written like this. I'd be happy to switch them back tho.

Comment on lines -184 to +188
_, user = login_admin(client)
_, current_user = login_admin(client)
Copy link
Collaborator Author

@michplunkett michplunkett Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the user variable is referencing feels more clear with this change.

session.add(user)

rv, _ = login_modified_disabled_user(client)
assert b"/user/sam" in rv.data

# Disable account again and check that login_required redirects user correctly
user.is_disabled = True
session.add(user)
user.disable_user(User.query.filter_by(is_administrator=True).first().id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we doing is_admin here?

Copy link
Collaborator Author

@michplunkett michplunkett Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way the disable_user function is setup, it requires a user.id so that we can see who made the action. In this case, I just pulled the first administrator user I could find and took that ID. I could have also just put 1 as the value as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very helpful and makes perfect sense. Thanks!

@michplunkett michplunkett requested a review from b-meson October 22, 2024 20:32
@michplunkett michplunkett merged commit 0097663 into develop Oct 24, 2024
3 checks passed
@michplunkett michplunkett deleted the finish-audit-fields-users branch October 24, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Complete auditing columns for users table
2 participants