def get(self): name = request.args.get("name", None) try: permissions.check_admin_permissions() return projects_service.open_projects(name=name) except permissions.PermissionDenied: return user_service.get_open_projects(name=name)
def get_context(): if permissions.has_admin_permissions(): projects = projects_service.open_projects() else: projects = get_open_projects() asset_types = assets_service.get_asset_types() custom_actions = custom_actions_service.get_custom_actions() status_automations = status_automations_service.get_status_automations() persons = persons_service.get_persons( minimal=not permissions.has_manager_permissions() ) notification_count = get_unread_notifications_count() project_status_list = projects_service.get_project_statuses() departments = tasks_service.get_departments() task_types = tasks_service.get_task_types() task_status_list = tasks_service.get_task_statuses() search_filters = get_filters() return { "asset_types": asset_types, "custom_actions": custom_actions, "status_automations": status_automations, "departments": departments, "notification_count": notification_count, "persons": persons, "project_status": project_status_list, "projects": projects, "task_types": task_types, "task_status": task_status_list, "search_filters": search_filters, }
def get_context(): if permissions.has_admin_permissions(): projects = projects_service.open_projects() else: projects = get_open_projects() asset_types = assets_service.get_asset_types() custom_actions = custom_actions_service.get_custom_actions() persons = persons_service.get_persons() notifications = get_last_notifications() project_status_list = projects_service.get_project_statuses() task_types = tasks_service.get_task_types() task_status_list = tasks_service.get_task_statuses() search_filters = get_filters() return { "asset_types": asset_types, "custom_actions": custom_actions, "notifications": notifications, "persons": persons, "project_status": project_status_list, "projects": projects, "task_types": task_types, "task_status": task_status_list, "search_filters": search_filters, }
def post(self): """ Search for resource --- tags: - Search parameters: - in: query name: query required: True schema: type: string example: name of asset responses: 200: description: Resource """ args = self.get_args([("query", "", True)]) query = args.get("query") if len(query) < 3: return {"assets": []} if permissions.has_admin_permissions(): projects = projects_service.open_projects() else: projects = user_service.get_open_projects() persons = index_service.search_persons(query) open_project_ids = [project["id"] for project in projects] return { "assets": index_service.search_assets(query, open_project_ids), "persons": persons, }
def get(self, person_id): """ Return task assigned to given user of which status has is_done flag sets to true. --- tags: - Tasks description: It return only tasks related to open projects. parameters: - in: path name: person_id required: True schema: type: UUID example: a24a6ea4-ce75-4665-a070-57453082c25 responses: 200: description: Tasks assigned to user that are done """ if not permissions.has_admin_permissions(): projects = user_service.related_projects() else: projects = projects_service.open_projects() if permissions.has_vendor_permissions(): person = persons_service.get(person_id) if person["role"] == "vendor": return [] elif permissions.has_client_permissions(): return [] return tasks_service.get_person_done_tasks(person_id, projects)
def get(self, person_id): if not permissions.has_admin_permissions(): projects = user_service.related_projects() else: projects = projects_service.open_projects() if permissions.has_vendor_permissions(): person = persons_service.get(person_id) if person["role"] == "vendor": return [] return tasks_service.get_person_done_tasks(person_id, projects)
def patch_task_data(): """ Patch to run after upgrade from 0.9.8 or lower to 0.9.9 or superior. """ from zou.app.models.task import Task from zou.app.services import projects_service, deletion_service for project in projects_service.open_projects(): print("Cleaning tasks for project %s" % project["name"]) for task in Task.get_all_by(project_id=project["id"]): deletion_service.reset_task_data(task.id) print("Task cleaning done.")
def get_person_related_tasks(person_id, task_type_id): """ Retrieve all tasks for given task types and to entiities that have at least one person assignation. """ person = Person.get(person_id) projects = projects_service.open_projects() project_ids = [project["id"] for project in projects] entities = (Entity.query.join(Task, Entity.id == Task.entity_id).filter( Task.assignees.contains(person)).filter( Entity.project_id.in_(project_ids))).all() entity_ids = [entity.id for entity in entities] tasks = (Task.query.filter(Task.entity_id.in_(entity_ids)).filter( Task.task_type_id == task_type_id)).all() return fields.serialize_models(tasks)
def get(self): """ Return the list of projects currently running. --- tags: - Projects description: Most of the time, past projects are not needed. responses: 200: description: All running projects """ name = request.args.get("name", None) try: permissions.check_admin_permissions() for_client = permissions.has_client_permissions() return projects_service.open_projects(name=name, for_client=for_client) except permissions.PermissionDenied: return user_service.get_open_projects(name=name)
def test_get_open_projects(self): projects = projects_service.open_projects() self.assertEqual(len(projects), 1) self.assertEqual("Cosmos Landromat", projects[0]["name"])
def get(self, person_id): if not permissions.has_admin_permissions(): projects = user_service.related_projects() else: projects = projects_service.open_projects() return tasks_service.get_person_done_tasks(person_id, projects)
def get(self, person_id, task_type_id): user = persons_service.get_current_user() if person_id != user["id"]: permissions.check_admin_permissions() projects = projects_service.open_projects() return tasks_service.get_person_related_tasks(person_id, task_type_id)
def get(self): try: permissions.check_manager_permissions() return projects_service.open_projects() except permissions.PermissionDenied: return user_service.get_projects()