def get(self, project_id, task_id): """ Get task for mapping --- tags: - mapping produces: - application/json parameters: - in: header name: Authorization description: Base64 encoded session token required: false type: string default: Token sessionTokenHere== - in: header name: Accept-Language description: Language user is requesting type: string required: true default: en - name: project_id in: path description: The ID of the project the task is associated with required: true type: integer default: 1 - name: task_id in: path description: The unique task ID required: true type: integer default: 1 responses: 200: description: Task found 404: description: Task not found 500: description: Internal Server Error """ try: preferred_locale = request.environ.get('HTTP_ACCEPT_LANGUAGE') token = request.environ.get('HTTP_AUTHORIZATION') # Login isn't required here, but if we have a token we can find out if the user can undo the task if token: verify_token(token[6:]) user_id = tm.authenticated_user_id task = MappingService.get_task_as_dto(task_id, project_id, preferred_locale, user_id) return task.to_primitive(), 200 except NotFound: return {"Error": "Task Not Found"}, 404 except Exception as e: error_msg = f'Task GET API - unhandled error: {str(e)}' current_app.logger.critical(error_msg) return {"Error": error_msg}, 500
def get(self): """ Search active projects --- tags: - search produces: - application/json parameters: - in: header name: Authorization description: Base64 encoded session token type: string default: Token sessionTokenHere== - in: header name: Accept-Language description: Language user is requesting type: string required: true default: en - in: query name: mapperLevel type: string default: BEGINNER - in: query name: mappingTypes type: string default: ROADS,BUILDINGS - in: query name: organisationTag type: string default: red cross - in: query name: campaignTag type: string default: malaria - in: query name: page description: Page of results user requested type: integer default: 1 - in: query name: textSearch description: text to search type: string default: serbia - in: query name: projectStatuses description: Authenticated PMs can search for archived or draft statuses type: string responses: 200: description: Projects found 404: description: No projects found 500: description: Internal Server Error """ try: search_dto = ProjectSearchDTO() search_dto.preferred_locale = request.environ.get( 'HTTP_ACCEPT_LANGUAGE') search_dto.mapper_level = request.args.get('mapperLevel') search_dto.organisation_tag = request.args.get('organisationTag') search_dto.campaign_tag = request.args.get('campaignTag') search_dto.page = int( request.args.get('page')) if request.args.get('page') else 1 search_dto.text_search = request.args.get('textSearch') # See https://github.com/hotosm/tasking-manager/pull/922 for more info try: verify_token( request.environ.get('HTTP_AUTHORIZATION').split(None, 1)[1]) if UserService.is_user_a_project_manager( tm.authenticated_user_id): search_dto.is_project_manager = True except: pass mapping_types_str = request.args.get('mappingTypes') if mapping_types_str: search_dto.mapping_types = map( str, mapping_types_str.split(',')) # Extract list from string project_statuses_str = request.args.get('projectStatuses') if project_statuses_str: search_dto.project_statuses = map( str, project_statuses_str.split(',')) search_dto.validate() except DataError as e: current_app.logger.error(f'Error validating request: {str(e)}') return str(e), 400 try: results_dto = ProjectSearchService.search_projects(search_dto) return results_dto.to_primitive(), 200 except NotFound: return {"Error": "No projects found"}, 404 except Exception as e: error_msg = f'Project GET - unhandled error: {str(e)}' current_app.logger.critical(error_msg) return {"error": error_msg}, 500