From 99d73405fb404e47ff140a31a1373dea7258df07 Mon Sep 17 00:00:00 2001 From: sahama Date: Sat, 3 Aug 2024 18:08:41 +0330 Subject: [PATCH] application detail view --- apps/gooyal_oauth2/forms.py | 5 ++--- apps/gooyal_oauth2/models.py | 8 ++++---- apps/gooyal_oauth2/scopes.py | 2 +- apps/gooyal_oauth2/views/pages.py | 9 +++------ templates/gooyal_oauth2/application_detail.html | 10 ++++++++++ 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/apps/gooyal_oauth2/forms.py b/apps/gooyal_oauth2/forms.py index 001e1bf..63ad581 100644 --- a/apps/gooyal_oauth2/forms.py +++ b/apps/gooyal_oauth2/forms.py @@ -69,11 +69,10 @@ class ApplicationCreateForm(forms.ModelForm): class ApplicationUpdateForm(forms.ModelForm): class Meta: model = Application - fields = ['name', - 'client_id', + fields = ['client_id', 'client_secret', # 'authorization_grant_type', 'redirect_uris', 'post_logout_redirect_uris'] - readonly_fields = ['client_id', 'client_secret'] + readonly_fields = ['name', 'client_id', 'client_secret'] diff --git a/apps/gooyal_oauth2/models.py b/apps/gooyal_oauth2/models.py index f149251..deed4a4 100644 --- a/apps/gooyal_oauth2/models.py +++ b/apps/gooyal_oauth2/models.py @@ -76,13 +76,13 @@ class Scope(models.Model): uuid = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4, unique=True, db_index=True) application = models.ForeignKey( oauth2_settings.APPLICATION_MODEL, - models.PROTECT, + models.CASCADE, # This field is nullable because it is only set for scopes created by # external resource servers, which have a corresponding OAuth application # record on the authorisation server blank=True, null=True, help_text='The application to which the scope belongs.', - related_name='available_scopes' + related_name='scopes' ) resource = models.ForeignKey( Resource, @@ -150,9 +150,9 @@ class Scope(models.Model): }, headers={"Authorization": token} ) - #  Raise the exception for anything other than 20x responses + # Raise the exception for anything other than 20x responses response.raise_for_status() - #  Always create/update the scope record locally + # Always create/update the scope record locally _ = Scope.objects.update_or_create( name=name, defaults={'description': description, 'is_default': is_default} diff --git a/apps/gooyal_oauth2/scopes.py b/apps/gooyal_oauth2/scopes.py index d7387b9..64d979f 100644 --- a/apps/gooyal_oauth2/scopes.py +++ b/apps/gooyal_oauth2/scopes.py @@ -9,7 +9,7 @@ from oauth2_provider.scopes import BaseScopes from .models import Scope - +# TODO: use redis for it class Scopes(BaseScopes): """ Scopes backend that provides scopes from a Django model. diff --git a/apps/gooyal_oauth2/views/pages.py b/apps/gooyal_oauth2/views/pages.py index 4ad080b..161ff11 100644 --- a/apps/gooyal_oauth2/views/pages.py +++ b/apps/gooyal_oauth2/views/pages.py @@ -4,7 +4,7 @@ from django.utils.decorators import method_decorator from django.views.generic import CreateView, DetailView, ListView, UpdateView from oauth2_provider.models import get_application_model -from apps.gooyal_oauth2.forms import ApplicationCreateForm +from apps.gooyal_oauth2.forms import ApplicationCreateForm, ApplicationUpdateForm from apps.gooyal_oauth2.models import Application @@ -19,14 +19,13 @@ class ApplicationCreateView(CreateView): def form_valid(self, form): form.instance.user = self.request.user form.instance.client_type = Application.CLIENT_PUBLIC - # form.instance.client_type = Application.CLIENT_PUBLIC return super().form_valid(form) @method_decorator(login_required, name='dispatch') class ApplicationUpdateView(UpdateView): template_name = "gooyal_oauth2/application_create.html" - form_class = ApplicationCreateForm + form_class = ApplicationUpdateForm def get_queryset(self): return Application.objects.filter(user=self.request.user) @@ -43,8 +42,7 @@ class ApplicationUpdateView(UpdateView): @method_decorator(login_required, name='dispatch') class ApplicationDetailView(DetailView): model = Application - template_name = "gooyal_oauth2/application_create.html" - + template_name = "gooyal_oauth2/application_detail.html" def get_queryset(self): return Application.objects.filter(user=self.request.user) @@ -56,6 +54,5 @@ class ApplicationListView(ListView): template_name = "gooyal_oauth2/application_list.html" paginate_by = 20 - def get_queryset(self): return Application.objects.filter(user=self.request.user) diff --git a/templates/gooyal_oauth2/application_detail.html b/templates/gooyal_oauth2/application_detail.html index 57d6d15..8f97c1f 100644 --- a/templates/gooyal_oauth2/application_detail.html +++ b/templates/gooyal_oauth2/application_detail.html @@ -9,4 +9,14 @@ {% block content %}

application: {{ object.name }}!

client id: {{ object.client_id }}!

+

allowed_scopes:

+ {% for scope in object.allowed_scopes %} +
{{ scope }}
+ {% endfor %} +

own_scopes:

+ {% for scope in object.scopes.all %} +
{{ scope }}
+ {% endfor %} + + {% endblock %}