From 3ef7793e70f02e7dc649ee25e00f086dbd88a56e Mon Sep 17 00:00:00 2001 From: Hironsan Date: Tue, 18 Jan 2022 07:55:55 +0900 Subject: [PATCH] Move API related to users to users app --- Pipfile | 2 +- backend/api/serializers.py | 8 -------- backend/api/urls.py | 13 +------------ backend/app/settings.py | 1 + backend/app/urls.py | 1 + backend/users/__init__.py | 0 backend/users/admin.py | 0 backend/users/apps.py | 6 ++++++ backend/users/migrations/__init__.py | 0 backend/users/models.py | 0 backend/users/serializers.py | 9 +++++++++ .../tests/api/test_user.py => users/tests.py} | 2 +- backend/users/urls.py | 18 ++++++++++++++++++ backend/{api/views/user.py => users/views.py} | 5 ++--- 14 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 backend/users/__init__.py create mode 100644 backend/users/admin.py create mode 100644 backend/users/apps.py create mode 100644 backend/users/migrations/__init__.py create mode 100644 backend/users/models.py create mode 100644 backend/users/serializers.py rename backend/{api/tests/api/test_user.py => users/tests.py} (97%) create mode 100644 backend/users/urls.py rename backend/{api/views/user.py => users/views.py} (90%) diff --git a/Pipfile b/Pipfile index bba08a7c..e69f61d3 100644 --- a/Pipfile +++ b/Pipfile @@ -60,6 +60,6 @@ python_version = "3.8" isort = "isort api -c --skip migrations" flake8 = "flake8 --filename \"*.py\" --extend-exclude \"server,api/migrations,api/views/__init__.py,authentification,api/apps.py\"" wait_for_db = "python manage.py wait_for_db" -test = "python manage.py test api.tests roles.tests members.tests metrics.tests" +test = "python manage.py test api.tests roles.tests members.tests metrics.tests users.tests" migrate = "python manage.py migrate" collectstatic = "python manage.py collectstatic --noinput" diff --git a/backend/api/serializers.py b/backend/api/serializers.py index 468c4009..904fbbda 100644 --- a/backend/api/serializers.py +++ b/backend/api/serializers.py @@ -1,5 +1,4 @@ from auto_labeling_pipeline.models import RequestModelFactory -from django.contrib.auth import get_user_model from rest_framework import serializers from rest_framework.exceptions import ValidationError from rest_polymorphic.serializers import PolymorphicSerializer @@ -14,13 +13,6 @@ from .models import (DOCUMENT_CLASSIFICATION, IMAGE_CLASSIFICATION, SEQ2SEQ, TextClassificationProject, TextLabel) -class UserSerializer(serializers.ModelSerializer): - - class Meta: - model = get_user_model() - fields = ('id', 'username', 'is_superuser', 'is_staff') - - class LabelSerializer(serializers.ModelSerializer): def validate(self, attrs): diff --git a/backend/api/urls.py b/backend/api/urls.py index eef0a90e..071e57df 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -2,7 +2,7 @@ from django.urls import include, path from .views import (annotation, auto_labeling, comment, example, example_state, export_dataset, health, import_dataset, import_export, - label, project, tag, task, user) + label, project, tag, task) from .views.tasks import category, relation, span, text urlpatterns_project = [ @@ -225,13 +225,7 @@ urlpatterns = [ view=health.Health.as_view(), name='health' ), - path('auth/', include('dj_rest_auth.urls')), path('fp/', include('django_drf_filepond.urls')), - path( - route='me', - view=user.Me.as_view(), - name='me' - ), path( route='features', view=import_export.Features.as_view(), @@ -242,11 +236,6 @@ urlpatterns = [ view=project.ProjectList.as_view(), name='project_list' ), - path( - route='users', - view=user.Users.as_view(), - name='user_list' - ), path( route='tasks/status/', view=task.TaskStatus.as_view(), diff --git a/backend/app/settings.py b/backend/app/settings.py index e6027214..3856c681 100644 --- a/backend/app/settings.py +++ b/backend/app/settings.py @@ -55,6 +55,7 @@ INSTALLED_APPS = [ 'roles.apps.RolesConfig', 'members.apps.MembersConfig', 'metrics.apps.MetricsConfig', + 'users.apps.UsersConfig', 'rest_framework', 'rest_framework.authtoken', 'django_filters', diff --git a/backend/app/urls.py b/backend/app/urls.py index 86f5231a..6a9a2961 100644 --- a/backend/app/urls.py +++ b/backend/app/urls.py @@ -42,6 +42,7 @@ urlpatterns += [ path('api-auth/', include('rest_framework.urls')), path('v1/', include('api.urls')), path('v1/', include('roles.urls')), + path('v1/', include('users.urls')), path('v1/projects//', include('members.urls')), path('v1/projects//metrics/', include('metrics.urls')), path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), diff --git a/backend/users/__init__.py b/backend/users/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/users/admin.py b/backend/users/admin.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/users/apps.py b/backend/users/apps.py new file mode 100644 index 00000000..72b14010 --- /dev/null +++ b/backend/users/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'users' diff --git a/backend/users/migrations/__init__.py b/backend/users/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/users/models.py b/backend/users/models.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/users/serializers.py b/backend/users/serializers.py new file mode 100644 index 00000000..830cd5d4 --- /dev/null +++ b/backend/users/serializers.py @@ -0,0 +1,9 @@ +from django.contrib.auth import get_user_model +from rest_framework import serializers + + +class UserSerializer(serializers.ModelSerializer): + + class Meta: + model = get_user_model() + fields = ('id', 'username', 'is_superuser', 'is_staff') diff --git a/backend/api/tests/api/test_user.py b/backend/users/tests.py similarity index 97% rename from backend/api/tests/api/test_user.py rename to backend/users/tests.py index 2572d220..831ac34b 100644 --- a/backend/api/tests/api/test_user.py +++ b/backend/users/tests.py @@ -2,7 +2,7 @@ from rest_framework import status from rest_framework.reverse import reverse from rest_framework.test import APITestCase -from .utils import make_user +from api.tests.api.utils import make_user class TestUserAPI(APITestCase): diff --git a/backend/users/urls.py b/backend/users/urls.py new file mode 100644 index 00000000..88e30347 --- /dev/null +++ b/backend/users/urls.py @@ -0,0 +1,18 @@ +from django.urls import include, path + +from .views import Me, Users + + +urlpatterns = [ + path( + route='me', + view=Me.as_view(), + name='me' + ), + path( + route='users', + view=Users.as_view(), + name='user_list' + ), + path('auth/', include('dj_rest_auth.urls')), +] diff --git a/backend/api/views/user.py b/backend/users/views.py similarity index 90% rename from backend/api/views/user.py rename to backend/users/views.py index 2761fcd0..26fc4bf3 100644 --- a/backend/api/views/user.py +++ b/backend/users/views.py @@ -1,13 +1,12 @@ from django.contrib.auth.models import User from django_filters.rest_framework import DjangoFilterBackend -from rest_framework import filters, generics +from rest_framework import generics, filters from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView from members.permissions import IsProjectAdmin - -from ..serializers import UserSerializer +from .serializers import UserSerializer class Me(APIView):