Skip to content

Commit

Permalink
Feature/tags order (#301)
Browse files Browse the repository at this point in the history
* feat: change sectortag order to be based on the name field

* feat: treat exceptions

* feat: remove unused imports
  • Loading branch information
helllllllder authored Oct 17, 2023
1 parent cd074cd commit 9fa1da7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
7 changes: 6 additions & 1 deletion chats/apps/api/v1/internal/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def create(self, request, *args, **kwargs):

def put(
self, request, *args, **kwargs
): # TODO: GAMBIARRA ALERT! MOVE THIS LOGIC TO THE SERIALIZER
): # TODO: GAMBIARRA ALERT! MOVE THIS LOGIC TO THE SERIALIZER or somewhere else
qs = self.queryset
try:
user_email = request.data["user"]
Expand All @@ -87,6 +87,11 @@ def put(
},
status.HTTP_400_BAD_REQUEST,
)
except Project.DoesNotExist:
return Response(
{"Detail": f"The project {request.data['project']} does not exist yet"},
status.HTTP_404_NOT_FOUND,
)
return Response({"Detail": "Updated"}, status.HTTP_200_OK)

@action(detail=False, methods=["POST", "GET"], permission_classes=[IsAuthenticated])
Expand Down
1 change: 1 addition & 0 deletions chats/apps/api/v1/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ class ProjectFlowStartSerializer(serializers.Serializer):
default="",
trim_whitespace=True,
)
params = serializers.JSONField(required=False)
6 changes: 3 additions & 3 deletions chats/apps/api/v1/quickmessages/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.core.exceptions import PermissionDenied
from rest_framework import exceptions, viewsets
from rest_framework.permissions import IsAuthenticated

Expand Down Expand Up @@ -45,9 +45,9 @@ def get_queryset(self, *args, **kwargs):
try:
project = self.request.GET.get("project")
perm = self.request.user.project_permissions.get(project=project)
except (AttributeError, ObjectDoesNotExist):
except Exception as error:
raise exceptions.APIException(
detail="You don't have permission to access this project"
detail=f"You don't have permission to access this project. {type(error)}: {error}"
)
sectors = perm.get_sectors()
return QuickMessage.objects.all().filter(
Expand Down
21 changes: 21 additions & 0 deletions chats/apps/sectors/migrations/0010_alter_sectortag_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.1.2 on 2023-10-16 11:42

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("sectors", "0009_sector_config"),
]

operations = [
migrations.AlterModelOptions(
name="sectortag",
options={
"ordering": ["name"],
"verbose_name": "Sector Tag",
"verbose_name_plural": "Sector Tags",
},
),
]
1 change: 1 addition & 0 deletions chats/apps/sectors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def get_permission(self, user):
class Meta:
verbose_name = _("Sector Tag")
verbose_name_plural = _("Sector Tags")
ordering = ["name"]

constraints = [
models.UniqueConstraint(fields=["sector", "name"], name="unique_tag_name")
Expand Down

0 comments on commit 9fa1da7

Please sign in to comment.