diff --git a/mwdb/app.py b/mwdb/app.py index cd7cc91a3..cfb065b36 100755 --- a/mwdb/app.py +++ b/mwdb/app.py @@ -49,13 +49,6 @@ ) from mwdb.resources.group import GroupListResource, GroupMemberResource, GroupResource from mwdb.resources.karton import KartonAnalysisResource, KartonObjectResource -from mwdb.resources.metakey import ( - MetakeyDefinitionManageResource, - MetakeyListDefinitionManageResource, - MetakeyListDefinitionResource, - MetakeyPermissionResource, - MetakeyResource, -) from mwdb.resources.metrics import MetricsResource from mwdb.resources.oauth import ( OpenIDAccountIdentitiesResource, @@ -319,17 +312,6 @@ def apply_rate_limit(): api.add_resource(AttributeDefinitionResource, "/attribute/") api.add_resource(AttributePermissionResource, "/attribute//permissions") -# Attribute (metakey) deprecated endpoints -api.add_resource(MetakeyListDefinitionResource, "/meta/list/") -api.add_resource( - MetakeyResource, "///meta" -) -api.add_resource(MetakeyListDefinitionManageResource, "/meta/manage") -api.add_resource(MetakeyDefinitionManageResource, "/meta/manage/") -api.add_resource( - MetakeyPermissionResource, "/meta/manage//permissions/" -) - # Karton endpoints api.add_resource( KartonObjectResource, diff --git a/mwdb/core/deprecated.py b/mwdb/core/deprecated.py index 451d78601..c17c57c95 100644 --- a/mwdb/core/deprecated.py +++ b/mwdb/core/deprecated.py @@ -19,14 +19,6 @@ class DeprecatedFeature(Enum): # API keys non-complaint with RFC7519 # Deprecated in v2.7.0 legacy_api_key_v2 = "legacy_api_key_v2" - # Legacy Metakey API - # Use Attribute API instead - # Deprecated in v2.6.0 - legacy_metakey_api = "legacy_metakey_api" - # Legacy Metakey API - # Use Attribute API instead - # Deprecated in v2.6.0 - legacy_metakeys_upload_option = "legacy_metakeys_upload_option" def uses_deprecated_api( diff --git a/mwdb/model/attribute.py b/mwdb/model/attribute.py index 09813f766..66e3ad52d 100644 --- a/mwdb/model/attribute.py +++ b/mwdb/model/attribute.py @@ -1,5 +1,3 @@ -from string import Template - from flask import g from sqlalchemy import cast, func from sqlalchemy.dialects.postgresql import JSONB @@ -35,14 +33,6 @@ class Attribute(db.Model): value = db.Column(JSONB, nullable=False) template = db.relationship("AttributeDefinition", lazy="joined") - @property - def url(self): - # deprecated, left for metakey compatibility - if self.template.url_template: - s = Template(self.template.url_template) - return s.safe_substitute(value=self.value) - return None - @property def label(self): return self.template.label diff --git a/mwdb/model/object.py b/mwdb/model/object.py index 8c428cc55..d9ed7d7dd 100644 --- a/mwdb/model/object.py +++ b/mwdb/model/object.py @@ -1,5 +1,4 @@ import datetime -from collections import namedtuple from typing import Any, Dict, Optional from uuid import UUID @@ -577,7 +576,6 @@ def get_attributes( as_dict=False, check_permissions=True, show_hidden=False, - show_karton=False, ): """ Gets all object attributes @@ -587,7 +585,6 @@ def get_attributes( :param check_permissions: | Filter results including current user permissions (default: True) :param show_hidden: Show hidden attributes - :param show_karton: Show Karton attributes (for compatibility) """ attributes = ( db.session.query(Attribute) @@ -611,19 +608,6 @@ def get_attributes( attributes = attributes.order_by(Attribute.id).all() - if show_karton: - KartonAttribute = namedtuple("KartonAttribute", ["key", "value"]) - - attributes += [ - KartonAttribute(key="karton", value=str(analysis.id)) - for analysis in ( - db.session.query(KartonAnalysis) - .filter(KartonAnalysis.objects.any(id=self.id)) - .order_by(KartonAnalysis.creation_time) - .all() - ) - ] - if not as_dict: return attributes @@ -635,23 +619,12 @@ def get_attributes( return dict_attributes def add_attribute( - self, key, value, commit=True, check_permissions=True, include_karton=True + self, + key, + value, + commit=True, + check_permissions=True, ): - if include_karton and key == "karton": - karton_id = UUID(value) - - if check_permissions and not g.auth_user.has_rights( - Capabilities.karton_assign - ): - # User doesn't have permissions to assign analysis - return None - - _, is_new = self.assign_analysis(karton_id, commit=False) - - if commit: - db.session.commit() - return is_new - if check_permissions: attribute_definition = AttributeDefinition.query_for_set(key).first() else: diff --git a/mwdb/resources/attribute.py b/mwdb/resources/attribute.py index 4bc8ddc2a..6c87ae7c0 100644 --- a/mwdb/resources/attribute.py +++ b/mwdb/resources/attribute.py @@ -154,7 +154,7 @@ def post(self, type, identifier): key = obj["key"] value = obj["value"] - is_new = db_object.add_attribute(key, value, include_karton=False) + is_new = db_object.add_attribute(key, value) if is_new is None: raise NotFound( f"Attribute '{key}' is not defined or you have " diff --git a/mwdb/resources/blob.py b/mwdb/resources/blob.py index 5e95a9969..5c2e35f0f 100644 --- a/mwdb/resources/blob.py +++ b/mwdb/resources/blob.py @@ -144,9 +144,6 @@ def post(self): content: "blob contents" parent: null upload_as: "*" - metakeys: - - key: string - value: string attributes: - key: string value: string @@ -164,7 +161,7 @@ def post(self): 403: description: | No permissions to perform additional operations - (e.g. adding metakeys) + (e.g. adding attributes) 404: description: Specified group doesn't exist 409: diff --git a/mwdb/resources/config.py b/mwdb/resources/config.py index 9fcd9e2d1..644c484a9 100644 --- a/mwdb/resources/config.py +++ b/mwdb/resources/config.py @@ -260,9 +260,6 @@ def post(self): config_type: static parent: null upload_as: "*" - metakeys: - - key: string - value: string attributes: - key: string value: string @@ -280,7 +277,7 @@ def post(self): 403: description: | No permissions to perform additional operations - (e.g. adding parent, metakeys) + (e.g. adding parent, attributes) 404: description: | One of attribute keys doesn't exist diff --git a/mwdb/resources/file.py b/mwdb/resources/file.py index f038b10b5..213f474fd 100644 --- a/mwdb/resources/file.py +++ b/mwdb/resources/file.py @@ -154,10 +154,6 @@ def post(self): type: array items: $ref: '#/components/schemas/AttributeItemRequest' - metakeys: - type: array - items: - $ref: '#/components/schemas/MetakeyItemRequest' tags: type: array items: diff --git a/mwdb/resources/metakey.py b/mwdb/resources/metakey.py deleted file mode 100644 index 7f8d294dc..000000000 --- a/mwdb/resources/metakey.py +++ /dev/null @@ -1,739 +0,0 @@ -from flask import g, request -from werkzeug.exceptions import BadRequest, Forbidden, NotFound - -from mwdb.core.capabilities import Capabilities -from mwdb.core.deprecated import DeprecatedFeature, deprecated_endpoint -from mwdb.core.service import Resource -from mwdb.model import AttributeDefinition, AttributePermission, Group, db -from mwdb.schema.metakey import ( - MetakeyDefinitionItemRequestArgsSchema, - MetakeyDefinitionItemRequestBodySchema, - MetakeyDefinitionItemResponseSchema, - MetakeyDefinitionListResponseSchema, - MetakeyDefinitionManageItemResponseSchema, - MetakeyDefinitionManageListResponseSchema, - MetakeyItemRemoveRequestSchema, - MetakeyItemRequestSchema, - MetakeyKeySchema, - MetakeyListRequestSchema, - MetakeyListResponseSchema, - MetakeyPermissionSetRequestArgsSchema, - MetakeyPermissionSetRequestBodySchema, - MetakeyUpdateRequestSchema, -) - -from . import ( - access_object, - is_valid_uuid, - load_schema, - loads_schema, - logger, - requires_authorization, - requires_capabilities, -) - - -class MetakeyResource(Resource): - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - def get(self, type, identifier): - """ - --- - summary: Get object attributes - description: | - Returns all attributes of specified object that user is allowed to read. - - Deprecated: use Attributes API instead - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - 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: hidden - schema: - type: int - description: | - Show hidden attributes - (requires `reading_all_attributes` capability) - required: false - responses: - 200: - description: Object attributes - content: - application/json: - schema: MetakeyListResponseSchema - 403: - description: | - When user requested hidden metakeys - but doesn't have `reading_all_attributes` 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 = MetakeyListRequestSchema() - obj = load_schema(request.args, schema) - - show_hidden = obj["hidden"] - if show_hidden and not g.auth_user.has_rights( - Capabilities.reading_all_attributes - ): - raise Forbidden("You are not permitted to read hidden metakeys") - - db_object = access_object(type, identifier) - if db_object is None: - raise NotFound("Object not found") - - metakeys = db_object.get_attributes(show_hidden=show_hidden, show_karton=True) - schema = MetakeyListResponseSchema() - return schema.dump({"metakeys": metakeys}) - - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - def post(self, type, identifier): - """ - --- - summary: Add object attribute - description: | - Adds attribute to specified object. - - User must have `set` access to the attribute key - or `adding_all_attributes` capability. - - Deprecated: use Attributes API instead - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - 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 - requestBody: - description: Attribute key and value - content: - application/json: - schema: MetakeyItemRequestSchema - responses: - 200: - description: When metakey was added successfully - content: - application/json: - schema: MetakeyListResponseSchema - 400: - description: For karton attribute when value is not UUID - 404: - description: | - When object doesn't exist or user doesn't have - access to this object. - - When attribute key is not defined or user doesn't have - privileges to set that one. - 503: - description: | - Request canceled due to database statement timeout. - """ - schema = MetakeyItemRequestSchema() - 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") - - key = obj["key"] - value = obj["value"] - - if key == "karton" and not is_valid_uuid(value): - raise BadRequest("'karton' attribute accepts only UUID values") - - is_new = db_object.add_attribute(key, value) - if is_new is None: - raise NotFound( - f"Attribute '{key}' is not defined or you have " - f"insufficient permissions to set it" - ) - - db.session.commit() - db.session.refresh(db_object) - metakeys = db_object.get_attributes(show_karton=True) - schema = MetakeyListResponseSchema() - return schema.dump({"metakeys": metakeys}) - - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - @requires_capabilities("removing_attributes") - def delete(self, type, identifier): - """ - --- - summary: Delete object attribute - description: | - Deletes attribute from specified object. - - User must have `removing_attributes` capability. - - If value is not specified, all values under the specified - key are removed. - - Deprecated: use Attributes API instead - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - 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: key - schema: - type: string - description: Key of attribute object to be deleted - required: true - - in: query - name: value - schema: - type: string - description: Value of attribute key object to be deleted - required: false - responses: - 200: - description: When metakey was deleted successfully - 404: - description: | - When object doesn't exist or user doesn't have access - to this object. - When attribute key is not defined or user doesn't have privileges - to set that one. - 503: - description: | - Request canceled due to database statement timeout. - """ - schema = MetakeyItemRemoveRequestSchema() - obj = load_schema(request.args, schema) - - db_object = access_object(type, identifier) - if db_object is None: - raise NotFound("Object not found") - - key = obj["key"] - value = obj.get("value") - - deleted_object = db_object.remove_attribute(key, value) - if deleted_object is False: - raise NotFound( - f"Attribute '{key}' is not defined or you have " - f"insufficient permissions to delete it" - ) - db.session.commit() - - -class MetakeyListDefinitionResource(Resource): - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - def get(self, access): - """ - --- - summary: Get list of attribute keys - description: | - Returns list of attribute keys which currently authenticated user - can read or set. - - Deprecated: use Attributes API instead - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - parameters: - - in: path - name: access - schema: - type: string - enum: [read, set] - description: Type of desired access - responses: - 200: - description: List of attribute keys and definitions - content: - application/json: - schema: MetakeyDefinitionListResponseSchema - 400: - description: When used unknown access type (other than read or set) - 503: - description: | - Request canceled due to database statement timeout. - """ - if access == "read": - metakeys = AttributeDefinition.query_for_read() - elif access == "set": - metakeys = AttributeDefinition.query_for_set() - else: - raise BadRequest(f"Unknown desired access type '{access}'") - - metakeys = metakeys.order_by(AttributeDefinition.key).all() - schema = MetakeyDefinitionListResponseSchema() - return schema.dump({"metakeys": metakeys}) - - -class MetakeyListDefinitionManageResource(Resource): - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - @requires_capabilities(Capabilities.manage_users) - def get(self): - """ - --- - summary: Get attribute key definitions - description: | - Returns list of attribute key definitions. - - Requires `manage_users` capability. - - Deprecated: use Attributes API instead - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - responses: - 200: - description: List of attribute keys and definitions - content: - application/json: - schema: MetakeyDefinitionManageListResponseSchema - 403: - description: When user doesn't have `manage_users` capability. - 503: - description: | - Request canceled due to database statement timeout. - """ - metakeys = ( - db.session.query(AttributeDefinition) - .order_by(AttributeDefinition.key) - .all() - ) - schema = MetakeyDefinitionManageListResponseSchema() - return schema.dump({"metakeys": metakeys}) - - -class MetakeyDefinitionManageResource(Resource): - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - @requires_capabilities(Capabilities.manage_users) - def get(self, key): - """ - --- - summary: Get attribute key details - description: | - Returns attribute key definition details. - - Requires `manage_users` capability. - - Deprecated: use Attributes API instead - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - parameters: - - in: path - name: key - schema: - type: string - description: Attribute key - responses: - 200: - description: Attribute key definition - content: - application/json: - schema: MetakeyDefinitionManageItemResponseSchema - 403: - description: When user doesn't have `manage_users` capability. - 404: - description: When specified attribute key doesn't exist - 503: - description: | - Request canceled due to database statement timeout. - """ - metakey = ( - db.session.query(AttributeDefinition) - .filter(AttributeDefinition.key == key) - .first() - ) - if metakey is None: - raise NotFound("No such metakey") - schema = MetakeyDefinitionManageItemResponseSchema() - return schema.dump(metakey) - - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - @requires_capabilities(Capabilities.manage_users) - def post(self, key): - """ - --- - summary: Create attribute key - description: | - Creates attribute key definition. - - Requires `manage_users` capability. - - Deprecated: use Attributes API instead - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - parameters: - - in: path - name: key - schema: - type: string - description: Attribute key - requestBody: - description: Attribute key definition - content: - application/json: - schema: MetakeyDefinitionItemRequestBodySchema - responses: - 200: - description: When metakey definition is successfully added - content: - application/json: - schema: MetakeyDefinitionItemResponseSchema - 400: - description: | - When one of attribute definition fields is missing or incorrect. - 403: - description: When user doesn't have `manage_users` capability. - 503: - description: | - Request canceled due to database statement timeout. - """ - schema = MetakeyDefinitionItemRequestArgsSchema() - args_obj = load_schema({"key": key}, schema) - - schema = MetakeyDefinitionItemRequestBodySchema() - obj = loads_schema(request.get_data(as_text=True), schema) - - metakey_definition = AttributeDefinition( - key=args_obj["key"], - url_template=obj["url_template"], - label=obj["label"], - description=obj["description"], - hidden=obj["hidden"], - ) - metakey_definition = db.session.merge(metakey_definition) - db.session.commit() - - schema = MetakeyDefinitionItemResponseSchema() - return schema.dump(metakey_definition) - - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - @requires_capabilities(Capabilities.manage_users) - def put(self, key): - """ - --- - summary: Update attribute key - description: | - Update attribute key definition. - - Requires `manage_users` capability. - - Deprecated: use Attribute API instead. - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - parameters: - - in: path - name: key - schema: - type: string - description: Attribute key - requestBody: - description: Attribute definition to update - content: - application/json: - schema: MetakeyUpdateRequestSchema - responses: - 200: - description: When metakey definition is successfully updated - content: - application/json: - schema: MetakeyDefinitionItemResponseSchema - 400: - description: | - When one of attribute definition fields is missing or incorrect. - 403: - description: When user doesn't have `manage_users` capability. - 404: - description: When metakey doesn't exist. - 503: - description: | - Request canceled due to database statement timeout. - """ - schema = MetakeyUpdateRequestSchema() - obj = loads_schema(request.get_data(as_text=True), schema) - - metakey_obj = load_schema({"key": key}, MetakeyKeySchema()) - metakey = ( - db.session.query(AttributeDefinition) - .filter(AttributeDefinition.key == metakey_obj["key"]) - .first() - ) - if metakey is None: - raise NotFound("No such metakey") - - label = obj["label"] - if label is not None: - metakey.label = label - - description = obj["description"] - if description is not None: - metakey.description = description - - url_template = obj["template"] - if url_template is not None: - metakey.url_template = url_template - - hidden = obj["hidden"] - if hidden is not None: - metakey.hidden = obj["hidden"] - - db.session.commit() - logger.info("Attribute updated", extra=obj) - - schema = MetakeyDefinitionItemResponseSchema() - return schema.dump(metakey) - - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - @requires_capabilities(Capabilities.manage_users) - def delete(self, key): - """ - --- - summary: Delete attribute key - description: | - Deletes attribute key including all related object attributes. - - Requires `manage_users` capability. - - Deprecated: use Attribute API instead. - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - parameters: - - in: path - name: key - schema: - type: string - description: Attribute key - responses: - 200: - description: When attribute key was deleted - 403: - description: When user doesn't have `manage_users` capability. - 404: - description: When specified attribute key doesn't exist - 503: - description: | - Request canceled due to database statement timeout. - """ - metakey = ( - db.session.query(AttributeDefinition) - .filter(AttributeDefinition.key == key) - .first() - ) - if metakey is None: - raise NotFound("No such metakey") - db.session.delete(metakey) - db.session.commit() - - -class MetakeyPermissionResource(Resource): - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - @requires_capabilities(Capabilities.manage_users) - def put(self, key, group_name): - """ - --- - summary: Add/modify attribute key permission - description: | - Adds or modifies attribute key group permission - for specified key and group name. - - Requires `manage_users` capability. - - Deprecated: use Attribute API instead. - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - parameters: - - in: path - name: key - schema: - type: string - description: Attribute key - - in: path - name: group_name - schema: - type: string - description: Group name to add/modify - requestBody: - description: Attribute key permission definition - content: - application/json: - schema: MetakeyPermissionSetRequestBodySchema - responses: - 200: - description: When group permission has been successfully changed - content: - application/json: - schema: MetakeyDefinitionManageItemResponseSchema - 400: - description: | - When one of attribute permission fields is missing or incorrect. - 403: - description: When user doesn't have `manage_users` capability. - 404: - description: When attribute key or group doesn't exist - 503: - description: | - Request canceled due to database statement timeout. - """ - schema = MetakeyPermissionSetRequestArgsSchema() - args_obj = load_schema({"key": key, "group_name": group_name}, schema) - - schema = MetakeyPermissionSetRequestBodySchema() - obj = loads_schema(request.get_data(as_text=True), schema) - - metakey_definition = ( - db.session.query(AttributeDefinition) - .filter(AttributeDefinition.key == args_obj["key"]) - .first() - ) - if metakey_definition is None: - raise NotFound("No such metakey") - - group = ( - db.session.query(Group).filter(Group.name == args_obj["group_name"]).first() - ) - if group is None: - raise NotFound("No such group") - - permission = AttributePermission( - key=args_obj["key"], - group_id=group.id, - can_read=obj["can_read"], - can_set=obj["can_set"], - ) - db.session.merge(permission) - db.session.commit() - - db.session.refresh(metakey_definition) - schema = MetakeyDefinitionManageItemResponseSchema() - return schema.dump(metakey_definition) - - @deprecated_endpoint(DeprecatedFeature.legacy_metakey_api) - @requires_authorization - @requires_capabilities(Capabilities.manage_users) - def delete(self, key, group_name): - """ - --- - summary: Delete attribute key permission - description: | - Removes attribute key permission for specified key and group name. - - Requires `manage_users` capability. - - Deprecated: use Attribute API instead. - security: - - bearerAuth: [] - deprecated: true - tags: - - metakey - parameters: - - in: path - name: key - schema: - type: string - description: Attribute key - - in: path - name: group_name - schema: - type: string - description: Group name to remove - responses: - 200: - description: When group permission has been successfully removed - 403: - description: When user doesn't have `manage_users` capability. - 404: - description: | - When attribute key or group or group permission doesn't exist - 503: - description: | - Request canceled due to database statement timeout. - """ - schema = MetakeyPermissionSetRequestArgsSchema() - args_obj = load_schema({"key": key, "group_name": group_name}, schema) - - group = ( - db.session.query(Group).filter(Group.name == args_obj["group_name"]).first() - ) - if group is None: - raise NotFound("No such group") - - metakey_permission = ( - db.session.query(AttributePermission) - .filter( - AttributePermission.key == args_obj["key"], - AttributePermission.group_id == group.id, - ) - .first() - ) - - if metakey_permission is None: - raise NotFound("No such metakey permission") - - db.session.delete(metakey_permission) - db.session.commit() diff --git a/mwdb/resources/object.py b/mwdb/resources/object.py index 688aeaba0..a077ba991 100644 --- a/mwdb/resources/object.py +++ b/mwdb/resources/object.py @@ -1,11 +1,8 @@ -from uuid import UUID - from flask import g, request from werkzeug.exceptions import BadRequest, Forbidden, NotFound from mwdb.core.capabilities import Capabilities from mwdb.core.config import app_config -from mwdb.core.deprecated import DeprecatedFeature, uses_deprecated_api from mwdb.core.plugins import hooks from mwdb.core.search import QueryBaseException, build_query from mwdb.core.service import Resource @@ -70,44 +67,19 @@ def create_object(self, params): else: parent_object = None - # Validate metakeys and Karton assignment - analysis_id = params.get("karton_id") - - if params["metakeys"]: - uses_deprecated_api(DeprecatedFeature.legacy_metakeys_upload_option) - # If 'metakeys' are defined: keep legacy behavior - if "attributes" in params and params["attributes"]: - raise BadRequest("'attributes' and 'metakeys' options can't be mixed") - - attributes = params["metakeys"] - for attribute in params["metakeys"]: - key = attribute["key"] - if key == "karton": - if analysis_id is not None: - raise BadRequest( - "You can't provide more than one Karton analysis identifier" - ) - try: - analysis_id = UUID(attribute["value"]) - except (ValueError, AttributeError): - raise BadRequest("'karton' attribute accepts only UUID values") - elif not AttributeDefinition.query_for_set(key).first(): - raise NotFound( - f"Attribute '{key}' not defined or insufficient " - "permissions to set that one" - ) - else: - # If not, rely on 'attributes' - attributes = params["attributes"] - for attribute in params["attributes"]: - key = attribute["key"] - if not AttributeDefinition.query_for_set(key).first(): - raise NotFound( - f"Attribute '{key}' not defined or insufficient " - "permissions to set that one" - ) - - if analysis_id is not None: + # If not, rely on 'attributes' + attributes = params["attributes"] + for attribute in params["attributes"]: + key = attribute["key"] + if not AttributeDefinition.query_for_set(key).first(): + raise NotFound( + f"Attribute '{key}' not defined or insufficient " + "permissions to set that one" + ) + + # Validate Karton assignment + karton_id = params.get("karton_id") + if karton_id is not None: if not g.auth_user.has_rights(Capabilities.karton_assign): raise Forbidden( "You are not permitted to assign Karton analysis to object" @@ -126,7 +98,7 @@ def create_object(self, params): parent_object, share_with, attributes, - analysis_id, + karton_id, tags, share_3rd_party, ) diff --git a/mwdb/schema/metakey.py b/mwdb/schema/metakey.py deleted file mode 100644 index c078ec056..000000000 --- a/mwdb/schema/metakey.py +++ /dev/null @@ -1,109 +0,0 @@ -import re - -from marshmallow import Schema, ValidationError, fields, pre_load, validates - - -class MetakeyKeySchema(Schema): - key = fields.Str(required=True, allow_none=False) - - @pre_load - def sanitize_key(self, params, **kwargs): - params = dict(params) - if params.get("key"): - params["key"] = params["key"].lower().strip() - return params - - @validates("key") - def validate_key(self, value): - if not re.match("^[A-Za-z0-9_-]{1,32}$", value): - raise ValidationError( - "Key should contain max 32 chars and include only letters, " - "digits, underscores and dashes" - ) - - -class MetakeyValueSchema(Schema): - value = fields.Str(required=True, allow_none=False) - - @validates("value") - def validate_value(self, value): - if not value: - raise ValidationError("Value shouldn't be empty") - - -class MetakeyListRequestSchema(Schema): - hidden = fields.Boolean(missing=False) - - -class MetakeyItemRequestSchema(MetakeyKeySchema, MetakeyValueSchema): - pass - - -class MetakeyItemRemoveRequestSchema(MetakeyKeySchema): - value = fields.Str(missing=None) - - -class MetakeyDefinitionItemRequestArgsSchema(MetakeyKeySchema): - pass - - -class MetakeyUpdateRequestSchema(Schema): - label = fields.Str(missing=None) - description = fields.Str(missing=None) - template = fields.Str(missing=None) - hidden = fields.Boolean(missing=None) - - -class MetakeyDefinitionItemRequestBodySchema(Schema): - template = fields.Str(attribute="url_template", required=True, allow_none=False) - label = fields.Str(required=True, allow_none=False) - description = fields.Str(required=True, allow_none=False) - hidden = fields.Boolean(required=True, allow_none=False) - - -class MetakeyPermissionSetRequestArgsSchema(MetakeyKeySchema): - group_name = fields.Str(required=True, allow_none=False) - - -class MetakeyPermissionSetRequestBodySchema(Schema): - can_read = fields.Boolean(required=True, allow_none=False) - can_set = fields.Boolean(required=True, allow_none=False) - - -class MetakeyItemResponseSchema(MetakeyKeySchema, MetakeyValueSchema): - url = fields.Str(required=True) - label = fields.Str(required=True) - description = fields.Str(required=True) - - -class MetakeyPermissionItemResponseSchema(Schema): - group_name = fields.Str(required=True, allow_none=False) - can_read = fields.Boolean(required=True, allow_none=False) - can_set = fields.Boolean(required=True, allow_none=False) - - -class MetakeyDefinitionItemResponseSchema(MetakeyKeySchema): - template = fields.Str(attribute="url_template", required=True, allow_none=False) - label = fields.Str(required=True, allow_none=False) - description = fields.Str(required=True, allow_none=False) - hidden = fields.Boolean(required=True, allow_none=False) - - -class MetakeyDefinitionManageItemResponseSchema(MetakeyKeySchema): - template = fields.Str(attribute="url_template", required=True, allow_none=False) - label = fields.Str(required=True, allow_none=False) - description = fields.Str(required=True, allow_none=False) - hidden = fields.Boolean(required=True, allow_none=False) - permissions = fields.Nested(MetakeyPermissionItemResponseSchema, many=True) - - -class MetakeyListResponseSchema(Schema): - metakeys = fields.Nested(MetakeyItemResponseSchema, many=True) - - -class MetakeyDefinitionListResponseSchema(Schema): - metakeys = fields.Nested(MetakeyDefinitionItemResponseSchema, many=True) - - -class MetakeyDefinitionManageListResponseSchema(Schema): - metakeys = fields.Nested(MetakeyDefinitionManageItemResponseSchema, many=True) diff --git a/mwdb/schema/object.py b/mwdb/schema/object.py index 198581f42..199c4da74 100644 --- a/mwdb/schema/object.py +++ b/mwdb/schema/object.py @@ -1,7 +1,6 @@ from marshmallow import Schema, fields, post_dump from .attribute import AttributeItemRequestSchema, AttributeItemResponseSchema -from .metakey import MetakeyItemRequestSchema from .tag import TagItemResponseSchema, TagRequestSchema from .utils import UTCDateTime @@ -18,7 +17,6 @@ class ObjectCountRequestSchema(Schema): class ObjectCreateRequestSchemaBase(Schema): parent = fields.Str(missing=None) - metakeys = fields.Nested(MetakeyItemRequestSchema, many=True, missing=[]) attributes = fields.Nested(AttributeItemRequestSchema, many=True, missing=[]) upload_as = fields.Str(missing="*", allow_none=False) karton_id = fields.UUID(missing=None) diff --git a/mwdb/templates/mwdb.ini.tmpl b/mwdb/templates/mwdb.ini.tmpl index adc117ca5..6ea01cc07 100644 --- a/mwdb/templates/mwdb.ini.tmpl +++ b/mwdb/templates/mwdb.ini.tmpl @@ -187,18 +187,7 @@ base_url = {{ base_url }} # kartonobject_post = # kartonanalysis_get = # kartonanalysis_put = -# metakey_get = -# metakey_post = -# metakey_delete = -# metakeylistdefinition_get = -# metakeylistdefinitionmanage_get = -# metakeydefinitionmanage_get = -# metakeydefinitionmanage_post = -# metakeydefinitionmanage_put = -# metakeydefinitionmanage_delete = -# metakeypermission_put = -# metakeypermission_delete = -# openidprovider_post = +# openidprovider_post = # openidsingleprovider_get = # openidsingleprovider_put = # openidsingleprovider_delete =