diff --git a/config/conf/__init__.py b/config/conf/__init__.py index 38d5c40..9ce96a4 100644 --- a/config/conf/__init__.py +++ b/config/conf/__init__.py @@ -2,4 +2,5 @@ from .djangorestframework import * from .simple_jwt import * from .jazzmin import * from .cors_headers import * -from .logs import * \ No newline at end of file +from .logs import * +from .swagger import * \ No newline at end of file diff --git a/config/conf/djangorestframework.py b/config/conf/djangorestframework.py index 8709aea..1495c72 100644 --- a/config/conf/djangorestframework.py +++ b/config/conf/djangorestframework.py @@ -1,7 +1,7 @@ REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.SessionAuthentication', - 'rest_framework.authentication.BasicAuthentication' + 'rest_framework.authentication.BasicAuthentication', 'rest_framework_simplejwt.authentication.JWTAuthentication', ], } \ No newline at end of file diff --git a/config/conf/swagger.py b/config/conf/swagger.py new file mode 100644 index 0000000..53142fc --- /dev/null +++ b/config/conf/swagger.py @@ -0,0 +1,3 @@ +SWAGGER_SETTINGS = { + 'DEFAULT_MODEL_RENDERING': 'example' +} \ No newline at end of file diff --git a/config/settings/base.py b/config/settings/base.py index 2b8eaeb..f9a6585 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -131,4 +131,4 @@ TENANT_MODEL = "customers.Client" TENANT_DOMAIN_MODEL = "customers.Domain" -import config.conf \ No newline at end of file +from config.conf import * \ No newline at end of file diff --git a/core/apps/accounts/management/__init__.py b/core/apps/accounts/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/accounts/management/commands/__init__.py b/core/apps/accounts/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/apps/accounts/management/commands/createuser.py b/core/apps/accounts/management/commands/createuser.py new file mode 100644 index 0000000..9eba9a5 --- /dev/null +++ b/core/apps/accounts/management/commands/createuser.py @@ -0,0 +1,52 @@ +# python +from getpass import getpass + +# django +from django.core.management import BaseCommand + +# django tenants +from django_tenants.utils import schema_context + + +# accounts +from core.apps.accounts.models import User + +# customers +from core.apps.customers.models import Client + + +class Command(BaseCommand): + def handle(self, *args, **options): + client = None + username = None + + while True: + schema_name = input("Schema nomini kiriting: ") + client = Client.objects.filter(schema_name=schema_name).first() + if not client: + self.stdout.write("Schema topilmadi") + else: break + + with schema_context(schema_name): + while True: + username = input("username kiriting: ") + user = User.objects.filter(username=username).first() + if user: + self.stdout.write("Foydalanuvchi bu username bilan mavjud") + else: + break + + first_name = input("Ism kiriting: ") + last_name = input("Familiya kiriting: ") + phone_number = input("Telefon raqam kiriting: ") + password = getpass("Parol kiriting: ") + + User.objects.create_superuser( + username=username, + first_name=first_name, + last_name=last_name, + password=password, + phone_number=phone_number, + ) + + self.stdout.write("Foydalanuvchi qo'shildi") diff --git a/core/apps/accounts/views/user/user.py b/core/apps/accounts/views/user/user.py index 139268f..dd20535 100644 --- a/core/apps/accounts/views/user/user.py +++ b/core/apps/accounts/views/user/user.py @@ -1,5 +1,5 @@ # rest framework -from rest_framework import viewsets +from rest_framework import viewsets, permissions from rest_framework.decorators import action # drf yasg @@ -13,12 +13,11 @@ from core.apps.accounts.serializers.user import user as serializers # utils from core.utils.response.mixin import ResponseMixin -from core.utils.permissions.tenant_user import IsTenantUser class UserViewSet(viewsets.GenericViewSet, ResponseMixin): queryset = User.objects.all() - permission_classes = [IsTenantUser] + permission_classes = [permissions.IsAuthenticated] def get_serializer_class(self): match self.action: @@ -28,7 +27,34 @@ class UserViewSet(viewsets.GenericViewSet, ResponseMixin): return case _: return serializers.UserSerializer - + + @swagger_auto_schema( + tags=['User'], + operation_description="User malumotlarini olish uchun api", + responses={ + 200: openapi.Response( + description="Success", + schema=None, + examples={ + "application/json": { + "status_code": 200, + "status": "success", + "message": "User ma'lumotlari", + "data": { + "id": 0, + "first_name": "string", + "last_name": "string", + "username": "string", + "phone_number": "+998951234567", + "profile_image": None or "string", + "created_at": "string", + "updated_at": "string" + } + } + } + ) + } + ) @action( methods=["GET"], url_name="me", url_path="me", detail=False ) diff --git a/core/utils/permissions/tenant_user.py b/core/utils/permissions/tenant_user.py deleted file mode 100644 index aacad6c..0000000 --- a/core/utils/permissions/tenant_user.py +++ /dev/null @@ -1,12 +0,0 @@ -# rest framework -from rest_framework.permissions import BasePermission - - -class IsTenantUser(BasePermission): - """ - Allow access only if request.tenant_user exists. - """ - - def has_permission(self, request, view): - - return bool(request.tenant_user) \ No newline at end of file