def post(self, project_id): args = self.get_args( [ ("entity_type", "Asset", False), ("name", "", True), ("for_client", "False", False), ("choices", [], False, "append"), ] ) permissions.check_admin_permissions() args["for_client"] = args["for_client"] == "True" if args["entity_type"] not in ["Asset", "Shot"]: raise WrongParameterException( "Wrong entity type. Please select Asset or Shot." ) if len(args["name"]) == 0: raise WrongParameterException("Name cannot be empty.") return ( projects_service.add_metadata_descriptor( project_id, args["entity_type"], args["name"], args["choices"], args["for_client"] ), 201, )
def get(self): args = self.get_args([ ("after", None, False), ("before", None, False), ("only_files", False, False), ("page_size", 100, False), ("project_id", None, False), ]) permissions.check_manager_permissions() before = None after = None if args["before"] is not None: try: before = fields.get_date_object( args["before"], "%Y-%m-%dT%H:%M:%S" ) except Exception: try: before = fields.get_date_object(args["before"], "%Y-%m-%d") except Exception: raise WrongParameterException( "Wrong date format for before argument." "Expected format: 2020-01-05T13:23:10 or 2020-01-05" ) if args["after"] is not None: try: after = fields.get_date_object( args["after"], "%Y-%m-%dT%H:%M:%S" ) except Exception: try: after = fields.get_date_object(args["after"], "%Y-%m-%d") except Exception: raise WrongParameterException( "Wrong date format for after argument." "Expected format: 2020-01-05T13:23:10 or 2020-01-05" ) page_size = args["page_size"] only_files = args["only_files"] == "true" project_id = args.get("project_id", None) if project_id is not None and not fields.is_valid_id(project_id): raise WrongParameterException( "The project_id parameter is not a valid id" ) else: return events_service.get_last_events( after=after, before=before, page_size=page_size, only_files=only_files, project_id=project_id )
def post(self, project_id): """ Create a new metadata descriptor --- description: It serves to describe extra fields listed in the data attribute of entities. tags: - Projects parameters: - in: path name: project_id required: true schema: type: UUID example: 5dc235ec-125e-4ba5-b1db-604d4babc315 responses: 201: description: Create a new metadata descriptor """ args = self.get_args([ ("entity_type", "Asset", False), ("name", "", True), ("for_client", "False", False), ("choices", [], False, "append"), ("departments", [], False, "append"), ]) user_service.check_all_departments_access(project_id, args["departments"]) args["for_client"] = args["for_client"] == "True" if args["entity_type"] not in ["Asset", "Shot", "Edit"]: raise WrongParameterException( "Wrong entity type. Please select Asset, Shot or Edit.") if len(args["name"]) == 0: raise WrongParameterException("Name cannot be empty.") return ( projects_service.add_metadata_descriptor( project_id, args["entity_type"], args["name"], args["choices"], args["for_client"], args["departments"], ), 201, )
def get_model_or_404(self, instance_id): if not fields.is_valid_id(instance_id): raise WrongParameterException("Malformed ID.") instance = self.model.get(instance_id) if instance is None: abort(404) return instance
def get_model_or_404(self, instance_id): if not fields.is_valid_id(instance_id): raise WrongParameterException("Malformed ID.") instance = self.model.get_by(id=instance_id) if instance is None: raise EntityLinkNotFoundException return instance
def post(self, person_id): """ Add a user to given department. --- tags: - Persons parameters: - in: path name: person_id required: True schema: type: UUID example: a24a6ea4-ce75-4665-a070-57453082c25 responses: 201: description: User added to given department """ permissions.check_admin_permissions() args = self.get_args( [ ("department_id", None, True), ] ) try: department = tasks_service.get_department(args["department_id"]) except DepartmentNotFoundException: raise WrongParameterException( "Department ID matches no department" ) person = persons_service.add_to_department(department["id"], person_id) return person, 201
def delete(self, person_id, department_id): """ Remove a user from given department. --- tags: - Persons parameters: - in: path name: person_id required: True schema: type: UUID example: a24a6ea4-ce75-4665-a070-57453082c25 - in: path name: department_id required: True schema: type: UUID example: a24a6ea4-ce75-4665-a070-57453082c25 responses: 204: description: User removed from given department """ permissions.check_admin_permissions() try: department = tasks_service.get_department(department_id) except DepartmentNotFoundException: raise WrongParameterException( "Department ID matches no department" ) persons_service.remove_from_department(department_id, person_id) return "", 204
def get(self): args = self.get_args([ ("after", None, False), ("before", None, False), ("only_files", False, False), ("page_size", 100, False), ("project_id", None, False), ]) permissions.check_manager_permissions() before = self.parse_date_parameter(args["before"]) after = self.parse_date_parameter(args["after"]) page_size = args["page_size"] only_files = args["only_files"] == "true" project_id = args.get("project_id", None) if project_id is not None and not fields.is_valid_id(project_id): raise WrongParameterException( "The project_id parameter is not a valid id") else: return events_service.get_last_events( after=after, before=before, page_size=page_size, only_files=only_files, project_id=project_id, )
def delete(self, person_id, department_id): permissions.check_admin_permissions() try: department = tasks_service.get_department(department_id) except DepartmentNotFoundException: raise WrongParameterException("Department ID matches no department") persons_service.remove_from_department(department_id, person_id) return "", 204
def put(self, project_id, descriptor_id): args = self.get_args([("name", "", False), ("choices", [], False, "append")]) permissions.check_admin_permissions() if len(args["name"]) == 0: raise WrongParameterException("Name cannot be empty.") return projects_service.update_metadata_descriptor(descriptor_id, args)
def post(self): kitsu_entries = request.json if type(kitsu_entries) != list: raise WrongParameterException("A list of entities is expected.") instances = [] for entry in kitsu_entries: if self.pre_check_entry(): instance = self.model.create_from_import(entry) instances.append(instance) return fields.serialize_models(instances)
def post(self): kitsu_entries = request.json if type(kitsu_entries) != list: raise WrongParameterException("A list of entities is expected.") instances = [] for entry in kitsu_entries: if self.check_access(entry): try: (instance, is_updated) = self.model.create_from_import(entry) if is_updated: self.emit_event("update", entry) else: self.emit_event("new", entry) except IntegrityError as exc: raise WrongParameterException(exc.orig) instances.append(instance) return fields.serialize_models(instances)
def post(self, person_id): permissions.check_admin_permissions() args = self.get_args([ ("department_id", None, True), ]) try: department = tasks_service.get_department(args["department_id"]) except DepartmentNotFoundException: raise WrongParameterException("Department ID matches no department") person = persons_service.add_to_department(department["id"], person_id) return person, 201
def parse_date_parameter(self, param): date = None if param is None: return date try: date = fields.get_date_object(param, "%Y-%m-%dT%H:%M:%S") except Exception: try: date = fields.get_date_object(param, "%Y-%m-%d") except Exception: raise WrongParameterException( "Wrong date format for before argument." "Expected format: 2020-01-05T13:23:10 or 2020-01-05") return date
def _check_retake_capping(task_status, task): if task_status["is_retake"]: project = projects_service.get_project(task["project_id"]) project_max_retakes = project["max_retakes"] or 0 if project_max_retakes > 0: entity = entities_service.get_entity_raw(task["entity_id"]) entity = entities_service.get_entity(task["entity_id"]) entity_data = entity.get("data", {}) or {} entity_max_retakes = entity_data.get("max_retakes", None) max_retakes = int(entity_max_retakes or project["max_retakes"]) if task["retake_count"] >= max_retakes and max_retakes > 0: raise WrongParameterException( "No more retakes allowed on this task") return True
def put(self, project_id, descriptor_id): """ Update a metadata descriptor. --- description: Descriptors serve to describe extra fields listed in the data attribute of entities. tags: - Projects parameters: - in: path name: project_id required: true schema: type: UUID example: 5dc235ec-125e-4ba5-b1db-604d4babc315 - in: path name: descriptor_id required: true schema: type: UUID example: 5dc235ec-125e-4ba5-b1db-604d4babc315 responses: 200: description: Metadata descriptor updated """ args = self.get_args([ ("name", "", False), ("for_client", "False", False), ("choices", [], False, "append"), ("departments", [], False, "append"), ]) user_service.check_all_departments_access( project_id, projects_service.get_metadata_descriptor(descriptor_id) ["departments"] + args["departments"], ) if len(args["name"]) == 0: raise WrongParameterException("Name cannot be empty.") args["for_client"] = args["for_client"] == "True" return projects_service.update_metadata_descriptor(descriptor_id, args)
def pre_update(self, instance_dict, data): if data.get("active", False) \ and not instance_dict.get("active", False) \ and persons_service.is_user_limit_reached(): raise WrongParameterException("User limit reached.") return instance_dict