Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/directories restructuring proposal #275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ env
/*/.env
/.DS_Store
__pycache__/
/FrontEnd/node_modules
/frontend/node_modules

public/*
!public/media/.gitkeep
!public/static/.gitkeep
backend/public/*
!backend/public/media/.gitkeep
!backend/public/static/.gitkeep
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev

RUN pip install --upgrade pip
COPY ./requirements.txt .
COPY backend/requirements.txt .
RUN pip3 install -r requirements.txt

COPY . /Forum
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions backend/api/permission_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from rest_framework import permissions
from rest_framework.permissions import SAFE_METHODS


class BaseNoObjectPermission(permissions.BasePermission):

def has_object_permission(self, request, view, obj):
return self.has_permission(request, view)


class RequestIsReadOnly(BaseNoObjectPermission):
def has_permission(self, request, view):
return request.method in SAFE_METHODS


class RequestIsCreate(BaseNoObjectPermission):
def has_permission(self, request, view):
return request.method == 'POST'


class RequestIsUpdate(BaseNoObjectPermission):
def has_permission(self, request, view):
return request.method in ('PUT', 'PATCH')


class RequestIsDelete(BaseNoObjectPermission):
def has_permission(self, request, view):
return request.method == 'DELETE'
6 changes: 6 additions & 0 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import include, path

urlpatterns = [
# /api/...
path('/authentication/', include('apps.authentication.api.urls')),
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from rest_framework import serializers
from djoser.serializers import UserSerializer

from authentication.models import CustomUser
from profiles.models import Profile
from backend.apps.authentication.models import CustomUser
from backend.apps.profiles.models import Profile


User = get_user_model()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path, re_path, include

from administration.views import (
from backend.apps.administration.views import (
AdminProfileList,
AdminProfileDetail,
UsersListView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
RetrieveUpdateDestroyAPIView,
)

from administration.serializers import (
from backend.apps.administration.serializers import (
AdminUserSerializer,
AdminCompanyListSerializer,
AdminCompanyDetailSerializer,
)
from administration.pagination import ListPagination
from authentication.models import CustomUser
from profiles.models import Profile
from backend.apps.administration.pagination import ListPagination
from backend.apps.authentication.models import CustomUser
from backend.apps.profiles.models import Profile


class UsersListView(ListAPIView):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from rest_framework import serializers
from rest_framework.validators import UniqueValidator

from profiles.models import Profile
from validation.validate_password import (
from backend.apps.profiles.models import Profile
from backend.api.validation.validate_password import (
validate_password_long,
validate_password_include_symbols,
)
Expand Down
6 changes: 6 additions & 0 deletions backend/apps/authentication/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path

urlpatterns = [
# /api/authentication/...
path('login/', )
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from utils.dump_response import dump # noqa
from utils.unittest_helper import AnyInt
from backend.apps.authentication.factories import UserFactory
from backend.utils.dump_response import dump # noqa
from backend.utils.unittest_helper import AnyInt


class UserLogoutAPITests(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase

from authentication.factories import UserFactory
from backend.apps.authentication.factories import UserFactory


class TestFactories(TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from rest_framework import status
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from utils.dump_response import dump # noqa
from utils.unittest_helper import AnyStr
from backend.apps.authentication.factories import UserFactory
from backend.utils.dump_response import dump # noqa
from backend.utils.unittest_helper import AnyStr


class UserLoginAPITests(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from rest_framework import status
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from utils.dump_response import dump # noqa
from backend.apps.authentication.factories import UserFactory
from backend.utils.dump_response import dump # noqa


class UserLogoutAPITests(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from rest_framework import status
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from profiles.models import Profile
from utils.dump_response import dump # noqa
from backend.apps.authentication.factories import UserFactory
from backend.apps.profiles.models import Profile
from backend.utils.dump_response import dump # noqa


class UserRegistrationAPITests(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from rest_framework import status
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from utils.dump_response import dump # noqa
from utils.unittest_helper import AnyInt
from backend.apps.authentication.factories import UserFactory
from backend.utils.dump_response import dump # noqa
from backend.utils.unittest_helper import AnyInt


class UserSelfAPITests(APITestCase):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion profiles/apps.py → backend/apps/profiles/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class ProfilesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "profiles"
name = "apps.profiles"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import validation.validate_edrpou
import validation.validate_foundation_year
import validation.validate_image
import validation.validate_phone_number
import backend.api.validation.validate_phone_number


class Migration(migrations.Migration):
Expand Down Expand Up @@ -43,14 +40,18 @@ class Migration(migrations.Migration):
('official_name', models.CharField(default=None, max_length=255, null=True, unique=True)),
('region', models.CharField(choices=[('Kyiv', 'Київ'), ('Vinnytsia region', 'Вінницька область'), ('Volyn region', 'Волинська область'), ('Dnipro region', 'Дніпропетровська область'), ('Donetsk region', 'Донецька область'), ('Zhytomyr region', 'Житомирська область'), ('Zakarpattia region', 'Закарпатська область'), ('Zaporizhzhia region', 'Запорізька область'), ('IvanoFrankivsk region', 'Івано-Франківська область'), ('Kyiv region', 'Київська область'), ('Kirovohrad region', 'Кіровоградська область'), ('Crimea', 'Автономна Республіка Крим'), ('Luhansk region', 'Луганська область'), ('Lviv region', 'Львівська область'), ('Mykolaiv region', 'Миколаївська область'), ('Odesa region', 'Одеська область'), ('Poltava region', 'Полтавська область'), ('Rivne region', 'Рівненська область'), ('Sevastopol', 'Севастополь'), ('Sumy region', 'Сумська область'), ('Ternopil region', 'Тернопільська область'), ('Kharkiv region', 'Харківська область'), ('Kherson region', 'Херсонська область'), ('Khmelnytskyi region', 'Хмельницька область'), ('Cherkasy region', 'Черкаська область'), ('Chernivtsi region', 'Чернівецька область'), ('Chernihiv region', 'Чернігівська область')], default=None, max_length=128, null=True)),
('common_info', models.CharField(default=None, max_length=255, null=True)),
('phone', models.CharField(default=None, max_length=12, null=True, validators=[validation.validate_phone_number.validate_phone_number_is_digit, validation.validate_phone_number.validate_phone_number_len])),
('edrpou', models.IntegerField(default=None, null=True, unique=True, validators=[validation.validate_edrpou.validate_edrpou])),
('founded', models.SmallIntegerField(default=None, null=True, validators=[validation.validate_foundation_year.validate_foundation_year_range])),
('phone', models.CharField(default=None, max_length=12, null=True, validators=[
backend.api.validation.validate_phone_number.validate_phone_number_is_digit, backend.api.validation.validate_phone_number.validate_phone_number_len])),
('edrpou', models.IntegerField(default=None, null=True, unique=True, validators=[
backend.validation.validate_edrpou.validate_edrpou])),
('founded', models.SmallIntegerField(default=None, null=True, validators=[
backend.api.validation.validate_foundation_year.validate_foundation_year_range])),
('service_info', models.TextField(default=None, null=True)),
('product_info', models.TextField(default=None, null=True)),
('address', models.TextField(default=None, null=True)),
('startup_idea', models.TextField(default=None, null=True)),
('banner_image', models.ImageField(null=True, upload_to='', validators=[validation.validate_image.validate_image_format, validation.validate_image.validate_image_size])),
('banner_image', models.ImageField(null=True, upload_to='', validators=[
backend.validation.validate_image.validate_image_format, backend.validation.validate_image.validate_image_size])),
('is_deleted', models.BooleanField(default=False)),
('activities', models.ManyToManyField(to='profiles.activity')),
('categories', models.ManyToManyField(to='profiles.category')),
Expand Down
Empty file.
10 changes: 5 additions & 5 deletions profiles/models.py → backend/apps/profiles/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from django.db import models

from authentication.models import CustomUser
from validation.validate_edrpou import validate_edrpou
from validation.validate_foundation_year import validate_foundation_year_range
from validation.validate_image import (
from backend.apps.authentication.models import CustomUser
from backend.api.validation.validate_edrpou import validate_edrpou
from backend.api.validation.validate_foundation_year import validate_foundation_year_range
from backend.api.validation.validate_image import (
validate_image_size,
validate_image_format,
)
from validation.validate_phone_number import (
from backend.api.validation.validate_phone_number import (
validate_phone_number_len,
validate_phone_number_is_digit,
)
Expand Down
14 changes: 6 additions & 8 deletions profiles/permissions.py → backend/apps/profiles/permissions.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from rest_framework.permissions import BasePermission, SAFE_METHODS
from django.core.exceptions import ObjectDoesNotExist
from profiles.models import Profile

from backend.api.permission_classes import BaseNoObjectPermission
from backend.apps.profiles.models import Profile

class UserIsProfileOwnerOrReadOnly(BasePermission):
def has_object_permission(self, request, view, obj):
if request.method in SAFE_METHODS:
if request.query_params.get("with_contacts"):
return True if request.user.is_authenticated else False
return True

return obj.person == request.user
class UserIsProfileOwner(BaseNoObjectPermission):

def has_permission(self, request, view):
return view._get_profile.person == request.user


class ReadOnly(BasePermission):
Expand Down
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from profiles.factories import ActivityFactory
from backend.apps.authentication.factories import UserFactory
from backend.apps.profiles.factories import ActivityFactory


class TestActivityList(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from profiles.factories import CategoryFactory
from backend.apps.authentication.factories import UserFactory
from backend.apps.profiles.factories import CategoryFactory


class TestCategoryList(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from rest_framework import status
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from profiles.factories import (
from backend.apps.authentication.factories import UserFactory
from backend.apps.profiles.factories import (
ProfileStartupFactory,
CategoryFactory,
ActivityFactory,
)
from profiles.models import Region
from utils.dump_response import dump # noqa
from utils.unittest_helper import AnyInt
from backend.apps.profiles.models import Region
from backend.utils.dump_response import dump # noqa
from backend.utils.unittest_helper import AnyInt


class TestProfileDetailAPIView(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase

from profiles.factories import (
from backend.apps.profiles.factories import (
ProfileFactory,
ProfileStartupFactory,
ProfileCompanyFactory,
Expand All @@ -10,7 +10,7 @@
SavedStartupFactory,
ViewedCompanyFactory,
)
from utils.dump_response import dump # noqa
from backend.utils.dump_response import dump # noqa


class TestFactories(TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from rest_framework import status
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from profiles.factories import (
from backend.apps.authentication.factories import UserFactory
from backend.apps.profiles.factories import (
ProfileStartupFactory,
ProfileCompanyFactory,
ActivityFactory,
)
from profiles.factories import SavedCompanyFactory, SavedStartupFactory
from profiles.models import Profile
from utils.dump_response import dump # noqa
from backend.apps.profiles.factories import SavedCompanyFactory, SavedStartupFactory
from backend.apps.profiles.models import Profile
from backend.utils.dump_response import dump # noqa


class TestProfileFilterCompanyType(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from unittest import skip

from rest_framework import status
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from profiles.factories import ProfileCompanyFactory, SavedCompanyFactory
from utils.dump_response import dump # noqa
from backend.apps.authentication.factories import UserFactory
from backend.apps.profiles.factories import ProfileCompanyFactory, SavedCompanyFactory
from backend.utils.dump_response import dump # noqa


class SavedCompaniesListCreateDestroyAPITest(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from rest_framework import status
from rest_framework.test import APITestCase

from authentication.factories import UserFactory
from profiles.factories import ProfileStartupFactory, ViewedCompanyFactory
from utils.dump_response import dump # noqa
from backend.apps.authentication.factories import UserFactory
from backend.apps.profiles.factories import ProfileStartupFactory, ViewedCompanyFactory
from backend.utils.dump_response import dump # noqa


class TestViewedCompanyAPI(APITestCase):
Expand Down
File renamed without changes.
Loading
Loading