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/tags order #301

Merged
merged 3 commits into from
Oct 17, 2023
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading