This commit is contained in:
mahdavi 2024-07-02 14:34:59 +03:30
parent 3c5ea1fefa
commit d532394d20
35 changed files with 24 additions and 265 deletions

View file

@ -51,10 +51,8 @@ INSTALLED_APPS = [
# local apps # local apps
'apps.users', 'apps.users',
'apps.wallet', 'apps.gooyal_oauth2',
'apps.accounts_oauth2', ]
'apps.superapp',
]
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
@ -69,20 +67,20 @@ MIDDLEWARE = [
] ]
# Tell Django OAuth Toolkit to use the Gooyal Application model # Tell Django OAuth Toolkit to use the Gooyal Application model
OAUTH2_PROVIDER_ID_TOKEN_MODEL = 'accounts_oauth2.IDToken' OAUTH2_PROVIDER_ID_TOKEN_MODEL = 'gooyal_oauth2.IDToken'
OAUTH2_PROVIDER_APPLICATION_MODEL = 'accounts_oauth2.Application' OAUTH2_PROVIDER_APPLICATION_MODEL = 'gooyal_oauth2.Application'
OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = 'accounts_oauth2.AccessToken' OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = 'gooyal_oauth2.AccessToken'
OAUTH2_PROVIDER_GRANT_MODEL = 'accounts_oauth2.Grant' OAUTH2_PROVIDER_GRANT_MODEL = 'gooyal_oauth2.Grant'
OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = 'accounts_oauth2.RefreshToken' OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = 'gooyal_oauth2.RefreshToken'
OAUTH2_PROVIDER = { OAUTH2_PROVIDER = {
# this is the list of available scopes # 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', 'SCOPES': {'read': 'Read scope',
'write': 'Write scope', 'write': 'Write scope',
'groups': 'Access to your groups', 'groups': 'Access to your groups',
'introspection': 'Introspect token scope'}, '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', # "INTROSPECTION_USER_CREATE_METHOD": 'apps.users.models.create_user_in_introspection',
} }

View file

@ -22,9 +22,7 @@ from rest_framework import permissions
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
# from apps.accounts_oauth2.views.introspect import introspect_token # from apps.gooyal_oauth2.views.introspect import introspect_token
from apps.wallet.views import TransactionList, TransactionDetail, TransactionPay, TransactionReceipt, \
WithdrawVerify, WithdrawSubmit, DepositSubmit, DepositVerify
from django.contrib.auth import urls as auth_urls 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('swagger/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('wallet/', include('apps.wallet.urls')),
path('users/', include('apps.users.urls')), path('users/', include('apps.users.urls')),
path('superapp/', include('apps.superapp.urls')),
path('oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')), path('oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')),

View file

@ -2,4 +2,4 @@ from django.apps import AppConfig
class GooyalOauthConfig(AppConfig): class GooyalOauthConfig(AppConfig):
name = 'apps.accounts_oauth2' name = 'apps.gooyal_oauth2'

View file

@ -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.')), ('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.')), ('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)), ('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')),
], ],
), ),
] ]

View file

@ -10,7 +10,7 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('accounts_oauth2', '0001_initial'), ('gooyal_oauth2', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL), migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]
@ -58,7 +58,7 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='application', model_name='application',
name='resource', 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( migrations.AddField(
model_name='application', model_name='application',

View file

@ -6,7 +6,7 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('accounts_oauth2', '0002_initial'), ('gooyal_oauth2', '0002_initial'),
] ]
operations = [ operations = [

View file

@ -1,4 +0,0 @@
from django.contrib import admin
from .models import App
# Register your models here.
admin.site.register(App)

View file

@ -1,6 +0,0 @@
from django.apps import AppConfig
class SuperappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.superapp'

View file

@ -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')),
],
),
]

View file

@ -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'),
),
]

View file

@ -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

View file

@ -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',
)

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View file

@ -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'),
]

View file

@ -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()

View file

@ -11,7 +11,7 @@ from rest_framework import generics, status, permissions
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView 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.forms import OTPAuthenticationForm, ProfileUpdateForm
from apps.users.models import User from apps.users.models import User
from apps.users.provinces_and_cities import State from apps.users.provinces_and_cities import State

View file

@ -9,7 +9,7 @@ from oauth2_provider.contrib.rest_framework import TokenHasScope, IsAuthenticate
from rest_framework import generics, permissions from rest_framework import generics, permissions
from rest_framework.response import Response 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.models import Transaction
from apps.wallet.serializers import TransactionSerializer, DepositSerializer, WithdrawSerializer, WalletSerializer from apps.wallet.serializers import TransactionSerializer, DepositSerializer, WithdrawSerializer, WalletSerializer
from .constans import StateChoices from .constans import StateChoices

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -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 %}

View file

@ -96,8 +96,8 @@ def handle_request(requet_bytes, handler):
"PATH_INFO": urlparse(request_data.uri).path, "PATH_INFO": urlparse(request_data.uri).path,
"CONTENT_LENGTH": request_data.headers.get('Content-Length', 0), "CONTENT_LENGTH": request_data.headers.get('Content-Length', 0),
"CONTENT_TYPE": request_data.headers.get('Content-Type', 'application/json'), "CONTENT_TYPE": request_data.headers.get('Content-Type', 'application/json'),
# "SERVER_NAME": 'kafka', "SERVER_NAME": 'kafka',
# "SERVER_PORT": '0', "SERVER_PORT": '0',
# "HTTP_X_FORWARDED_PORT": '0', # "HTTP_X_FORWARDED_PORT": '0',
"wsgi.input": BytesIO(request_data.body) "wsgi.input": BytesIO(request_data.body)
} }

View file

@ -62,8 +62,9 @@ request = Request(method=method, url=url, json={'key_1': 'requests_lib'})
rpc = RpcClient() rpc = RpcClient()
print(" [x] Requesting ...") print(" [x] Requesting ...")
for i in range(1000): # for i in range(1000):
response = rpc.call(request) response = rpc.call(request)
# print(response.decode()) print(response.decode())
# print(type(response.decode())) # print(type(response.decode()))
print(i)
# print(i)