Skip to content

Refactor all has_access usages to use list argument instead of multiple or calls #89

@bduke-dev

Description

@bduke-dev

Update all usages of the has_access function to use a single call with a list for sec_permission instead of two separate calls joined by an or statement. For example, refactor:

has_access(request.user.id, auth_obj) or has_access(request.user.id, "scoutadmin")

to:

has_access(request.user.id, [auth_obj, "scoutadmin"])

The has_access function has already been modified to accept a list or single parameter for sec_permission. Only update the usages throughout the codebase on the update-has-access branch that currently use multiple calls joined by or.

Relevant Code References

Below are code snippets showing current usages of has_access. Refactor any instances where two calls are joined by or (these are likely found in your codebase, including these files):

Example Function Implementation

general/security.py

# ...
def has_access(user_id, sec_permission):
    # ...

Usage Examples

See these files for likely locations containing patterns such as:

has_access(request.user.id, X) or has_access(request.user.id, Y)

Replace with:

has_access(request.user.id, [X, Y])
  • Search and refactor all such instances in the codebase.
  • Ensure that the updated code is functionally identical to the old logic, just consolidated into a single call.
  • Test all changes to confirm no regressions in access control logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions