Skip to content

Commit df05afa

Browse files
committed
Use redis role cache when validating access to form resources
1 parent dd28ea2 commit df05afa

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Diff for: backend/discord.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,14 @@ async def _verify_access_helper(
151151
return
152152

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

155-
for role_id in getattr(form, attribute, None) or []:
156-
role = await request.state.db.roles.find_one({"id": role_id})
157-
if not role:
158-
continue
159-
160-
role = models.DiscordRole(**json.loads(role["data"]))
156+
for role_name_or_id in getattr(form, attribute, None) or []:
157+
if role_name_or_id in request.auth.scopes:
158+
return
161159

162-
if role.name in request.auth.scopes:
160+
role = role_id_lookup.get(role_name_or_id)
161+
if role and role.name in request.auth.scopes:
163162
return
164163

165164
raise UnauthorizedError(status_code=401)

0 commit comments

Comments
 (0)