Loading rpc/const.py +2 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ NO_PROJECT_ACCESS = "No access ({}) for project {}" NO_PROJECT_ID = "project_id is not set" NO_SUCH_COLLECTION = "no such collection" NO_SUCH_METADATASET = "no such metadatas set" NO_SUCH_METADATA = "no such metadata" NO_SUCH_METADATATYPE = "no such metadatatype" NO_SUCH_PROJECT = "no such project" NO_SUCH_RESOURCE = "no such resource" NO_PROJECT_ROOT = "project has no root" Loading rpc/methods.py +23 −15 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import os import re from glob import glob as _glob import unidecode from django.utils.timezone import now as _now from functools import wraps as _wraps Loading Loading @@ -217,7 +216,7 @@ def metadatas(user: User, metadata_set_id: int) -> List[Dict]: @_rpc_groups(["Metadatas"]) def metadata(user: User, metadata_id: int) -> Union[Dict, None]: def metadata(user: User, metadata_id: int) -> Dict: """ Get one particular metadata given its id. Loading @@ -241,7 +240,7 @@ def metadata(user: User, metadata_id: int) -> Union[Dict, None]: ) metadata_instance = query_set.first() if not metadata_instance: return None raise ServiceException(NO_SUCH_METADATA) return serializers.metadata(metadata_instance) Loading Loading @@ -346,7 +345,7 @@ def collections( @_rpc_groups(["Collections"]) def collection(user: User, collection_id: int) -> Union[Dict, None]: def collection(user: User, collection_id: int) -> Dict: """ Get a particular collection given its id. Loading Loading @@ -382,7 +381,7 @@ def collection(user: User, collection_id: int) -> Union[Dict, None]: @_rpc_groups(["Collections"]) def add_collection(user: User, title: str, parent_id: int) -> Union[Dict, None]: def add_collection(user: User, title: str, parent_id: int) -> Dict: """ Create a new collection based on 'title' and parent_id Loading Loading @@ -746,7 +745,7 @@ def resources( @_rpc_groups(["Resources"]) def resource(user: User, resource_id: int) -> Union[Dict, None]: def resource(user: User, resource_id: int) -> Dict: """ Get a resource given its id. Loading @@ -770,7 +769,7 @@ def resource(user: User, resource_id: int) -> Union[Dict, None]: ) resource_instance = query_set.first() if not resource_instance: return None raise ServiceException(NO_SUCH_RESOURCE) # if resource in a private collection and user has limiting access right, do not expose. public_only = _user_has_permission( user, resource_instance.ptr_project, PERM_COLLECTION_PUBLIC_ONLY Loading Loading @@ -1278,7 +1277,7 @@ def add_metadataset(user: User, title: str, project_id: int) -> int: @_rpc_groups(["Metadatas"]) def add_metadata( user: User, title: str, metas_set_id: int, metadata_type_id: int = None ) -> Union[int, bool]: ) -> int: """ Add a new metadata to metadata set. Loading @@ -1298,10 +1297,13 @@ def add_metadata( except ( MetadataSet.DoesNotExist, MetadataSet.MultipleObjectsReturned, ): raise ServiceException(NO_SUCH_METADATASET) except ( MetadataType.DoesNotExist, MetadataType.MultipleObjectsReturned, ): return False raise ServiceException(NO_SUCH_METADATATYPE) @_rpc_groups(["Metadatas", "Resources"]) Loading Loading @@ -1420,12 +1422,12 @@ def set_metas_to_collection( @_rpc_groups(["Metadatas", "Resources"]) def add_meta_to_resource( user: User, resource_id: int, meta_id: int, meta_value: str ) -> Union[int, bool]: ) -> int: """ Add a meta value to a resource given their ids. """ if meta_value == "" or meta_value is None: return False raise ServiceException(WRONG_ARGUMENT) try: resource_instance = Resource.objects.get( pk=resource_id, Loading @@ -1450,10 +1452,13 @@ def add_meta_to_resource( except ( Resource.DoesNotExist, Resource.MultipleObjectsReturned, ): raise ServiceException(NO_SUCH_RESOURCE) except ( Metadata.DoesNotExist, Metadata.MultipleObjectsReturned, ): return False raise ServiceException(NO_SUCH_METADATA) @_rpc_groups(["Deprecated"]) Loading Loading @@ -1490,7 +1495,7 @@ def remove_meta_value_from_collection( @_rpc_groups(["Metadatas", "Collections"]) def add_meta_to_collection( user: User, collection_id: int, meta_id: int, meta_value: str, cascade: bool = False ) -> Union[int, bool]: ) -> int: """ Add a meta value to a collection given their ids. Loading @@ -1498,7 +1503,7 @@ def add_meta_to_collection( collections and resources alike. """ if meta_value == "" or meta_value is None: return False raise ServiceException(WRONG_ARGUMENT) try: collection_instance = Collection.objects.get( pk=collection_id, Loading Loading @@ -1530,10 +1535,13 @@ def add_meta_to_collection( except ( Collection.DoesNotExist, Collection.MultipleObjectsReturned, ): raise ServiceException(NO_SUCH_COLLECTION) except ( Metadata.DoesNotExist, Metadata.MultipleObjectsReturned, ): return False raise ServiceException(NO_SUCH_METADATA) @_rpc_groups(["Metadatas", "Collections"]) Loading Loading
rpc/const.py +2 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ NO_PROJECT_ACCESS = "No access ({}) for project {}" NO_PROJECT_ID = "project_id is not set" NO_SUCH_COLLECTION = "no such collection" NO_SUCH_METADATASET = "no such metadatas set" NO_SUCH_METADATA = "no such metadata" NO_SUCH_METADATATYPE = "no such metadatatype" NO_SUCH_PROJECT = "no such project" NO_SUCH_RESOURCE = "no such resource" NO_PROJECT_ROOT = "project has no root" Loading
rpc/methods.py +23 −15 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import os import re from glob import glob as _glob import unidecode from django.utils.timezone import now as _now from functools import wraps as _wraps Loading Loading @@ -217,7 +216,7 @@ def metadatas(user: User, metadata_set_id: int) -> List[Dict]: @_rpc_groups(["Metadatas"]) def metadata(user: User, metadata_id: int) -> Union[Dict, None]: def metadata(user: User, metadata_id: int) -> Dict: """ Get one particular metadata given its id. Loading @@ -241,7 +240,7 @@ def metadata(user: User, metadata_id: int) -> Union[Dict, None]: ) metadata_instance = query_set.first() if not metadata_instance: return None raise ServiceException(NO_SUCH_METADATA) return serializers.metadata(metadata_instance) Loading Loading @@ -346,7 +345,7 @@ def collections( @_rpc_groups(["Collections"]) def collection(user: User, collection_id: int) -> Union[Dict, None]: def collection(user: User, collection_id: int) -> Dict: """ Get a particular collection given its id. Loading Loading @@ -382,7 +381,7 @@ def collection(user: User, collection_id: int) -> Union[Dict, None]: @_rpc_groups(["Collections"]) def add_collection(user: User, title: str, parent_id: int) -> Union[Dict, None]: def add_collection(user: User, title: str, parent_id: int) -> Dict: """ Create a new collection based on 'title' and parent_id Loading Loading @@ -746,7 +745,7 @@ def resources( @_rpc_groups(["Resources"]) def resource(user: User, resource_id: int) -> Union[Dict, None]: def resource(user: User, resource_id: int) -> Dict: """ Get a resource given its id. Loading @@ -770,7 +769,7 @@ def resource(user: User, resource_id: int) -> Union[Dict, None]: ) resource_instance = query_set.first() if not resource_instance: return None raise ServiceException(NO_SUCH_RESOURCE) # if resource in a private collection and user has limiting access right, do not expose. public_only = _user_has_permission( user, resource_instance.ptr_project, PERM_COLLECTION_PUBLIC_ONLY Loading Loading @@ -1278,7 +1277,7 @@ def add_metadataset(user: User, title: str, project_id: int) -> int: @_rpc_groups(["Metadatas"]) def add_metadata( user: User, title: str, metas_set_id: int, metadata_type_id: int = None ) -> Union[int, bool]: ) -> int: """ Add a new metadata to metadata set. Loading @@ -1298,10 +1297,13 @@ def add_metadata( except ( MetadataSet.DoesNotExist, MetadataSet.MultipleObjectsReturned, ): raise ServiceException(NO_SUCH_METADATASET) except ( MetadataType.DoesNotExist, MetadataType.MultipleObjectsReturned, ): return False raise ServiceException(NO_SUCH_METADATATYPE) @_rpc_groups(["Metadatas", "Resources"]) Loading Loading @@ -1420,12 +1422,12 @@ def set_metas_to_collection( @_rpc_groups(["Metadatas", "Resources"]) def add_meta_to_resource( user: User, resource_id: int, meta_id: int, meta_value: str ) -> Union[int, bool]: ) -> int: """ Add a meta value to a resource given their ids. """ if meta_value == "" or meta_value is None: return False raise ServiceException(WRONG_ARGUMENT) try: resource_instance = Resource.objects.get( pk=resource_id, Loading @@ -1450,10 +1452,13 @@ def add_meta_to_resource( except ( Resource.DoesNotExist, Resource.MultipleObjectsReturned, ): raise ServiceException(NO_SUCH_RESOURCE) except ( Metadata.DoesNotExist, Metadata.MultipleObjectsReturned, ): return False raise ServiceException(NO_SUCH_METADATA) @_rpc_groups(["Deprecated"]) Loading Loading @@ -1490,7 +1495,7 @@ def remove_meta_value_from_collection( @_rpc_groups(["Metadatas", "Collections"]) def add_meta_to_collection( user: User, collection_id: int, meta_id: int, meta_value: str, cascade: bool = False ) -> Union[int, bool]: ) -> int: """ Add a meta value to a collection given their ids. Loading @@ -1498,7 +1503,7 @@ def add_meta_to_collection( collections and resources alike. """ if meta_value == "" or meta_value is None: return False raise ServiceException(WRONG_ARGUMENT) try: collection_instance = Collection.objects.get( pk=collection_id, Loading Loading @@ -1530,10 +1535,13 @@ def add_meta_to_collection( except ( Collection.DoesNotExist, Collection.MultipleObjectsReturned, ): raise ServiceException(NO_SUCH_COLLECTION) except ( Metadata.DoesNotExist, Metadata.MultipleObjectsReturned, ): return False raise ServiceException(NO_SUCH_METADATA) @_rpc_groups(["Metadatas", "Collections"]) Loading