@@ -15,4 +15,9 @@ docker exec -it <container_name> bash
|
||||
python manage.py createclient
|
||||
```
|
||||
|
||||
## Tenant Superuser qo'shish
|
||||
```bash
|
||||
docker exec -it <container_name> bash
|
||||
|
||||
python manage.py createuser
|
||||
```
|
||||
|
||||
@@ -2,4 +2,5 @@ from .djangorestframework import *
|
||||
from .simple_jwt import *
|
||||
from .jazzmin import *
|
||||
from .cors_headers import *
|
||||
from .logs import *
|
||||
from .logs import *
|
||||
from .swagger import *
|
||||
@@ -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',
|
||||
],
|
||||
}
|
||||
3
config/conf/swagger.py
Normal file
3
config/conf/swagger.py
Normal file
@@ -0,0 +1,3 @@
|
||||
SWAGGER_SETTINGS = {
|
||||
'DEFAULT_MODEL_RENDERING': 'example'
|
||||
}
|
||||
@@ -131,4 +131,4 @@ TENANT_MODEL = "customers.Client"
|
||||
TENANT_DOMAIN_MODEL = "customers.Domain"
|
||||
|
||||
|
||||
import config.conf
|
||||
from config.conf import *
|
||||
0
core/apps/accounts/management/__init__.py
Normal file
0
core/apps/accounts/management/__init__.py
Normal file
0
core/apps/accounts/management/commands/__init__.py
Normal file
0
core/apps/accounts/management/commands/__init__.py
Normal file
52
core/apps/accounts/management/commands/createuser.py
Normal file
52
core/apps/accounts/management/commands/createuser.py
Normal file
@@ -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")
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user