application detail view
This commit is contained in:
parent
19d5742563
commit
99d73405fb
5 changed files with 20 additions and 14 deletions
|
|
@ -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']
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -9,4 +9,14 @@
|
|||
{% block content %}
|
||||
<p>application: {{ object.name }}!</p>
|
||||
<p>client id: {{ object.client_id }}!</p>
|
||||
<p>allowed_scopes:</p>
|
||||
{% for scope in object.allowed_scopes %}
|
||||
<div>{{ scope }}</div>
|
||||
{% endfor %}
|
||||
<p>own_scopes:</p>
|
||||
{% for scope in object.scopes.all %}
|
||||
<div>{{ scope }}</div>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue