Repository: Cloud-CV/EvalAI

Issue:
Display the participant team name by which a participant participates in a challenge
## Current Behaviour
In the current setup, a participant doesn't know the participant team by which they have participated until they select the submissions under `My Submissions` Tab.


## Expected Behaviour

The participant team should be constantly visible under the `My Submissions` Tab.

## Deliverables
- [x] Add an API to fetch the participant team of the user corresponding the challenge.
- [ ] Write tests for the API
- [ ] Add frontend code in `My Submissions` Tab to display the participant team of the user for the corresponding challenge.
- [ ] Paste a screenshot of the UI with the PR

Please feel free to ask if you have any doubts!


Discussion:
Can i take this up?
Sure! But you are already working on a feature. You can take it up after finishing that. Till then, it is open to everyone.
May I take this up, as I'm not working on any feature currently?
Sure! You can work on it.
@deshraj @RishabhJain2018 Can I take this up if I've finished all of my other tasks and are waiting for review ?
@yashdusing  I've actually started on this one, and will make a PR for my other task soon. So, please be free to take up other issues :)
@RishabhJain2018 Sorry for the delay, been busy lately :). However, here's a screenshot. Will this do?
![screenshot from 2019-03-04 16-03-32](https://user-images.githubusercontent.com/31621523/53727835-3b74b980-3e97-11e9-8c34-40d229775560.png)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed as there is no further activity. Thank you for your contributions.


Resolving patch:
diff --git a/apps/challenges/urls.py b/apps/challenges/urls.py
--- a/apps/challenges/urls.py
+++ b/apps/challenges/urls.py
@@ -13,6 +13,11 @@
         views.challenge_detail,
         name="get_challenge_detail",
     ),
+    url(
+        r"^(?P<challenge_pk>[0-9]+)/participant_team/team_detail$",
+        views.participant_team_detail_for_challenge,
+        name="participant_team_detail_for_challenge",
+    ),
     url(
         r"^challenge/(?P<challenge_pk>[0-9]+)/participant_team/(?P<participant_team_pk>[0-9]+)$",
         views.add_participant_team_to_challenge,
@@ -181,9 +186,4 @@
         views.manage_worker,
         name="manage_worker",
     ),
-    url(
-        r"^phases/(?P<challenge_phase_pk>[0-9]+)/get_annotation_file_presigned_url/$",
-        views.get_annotation_file_presigned_url,
-        name="get_annotation_file_presigned_url",
-    ),
 ]
diff --git a/apps/challenges/utils.py b/apps/challenges/utils.py
--- a/apps/challenges/utils.py
+++ b/apps/challenges/utils.py
@@ -18,6 +18,7 @@
     Leaderboard,
     DatasetSplit,
     ChallengePhaseSplit,
+    ParticipantTeam,
 )
 
 logger = logging.getLogger(__name__)
@@ -32,6 +33,8 @@
 
 get_challenge_phase_split_model = get_model_object(ChallengePhaseSplit)
 
+get_participant_model = get_model_object(ParticipantTeam)
+
 
 def get_missing_keys_from_dict(dictionary, keys):
     """
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -55,6 +55,7 @@
     get_challenge_phase_split_model,
     get_dataset_split_model,
     get_leaderboard_model,
+    get_participant_model,
     get_unique_alpha_numeric_key,
     is_user_in_allowed_email_domains,
     is_user_in_blocked_email_domains,
@@ -83,6 +84,7 @@
     ChallengeSubmissionManagementSerializer,
 )
 from participants.models import Participant, ParticipantTeam
+from participants.serializers import ParticipantTeamDetailSerializer
 from participants.utils import (
     get_participant_teams_for_user,
     has_user_participated_in_challenge,
@@ -248,6 +250,30 @@ def challenge_detail(request, challenge_host_team_pk, challenge_pk):
         return Response(status=status.HTTP_204_NO_CONTENT)
 
 
+@api_view(['GET'])
+@throttle_classes([UserRateThrottle])
+@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))
+@authentication_classes((ExpiringTokenAuthentication,))
+def participant_team_detail_for_challenge(request, challenge_pk):
+    """
+        Returns the participated team detail in the challenge
+        Arguments:
+            challenge_pk {int} -- Challenge primary key
+        Returns:
+            {dict} -- Participant team detail that has participated in the challenge
+    """
+    if has_user_participated_in_challenge(user=request.user, challenge_id=challenge_pk):
+        participant_team_pk = get_participant_team_id_of_user_for_a_challenge(request.user, challenge_pk)
+        participant_team = get_participant_model(participant_team_pk)
+        serializer = ParticipantTeamDetailSerializer(participant_team)
+        response_data = serializer.data
+        return Response(response_data, status=status.HTTP_200_OK)
+    else:
+        message = ("You are not a participant!")
+        response_data = {"error": message}
+        return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
+
+
 @api_view(["POST"])
 @throttle_classes([UserRateThrottle])
 @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))


Test patch:
diff --git a/tests/unit/challenges/test_urls.py b/tests/unit/challenges/test_urls.py
--- a/tests/unit/challenges/test_urls.py
+++ b/tests/unit/challenges/test_urls.py
@@ -121,6 +121,19 @@ def test_challenges_urls(self):
             + str(self.challenge.pk),
         )
 
+        url = reverse_lazy(
+            "challenges:participant_team_detail_for_challenge",
+            kwargs={
+                "challenge_pk": self.challenge.pk,
+            },
+        )
+        self.assertEqual(
+            url,
+            "/api/challenges/"
+            + str(self.challenge.pk)
+            + "/participant_team/team_detail",
+        )
+
         url = reverse_lazy(
             "challenges:add_participant_team_to_challenge",
             kwargs={
diff --git a/tests/unit/challenges/test_views.py b/tests/unit/challenges/test_views.py
--- a/tests/unit/challenges/test_views.py
+++ b/tests/unit/challenges/test_views.py
@@ -185,6 +185,37 @@ def test_particular_challenge_host_team_for_challenge_does_not_exist(self):
         self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
 
 
+class GetParticipantTeamNameTest(BaseAPITestClass):
+
+    def setUp(self):
+        super(GetParticipantTeamNameTest, self).setUp()
+
+        self.participant = Participant.objects.create(
+            user=self.user,
+            status=Participant.ACCEPTED,
+            team=self.participant_team
+        )
+
+        self.challenge.participant_teams.add(self.participant_team)
+
+    def test_team_name_for_challenge(self):
+        self.url = reverse_lazy('challenges:participant_team_detail_for_challenge',
+                                kwargs={'challenge_pk': self.challenge.pk})
+
+        expected = "Participant Team for Challenge"
+        response = self.client.get(self.url, {})
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        self.assertEqual(response.data['team_name'], expected)
+
+    def test_team_name_for_challenge_with_participant_team_does_not_exist(self):
+        self.url = reverse_lazy('challenges:participant_team_detail_for_challenge',
+                                kwargs={'challenge_pk': self.challenge.pk + 2})
+        expected = {"error": "You are not a participant!"}
+        response = self.client.get(self.url, {})
+        self.assertEqual(response.data, expected)
+        self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
+
+
 class CreateChallengeTest(BaseAPITestClass):
     def setUp(self):
         super(CreateChallengeTest, self).setUp()