cleanup
This commit is contained in:
parent
3c5ea1fefa
commit
d532394d20
35 changed files with 24 additions and 265 deletions
|
|
@ -51,10 +51,8 @@ INSTALLED_APPS = [
|
|||
|
||||
# local apps
|
||||
'apps.users',
|
||||
'apps.wallet',
|
||||
'apps.accounts_oauth2',
|
||||
'apps.superapp',
|
||||
]
|
||||
'apps.gooyal_oauth2',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
|
|
@ -69,20 +67,20 @@ MIDDLEWARE = [
|
|||
]
|
||||
|
||||
# Tell Django OAuth Toolkit to use the Gooyal Application model
|
||||
OAUTH2_PROVIDER_ID_TOKEN_MODEL = 'accounts_oauth2.IDToken'
|
||||
OAUTH2_PROVIDER_APPLICATION_MODEL = 'accounts_oauth2.Application'
|
||||
OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = 'accounts_oauth2.AccessToken'
|
||||
OAUTH2_PROVIDER_GRANT_MODEL = 'accounts_oauth2.Grant'
|
||||
OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = 'accounts_oauth2.RefreshToken'
|
||||
OAUTH2_PROVIDER_ID_TOKEN_MODEL = 'gooyal_oauth2.IDToken'
|
||||
OAUTH2_PROVIDER_APPLICATION_MODEL = 'gooyal_oauth2.Application'
|
||||
OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = 'gooyal_oauth2.AccessToken'
|
||||
OAUTH2_PROVIDER_GRANT_MODEL = 'gooyal_oauth2.Grant'
|
||||
OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = 'gooyal_oauth2.RefreshToken'
|
||||
|
||||
OAUTH2_PROVIDER = {
|
||||
# this is the list of available scopes
|
||||
'SCOPES_BACKEND_CLASS': 'apps.accounts_oauth2.scopes.Scopes',
|
||||
'SCOPES_BACKEND_CLASS': 'apps.gooyal_oauth2.scopes.Scopes',
|
||||
'SCOPES': {'read': 'Read scope',
|
||||
'write': 'Write scope',
|
||||
'groups': 'Access to your groups',
|
||||
'introspection': 'Introspect token scope'},
|
||||
'OAUTH2_VALIDATOR_CLASS': 'apps.accounts_oauth2.validators.OAuth2Validator',
|
||||
'OAUTH2_VALIDATOR_CLASS': 'apps.gooyal_oauth2.validators.OAuth2Validator',
|
||||
# "INTROSPECTION_USER_CREATE_METHOD": 'apps.users.models.create_user_in_introspection',
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,7 @@ from rest_framework import permissions
|
|||
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
|
||||
|
||||
|
||||
# from apps.accounts_oauth2.views.introspect import introspect_token
|
||||
from apps.wallet.views import TransactionList, TransactionDetail, TransactionPay, TransactionReceipt, \
|
||||
WithdrawVerify, WithdrawSubmit, DepositSubmit, DepositVerify
|
||||
# from apps.gooyal_oauth2.views.introspect import introspect_token
|
||||
from django.contrib.auth import urls as auth_urls
|
||||
|
||||
|
||||
|
|
@ -34,9 +32,7 @@ urlpatterns = [
|
|||
path('swagger/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
|
||||
|
||||
path('admin/', admin.site.urls),
|
||||
path('wallet/', include('apps.wallet.urls')),
|
||||
path('users/', include('apps.users.urls')),
|
||||
path('superapp/', include('apps.superapp.urls')),
|
||||
path('oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')),
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ from django.apps import AppConfig
|
|||
|
||||
|
||||
class GooyalOauthConfig(AppConfig):
|
||||
name = 'apps.accounts_oauth2'
|
||||
name = 'apps.gooyal_oauth2'
|
||||
|
|
@ -117,7 +117,7 @@ class Migration(migrations.Migration):
|
|||
('description', models.TextField(help_text='A brief description of the scope. This text is displayed to users when authorising access for the scope.')),
|
||||
('is_default', models.BooleanField(default=False, help_text='Indicates if this scope should be included in the default scopes.')),
|
||||
('application', models.ForeignKey(blank=True, help_text='The application to which the scope belongs.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='scopes', to=settings.OAUTH2_PROVIDER_APPLICATION_MODEL)),
|
||||
('resource', models.ForeignKey(blank=True, help_text='The resource of scope.', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='scopes', to='accounts_oauth2.resource')),
|
||||
('resource', models.ForeignKey(blank=True, help_text='The resource of scope.', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='scopes', to='gooyal_oauth2.resource')),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
@ -10,7 +10,7 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('accounts_oauth2', '0001_initial'),
|
||||
('gooyal_oauth2', '0001_initial'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ class Migration(migrations.Migration):
|
|||
migrations.AddField(
|
||||
model_name='application',
|
||||
name='resource',
|
||||
field=models.OneToOneField(blank=True, help_text='The resource of application.', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='application', to='accounts_oauth2.resource'),
|
||||
field=models.OneToOneField(blank=True, help_text='The resource of application.', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='application', to='gooyal_oauth2.resource'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='application',
|
||||
|
|
@ -6,7 +6,7 @@ from django.db import migrations, models
|
|||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts_oauth2', '0002_initial'),
|
||||
('gooyal_oauth2', '0002_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
from django.contrib import admin
|
||||
from .models import App
|
||||
# Register your models here.
|
||||
admin.site.register(App)
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SuperappConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.superapp'
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
# Generated by Django 4.1 on 2022-09-03 20:02
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='App',
|
||||
fields=[
|
||||
('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
|
||||
('title', models.CharField(blank=True, max_length=30, verbose_name='title')),
|
||||
('description', models.TextField(blank=True, null=True, verbose_name='description')),
|
||||
('order', models.IntegerField(blank=True, null=True, verbose_name='order')),
|
||||
('logo', models.ImageField(blank=True, null=True, upload_to='apps_logo')),
|
||||
('type', models.IntegerField(blank=True, choices=[(0, 'internal'), (1, 'external')], null=True, verbose_name='app type')),
|
||||
('link', models.URLField(blank=True, null=True, verbose_name='link')),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
# Generated by Django 4.1 on 2022-09-03 20:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('superapp', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='app',
|
||||
name='link',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='app',
|
||||
name='url',
|
||||
field=models.CharField(blank=True, max_length=30, verbose_name='url'),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
import uuid
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class App(models.Model):
|
||||
class AppTypeChoices(models.IntegerChoices):
|
||||
INTERNAL = 0, _('internal')
|
||||
EXTERNAL = 1, _('external')
|
||||
|
||||
uuid = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4, unique=True, db_index=True)
|
||||
title = models.CharField(_('title'), max_length=30, blank=True)
|
||||
description = models.TextField(_('description'), null=True, blank=True)
|
||||
order = models.IntegerField(_("order"), blank=True, null=True)
|
||||
logo = models.ImageField(upload_to='apps_logo', null=True, blank=True)
|
||||
type = models.IntegerField(_("app type"), choices=AppTypeChoices.choices, blank=True, null=True)
|
||||
url = models.CharField(_('url'), max_length=30, blank=True)
|
||||
|
||||
def get_uuid(self):
|
||||
return str(self.uuid)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
from apps.users.serializers import PublicUserSerializer
|
||||
from .models import App
|
||||
|
||||
|
||||
class AppSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = App
|
||||
fields = (
|
||||
'uuid',
|
||||
'title',
|
||||
'description',
|
||||
'order',
|
||||
"logo",
|
||||
"type",
|
||||
'url',
|
||||
)
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
from django.urls import path
|
||||
from .views import AppListView, AppDetailView, AppListAPIView, AppDetailAPIView
|
||||
|
||||
app_name = "superapp"
|
||||
|
||||
urlpatterns = [
|
||||
path('api/applications/', AppListAPIView.as_view(), name='app_list_api'),
|
||||
path('api/applications/<uuid>', AppDetailAPIView.as_view(), name='app_detail_api'),
|
||||
path('', AppListView.as_view(), name='app_list'),
|
||||
path('<uuid>', AppDetailView.as_view(), name='app_detail'),
|
||||
]
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import render
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic import ListView, DetailView
|
||||
from rest_framework import generics
|
||||
|
||||
from .models import App
|
||||
from .serializers import AppSerializer
|
||||
from ..accounts_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
||||
|
||||
|
||||
@method_decorator(login_required, name='dispatch')
|
||||
class AppListView(ListView):
|
||||
model = App
|
||||
template_name = 'superapp/app_list.html'\
|
||||
|
||||
|
||||
@method_decorator(login_required, name='dispatch')
|
||||
class AppDetailView(DetailView):
|
||||
model = App
|
||||
template_name = 'superapp/app_detail.html'
|
||||
pk_url_kwarg = 'uuid'
|
||||
|
||||
# def get_queryset(self):
|
||||
# return App.objects.filter(type=App.AppTypeChoices.EXTERNAL)
|
||||
|
||||
|
||||
class AppListAPIView(generics.ListAPIView):
|
||||
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
||||
serializer_class = AppSerializer
|
||||
required_alternate_scopes = {
|
||||
"GET": [['superapp.applications:list']],
|
||||
}
|
||||
|
||||
def get_queryset(self):
|
||||
return App.objects.all()
|
||||
|
||||
|
||||
class AppDetailAPIView(generics.RetrieveAPIView):
|
||||
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
||||
serializer_class = AppSerializer
|
||||
lookup_field = 'uuid'
|
||||
required_alternate_scopes = {
|
||||
"GET": [['superapp.applications:retrieve']],
|
||||
}
|
||||
|
||||
def get_queryset(self):
|
||||
return App.objects.all()
|
||||
|
|
@ -11,7 +11,7 @@ from rest_framework import generics, status, permissions
|
|||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from apps.accounts_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
||||
from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
||||
from apps.users.forms import OTPAuthenticationForm, ProfileUpdateForm
|
||||
from apps.users.models import User
|
||||
from apps.users.provinces_and_cities import State
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from oauth2_provider.contrib.rest_framework import TokenHasScope, IsAuthenticate
|
|||
from rest_framework import generics, permissions
|
||||
from rest_framework.response import Response
|
||||
|
||||
from apps.accounts_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
||||
from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
||||
from apps.wallet.models import Transaction
|
||||
from apps.wallet.serializers import TransactionSerializer, DepositSerializer, WithdrawSerializer, WalletSerializer
|
||||
from .constans import StateChoices
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
{% extends "base_generic.html" %}
|
||||
|
||||
{% block content %}
|
||||
<link rel="import" href="{{ object.url }}">
|
||||
<br>
|
||||
<object data="{{ object.url }}" width="100%" height="100%">
|
||||
<embed src="{{ object.url }}" width="100%" height="100%"> </embed>
|
||||
Error: Embedded data could not be displayed.
|
||||
</object>
|
||||
<br>
|
||||
<iframe src="{{ object.url }}" name="iframe_a"></iframe>
|
||||
<p><a href="http://www.w3schools.com" target="iframe_a">www.google.com</a></p>
|
||||
|
||||
<a href="{{ object.url }}" target="_self">link</a>
|
||||
{% endblock %}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
{% extends "base_generic.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% for app in object_list %}
|
||||
{% if app.type == app.AppTypeChoices.EXTERNAL %}
|
||||
<a href="{% url 'superapp:app_detail' app.uuid|lower %}">{{ app }}</a><br>
|
||||
{% else %}
|
||||
<a href="{% url app.url %}">{{ app }}</a><br>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
{% extends "base_generic.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if object.payee == request.user %}
|
||||
دریافت مبلغ {{ object.amount }}از: {{ object.payer }} در وضعیت {{ object.get_state_display }}
|
||||
{% else %}
|
||||
پرداخت مبلغ {{ object.amount }} به: {{ object.payee }}
|
||||
{% endif %}
|
||||
|
||||
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{% if object.state == object.state_choices.created %}
|
||||
<div class="col-6 mb-3">
|
||||
<input class="w-100 btn btn-primary btn" type="submit" value="پرداخت" name="pay"/>
|
||||
</div>
|
||||
{% elif object.state == object.state_choices.delayed %}
|
||||
<div class="col-6 mb-3">
|
||||
<input class="w-100 btn btn-primary btn" type="submit" value="تایید پرداخت" name="receipt"/>
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
{% extends "base_generic.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% for transaction in object_list %}
|
||||
{% if transaction.payee == request.user %}
|
||||
<a href="{% url 'wallet:transaction_detail' transaction.pk %}">
|
||||
{{ transaction.amount }}
|
||||
</a>
|
||||
از: {{ transaction.payer }} در وضعیت {{ transaction.get_state_display }}
|
||||
{% else %}
|
||||
<a href="{% url 'wallet:transaction_detail' transaction.pk %}">
|
||||
{{ transaction.amount }}
|
||||
</a>
|
||||
به: {{ transaction.payee }} در وضعیت {{ transaction.get_state_display }}
|
||||
{% endif %}
|
||||
<br>
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -96,8 +96,8 @@ def handle_request(requet_bytes, handler):
|
|||
"PATH_INFO": urlparse(request_data.uri).path,
|
||||
"CONTENT_LENGTH": request_data.headers.get('Content-Length', 0),
|
||||
"CONTENT_TYPE": request_data.headers.get('Content-Type', 'application/json'),
|
||||
# "SERVER_NAME": 'kafka',
|
||||
# "SERVER_PORT": '0',
|
||||
"SERVER_NAME": 'kafka',
|
||||
"SERVER_PORT": '0',
|
||||
# "HTTP_X_FORWARDED_PORT": '0',
|
||||
"wsgi.input": BytesIO(request_data.body)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,8 +62,9 @@ request = Request(method=method, url=url, json={'key_1': 'requests_lib'})
|
|||
rpc = RpcClient()
|
||||
|
||||
print(" [x] Requesting ...")
|
||||
for i in range(1000):
|
||||
response = rpc.call(request)
|
||||
# print(response.decode())
|
||||
# for i in range(1000):
|
||||
response = rpc.call(request)
|
||||
print(response.decode())
|
||||
# print(type(response.decode()))
|
||||
print(i)
|
||||
|
||||
# print(i)
|
||||
Loading…
Add table
Reference in a new issue