diff --git a/aleksis/apps/resint/apps.py b/aleksis/apps/resint/apps.py index 2e8c76c821b98df70c383c57ba959598711330cc..cc51922c72bba0981accaac656535ed067adc4c0 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 e7acd0439c22f8a53798bddf7f0f6ed8964af274..abf4b54c5eea893c07ba4963dd09f8b3230c3fe5 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)