Loading rpc/cache.py +0 −1 Original line number Diff line number Diff line Loading @@ -23,5 +23,4 @@ class SerializerCache: self._cache_dict[cache_key] = models.FileType.objects.get(pk=obj_id) else: raise ValueError("unsupported object type: {}".format(obj_type)) print("cache size: {}".format(len(self._cache_dict))) return self._cache_dict.get(cache_key) rpc/const.py +1 −0 Original line number Diff line number Diff line Loading @@ -37,3 +37,4 @@ SUPERUSER_NEEDED = "only for superusers" TOO_MANY_SEARCH_TERMS = "Too many search terms." WRONG_ARGUMENT = "wrong argument" NO_FOOTGUNS = "Can't shoot your own foot" PROJECT_MISMATCH = "Can't mix items from different collections" rpc/methods.py +34 −6 Original line number Diff line number Diff line Loading @@ -59,9 +59,12 @@ def _log_call(func): @_wraps(func) def wrapper(*args, **kwargs): print(func) print(args) print(kwargs) if settings.DEBUG: print( 'RPC method "{}", called by {} (user #{}) with params {}.'.format( func.__name__, args[0].username, args[0].pk, args[1:] ) ) return func(*args, **kwargs) return wrapper Loading Loading @@ -2556,16 +2559,41 @@ def recycle_bin(user: User, project_id: int) -> List[Dict]: @_log_call @_rpc_groups(["Resources"]) def restore_resource(user: User, resource_id: int) -> bool: def restore_resource( user: User, resource_id: int, destination_collection_id: int ) -> bool: """ Restore a deleted resource from the recycle bin """ pass resource_instance = Resource.objects.filter(pk=resource_id).first() if not resource_instance: raise ServiceException(NO_SUCH_RESOURCE) destination_collection_instance = Collection.objects.filter( pk=destination_collection_id ).first() if not destination_collection_instance: raise ServiceException(NO_SUCH_COLLECTION) if resource_instance.ptr_project_id != destination_collection_instance.project_id: raise ServiceException(PROJECT_MISMATCH) _check_project_permission(user, resource_instance.ptr_project, PERM_RESOURCE_UPDATE) _check_project_permission( user, destination_collection_instance.project, PERM_COLLECTION_UPDATE ) resource_instance.deleted_at = None resource_instance.save() for old_collection in resource_instance.collections.all(): remove_resource_from_collection(user, resource_instance.pk, old_collection.pk) add_resource_to_collection( user, resource_instance.pk, destination_collection_instance.pk ) return True @_log_call @_rpc_groups(["Collections"]) def restore_collection(user: User, collection_id: int) -> bool: def restore_collection( user: User, collection_id: int, destination_collection_id: int ) -> bool: """ Restore a deleted collection from the recycle bin """ Loading rpc/views.py +1 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ def _debug_sql(): print("#--- End PostgreSQL Queries ({} queries) ---#".format(req_count)) if has_doubled_queries: print("") print("#--- Doubles ---#") print("Queries being doubled:") print("") for k, v in req_mult_count.items(): if v > 1: Loading Loading
rpc/cache.py +0 −1 Original line number Diff line number Diff line Loading @@ -23,5 +23,4 @@ class SerializerCache: self._cache_dict[cache_key] = models.FileType.objects.get(pk=obj_id) else: raise ValueError("unsupported object type: {}".format(obj_type)) print("cache size: {}".format(len(self._cache_dict))) return self._cache_dict.get(cache_key)
rpc/const.py +1 −0 Original line number Diff line number Diff line Loading @@ -37,3 +37,4 @@ SUPERUSER_NEEDED = "only for superusers" TOO_MANY_SEARCH_TERMS = "Too many search terms." WRONG_ARGUMENT = "wrong argument" NO_FOOTGUNS = "Can't shoot your own foot" PROJECT_MISMATCH = "Can't mix items from different collections"
rpc/methods.py +34 −6 Original line number Diff line number Diff line Loading @@ -59,9 +59,12 @@ def _log_call(func): @_wraps(func) def wrapper(*args, **kwargs): print(func) print(args) print(kwargs) if settings.DEBUG: print( 'RPC method "{}", called by {} (user #{}) with params {}.'.format( func.__name__, args[0].username, args[0].pk, args[1:] ) ) return func(*args, **kwargs) return wrapper Loading Loading @@ -2556,16 +2559,41 @@ def recycle_bin(user: User, project_id: int) -> List[Dict]: @_log_call @_rpc_groups(["Resources"]) def restore_resource(user: User, resource_id: int) -> bool: def restore_resource( user: User, resource_id: int, destination_collection_id: int ) -> bool: """ Restore a deleted resource from the recycle bin """ pass resource_instance = Resource.objects.filter(pk=resource_id).first() if not resource_instance: raise ServiceException(NO_SUCH_RESOURCE) destination_collection_instance = Collection.objects.filter( pk=destination_collection_id ).first() if not destination_collection_instance: raise ServiceException(NO_SUCH_COLLECTION) if resource_instance.ptr_project_id != destination_collection_instance.project_id: raise ServiceException(PROJECT_MISMATCH) _check_project_permission(user, resource_instance.ptr_project, PERM_RESOURCE_UPDATE) _check_project_permission( user, destination_collection_instance.project, PERM_COLLECTION_UPDATE ) resource_instance.deleted_at = None resource_instance.save() for old_collection in resource_instance.collections.all(): remove_resource_from_collection(user, resource_instance.pk, old_collection.pk) add_resource_to_collection( user, resource_instance.pk, destination_collection_instance.pk ) return True @_log_call @_rpc_groups(["Collections"]) def restore_collection(user: User, collection_id: int) -> bool: def restore_collection( user: User, collection_id: int, destination_collection_id: int ) -> bool: """ Restore a deleted collection from the recycle bin """ Loading
rpc/views.py +1 −1 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ def _debug_sql(): print("#--- End PostgreSQL Queries ({} queries) ---#".format(req_count)) if has_doubled_queries: print("") print("#--- Doubles ---#") print("Queries being doubled:") print("") for k, v in req_mult_count.items(): if v > 1: Loading