scope registration list
This commit is contained in:
parent
b852161ed6
commit
7cf960852f
11 changed files with 267 additions and 11 deletions
|
|
@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType
|
||||||
from jalali_date.widgets import AdminJalaliDateWidget
|
from jalali_date.widgets import AdminJalaliDateWidget
|
||||||
from jalali_date.fields import JalaliDateField
|
from jalali_date.fields import JalaliDateField
|
||||||
|
|
||||||
from .models import Application
|
from .models import Application, Scope
|
||||||
|
|
||||||
|
|
||||||
class JalaliDateFilter(django_filters.DateFilter):
|
class JalaliDateFilter(django_filters.DateFilter):
|
||||||
|
|
@ -15,6 +15,14 @@ class ApplicationFilter(django_filters.FilterSet):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Application
|
model = Application
|
||||||
fields = {
|
fields = {
|
||||||
'name': ['contains'],
|
'name': ['icontains'],
|
||||||
'client_id': ['contains'],
|
'client_id': ['icontains'],
|
||||||
|
}
|
||||||
|
|
||||||
|
class ScopeFilter(django_filters.FilterSet):
|
||||||
|
class Meta:
|
||||||
|
model = Scope
|
||||||
|
fields = {
|
||||||
|
'name': ['icontains'],
|
||||||
|
'description': ['icontains'],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ Django forms for use with the gooyal-restrict-scopes package.
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from oauth2_provider.scopes import get_scopes_backend
|
from oauth2_provider.scopes import get_scopes_backend
|
||||||
from .models import Application
|
from .models import Application, Scope
|
||||||
|
|
||||||
|
|
||||||
class DelimitedListField(forms.MultipleChoiceField):
|
class DelimitedListField(forms.MultipleChoiceField):
|
||||||
|
|
@ -82,3 +82,12 @@ class ApplicationUpdateForm(forms.ModelForm):
|
||||||
]
|
]
|
||||||
|
|
||||||
readonly_fields = ['name', 'client_id', 'client_secret']
|
readonly_fields = ['name', 'client_id', 'client_secret']
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationScopeCreateForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Scope
|
||||||
|
fields = [
|
||||||
|
'name',
|
||||||
|
'description'
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,15 @@ router = routers.SimpleRouter()
|
||||||
router.register(r'apis/applications', api_views.ApplicationViewSet, basename='application')
|
router.register(r'apis/applications', api_views.ApplicationViewSet, basename='application')
|
||||||
|
|
||||||
management_urlpatterns = [
|
management_urlpatterns = [
|
||||||
# re_path(r"^applications/$", views.ApplicationList.as_view(), name="application_list"),
|
|
||||||
path("applications/", pages.ApplicationListView.as_view(), name="application_list"),
|
path("applications/", pages.ApplicationListView.as_view(), name="application_list"),
|
||||||
path('applications/register/', pages.ApplicationCreateView.as_view(), name='application_create'),
|
path('applications/register/', pages.ApplicationCreateView.as_view(), name='application_create'),
|
||||||
path("applications/<pk>/", pages.ApplicationDetailView.as_view(), name="application_detail"),
|
path("applications/<pk>/", pages.ApplicationDetailView.as_view(), name="application_detail"),
|
||||||
# re_path(r"^applications/(?P<pk>[\w-]+)/delete/$", views.ApplicationDelete.as_view(), name="delete"),
|
|
||||||
path("applications/<pk>/update/", pages.ApplicationUpdateView.as_view(), name="application_update"),
|
path("applications/<pk>/update/", pages.ApplicationUpdateView.as_view(), name="application_update"),
|
||||||
|
path("applications/<application_pk>/scopes/", pages.ApplicationScopeListView.as_view(), name="application_scope_list"),
|
||||||
|
path("applications/<application_pk>/scopes/register/", pages.ApplicationScopeCreateView.as_view(), name="application_scope_create"),
|
||||||
|
path("applications/<application_pk>/scopes/<pk>/", pages.ApplicationScopeDetailView.as_view(), name="application_scope_detail"),
|
||||||
|
path("applications/<application_pk>/scopes/<pk>/update/", pages.ApplicationScopeUpdateView.as_view(), name="application_scope_update"),
|
||||||
|
|
||||||
# Token management views
|
# Token management views
|
||||||
# re_path(r"^authorized_tokens/$", views.AuthorizedTokensListView.as_view(), name="authorized-token-list"),
|
# re_path(r"^authorized_tokens/$", views.AuthorizedTokensListView.as_view(), name="authorized-token-list"),
|
||||||
# re_path(
|
# re_path(
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ from django.utils.decorators import method_decorator
|
||||||
from django.views.generic import CreateView, DetailView, ListView, UpdateView
|
from django.views.generic import CreateView, DetailView, ListView, UpdateView
|
||||||
from oauth2_provider.models import get_application_model
|
from oauth2_provider.models import get_application_model
|
||||||
|
|
||||||
from apps.gooyal_oauth2.filters import ApplicationFilter
|
from apps.gooyal_oauth2.filters import ApplicationFilter, ScopeFilter
|
||||||
from apps.gooyal_oauth2.forms import ApplicationCreateForm, ApplicationUpdateForm
|
from apps.gooyal_oauth2.forms import ApplicationCreateForm, ApplicationUpdateForm, ApplicationScopeCreateForm
|
||||||
from apps.gooyal_oauth2.models import Application
|
from apps.gooyal_oauth2.models import Application, Scope
|
||||||
from utils.views import FilterMixin
|
from utils.views import FilterMixin
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -68,3 +68,88 @@ class ApplicationListView(FilterMixin, ListView):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
qs = super().get_queryset()
|
qs = super().get_queryset()
|
||||||
return qs.filter(user=self.request.user)
|
return qs.filter(user=self.request.user)
|
||||||
|
|
||||||
|
|
||||||
|
class ApplicationScopeMixin:
|
||||||
|
application = None
|
||||||
|
|
||||||
|
def get_application(self):
|
||||||
|
if not self.application:
|
||||||
|
application_pk = self.kwargs['application_pk']
|
||||||
|
application = Application.objects.get(pk=application_pk, user=self.request.user)
|
||||||
|
self.application = application
|
||||||
|
|
||||||
|
return self.application
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
application = self.get_application()
|
||||||
|
|
||||||
|
context_data = super().get_context_data(**kwargs)
|
||||||
|
context_data['application'] = application
|
||||||
|
return context_data
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(login_required, name='dispatch')
|
||||||
|
class ApplicationScopeListView(ApplicationScopeMixin, FilterMixin, ListView):
|
||||||
|
model = Scope
|
||||||
|
template_name = "gooyal_oauth2/application_scope_list.html"
|
||||||
|
paginate_by = settings.PAGE_SIZE
|
||||||
|
filterset_class = ScopeFilter
|
||||||
|
|
||||||
|
def get_ordering(self):
|
||||||
|
ordering = self.request.GET.get('ordering', 'name')
|
||||||
|
return ordering
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = super().get_queryset()
|
||||||
|
application = self.get_application()
|
||||||
|
return qs.filter(application__user=self.request.user, application=application)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(login_required, name='dispatch')
|
||||||
|
class ApplicationScopeCreateView(ApplicationScopeMixin, CreateView):
|
||||||
|
template_name = "gooyal_oauth2/application_scope_create.html"
|
||||||
|
form_class = ApplicationScopeCreateForm
|
||||||
|
model = Scope
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = super().get_queryset()
|
||||||
|
application = self.get_application()
|
||||||
|
return qs.filter(application__user=self.request.user, application=application)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy("gooyal_oauth2:application_scope_detail", kwargs={"pk": self.object.pk, "application_pk": self.get_application().pk})
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.instance.application = self.get_application()
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(login_required, name='dispatch')
|
||||||
|
class ApplicationScopeDetailView(ApplicationScopeMixin, DetailView):
|
||||||
|
model = Scope
|
||||||
|
template_name = "gooyal_oauth2/application_scope_detail.html"
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
application = self.get_application()
|
||||||
|
return Scope.objects.filter(application=application)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(login_required, name='dispatch')
|
||||||
|
class ApplicationScopeUpdateView(ApplicationScopeMixin, UpdateView):
|
||||||
|
template_name = "gooyal_oauth2/application_scope_update.html"
|
||||||
|
form_class = ApplicationScopeCreateForm
|
||||||
|
model = Scope
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = super().get_queryset()
|
||||||
|
application = self.get_application()
|
||||||
|
return qs.filter(application__user=self.request.user, application=application)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy("gooyal_oauth2:application_scope_detail", kwargs={"pk": self.object.pk, "application_pk": self.get_application().pk})
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
# form.instance.user = self.request.user
|
||||||
|
# form.instance.client_type = Application.CLIENT_PUBLIC
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,13 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="me-2">
|
||||||
|
<a href="{% url 'gooyal_oauth2:application_scope_list' object.pk %}">
|
||||||
|
<div class="btn btn-success">
|
||||||
|
<span class="bi bi-list-ul"></span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,14 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th><a href="?{% get_filter_link request 'ordering' 'name' %}" >name{% if request.GET.ordering and 'name' in request.GET.ordering %}<i class="bi bi-arrow-down-short"></i>{% endif %}</a></th>
|
<th><a href="?{% get_filter_link request 'ordering' 'name' %}" >name{% if request.GET.ordering and 'name' in request.GET.ordering %}<i class="bi bi-arrow-down-short"></i>{% endif %}</a></th>
|
||||||
<th><a href="?{% get_filter_link request 'ordering' 'client_id' %}" >client id{% if request.GET.ordering and 'client_id' in request.GET.ordering %}<i class="bi bi-arrow-down-short"></i>{% endif %}</a></th>
|
<th><a href="?{% get_filter_link request 'ordering' 'client_id' %}" >client id{% if request.GET.ordering and 'client_id' in request.GET.ordering %}<i class="bi bi-arrow-down-short"></i>{% endif %}</a></th>
|
||||||
|
<th>type</th>
|
||||||
<th>actions</th>
|
<th>actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for obj in object_list %}
|
{% for obj in object_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ obj.name }}</td>
|
<td>{{ obj.name }}</td>
|
||||||
<td>{{ obj.client_id }}</td>
|
<td>{{ obj.client_id }}</td>
|
||||||
|
<td>{{ obj.allows_grant_type }}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
|
|
|
||||||
24
templates/gooyal_oauth2/application_scope_create.html
Normal file
24
templates/gooyal_oauth2/application_scope_create.html
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% load jalali_tags %}
|
||||||
|
|
||||||
|
{% block title %}Application Scope Register{% endblock %}
|
||||||
|
{% block page_title %}Application Scope Register{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data" novalidate>
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="col-md-12 col-lg-12" id="formset">
|
||||||
|
{{ form|crispy }}
|
||||||
|
</div>
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="grid">
|
||||||
|
<div class="d-flex justify-content-end">
|
||||||
|
<a href="{% url 'gooyal_oauth2:application_scope_list' application.pk %}" class="btn btn-danger ms-2">انصراف</a>
|
||||||
|
<input class="btn btn-success ms-2" type="submit" value="ثبت" name="save"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
33
templates/gooyal_oauth2/application_scope_detail.html
Normal file
33
templates/gooyal_oauth2/application_scope_detail.html
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% load jalali_tags %}
|
||||||
|
|
||||||
|
{% block title %}Application Scope Detail: {{ object.name }}{% endblock %}
|
||||||
|
{% block page_title %}Application Scope Detail: {{ object.name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block page_action %}
|
||||||
|
<div class="me-2">
|
||||||
|
<a href="{% url 'gooyal_oauth2:application_scope_update' pk=object.pk application_pk=application.pk %}">
|
||||||
|
<div class="btn btn-success">
|
||||||
|
<span class="bi bi-gear-fill"></span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% 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 %}
|
||||||
61
templates/gooyal_oauth2/application_scope_list.html
Normal file
61
templates/gooyal_oauth2/application_scope_list.html
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
{% load jalali_tags %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% load tags %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block title %}Application Scope List: {{ application }}{% endblock %}
|
||||||
|
{% block page_title %}Application Scope List: {{ application }}{% endblock %}
|
||||||
|
{% block page_action %}
|
||||||
|
{% include "include/filter_action.html" %}
|
||||||
|
<div class="me-2">
|
||||||
|
<a href="{% url 'gooyal_oauth2:application_scope_create' application.pk %}">
|
||||||
|
<div class="btn btn-success">
|
||||||
|
<span class="bi bi-plus-circle-fill"></span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th><a href="?{% get_filter_link request 'ordering' 'name' %}" >name{% if request.GET.ordering and 'name' in request.GET.ordering %}<i class="bi bi-arrow-down-short"></i>{% endif %}</a></th>
|
||||||
|
{# <th><a href="?{% get_filter_link request 'ordering' 'client_id' %}" >client id{% if request.GET.ordering and 'client_id' in request.GET.ordering %}<i class="bi bi-arrow-down-short"></i>{% endif %}</a></th>#}
|
||||||
|
<th>description</th>
|
||||||
|
<th>actions</th>
|
||||||
|
</tr>
|
||||||
|
{% for obj in object_list %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ obj.name }}</td>
|
||||||
|
{# <td>{{ obj.client_id }}</td>#}
|
||||||
|
<td>{{ obj.description }}</td>
|
||||||
|
<td>
|
||||||
|
<div class="grid">
|
||||||
|
<div class="d-flex justify-content-end">
|
||||||
|
<div class="me-2">
|
||||||
|
<a href="{% url 'gooyal_oauth2:application_scope_detail' pk=obj.pk application_pk=application.pk %}">
|
||||||
|
<div class="btn btn-success">
|
||||||
|
<span class="bi bi-gear-fill"></span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{# <div class="me-2">#}
|
||||||
|
{# <a href="{% url 'gooyal_oauth2:application_update' pk=obj.pk %}">#}
|
||||||
|
{# <div class="btn btn-success">#}
|
||||||
|
{# <span class="bi bi-info-circle-fill"></span>#}
|
||||||
|
{# </div>#}
|
||||||
|
{# </a>#}
|
||||||
|
{# </div>#}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% include 'include/paginator.html' %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
24
templates/gooyal_oauth2/application_scope_update.html
Normal file
24
templates/gooyal_oauth2/application_scope_update.html
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% load jalali_tags %}
|
||||||
|
|
||||||
|
{% block title %}Application Update: {{ object.name }}{% endblock %}
|
||||||
|
{% block page_title %}Application Update: {{ object.name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data" novalidate>
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="col-md-12 col-lg-12" id="formset">
|
||||||
|
{{ form|crispy }}
|
||||||
|
</div>
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="grid">
|
||||||
|
<div class="d-flex justify-content-end">
|
||||||
|
<a href="{% url "gooyal_oauth2:application_scope_detail" pk=object.pk application_pk=application.pk %}" class="btn btn-danger ms-2">انصراف</a>
|
||||||
|
<input class="btn btn-success ms-2" type="submit" value="ثبت" name="save"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
{% load crispy_forms_tags %}
|
{% load crispy_forms_tags %}
|
||||||
{% load jalali_tags %}
|
{% load jalali_tags %}
|
||||||
|
|
||||||
{% block title %}Application Update: {{ object }}{% endblock %}
|
{% block title %}Application Update: {{ object.name }}{% endblock %}
|
||||||
{% block page_title %}Application Update: {{ object }}{% endblock %}
|
{% block page_title %}Application Update: {{ object.name }}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data" novalidate>
|
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data" novalidate>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue