diff --git a/apps/permission/scopes.py b/apps/permission/scopes.py index 0702aefa..b1fbad78 100644 --- a/apps/permission/scopes.py +++ b/apps/permission/scopes.py @@ -18,7 +18,18 @@ class PermissionScopes(BaseScopes): and can be useful to make queries through the API with limited privileges. """ - def get_all_scopes(self): + def get_all_scopes(self, **kwargs): + scopes = {} + if 'scopes' in kwargs: + for scope in kwargs['scopes']: + if scope == 'openid' : + scopes['openid'] = "OpenID Connect" + else: + p = Permission.objects.get(id=scope.split('_')[0]) + club = Club.objects.get(id=scope.split('_')[1]) + scopes[scope] = f"{p.description} (club {club.name})" + return scopes + scopes = {f"{p.id}_{club.id}": f"{p.description} (club {club.name})" for p in Permission.objects.all() for club in Club.objects.all()} scopes['openid'] = "OpenID Connect" diff --git a/apps/permission/views.py b/apps/permission/views.py index 39e1f98c..469cdf99 100644 --- a/apps/permission/views.py +++ b/apps/permission/views.py @@ -163,15 +163,25 @@ class ScopesView(LoginRequiredMixin, TemplateView): from oauth2_provider.models import Application from .scopes import PermissionScopes - - scopes = PermissionScopes() + + oidc = False context["scopes"] = {} - all_scopes = scopes.get_all_scopes() for app in Application.objects.filter(user=self.request.user).all(): - available_scopes = scopes.get_available_scopes(app) + available_scopes = PermissionScopes().get_available_scopes(app) context["scopes"][app] = OrderedDict() - items = [(k, v) for (k, v) in all_scopes.items() if k in available_scopes] - # items.sort(key=lambda x: (int(x[0].split("_")[1]), int(x[0].split("_")[0]))) + all_scopes = PermissionScopes().get_all_scopes(scopes=available_scopes) + scopes = {} + for scope in available_scopes: + scopes[scope] = all_scopes[scope] + # remove OIDC scope for sort + if 'openid' in scopes: + del scopes['openid'] + oidc = True + items = [(k, v) for (k, v) in scopes.items()] + items.sort(key=lambda x: (int(x[0].split("_")[1]), int(x[0].split("_")[0]))) + # add oidc if necessary + if oidc: + items.append(('openid', PermissionScopes().get_all_scopes(scopes=['openid'])['openid'])) for k, v in items: context["scopes"][app][k] = v diff --git a/entrypoint.sh b/entrypoint.sh index e09832f9..7f19eb59 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,10 +11,6 @@ else sed -i -e "s/REPLACEME/La Note Kfet \\\\ud83c\\\\udf7b/g" /var/www/note_kfet/note_kfet/fixtures/cas.json fi -# fix lag issues with django-oauth-toolkit (cf https://gitlab.crans.org/bde/nk20/issues/134 ) -sed -i -e "s/all_scopes =/# all_scopes =/g" /var/www/note_kfet/env/lib/python3.11/site-packages/oauth2_provider/views/base.py -sed -i -e 's/kwargs\["scopes_descriptions"\] =/# kwargs\["scopes_descriptions"\] =/g' /var/www/note_kfet/env/lib/python3.11/site-packages/oauth2_provider/views/base.py - # Set up Django project python3 manage.py collectstatic --noinput python3 manage.py compilemessages