From 206ab1114e4137b091207a7f20bb532da7449b4c Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 22 Apr 2024 11:23:04 +0530 Subject: [PATCH] [mob]Discard upload to deleted or others collection --- mobile/lib/services/collections_service.dart | 17 +++++++++++++++++ mobile/lib/utils/file_uploader.dart | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/mobile/lib/services/collections_service.dart b/mobile/lib/services/collections_service.dart index 8b82f6576..0716ea18e 100644 --- a/mobile/lib/services/collections_service.dart +++ b/mobile/lib/services/collections_service.dart @@ -189,6 +189,23 @@ class CollectionsService { return result; } + bool allowUpload(int collectionID) { + final Collection? c = _collectionIDToCollections[collectionID]; + if (c == null) { + _logger.info('discardUpload: collectionMissing $collectionID'); + return false; + } + if (c.isDeleted) { + _logger.info('discardUpload: collectionDeleted $collectionID'); + return false; + } + if (!c.isOwner(_config.getUserID()!)) { + _logger.info('discardUpload: notOwner $collectionID'); + return false; + } + return true; + } + Future> getArchivedCollection() async { final allCollections = getCollectionsForUI(); return allCollections diff --git a/mobile/lib/utils/file_uploader.dart b/mobile/lib/utils/file_uploader.dart index ec77b035a..d77bc95d7 100644 --- a/mobile/lib/utils/file_uploader.dart +++ b/mobile/lib/utils/file_uploader.dart @@ -401,6 +401,16 @@ class FileUploader { _logger.severe('Trying to upload file with missing localID'); return file; } + if (!CollectionsService.instance.allowUpload(collectionID)) { + _logger.warning( + 'Upload not allowed for collection $collectionID', + ); + if (!file.isUploaded && file.generatedID != null) { + _logger.info("Deleting file entry for " + file.toString()); + await FilesDB.instance.deleteByGeneratedID(file.generatedID!); + } + return file; + } final String lockKey = file.localID!;