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

feat(org/view): Add api to get organisation by uuid #4878

Merged
merged 1 commit into from
Dec 3, 2024
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
1 change: 1 addition & 0 deletions api/organisations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Meta:
model = Organisation
fields = (
"id",
"uuid",
"name",
"created_date",
"webhook_notification_email",
Expand Down
13 changes: 12 additions & 1 deletion api/organisations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from rest_framework.authentication import BasicAuthentication
from rest_framework.decorators import action, api_view, authentication_classes
from rest_framework.exceptions import ValidationError
from rest_framework.generics import ListAPIView
from rest_framework.generics import ListAPIView, get_object_or_404
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import Request
from rest_framework.response import Response
Expand Down Expand Up @@ -124,6 +124,17 @@ def create(self, request, **kwargs):
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

@action(
detail=False,
url_path=r"get-by-uuid/(?P<uuid>[0-9a-f-]+)",
methods=["get"],
)
def get_by_uuid(self, request, uuid):
qs = self.get_queryset()
organisation = get_object_or_404(qs, uuid=uuid)
serializer = self.get_serializer(organisation)
return Response(serializer.data)

@action(detail=True, permission_classes=[IsAuthenticated])
def projects(self, request, pk):
organisation = self.get_object()
Expand Down
36 changes: 36 additions & 0 deletions api/tests/unit/organisations/test_unit_organisations_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@ def test_should_return_organisation_list_when_requested(
assert response.data["results"][0]["name"] == organisation.name


def test_get_by_uuid_returns_organisation(
admin_client: APIClient,
organisation: Organisation,
) -> None:
# Given
url = reverse(
"api-v1:organisations:organisation-get-by-uuid",
args=[organisation.uuid],
)

# When
response = admin_client.get(url)

# Then
assert response.status_code == status.HTTP_200_OK
assert response.json()["uuid"] == str(organisation.uuid)


def test_get_by_uuid_returns_404_for_organisation_that_does_not_belong_to_the_user(
admin_client: APIClient,
organisation: Organisation,
) -> None:
# Given
different_org = Organisation.objects.create(name="Different org")
url = reverse(
"api-v1:organisations:organisation-get-by-uuid",
args=[different_org.uuid],
)

# When
response = admin_client.get(url)

# Then
assert response.status_code == status.HTTP_404_NOT_FOUND


def test_non_superuser_can_create_new_organisation_by_default(
staff_client: APIClient,
staff_user: FFAdminUser,
Expand Down
Loading