Skip to content

Commit

Permalink
Merge pull request #760 from Ilhasoft/feature/generic-list-auth
Browse files Browse the repository at this point in the history
feat: generic list repository authorization
  • Loading branch information
Sandro-Meireles committed Dec 29, 2022
2 parents e673d2e + 482eac8 commit 09efdf3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions bothub/api/v2/repository/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError as DjangoValidationError
from django.db.models import Q
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -126,6 +127,8 @@
ConnectRESTClient as ConnectClient,
)

User = get_user_model()


class NewRepositoryViewSet(
MultipleFieldLookupMixin, mixins.RetrieveModelMixin, GenericViewSet
Expand Down Expand Up @@ -1091,19 +1094,22 @@ def list(self, request, **kwargs):
Get repository access token based on logged user
"""

repository_id = settings.TEST_REPOSITORY_ID
if not repository_id:
repository_uuid = request.query_params.get("repository_uuid")
if not repository_uuid:
return Response(
{"TEST_REPOSITORY_ID": "Not set"}, status=status.HTTP_400_BAD_REQUEST
{"TEST_REPOSITORY_UUID": "Not set"}, status=status.HTTP_400_BAD_REQUEST
)
try:
repository = Repository.objects.get(pk=repository_id)
repository = Repository.objects.get(pk=repository_uuid)
except Repository.DoesNotExist:
return Response(
{"Repository": "Does Not Exist"}, status=status.HTTP_404_NOT_FOUND
)

authorization = repository.get_user_authorization(request.user)
user = User.objects.get(email=request.query_params.get("user_email"))

authorization = repository.get_user_authorization(user)

return Response({"access_token": str(authorization.uuid)})


Expand Down

0 comments on commit 09efdf3

Please sign in to comment.