Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

[mob] Allow admins to remove photos

Neeraj Gupta13419a7f664f
diff --git a/mobile/apps/photos/lib/l10n/intl_el.arb b/mobile/apps/photos/lib/l10n/intl_el.arb
index c1db76f74d..c806f9f21c 100644
--- a/mobile/apps/photos/lib/l10n/intl_el.arb
+++ b/mobile/apps/photos/lib/l10n/intl_el.arb
@@ -197,7 +197,7 @@
"publicLinkEnabled": "Ο δημόσιος σύνδεσμος ενεργοποιήθηκε",
"shareALink": "Μοιραστείτε έναν σύνδεσμο",
"sharedAlbumSectionDescription": "Δημιουργία κοινόχρηστων και συνεργατικών άλμπουμ με άλλους χρήστες Ente, συμπεριλαμβανομένων των χρηστών με δωρεάν συνδρομή.",
- "shareWithPeopleSectionTitle": "{numberOfPeople, plural, one {}=0 {Μοιραστείτε με συγκεκριμένους ανθρώπους} =1 {Μοιραστείτε με 1 άτομο} other {Μοιραστείτε με {numberOfPeople} άτομα}}",
+ "shareWithPeopleSectionTitle": "{numberOfPeople, plural, =0 {Μοιραστείτε με συγκεκριμένους ανθρώπους} =1 {Μοιραστείτε με 1 άτομο} other {Μοιραστείτε με {numberOfPeople} άτομα}}",
"@shareWithPeopleSectionTitle": {
"placeholders": {
"numberOfPeople": {
@@ -1179,4 +1179,4 @@
},
"videoStreaming": "Βίντεο με υποστήριξη μετάδοσης",
"processingVideos": "Επεξεργασία βίντεο"
-}
\ No newline at end of file
+}
diff --git a/mobile/apps/photos/lib/models/collection/collection.dart b/mobile/apps/photos/lib/models/collection/collection.dart
index 38b3350ffb..604e650ba5 100644
--- a/mobile/apps/photos/lib/models/collection/collection.dart
+++ b/mobile/apps/photos/lib/models/collection/collection.dart
@@ -140,6 +140,10 @@ class Collection {
return (owner.id ?? -100) == userID;
}
+ bool isAdmin(int userID) {
+ return getRole(userID) == CollectionParticipantRole.admin;
+ }
+
bool canAutoAdd(int userID) {
final participantRole = getRole(userID);
final canEditCollection = isOwner(userID) ||
diff --git a/mobile/apps/photos/lib/services/collections_service.dart b/mobile/apps/photos/lib/services/collections_service.dart
index 43ada6c5e7..44da931cfb 100644
--- a/mobile/apps/photos/lib/services/collections_service.dart
+++ b/mobile/apps/photos/lib/services/collections_service.dart
@@ -401,6 +401,20 @@ class CollectionsService {
.toList();
}
+ bool canRemoveFilesFromAllParticipants(Collection collection) {
+ final int? userID = _config.getUserID();
+ if (userID == null) {
+ return false;
+ }
+ if (collection.isOwner(userID)) {
+ return true;
+ }
+ if (!flagService.enableAdminRole) {
+ return false;
+ }
+ return collection.isAdmin(userID);
+ }
+
List<int> getAllOwnedCollectionIDs() {
final int userID = _config.getUserID()!;
return _collectionIDToCollections.values
diff --git a/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart b/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
index ed9c229d65..91aaaafa1b 100644
--- a/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
+++ b/mobile/apps/photos/lib/ui/actions/collection/collection_sharing_actions.dart
@@ -583,10 +583,26 @@ class CollectionActions {
}) async {
final int currentUserID = Configuration.instance.getUserID()!;
final isCollectionOwner = collection.owner.id == currentUserID;
+ final bool canRemoveAllParticipants =
+ collectionsService.canRemoveFilesFromAllParticipants(collection);
+ final bool isCollectionAdmin = canRemoveAllParticipants && !isCollectionOwner;
final FilesSplit split = FilesSplit.split(
files,
Configuration.instance.getUserID()!,
);
+ if (isCollectionAdmin) {
+ final filesToRemove = <EnteFile>[
+ ...split.ownedByCurrentUser,
+ ...split.ownedByOtherUsers,
+ ];
+ if (filesToRemove.isNotEmpty) {
+ await collectionsService.removeFromCollection(
+ collection.id,
+ filesToRemove,
+ );
+ }
+ return;
+ }
if (isCollectionOwner && split.ownedByOtherUsers.isNotEmpty) {
await collectionsService.removeFromCollection(
collection.id,
diff --git a/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart b/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
index ea485a0235..a2590afed0 100644
--- a/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
+++ b/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
@@ -505,7 +505,7 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
}) {
if (mounted) {
if (Navigator.of(context).canPop()) {
- Navigator.of(context).pop(ButtonResult(widget.buttonAction, exception));
+ Navigator.of(context).pop(ButtonResult(buttonAction, exception));
} else if (exception != null) {
//This is to show the execution was unsuccessful if the dialog is manually
//closed before the execution completes.
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
index f41e4770b0..1aa4c82e59 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
@@ -78,7 +78,6 @@ class _FileSelectionActionsWidgetState
late int currentUserID;
late FilesSplit split;
late CollectionActions collectionActions;
- late bool isCollectionOwner;
final ScreenshotController screenshotController = ScreenshotController();
late Uint8List placeholderBytes;
// _cachedCollectionForSharedLink is primarily used to avoid creating duplicate
@@ -90,6 +89,11 @@ class _FileSelectionActionsWidgetState
final StreamController<double> _progressController =
StreamController<double>();
+ bool get _canRemoveOthersFiles =>
+ widget.collection != null &&
+ CollectionsService.instance
+ .canRemoveFilesFromAllParticipants(widget.collection!);
+
@override
void initState() {
super.initState();
@@ -99,8 +103,6 @@ class _FileSelectionActionsWidgetState
split = FilesSplit.split(<EnteFile>[], currentUserID);
widget.selectedFiles.addListener(_selectFileChangeListener);
collectionActions = CollectionActions(CollectionsService.instance);
- isCollectionOwner =
- widget.collection != null && widget.collection!.isOwner(currentUserID);
if (widget.selectedFiles.files.isNotEmpty) {
_selectFileChangeListener();
}
@@ -131,8 +133,9 @@ class _FileSelectionActionsWidgetState
final ownedFilesCount = split.ownedByCurrentUser.length;
final ownedAndPendingUploadFilesCount =
ownedFilesCount + split.pendingUploads.length;
+ final bool canRemoveOthersFiles = _canRemoveOthersFiles;
final int removeCount = split.ownedByCurrentUser.length +
- (isCollectionOwner ? split.ownedByOtherUsers.length : 0);
+ (canRemoveOthersFiles ? split.ownedByOtherUsers.length : 0);
final bool anyOwnedFiles =
split.pendingUploads.isNotEmpty || split.ownedByCurrentUser.isNotEmpty;
@@ -576,12 +579,12 @@ class _FileSelectionActionsWidgetState
widget.selectedFiles
.unSelectAll(split.pendingUploads.toSet(), skipNotify: true);
}
- if (!isCollectionOwner && split.ownedByOtherUsers.isNotEmpty) {
+ if (!_canRemoveOthersFiles && split.ownedByOtherUsers.isNotEmpty) {
widget.selectedFiles
.unSelectAll(split.ownedByOtherUsers.toSet(), skipNotify: true);
}
final bool removingOthersFile =
- isCollectionOwner && split.ownedByOtherUsers.isNotEmpty;
+ _canRemoveOthersFiles && split.ownedByOtherUsers.isNotEmpty;
await collectionActions.showRemoveFromCollectionSheetV2(
context,
widget.collection!,