def test_get_team_as_dto(self): team_id = 1 user_id = 123 abbreviated = False result = TeamService.get_team_as_dto(team_id, user_id, abbreviated) self.assertEqual(result.team_id, 1)
def get(self, team_id): """ Retrieves a Team --- tags: - teams produces: - application/json parameters: - name: team_id in: path description: Unique team ID required: true type: integer default: 1 - in: query name: omitMemberList type: boolean description: Set it to true if you don't want the members list on the response. default: False responses: 200: description: Team found 401: description: Unauthorized - Invalid credentials 404: description: Team not found 500: description: Internal Server Error """ try: authenticated_user_id = token_auth.current_user() omit_members = strtobool( request.args.get("omitMemberList", "false")) if authenticated_user_id is None: user_id = 0 else: user_id = authenticated_user_id team_dto = TeamService.get_team_as_dto(team_id, user_id, omit_members) return team_dto.to_primitive(), 200 except NotFound: return {"Error": "Team Not Found"}, 404 except Exception as e: error_msg = f"Team GET - unhandled error: {str(e)}" current_app.logger.critical(error_msg) return {"Error": error_msg}, 500
def get(self, team_id): """ Retrieves a Team --- tags: - teams produces: - application/json parameters: - name: team_id in: path description: Unique team ID required: true type: integer default: 1 responses: 200: description: Team found 401: description: Unauthorized - Invalid credentials 404: description: Team not found 500: description: Internal Server Error """ try: authenticated_user_id = token_auth.current_user() if authenticated_user_id is None: user_id = 0 else: user_id = authenticated_user_id team_dto = TeamService.get_team_as_dto(team_id, user_id) return team_dto.to_primitive(), 200 except NotFound: return {"Error": "Team Not Found"}, 404 except Exception as e: error_msg = f"Team GET - unhandled error: {str(e)}" current_app.logger.critical(error_msg) return {"Error": error_msg}, 500
def post(self, team_id): """ Updates a team information --- tags: - teams produces: - application/json parameters: - in: header name: Authorization description: Base64 encoded session token required: true type: string default: Token sessionTokenHere== - name: team_id in: path description: Unique team ID required: true type: integer default: 1 - in: body name: body required: true description: JSON object for updating a team schema: properties: name: type: string default: HOT - Mappers logo: type: string default: https://tasks.hotosm.org/assets/img/hot-tm-logo.svg members: type: array items: schema: $ref: "#/definitions/TeamMembers" organisation: type: string default: HOT description: type: string default: HOT's mapping editors inviteOnly: type: boolean default: false responses: 201: description: Team updated successfully 400: description: Client Error - Invalid Request 401: description: Unauthorized - Invalid credentials 500: description: Internal Server Error """ try: team_dto = TeamDTO(request.get_json()) team_dto.team_id = team_id team_dto.validate() authenticated_user_id = token_auth.current_user() team_details_dto = TeamService.get_team_as_dto( team_id, authenticated_user_id) org = TeamService.assert_validate_organisation( team_dto.organisation_id) TeamService.assert_validate_members(team_details_dto) if not TeamService.is_user_team_manager( team_id, authenticated_user_id ) and not OrganisationService.can_user_manage_organisation( org.id, authenticated_user_id): return { "Error": "User is not a admin or a manager for the team" }, 401 except DataError as e: current_app.logger.error(f"error validating request: {str(e)}") return str(e), 400 try: TeamService.update_team(team_dto) return {"Status": "Updated"}, 200 except NotFound as e: return {"Error": str(e)}, 404 except TeamServiceError as e: return str(e), 402 except Exception as e: error_msg = f"Team POST - unhandled error: {str(e)}" current_app.logger.critical(error_msg) return {"Error": error_msg}, 500