Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat: helper function checks if user is staff or superuser #2653

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

lalver1
Copy link
Member

@lalver1 lalver1 commented Jan 30, 2025

Part of #2201

Following our approach to breaking up Refactor: Admin permissions for Cal-ITP Staff into smaller PRs, this PR adds the is_staff_or_superuser helper function to check if user is staff or superuser and adds more tests for the helper functions in benefits/core/admin/users.py.

@lalver1 lalver1 self-assigned this Jan 30, 2025
@github-actions github-actions bot added tests Related to automated testing (unit, UI, integration, etc.) back-end Django views, sessions, middleware, models, migrations etc. deployment-dev [auto] Changes that will trigger a deploy if merged to dev labels Jan 30, 2025
Copy link

github-actions bot commented Jan 30, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/core/admin
  enrollment.py
  users.py
Project Total  

This report was generated by python-coverage-comment-action

@lalver1 lalver1 marked this pull request as ready for review January 30, 2025 20:43
@lalver1 lalver1 requested a review from a team as a code owner January 30, 2025 20:43
thekaveman
thekaveman previously approved these changes Jan 30, 2025
Copy link
Member

@thekaveman thekaveman left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@angela-tran angela-tran left a comment

Choose a reason for hiding this comment

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

I just have a minor naming request, sorry

@@ -54,6 +54,10 @@ def is_staff_member(user):
return staff_group.user_set.contains(user)


def is_staff_or_superuser(user):
Copy link
Member

Choose a reason for hiding this comment

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

I suggest we name this is_staff_member_or_superuser so we don't start getting confused between Django's is_staff vs. our concept of being "staff" -- the former simply means the user can log in to the admin, and the latter means that the user is in the "Cal-ITP" group.

I know it makes the name a little longer, but this distinction is important.

Copy link
Member

Choose a reason for hiding this comment

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

I totally agree with @angela-tran, good catch!

Copy link
Member

Choose a reason for hiding this comment

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

This method would be a great place to have some comments to explain the concept @angela-tran pointed out above. Could be full-on docstrings format or just comments https://realpython.com/documenting-python-code/#docstring-types

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes complete sense! Renamed it in 548ac86 as a new commit to make it easier to review the change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion @machikoyasuda! Added some docstrings in 3eb9599

is_staff_member_or_superuser for added clarity between Django's
staff (users that can log in to the admin) and Benefits' staff
(users that are in the Cal-ITP group).
between Django's 'staff' and Benefits' 'staff' group
angela-tran
angela-tran previously approved these changes Jan 30, 2025
Copy link
Member

@angela-tran angela-tran left a comment

Choose a reason for hiding this comment

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

Thanks for the docstrings!

@lalver1 lalver1 merged commit 6862a89 into main Jan 30, 2025
14 checks passed
@lalver1 lalver1 deleted the feat/users-helper-functions branch January 30, 2025 22:13
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
back-end Django views, sessions, middleware, models, migrations etc. deployment-dev [auto] Changes that will trigger a deploy if merged to dev tests Related to automated testing (unit, UI, integration, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants