π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][locker] Restrict restore to one collection (#13990)
aman-pilot8a7320888676
diff --git a/mobile/apps/locker/changes/restore-single-collection.md b/mobile/apps/locker/changes/restore-single-collection.mdnew file mode 100644index 0000000000..47aa206468--- /dev/null+++ b/mobile/apps/locker/changes/restore-single-collection.md@@ -0,0 +1 @@+- Limited restore selection to one collection.diff --git a/mobile/apps/locker/lib/ui/components/add_to_collection_sheet.dart b/mobile/apps/locker/lib/ui/components/add_to_collection_sheet.dartindex ec8875448b..be73539313 100644--- a/mobile/apps/locker/lib/ui/components/add_to_collection_sheet.dart+++ b/mobile/apps/locker/lib/ui/components/add_to_collection_sheet.dart@@ -13,8 +13,13 @@ class AddToCollectionSheetResult {class AddToCollectionSheet extends StatefulWidget {final List<Collection> collections;+ final bool allowMultiple;- const AddToCollectionSheet({super.key, required this.collections});+ const AddToCollectionSheet({+ super.key,+ required this.collections,+ this.allowMultiple = true,+ });@overrideState<AddToCollectionSheet> createState() => _AddToCollectionSheetState();@@ -37,6 +42,7 @@ class _AddToCollectionSheetState extends State<AddToCollectionSheet> {if (_selectedCollectionIds.contains(collectionId)) {_selectedCollectionIds.remove(collectionId);} else {+ if (!widget.allowMultiple) _selectedCollectionIds.clear();_selectedCollectionIds.add(collectionId);}});@@ -84,9 +90,13 @@ class _AddToCollectionSheetState extends State<AddToCollectionSheet> {Future<AddToCollectionSheetResult?> showAddToCollectionSheet(BuildContext context, {required List<Collection> collections,+ bool allowMultiple = true,}) {return showBottomSheetComponent<AddToCollectionSheetResult>(context: context,- builder: (_) => AddToCollectionSheet(collections: collections),+ builder: (_) => AddToCollectionSheet(+ collections: collections,+ allowMultiple: allowMultiple,+ ),);}diff --git a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dartindex 800a6c9579..4d4d35976a 100644--- a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart+++ b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart@@ -853,6 +853,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {final result = await showAddToCollectionSheet(context,collections: dedupedCollections,+ allowMultiple: false,);if (result == null || result.selectedCollections.isEmpty) {diff --git a/mobile/apps/locker/test/ui/components/add_to_collection_sheet_test.dart b/mobile/apps/locker/test/ui/components/add_to_collection_sheet_test.dartnew file mode 100644index 0000000000..716d0e08a6--- /dev/null+++ b/mobile/apps/locker/test/ui/components/add_to_collection_sheet_test.dart@@ -0,0 +1,110 @@+import 'dart:io';++import 'package:ente_components/ente_components.dart';+import 'package:ente_sharing/models/user.dart';+import 'package:ente_strings/ente_strings.dart';+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:locker/services/collections/models/collection.dart';+import 'package:locker/services/configuration.dart';+import 'package:locker/ui/components/add_to_collection_sheet.dart';++import '../../test_utils/configuration_test_util.dart';++void main() {+ late Directory root;++ setUp(() async {+ root = await setupLockerConfigurationForTest('restore_picker');+ await Configuration.instance.setUserID(1);+ });++ tearDown(() async {+ clearLockerConfigurationTestHandlers();+ await root.delete(recursive: true);+ });++ for (final allowMultiple in [false, true]) {+ testWidgets(+ 'collection picker ${allowMultiple ? 'keeps multiple destinations by default' : 'replaces the restore destination'}',+ (tester) async {+ AddToCollectionSheetResult? result;+ final collections = [_collection(1, 'A'), _collection(2, 'B')];+ await tester.pumpWidget(+ MaterialApp(+ theme: ComponentTheme.lightTheme(app: ComponentApp.locker),+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: const [Locale('en')],+ home: Scaffold(+ body: Builder(+ builder: (context) => TextButton(+ onPressed: () async {+ result = allowMultiple+ ? await showAddToCollectionSheet(+ context,+ collections: collections,+ )+ : await showAddToCollectionSheet(+ context,+ collections: collections,+ allowMultiple: false,+ );+ },+ child: const Text('Open'),+ ),+ ),+ ),+ ),+ );+ await tester.tap(find.text('Open'));+ await tester.pumpAndSettle();+ expect(+ tester.widget<ButtonComponent>(find.byType(ButtonComponent)).onTap,+ isNull,+ );+ await tester.tap(find.text('A'));+ await tester.pumpAndSettle();+ await tester.tap(find.text('B'));+ await tester.pumpAndSettle();+ expect(+ tester+ .widgetList<TagChipComponent>(find.byType(TagChipComponent))+ .where((chip) => chip.state == TagChipComponentState.selected)+ .map((chip) => chip.label),+ allowMultiple ? ['A', 'B'] : ['B'],+ );+ if (!allowMultiple) {+ await tester.tap(find.text('B'));+ await tester.pumpAndSettle();+ expect(+ tester.widget<ButtonComponent>(find.byType(ButtonComponent)).onTap,+ isNull,+ );+ await tester.tap(find.text('B'));+ await tester.pumpAndSettle();+ }+ await tester.tap(find.text('Save'));+ await tester.pumpAndSettle();+ expect(+ result!.selectedCollections.map((c) => c.id),+ allowMultiple ? [1, 2] : [2],+ );+ },+ );+ }+}++Collection _collection(int id, String name) => Collection(+ id,+ User(id: 1, email: '[email protected]'),+ '',+ null,+ name,+ null,+ null,+ CollectionType.folder,+ CollectionAttributes(),+ const [],+ const [],+ 0,+);