From 74f40abc65567674448bb5c4dfec4cc835d1a523 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 8 Oct 2020 21:03:54 +0300 Subject: [PATCH] Account: add a dashboard url endpoint. This lets servers share a dashboard url with clients so that they in turn can present clients with a settings dashboard. We currently use it on the main server, but self-hosted servers may also benefit from it for letting users manage some of their settings (e.g. 2FA). --- django_etebase/app_settings.py | 7 +++++++ django_etebase/views.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/django_etebase/app_settings.py b/django_etebase/app_settings.py index 33dc65f..3c580b2 100644 --- a/django_etebase/app_settings.py +++ b/django_etebase/app_settings.py @@ -61,6 +61,13 @@ class AppSettings: return self.import_from_str(func) return None + @cached_property + def DASHBOARD_URL_FUNC(self): # pylint: disable=invalid-name + func = self._setting("DASHBOARD_URL_FUNC", None) + if func is not None: + return self.import_from_str(func) + return None + @cached_property def CHUNK_PATH_FUNC(self): # pylint: disable=invalid-name func = self._setting("CHUNK_PATH_FUNC", None) diff --git a/django_etebase/views.py b/django_etebase/views.py index 6003d4b..d421e43 100644 --- a/django_etebase/views.py +++ b/django_etebase/views.py @@ -783,6 +783,18 @@ class AuthenticationViewSet(viewsets.ViewSet): return Response({}, status=status.HTTP_200_OK) + @action_decorator(detail=False, methods=['POST'], permission_classes=BaseViewSet.permission_classes) + def dashboard_url(self, request, *args, **kwargs): + get_dashboard_url = app_settings.DASHBOARD_URL_FUNC + if get_dashboard_url is None: + raise EtebaseValidationError('not_supported', 'This server doesn\'t have a user dashboard.', + status_code=status.HTTP_400_BAD_REQUEST) + + ret = { + 'url': get_dashboard_url(request, *args, **kwargs), + } + return Response(ret) + class TestAuthenticationViewSet(viewsets.ViewSet): allowed_methods = ['POST']