Skip to content

Commit

Permalink
Merge pull request #183 from volunteers-for-city-projects/project
Browse files Browse the repository at this point in the history
Project
  • Loading branch information
MrRuzal authored Nov 13, 2023
2 parents 931e6d1 + 96798cb commit 715537d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
8 changes: 7 additions & 1 deletion backend/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ class IsOrganizerOfProject(BasePermission):
Разрешает доступ только организатору проекта.
"""

def has_permission(self, request, view):
return request.user.is_authenticated and request.user.is_organizer

def has_object_permission(self, request, view, obj):
return obj.project.organization.contact_person == request.user
return (
request.user.is_authenticated
and obj.project.organization.contact_person == request.user
)


class IsVolunteer(BasePermission):
Expand Down
2 changes: 2 additions & 0 deletions backend/api/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def validate_dates(event_start_date, event_end_date, application_date):
'Дата окончания мероприятия должна быть позже даты начала.'
)

# start_date_application ДОДЕЛАТЬ
# end_date_application ДОДЕЛАТЬ
if not (application_date <= event_start_date <= event_end_date):
raise serializers.ValidationError(
'Дата подачи заявки должна быть позже или равна дате начала '
Expand Down
20 changes: 12 additions & 8 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from drf_yasg.utils import swagger_auto_schema
from rest_framework import filters, generics, mixins, status, viewsets
from rest_framework.decorators import action
from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import SAFE_METHODS, AllowAny
from rest_framework.response import Response
from taggit.models import Tag
Expand Down Expand Up @@ -167,11 +166,13 @@ def update(self, request, *args, **kwargs):
return Response(
{"detail": message}, status=status.HTTP_403_FORBIDDEN
)
if instance.status_approve == Project.APPROVED and \
instance.end_datetime < timezone.now():
if (
instance.status_approve == Project.APPROVED
and instance.end_datetime < timezone.now()
):
return Response(
{"detail": "Вы не можете редактировать завершенные проекты"},
status=status.HTTP_400_BAD_REQUEST
status=status.HTTP_400_BAD_REQUEST,
)
partial = kwargs.pop('partial', False)
serializer = self.get_serializer(
Expand All @@ -198,10 +199,13 @@ def destroy(self, request, *args, **kwargs):
)
# Проверяем статус проекта возможно нужно еще добавить какие то статусы
if instance.status_approve not in [
Project.EDITING, Project.CANCELED_BY_ORGANIZER
Project.EDITING,
Project.CANCELED_BY_ORGANIZER,
]:
message = ('Вы не можете удалить проекты, '
'не находящиеся в архиве или в черновике.')
message = (
'Вы не можете удалить проекты, '
'не находящиеся в архиве или в черновике.'
)
return Response(
{"detail": message}, status=status.HTTP_400_BAD_REQUEST
)
Expand Down Expand Up @@ -391,14 +395,14 @@ class ProjectIncomesViewSet(
"""

queryset = ProjectIncomes.objects.all()
permission_classes = [IsOrganizerOfProject]

def get_queryset(self):
user = self.request.user
if user.is_authenticated and user.is_organizer:
return ProjectIncomes.objects.filter(
project__organization__contact_person=user
)
raise PermissionDenied('Нет доступа к этой странице')

def get_serializer_class(self):
if self.request.method in SAFE_METHODS:
Expand Down
2 changes: 0 additions & 2 deletions backend/projects/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,11 @@ def validate_name(value):
MAX_LEN,
message=f'Максимальная длина поля должна быть: {MAX_LEN}.',
)

regex_validator = RegexValidator(
regex=NAME_REGEX,
message='Недопустимые символы в названии проекта. Разрешены латинские '
'и кириллические буквы, цифры и спецсимволы.',
)

min_length_validator(value)
max_length_validator(value)
regex_validator(value)
Expand Down

0 comments on commit 715537d

Please sign in to comment.