1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-11-08 15:59:50 +01:00

Add test for oauth2 flow, add temporary ROPB for NoteApp #137

This commit is contained in:
quark
2025-11-07 10:31:59 +01:00
parent d2cc1b902d
commit 68341a2a7e
4 changed files with 160 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ from .models import Permission
from django.utils.translation import gettext_lazy as _
class PermissionScopes(BaseScopes):
"""
An OAuth2 scope is defined by a permission object and a club.
@@ -83,8 +84,12 @@ class PermissionOAuth2Validator(OAuth2Validator):
valid_scopes = set()
# simple patch for have functionnal ROPB flow
# TODO rewrite
r = get_current_request()
r.user = request.user
for t in Permission.PERMISSION_TYPES:
for p in PermissionBackend.get_raw_permissions(get_current_request(), t[0]):
for p in PermissionBackend.get_raw_permissions(r, t[0]):
scope = f"{p.id}_{p.membership.club.id}"
if scope in scopes:
valid_scopes.add(scope)