From 1fd13f936062b180fb5a3a2b665412ed2dd08ed4 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Thu, 4 Nov 2021 22:05:15 +0100 Subject: [PATCH] Add OAuth2 scopes to app config (cherry picked from commit 1d3401aaec559a9ea85fcd2acb0714f6a611a26f) --- aleksis/apps/resint/apps.py | 14 ++++++++++++++ aleksis/apps/resint/models.py | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/aleksis/apps/resint/apps.py b/aleksis/apps/resint/apps.py index 2e8c76c..cc51922 100644 --- a/aleksis/apps/resint/apps.py +++ b/aleksis/apps/resint/apps.py @@ -1,3 +1,6 @@ +from django.apps import apps +from django.utils.translation import gettext as _ + from aleksis.core.util.apps import AppConfig @@ -14,3 +17,14 @@ class ResintConfig(AppConfig): ([2020, 2021], "Frank Poetzsch-Heffter", "p-h@katharineum.de"), ([2019], "Julian Leucker", "leuckeju@katharineum.de"), ) + + @classmethod + def get_all_scopes(cls) -> dict[str, str]: + """Return all OAuth scopes and their descriptions for this app.""" + LiveDocument = apps.get_model("resint", "LiveDocument") + scopes = {} + for live_document in LiveDocument.objects.all(): + scopes[live_document.scope] = _("Access PDF file for live document {}").format( + live_document.name + ) + return scopes diff --git a/aleksis/apps/resint/models.py b/aleksis/apps/resint/models.py index e7acd04..abf4b54 100644 --- a/aleksis/apps/resint/models.py +++ b/aleksis/apps/resint/models.py @@ -193,6 +193,11 @@ class LiveDocument(ExtensiblePolymorphicModel): """Get the filename without path of the PDF file.""" return f"{self.slug}.pdf" + @property + def scope(self) -> str: + """Return OAuth2 scope name to access PDF file via API.""" + return f"live_document_pdf_{self.slug}" + def save(self, *args, **kwargs): with reversion.create_revision(): super().save(*args, **kwargs) -- GitLab