def list_teams(self, request):
     current_user = endpoints.get_current_user()
     if current_user is None:
         raise endpoints.UnauthorizedException()
     organisation = Organisation.get_by_id(request.code_organisation)
     if organisation is None:
         raise endpoints.BadRequestException("Organisation %s does not exists" % request.code_organisation)
     if current_user.email() not in organisation.admins_mail:
         teams = Team.query(Team.users_mails == current_user.email(), ancestor=organisation.key).fetch()
     else:
         teams = Team.query(ancestor=organisation.key).fetch()
     return OrganisationConverter().convert_team_collection(teams)
 def add_team(self, request):
     current_user = endpoints.get_current_user()
     organisation = Organisation.get_by_id(request.code_organisation)
     if current_user is None or current_user.email() not in organisation.admins_mail:
         raise endpoints.UnauthorizedException(message="Team creation is reserved to admins")
     team = Team(
         name=request.name,
         parent=organisation.key
     )
     team.put()
     organisation.teams.append(team.key)
     organisation.put()
     return OrganisationConverter().convert_team(team)
 def add_organisation(self, request):
     current_user = endpoints.get_current_user()
     if current_user is None:
         raise endpoints.UnauthorizedException(message="Organisation creation is reserved to admins")
         # Check organisation code unicity
     if Organisation.get_by_id(request.code) is not None:
         raise endpoints.ConflictException(message="Code already attributed")
     organisation = Organisation(
         name=request.name,
         id=request.code,
         admins_mail=[current_user.email()]
     )
     organisation.put()
     return OrganisationConverter().convert_organisation(organisation)