Skip to content

Commit

Permalink
update graphql endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
RulaKhaled committed Jan 23, 2024
1 parent c55a1f4 commit bd7edf8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 7 additions & 3 deletions codecov_auth/commands/owner/interactors/get_org_upload_token.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated
from codecov.commands.exceptions import Unauthenticated, Unauthorized
from codecov.db import sync_to_async
from codecov_auth.helpers import current_user_part_of_org
from codecov_auth.models import OrganizationLevelToken


class GetOrgUploadToken(BaseInteractor):
def validate(self):
def validate(self, owner):
if not self.current_user.is_authenticated:
raise Unauthenticated()

if not current_user_part_of_org(self.current_owner, owner):
raise Unauthorized()

@sync_to_async
def execute(self, owner):
self.validate()
self.validate(owner)

org_token = OrganizationLevelToken.objects.filter(owner=owner).first()
if org_token:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from django.test import TransactionTestCase

from codecov.commands.exceptions import Unauthenticated
from codecov.commands.exceptions import Unauthenticated, Unauthorized
from codecov_auth.tests.factories import OrganizationLevelTokenFactory, OwnerFactory

from ..get_org_upload_token import GetOrgUploadToken
Expand Down Expand Up @@ -33,3 +33,11 @@ async def test_owner_with_org_upload_token_and_anonymous_user(self):
)

assert token == None

async def test_owner_with_org_upload_token_and_unauthorized_user(self):
with pytest.raises(Unauthorized):
token = await GetOrgUploadToken(
self.owner_with_upload_token, "github"
).execute(self.owner_with_no_upload_token)

assert token == None

0 comments on commit bd7edf8

Please sign in to comment.