Skip to content

Commit

Permalink
Simplify User object check by updating tokens instead of resolved values
Browse files Browse the repository at this point in the history
  • Loading branch information
bctiemann committed Aug 26, 2024
1 parent 8f5162e commit 5e6aab3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions netbox/utilities/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ def qs_filter_from_constraints(constraints, tokens=None):
if tokens is None:
tokens = {}

User = apps.get_model('users.User')
for token, value in tokens.items():
if token == CONSTRAINT_TOKEN_USER and isinstance(value, User):
tokens[token] = value.id

def _replace_tokens(value, tokens):
if type(value) is list:
return list(map(lambda v: tokens.get(v, v), value))
User = apps.get_model('users.User')
if value == CONSTRAINT_TOKEN_USER and isinstance(tokens.get(CONSTRAINT_TOKEN_USER), User):
return tokens[CONSTRAINT_TOKEN_USER].id
return tokens.get(value, value)

params = Q()
Expand Down

0 comments on commit 5e6aab3

Please sign in to comment.