def put(self, type, identifier): """ --- summary: Add object tag description: | Add new tag to an object. Requires `adding_tags` capability. security: - bearerAuth: [] tags: - tag parameters: - in: path name: type schema: type: string enum: [file, config, blob, object] description: Type of target object - in: path name: identifier schema: type: string description: Object identifier requestBody: description: Tag value content: application/json: schema: TagRequestSchema responses: 200: description: When tag is successfully added content: application/json: schema: type: array items: $ref: '#/components/schemas/TagItemResponse' 400: description: When tag is invalid 403: description: When user doesn't have `adding_tags` capability. 404: description: When object doesn't exist or user doesn't have access to this object. """ schema = TagRequestSchema() obj = loads_schema(request.get_data(as_text=True), schema) db_object = access_object(type, identifier) if db_object is None: raise NotFound("Object not found") tag_name = obj["tag"] db_object.add_tag(tag_name) logger.info('Tag added', extra={ 'tag': tag_name, 'dhash': db_object.dhash }) db.session.refresh(db_object) schema = TagItemResponseSchema(many=True) return schema.dump(db_object.tags)
def delete(self, type, identifier): """ --- summary: Delete object tag description: | Removes tag from object. Requires `removing_tags` capability. security: - bearerAuth: [] tags: - tag parameters: - in: path name: type schema: type: string enum: [file, config, blob, object] description: Type of object - in: path name: identifier schema: type: string description: Object identifier - in: query name: tag schema: type: string description: Tag to be deleted required: true responses: 200: description: When tag is successfully removed content: application/json: schema: type: array items: $ref: '#/components/schemas/TagItemResponse' 400: description: When tag is invalid 403: description: When user doesn't have `removing_tags` capability. 404: description: When object doesn't exist or user doesn't have access to this object. """ schema = TagRequestSchema() obj = load_schema(request.args, schema) db_object = access_object(type, identifier) if db_object is None: raise NotFound("Object not found") tag_name = obj["tag"] db_object.remove_tag(tag_name) logger.info('Tag removed', extra={ 'tag': tag_name, 'dhash': db_object.dhash }) db.session.refresh(db_object) schema = TagItemResponseSchema(many=True) return schema.dump(db_object.tags)
def put(self, type, identifier): """ --- summary: Add object tag description: | Add new tag to an object. Requires `adding_tags` capability. security: - bearerAuth: [] tags: - tag parameters: - in: path name: type schema: type: string enum: [file, config, blob, object] description: Type of target object - in: path name: identifier schema: type: string description: Object identifier requestBody: description: Tag value content: application/json: schema: TagRequestSchema responses: 200: description: When tag is successfully added content: application/json: schema: type: array items: $ref: '#/components/schemas/TagItemResponse' 400: description: When tag is invalid 403: description: When user doesn't have `adding_tags` capability. 404: description: | When object doesn't exist or user doesn't have access to this object. 503: description: | Request canceled due to database statement timeout. """ schema = TagRequestSchema() obj = loads_schema(request.get_data(as_text=True), schema) db_object = access_object(type, identifier) if db_object is None: raise NotFound("Object not found") tag_name = obj["tag"] is_new = db_object.add_tag(tag_name) logger.info("Tag added", extra={"tag": tag_name, "dhash": db_object.dhash}) db.session.refresh(db_object) tag = next((t for t in db_object.tags if t.tag == tag_name), None) if is_new and tag: hooks.on_created_tag(db_object, tag) hooks.on_changed_object(db_object) elif tag: hooks.on_reuploaded_tag(db_object, tag) schema = TagItemResponseSchema(many=True) return schema.dump(db_object.tags)