Repository: Cloud-CV/EvalAI
Issue: Hosts: User cannot see all of his Host Teams
GitHub labels: bug

GSOC-2019

backend

critical

## CURRENT STATE - 
`challenge-host-teams` page only shows teams `created_by` the user.

## ISSUE - 
On `challenge-host-teams` page, user should be able to see all host teams he is a part of.

## RELATED ISSUE -
#607 Refer to this issue also. 


To give more clarification about this issue, in the host team view, the user cannot see the teams of which he is a part of. He can only see the teams which he created. There are some minor changes in the checks that are done in the API. 

@deshraj can i take it up?

Sure. :-) 

while working on this i found out that when we invite another user through ```challenge-host-teams``` page. the model entry is by default ```ChallengeHost.ACCEPTED```. Should that be the case? Shoudn't the status by default be Not Accepted and then the invited user should be able to accept the invitation?

the possible reason for the issue is 
Line 27 at ```challenge_host_team_list``` view in hosts app: 

`challenge_host_teams = ChallengeHostTeam.objects.filter(created_by=request.user)`

the host teams retrieved in the query set are the ones "created_by" the user and not all. 

Trying to resolve this :+1: 



If somebody can explain me the purpose of `ChallengeHost` model and how it is in relation to `ChallengeHostTeam` model, it will be very helpful

@daas-ankur-shukla Please take a look at the db-schema after running your local server at `127.0.0.1:8000/dbschema/`.

@RishabhJain2018 thanks for your reply Rishabh. The description for ChallengeHostTeam says "Model representing the Host Team for a partiuclar challenge" but there is not such description available for ChallengeHost, even in the dbschema. 

Silly but I thought would be helpful for new contributors like me.
What can be added as its description?

@daas-ankur-shukla it would be nice if you can think through this since we cannot document each business login in paragraphs. It might be a good idea if you can go through the models and the business logic written. That will give you a better sense of what is happening at the backend.  

I have solved the issue apparently by modifying the `challenge_host_team_list` view in the hosts app and creating a new `MyHostTeamSerializer` for the same, but I am messing up somewhere. My code is creating a problem in inviting other people to the host team. 
The post request from 'Send Invite' button returns a 406 http status code. 
Can't figure out the reason for this as of now. Any help or suggestion is welcome

`challenge_host_team_list` view:

```python
if request.method == 'GET':
        print("challenge_host list view")
        challenge_host = ChallengeHost.objects.filter(Q(user_id=request.user) & Q(Q(status=ChallengeHost.ACCEPTED) | Q(status=ChallengeHost.SELF)))
        paginator, result_page = paginated_queryset(challenge_host, request)
        serializer = MyHostTeamSerializer(result_page, many=True)
        response_data = serializer.data
        return paginator.get_paginated_response(response_data)
```

`MyHostTeamSerializer`

```python
team_name = serializers.SlugRelatedField(slug_field='team_name', queryset=ChallengeHostTeam.objects.all())
created_by = serializers.SerializerMethodField()

    class Meta:
        model = ChallengeHost
        fields = ('id', 'team_name', 'created_by')

    def get_created_by(self, obj):
        host_team = ChallengeHostTeam.objects.filter(id=obj.team_name_id)
        serializer = ChallengeHostTeamSerializer(host_team, many=True)
        return serializer.data[0]['created_by']
```

@daas-ankur-shukla I think there is no need to create a new serializer for this task. Should be doable with the current existing serializers. 

@daas-ankur-shukla @yadavankit Please do not work on this issue now. I have resolved it since we needed it ASAP. 

quite and elegant solution that was @deshraj. apologies that i could not solve it in time. :) hope will do better in other issues :)

No Problem @daas-ankur-shukla. :)