Skip to content

Commit

Permalink
Use redis role cache when validating access to form resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Jul 28, 2024
1 parent dd28ea2 commit df05afa
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions backend/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,14 @@ async def _verify_access_helper(
return

form = models.Form(**form)
role_id_lookup = {role.id: role for role in await get_roles()}

for role_id in getattr(form, attribute, None) or []:
role = await request.state.db.roles.find_one({"id": role_id})
if not role:
continue

role = models.DiscordRole(**json.loads(role["data"]))
for role_name_or_id in getattr(form, attribute, None) or []:
if role_name_or_id in request.auth.scopes:
return

if role.name in request.auth.scopes:
role = role_id_lookup.get(role_name_or_id)
if role and role.name in request.auth.scopes:
return

raise UnauthorizedError(status_code=401)
Expand Down

0 comments on commit df05afa

Please sign in to comment.