π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web][mobile] Allow adding admins
Neeraj Gupta8d3498255736
diff --git a/mobile/apps/photos/lib/models/api/collection/user.dart b/mobile/apps/photos/lib/models/api/collection/user.dartindex 30785b0504..d52c417169 100644--- a/mobile/apps/photos/lib/models/api/collection/user.dart+++ b/mobile/apps/photos/lib/models/api/collection/user.dart@@ -22,6 +22,8 @@ class User {bool get isCollaborator =>role != null && role?.toUpperCase() == 'COLLABORATOR';+ bool get isAdmin => role != null && role?.toUpperCase() == 'ADMIN';+Map<String, dynamic> toMap() {// ignore: deprecated_member_use_from_same_packagereturn {'id': id, 'email': email, 'name': name, "role": role};diff --git a/mobile/apps/photos/lib/models/collection/collection.dart b/mobile/apps/photos/lib/models/collection/collection.dartindex 7e9743e818..38b3350ffb 100644--- a/mobile/apps/photos/lib/models/collection/collection.dart+++ b/mobile/apps/photos/lib/models/collection/collection.dart@@ -141,8 +141,10 @@ class Collection {}bool canAutoAdd(int userID) {+ final participantRole = getRole(userID);final canEditCollection = isOwner(userID) ||- getRole(userID) == CollectionParticipantRole.collaborator;+ participantRole == CollectionParticipantRole.collaborator ||+ participantRole == CollectionParticipantRole.admin;final isFavoritesOrUncategorized = type == CollectionType.favorites ||type == CollectionType.uncategorized;return canEditCollection && !isDeleted && !isFavoritesOrUncategorized;@@ -178,10 +180,12 @@ class Collection {}for (final User u in sharees) {if (u.id == userID) {- if (u.isViewer) {- return CollectionParticipantRole.viewer;+ if (u.isAdmin) {+ return CollectionParticipantRole.admin;} else if (u.isCollaborator) {return CollectionParticipantRole.collaborator;+ } else if (u.isViewer) {+ return CollectionParticipantRole.viewer;}}}@@ -324,6 +328,7 @@ enum CollectionParticipantRole {unknown,viewer,collaborator,+ admin,owner,}diff --git a/mobile/apps/photos/lib/models/gallery_type.dart b/mobile/apps/photos/lib/models/gallery_type.dartindex 7afaf0433a..2677373e53 100644--- a/mobile/apps/photos/lib/models/gallery_type.dart+++ b/mobile/apps/photos/lib/models/gallery_type.dart@@ -304,7 +304,9 @@ extension GalleryAppBarExtn on GalleryType {return true;}if (this == GalleryType.sharedCollection) {- return c?.getRole(userID) == CollectionParticipantRole.collaborator;+ final role = c?.getRole(userID);+ return role == CollectionParticipantRole.collaborator ||+ role == CollectionParticipantRole.admin;}return false;}diff --git a/mobile/apps/photos/lib/services/account/user_service.dart b/mobile/apps/photos/lib/services/account/user_service.dartindex 3543aa4cc7..90887a330e 100644--- a/mobile/apps/photos/lib/services/account/user_service.dart+++ b/mobile/apps/photos/lib/services/account/user_service.dart@@ -1385,9 +1385,11 @@ class UserService {if (u.id != null &&u.email.isNotEmpty &&u.email == ownerEmail &&- (u.isCollaborator || u.isViewer)) {+ (u.isAdmin || u.isCollaborator || u.isViewer)) {for (final User u in c.sharees) {- if (u.id != null && u.email.isNotEmpty && u.isCollaborator) {+ if (u.id != null &&+ u.email.isNotEmpty &&+ (u.isCollaborator || u.isAdmin)) {if (!existingEmails.contains(u.email)) {relevantUsers.add(u);existingEmails.add(u.email);@@ -1460,9 +1462,11 @@ class UserService {if (u.id != null &&u.email.isNotEmpty &&u.email == ownerEmail &&- (u.isCollaborator || u.isViewer)) {+ (u.isAdmin || u.isCollaborator || u.isViewer)) {for (final User u in c.sharees) {- if (u.id != null && u.email.isNotEmpty && u.isCollaborator) {+ if (u.id != null &&+ u.email.isNotEmpty &&+ (u.isCollaborator || u.isAdmin)) {if (!emailIDs.contains(u.email)) {emailIDs.add(u.email);}diff --git a/mobile/apps/photos/lib/services/collections_service.dart b/mobile/apps/photos/lib/services/collections_service.dartindex b1b6868492..811d924502 100644--- a/mobile/apps/photos/lib/services/collections_service.dart+++ b/mobile/apps/photos/lib/services/collections_service.dart@@ -386,6 +386,7 @@ class CollectionsService {}if (includedShared || includeCollab) {allowedRoles.add(CollectionParticipantRole.collaborator);+ allowedRoles.add(CollectionParticipantRole.admin);}final int userID = _config.getUserID()!;return _collectionIDToCollections.valuesdiff --git a/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart b/mobile/apps/photos/lib/ui/sharing/add_participant_page.dartindex e536891ad2..e923c8dcc4 100644--- a/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart+++ b/mobile/apps/photos/lib/ui/sharing/add_participant_page.dart@@ -23,6 +23,7 @@ import "package:photos/utils/separators_util.dart";enum ActionTypesToShow {addViewer,addCollaborator,+ addAdmin,}class AddParticipantPage extends StatefulWidget {@@ -242,37 +243,34 @@ class _AddParticipantPage extends State<AddParticipantPage> {List<Widget> _actionButtons() {final widgets = <Widget>[];- if (widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)) {+ if (widget.actionTypesToShow.contains(ActionTypesToShow.addAdmin)) {widgets.add(ButtonWidget(- buttonType: ButtonType.primary,+ buttonType: widget.actionTypesToShow.length == 1+ ? ButtonType.primary+ : ButtonType.neutral,buttonSize: ButtonSize.large,- labelText: AppLocalizations.of(context)- .addViewers(count: _selectedEmails.length),+ labelText: _adminActionLabel(_selectedEmails.length),isDisabled: _selectedEmails.isEmpty,onTap: () async {final results = <bool>[];final collections = widget.collections;- for (String email in _selectedEmails) {+ for (final email in _selectedEmails) {bool result = false;- for (Collection collection in collections) {+ for (final collection in collections) {result = await collectionActions.addEmailToCollection(context,collection,email,- CollectionParticipantRole.viewer,+ CollectionParticipantRole.admin,);}results.add(result);}- final noOfSuccessfullAdds = results.where((e) => e).length;- showToast(- context,- AppLocalizations.of(context)- .viewersSuccessfullyAdded(count: noOfSuccessfullAdds),- );+ final successful = results.where((e) => e).length;+ showToast(context, _adminSuccessMessage(successful));if (!results.any((e) => e == false) && mounted) {Navigator.of(context).pop(true);@@ -329,6 +327,81 @@ class _AddParticipantPage extends State<AddParticipantPage> {),);}+ if (widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)) {+ widgets.add(+ ButtonWidget(+ buttonType: ButtonType.primary,+ buttonSize: ButtonSize.large,+ labelText: AppLocalizations.of(context)+ .addViewers(count: _selectedEmails.length),+ isDisabled: _selectedEmails.isEmpty,+ onTap: () async {+ final results = <bool>[];+ final collections = widget.collections;++ for (final email in _selectedEmails) {+ bool result = false;+ for (final collection in collections) {+ result = await collectionActions.addEmailToCollection(+ context,+ collection,+ email,+ CollectionParticipantRole.viewer,+ );+ }+ results.add(result);+ }++ final noOfSuccessfullAdds = results.where((e) => e).length;+ showToast(+ context,+ AppLocalizations.of(context)+ .viewersSuccessfullyAdded(count: noOfSuccessfullAdds),+ );++ if (!results.any((e) => e == false) && mounted) {+ Navigator.of(context).pop(true);+ }+ },+ ),+ );+ }+ if (widget.actionTypesToShow.contains(ActionTypesToShow.addAdmin)) {+ widgets.add(+ ButtonWidget(+ buttonType: widget.actionTypesToShow.length == 1+ ? ButtonType.primary+ : ButtonType.neutral,+ buttonSize: ButtonSize.large,+ labelText: _adminActionLabel(_selectedEmails.length),+ isDisabled: _selectedEmails.isEmpty,+ onTap: () async {+ final results = <bool>[];+ final collections = widget.collections;++ for (final email in _selectedEmails) {+ bool result = false;+ for (final collection in collections) {+ result = await collectionActions.addEmailToCollection(+ context,+ collection,+ email,+ CollectionParticipantRole.admin,+ );+ }+ results.add(result);+ }++ final successful = results.where((e) => e).length;+ showToast(context, _adminSuccessMessage(successful));++ if (!results.any((e) => e == false) && mounted) {+ Navigator.of(context).pop(true);+ }+ },+ ),+ );+ }final widgetsWithSpaceBetween = addSeparators(widgets,const SizedBox(@@ -437,6 +510,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {if (collections.isEmpty) {return [];}+ final Set<String> ownerEmails = {};for (final Collection collection in collections) {for (final User u in collection.sharees) {@@ -444,6 +518,11 @@ class _AddParticipantPage extends State<AddParticipantPage> {existingEmails.add(u.email);}}+ final ownerEmail = collection.owner.email;+ if (ownerEmail.isNotEmpty) {+ ownerEmails.add(ownerEmail);+ existingEmails.add(ownerEmail);+ }}final List<User> suggestedUsers = UserService.instance.getRelevantContacts()@@ -458,6 +537,9 @@ class _AddParticipantPage extends State<AddParticipantPage> {.contains(_textController.text.trim().toLowerCase()),);}+ suggestedUsers.removeWhere(+ (element) => ownerEmails.contains(element.email),+ );suggestedUsers.sort((a, b) => a.email.compareTo(b.email));return suggestedUsers;@@ -466,10 +548,29 @@ class _AddParticipantPage extends State<AddParticipantPage> {String _getTitle() {if (widget.actionTypesToShow.length > 1) {return AppLocalizations.of(context).addParticipants;- } else if (widget.actionTypesToShow.first == ActionTypesToShow.addViewer) {- return AppLocalizations.of(context).addViewer;- } else {- return AppLocalizations.of(context).addCollaborator;}+ switch (widget.actionTypesToShow.first) {+ case ActionTypesToShow.addViewer:+ return AppLocalizations.of(context).addViewer;+ case ActionTypesToShow.addCollaborator:+ return AppLocalizations.of(context).addCollaborator;+ case ActionTypesToShow.addAdmin:+ return _adminTitle();+ }+ }++ String _adminActionLabel(int count) =>+ count == 1 ? "Add admin" : "Add admins";++ String _adminSuccessMessage(int count) {+ if (count == 0) {+ return "No admins were added";+ }+ if (count == 1) {+ return "1 admin successfully added";+ }+ return "$count admins successfully added";}++ String _adminTitle() => "Add admin";}diff --git a/mobile/apps/photos/lib/ui/sharing/album_participants_page.dart b/mobile/apps/photos/lib/ui/sharing/album_participants_page.dartindex 8c7b608506..44195b7ff7 100644--- a/mobile/apps/photos/lib/ui/sharing/album_participants_page.dart+++ b/mobile/apps/photos/lib/ui/sharing/album_participants_page.dart@@ -1,10 +1,10 @@import 'package:flutter/material.dart';import 'package:photos/core/configuration.dart';-import 'package:photos/extensions/list.dart';import "package:photos/extensions/user_extension.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/api/collection/user.dart";import 'package:photos/models/collection/collection.dart';+import 'package:photos/service_locator.dart';import 'package:photos/theme/ente_theme.dart';import 'package:photos/ui/components/captioned_text_widget.dart';import 'package:photos/ui/components/divider_widget.dart';@@ -20,10 +20,7 @@ import 'package:photos/utils/navigation_util.dart';class AlbumParticipantsPage extends StatefulWidget {final Collection collection;- const AlbumParticipantsPage(- this.collection, {- super.key,- });+ const AlbumParticipantsPage(this.collection, {super.key});@overrideState<AlbumParticipantsPage> createState() => _AlbumParticipantsPageState();@@ -51,15 +48,10 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {}}- Future<void> _navigateToAddUser(bool addingViewer) async {+ Future<void> _navigateToAddUser(List<ActionTypesToShow> actions) async {await routeToPage(context,- AddParticipantPage(- [widget.collection],- addingViewer- ? [ActionTypesToShow.addViewer]- : [ActionTypesToShow.addCollaborator],- ),+ AddParticipantPage([widget.collection], actions),);if (mounted) {setState(() => {});@@ -68,21 +60,56 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {@overrideWidget build(BuildContext context) {- final isOwner =- widget.collection.owner.id == Configuration.instance.getUserID();- final colorScheme = getEnteColorScheme(context);final currentUserID = Configuration.instance.getUserID()!;+ final role = widget.collection.getRole(currentUserID);+ final bool adminRoleEnabled = flagService.enableAdminRole;+ final bool isOwner = role == CollectionParticipantRole.owner;+ final bool isAdmin = role == CollectionParticipantRole.admin;+ final bool canManageParticipants = isOwner || (adminRoleEnabled && isAdmin);+ final colorScheme = getEnteColorScheme(context);final int participants = 1 + widget.collection.getSharees().length;final User owner = widget.collection.owner;if (owner.id == currentUserID && owner.email == "") {owner.email = Configuration.instance.getEmail()!;}- final splitResult =- widget.collection.getSharees().splitMatch((x) => x.isViewer);- final List<User> viewers = splitResult.matched;- viewers.sort((a, b) => a.email.compareTo(b.email));- final List<User> collaborators = splitResult.unmatched;- collaborators.sort((a, b) => a.email.compareTo(b.email));+ final List<User> allSharees = widget.collection.getSharees();+ final List<User> admins = [];+ final List<User> collaborators = [];+ final List<User> viewers = [];+ if (adminRoleEnabled) {+ for (final User sharee in allSharees) {+ if (sharee.isAdmin) {+ admins.add(sharee);+ } else if (sharee.isCollaborator) {+ collaborators.add(sharee);+ } else {+ viewers.add(sharee);+ }+ }+ admins.sort((a, b) => a.email.compareTo(b.email));+ collaborators.sort((a, b) => a.email.compareTo(b.email));+ viewers.sort((a, b) => a.email.compareTo(b.email));+ if (isAdmin && !admins.any((u) => u.id == currentUserID)) {+ admins.insert(+ 0,+ User(+ id: currentUserID,+ email: Configuration.instance.getEmail() ?? "",+ role: CollectionParticipantRole.admin.toStringVal(),+ ),+ );+ }+ } else {+ for (final User sharee in allSharees) {+ if (sharee.isCollaborator) {+ collaborators.add(sharee);+ } else {+ viewers.add(sharee);+ }+ }+ collaborators.sort((a, b) => a.email.compareTo(b.email));+ viewers.sort((a, b) => a.email.compareTo(b.email));+ }return Scaffold(body: CustomScrollView(@@ -92,8 +119,9 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {flexibleSpaceTitle: TitleBarTitleWidget(title: widget.collection.displayName,),- flexibleSpaceCaption: AppLocalizations.of(context)- .albumParticipantsCount(count: participants),+ flexibleSpaceCaption: AppLocalizations.of(+ context,+ ).albumParticipantsCount(count: participants),),SliverList(delegate: SliverChildBuilderDelegate(@@ -135,12 +163,96 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {childCount: 1,),),+ if (adminRoleEnabled && (admins.isNotEmpty || canManageParticipants))+ SliverPadding(+ padding: const EdgeInsets.only(top: 20, left: 16, right: 16),+ sliver: SliverList(+ delegate: SliverChildBuilderDelegate(+ (context, index) {+ if (index == 0 &&+ (canManageParticipants || admins.isNotEmpty)) {+ return MenuSectionTitle(+ title: 'Admins',+ iconData: Icons.admin_panel_settings_outlined,+ );+ } else if (index > 0 && index <= admins.length) {+ final listIndex = index - 1;+ final currentUser = admins[listIndex];+ final isSameAsLoggedInUser =+ currentUserID == currentUser.id;+ final isLastItem =+ !canManageParticipants && index == admins.length;+ return Column(+ children: [+ MenuItemWidget(+ captionedTextWidget: CaptionedTextWidget(+ title: isSameAsLoggedInUser+ ? AppLocalizations.of(context).you+ : _nameIfAvailableElseEmail(currentUser),+ makeTextBold: isSameAsLoggedInUser,+ ),+ leadingIconSize: 24.0,+ leadingIconWidget: UserAvatarWidget(+ currentUser,+ type: AvatarType.mini,+ currentUserID: currentUserID,+ ),+ menuItemColor: colorScheme.fillFaint,+ trailingIcon:+ canManageParticipants && !isSameAsLoggedInUser+ ? Icons.chevron_right+ : null,+ trailingIconIsMuted: true,+ onTap: canManageParticipants &&+ !isSameAsLoggedInUser+ ? () async {+ await _navigateToManageUser(currentUser);+ }+ : null,+ isTopBorderRadiusRemoved: listIndex > 0,+ isBottomBorderRadiusRemoved: !isLastItem,+ singleBorderRadius: 8,+ ),+ isLastItem+ ? const SizedBox.shrink()+ : DividerWidget(+ dividerType: DividerType.menu,+ bgColor: colorScheme.fillFaint,+ ),+ ],+ );+ } else if (index == (1 + admins.length) &&+ canManageParticipants) {+ return MenuItemWidget(+ captionedTextWidget: CaptionedTextWidget(+ title: admins.isNotEmpty+ ? 'Add more admins'+ : 'Add admin',+ makeTextBold: true,+ ),+ leadingIcon: Icons.add_outlined,+ menuItemColor: colorScheme.fillFaint,+ onTap: () async {+ await _navigateToAddUser(+ [ActionTypesToShow.addAdmin]);+ },+ isTopBorderRadiusRemoved: admins.isNotEmpty,+ singleBorderRadius: 8,+ );+ }+ return const SizedBox.shrink();+ },+ childCount: 1 + admins.length + 1,+ ),+ ),+ ),SliverPadding(padding: const EdgeInsets.only(top: 20, left: 16, right: 16),sliver: SliverList(delegate: SliverChildBuilderDelegate((context, index) {- if (index == 0 && (isOwner || collaborators.isNotEmpty)) {+ if (index == 0 &&+ (canManageParticipants || collaborators.isNotEmpty)) {return MenuSectionTitle(title: AppLocalizations.of(context).collaborator,iconData: Icons.edit_outlined,@@ -151,7 +263,7 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {final isSameAsLoggedInUser =currentUserID == currentUser.id;final isLastItem =- !isOwner && index == collaborators.length;+ !canManageParticipants && index == collaborators.length;return Column(children: [MenuItemWidget(@@ -167,15 +279,14 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {type: AvatarType.mini,currentUserID: currentUserID,),- menuItemColor: getEnteColorScheme(context).fillFaint,- trailingIcon: isOwner ? Icons.chevron_right : null,+ menuItemColor: colorScheme.fillFaint,+ trailingIcon: canManageParticipants+ ? Icons.chevron_right+ : null,trailingIconIsMuted: true,- onTap: isOwner+ onTap: canManageParticipants? () async {- if (isOwner) {- // ignore: unawaited_futures- _navigateToManageUser(currentUser);- }+ await _navigateToManageUser(currentUser);}: null,isTopBorderRadiusRemoved: listIndex > 0,@@ -186,11 +297,12 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {? const SizedBox.shrink(): DividerWidget(dividerType: DividerType.menu,- bgColor: getEnteColorScheme(context).fillFaint,+ bgColor: colorScheme.fillFaint,),],);- } else if (index == (1 + collaborators.length) && isOwner) {+ } else if (index == (1 + collaborators.length) &&+ canManageParticipants) {return MenuItemWidget(captionedTextWidget: CaptionedTextWidget(title: collaborators.isNotEmpty@@ -199,10 +311,11 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {makeTextBold: true,),leadingIcon: Icons.add_outlined,- menuItemColor: getEnteColorScheme(context).fillFaint,+ menuItemColor: colorScheme.fillFaint,onTap: () async {- // ignore: unawaited_futures- _navigateToAddUser(false);+ await _navigateToAddUser([+ ActionTypesToShow.addCollaborator,+ ]);},isTopBorderRadiusRemoved: collaborators.isNotEmpty,singleBorderRadius: 8,@@ -219,7 +332,8 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {sliver: SliverList(delegate: SliverChildBuilderDelegate((context, index) {- if (index == 0 && (isOwner || viewers.isNotEmpty)) {+ if (index == 0 &&+ (canManageParticipants || viewers.isNotEmpty)) {return MenuSectionTitle(title: AppLocalizations.of(context).viewer,iconData: Icons.photo_outlined,@@ -229,7 +343,8 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {final currentUser = viewers[listIndex];final isSameAsLoggedInUser =currentUserID == currentUser.id;- final isLastItem = !isOwner && index == viewers.length;+ final isLastItem =+ !canManageParticipants && index == viewers.length;return Column(children: [MenuItemWidget(@@ -245,15 +360,14 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {type: AvatarType.mini,currentUserID: currentUserID,),- menuItemColor: getEnteColorScheme(context).fillFaint,- trailingIcon: isOwner ? Icons.chevron_right : null,+ menuItemColor: colorScheme.fillFaint,+ trailingIcon: canManageParticipants+ ? Icons.chevron_right+ : null,trailingIconIsMuted: true,- onTap: isOwner+ onTap: canManageParticipants? () async {- if (isOwner) {- // ignore: unawaited_futures- _navigateToManageUser(currentUser);- }+ await _navigateToManageUser(currentUser);}: null,isTopBorderRadiusRemoved: listIndex > 0,@@ -264,11 +378,12 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {? const SizedBox.shrink(): DividerWidget(dividerType: DividerType.menu,- bgColor: getEnteColorScheme(context).fillFaint,+ bgColor: colorScheme.fillFaint,),],);- } else if (index == (1 + viewers.length) && isOwner) {+ } else if (index == (1 + viewers.length) &&+ canManageParticipants) {return MenuItemWidget(captionedTextWidget: CaptionedTextWidget(title: viewers.isNotEmpty@@ -277,10 +392,9 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {makeTextBold: true,),leadingIcon: Icons.add_outlined,- menuItemColor: getEnteColorScheme(context).fillFaint,+ menuItemColor: colorScheme.fillFaint,onTap: () async {- // ignore: unawaited_futures- _navigateToAddUser(true);+ await _navigateToAddUser([ActionTypesToShow.addViewer]);},isTopBorderRadiusRemoved: viewers.isNotEmpty,singleBorderRadius: 8,diff --git a/mobile/apps/photos/lib/ui/sharing/manage_album_participant.dart b/mobile/apps/photos/lib/ui/sharing/manage_album_participant.dartindex d94c2f7ab9..192e86ae22 100644--- a/mobile/apps/photos/lib/ui/sharing/manage_album_participant.dart+++ b/mobile/apps/photos/lib/ui/sharing/manage_album_participant.dart@@ -3,6 +3,7 @@ import "package:photos/extensions/user_extension.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/api/collection/user.dart";import 'package:photos/models/collection/collection.dart';+import 'package:photos/service_locator.dart';import 'package:photos/services/collections_service.dart';import 'package:photos/theme/colors.dart';import 'package:photos/theme/ente_theme.dart';@@ -32,13 +33,18 @@ class ManageIndividualParticipant extends StatefulWidget {class _ManageIndividualParticipantStateextends State<ManageIndividualParticipant> {- final CollectionActions collectionActions =- CollectionActions(CollectionsService.instance);+ final CollectionActions collectionActions = CollectionActions(+ CollectionsService.instance,+ );@overrideWidget build(BuildContext context) {final colorScheme = getEnteColorScheme(context);final textTheme = getEnteTextTheme(context);+ final adminRoleEnabled = flagService.enableAdminRole;+ final isAdmin = widget.user.isAdmin;+ final isCollaborator = widget.user.isCollaborator;+ final isViewer = widget.user.isViewer;bool isConvertToViewSuccess = false;return Scaffold(appBar: AppBar(),@@ -52,31 +58,59 @@ class _ManageIndividualParticipantStatechild: Column(crossAxisAlignment: CrossAxisAlignment.start,children: [- const SizedBox(- height: 12,- ),+ const SizedBox(height: 12),TitleBarTitleWidget(title: AppLocalizations.of(context).manage,),Text(widget.user.displayName ?? widget.user.email,textAlign: TextAlign.left,- style:- textTheme.small.copyWith(color: colorScheme.textMuted),+ style: textTheme.small.copyWith(+ color: colorScheme.textMuted,+ ),),],),),const SizedBox(height: 12),MenuSectionTitle(title: AppLocalizations.of(context).addedAs),+ if (adminRoleEnabled)+ MenuItemWidget(+ captionedTextWidget: const CaptionedTextWidget(title: 'Admin'),+ leadingIcon: Icons.admin_panel_settings_outlined,+ menuItemColor: colorScheme.fillFaint,+ trailingIcon: isAdmin ? Icons.check : null,+ onTap: isAdmin+ ? null+ : () async {+ final result =+ await collectionActions.addEmailToCollection(+ context,+ widget.collection,+ widget.user.email,+ CollectionParticipantRole.admin,+ );+ if (result && mounted) {+ widget.user.role =+ CollectionParticipantRole.admin.toStringVal();+ setState(() => {});+ }+ },+ isBottomBorderRadiusRemoved: true,+ ),+ if (adminRoleEnabled)+ DividerWidget(+ dividerType: DividerType.menu,+ bgColor: colorScheme.fillFaint,+ ),MenuItemWidget(captionedTextWidget: CaptionedTextWidget(title: AppLocalizations.of(context).collaborator,),leadingIcon: Icons.edit_outlined,- menuItemColor: getEnteColorScheme(context).fillFaint,- trailingIcon: widget.user.isCollaborator ? Icons.check : null,- onTap: widget.user.isCollaborator+ menuItemColor: colorScheme.fillFaint,+ trailingIcon: isCollaborator ? Icons.check : null,+ onTap: isCollaborator? null: () async {final result =@@ -93,29 +127,31 @@ class _ManageIndividualParticipantStatesetState(() => {});}},+ isTopBorderRadiusRemoved: adminRoleEnabled,isBottomBorderRadiusRemoved: true,),DividerWidget(dividerType: DividerType.menu,- bgColor: getEnteColorScheme(context).fillFaint,+ bgColor: colorScheme.fillFaint,),MenuItemWidget(captionedTextWidget: CaptionedTextWidget(title: AppLocalizations.of(context).viewer,),leadingIcon: Icons.photo_outlined,- leadingIconColor: getEnteColorScheme(context).strokeBase,- menuItemColor: getEnteColorScheme(context).fillFaint,- trailingIcon: widget.user.isViewer ? Icons.check : null,+ leadingIconColor: colorScheme.strokeBase,+ menuItemColor: colorScheme.fillFaint,+ trailingIcon: isViewer ? Icons.check : null,showOnlyLoadingState: true,- onTap: widget.user.isViewer+ onTap: isViewer? null: () async {final actionResult = await showChoiceActionSheet(context,title: AppLocalizations.of(context).changePermissions,- firstButtonLabel:- AppLocalizations.of(context).yesConvertToViewer,+ firstButtonLabel: AppLocalizations.of(+ context,+ ).yesConvertToViewer,body: AppLocalizations.of(context).cannotAddMorePhotosAfterBecomingViewer(user: widget.user.displayName ?? widget.user.email,@@ -151,8 +187,11 @@ class _ManageIndividualParticipantStateisTopBorderRadiusRemoved: true,),MenuSectionDescriptionWidget(- content: AppLocalizations.of(context)- .collaboratorsCanAddPhotosAndVideosToTheSharedAlbum,+ content: adminRoleEnabled+ ? 'Admins and collaborators can add photos and videos to the shared album.'+ : AppLocalizations.of(+ context,+ ).collaboratorsCanAddPhotosAndVideosToTheSharedAlbum,),const SizedBox(height: 24),MenuSectionTitle(@@ -166,7 +205,7 @@ class _ManageIndividualParticipantState),leadingIcon: Icons.not_interested_outlined,leadingIconColor: warning500,- menuItemColor: getEnteColorScheme(context).fillFaint,+ menuItemColor: colorScheme.fillFaint,surfaceExecutionStates: false,onTap: () async {final result = await collectionActions.removeParticipant(diff --git a/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart b/mobile/apps/photos/lib/ui/sharing/share_collection_page.dartindex d1bde66acd..f6bf42c180 100644--- a/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart+++ b/mobile/apps/photos/lib/ui/sharing/share_collection_page.dart@@ -6,7 +6,9 @@ import "package:photos/extensions/user_extension.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/api/collection/user.dart";import 'package:photos/models/collection/collection.dart';+import 'package:photos/service_locator.dart';import 'package:photos/services/collections_service.dart';+import 'package:photos/service_locator.dart';import 'package:photos/theme/ente_theme.dart';import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';import 'package:photos/ui/components/captioned_text_widget.dart';@@ -64,6 +66,7 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {Widget build(BuildContext context) {_sharees = widget.collection.sharees;final bool hasUrl = widget.collection.hasLink;+ final bool adminRoleEnabled = flagService.enableAdminRole;final children = <Widget>[];children.add(MenuSectionTitle(@@ -80,23 +83,56 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {),);+ if (adminRoleEnabled) {+ children.add(+ MenuItemWidget(+ captionedTextWidget: const CaptionedTextWidget(+ title: 'Add admin',+ makeTextBold: true,+ ),+ leadingIcon: Icons.add,+ menuItemColor: getEnteColorScheme(context).fillFaint,+ isTopBorderRadiusRemoved: _sharees.isNotEmpty,+ onTap: () async {+ routeToPage(+ context,+ AddParticipantPage(+ [widget.collection],+ const [ActionTypesToShow.addAdmin],+ ),+ ).then(+ (value) => {+ if (mounted) {setState(() => {})},+ },+ );+ },+ ),+ );+ children.add(+ DividerWidget(+ dividerType: DividerType.menu,+ bgColor: getEnteColorScheme(context).fillFaint,+ ),+ );+ }children.add(MenuItemWidget(captionedTextWidget: CaptionedTextWidget(- title: AppLocalizations.of(context).addViewer,+ title: AppLocalizations.of(context).addCollaborator,makeTextBold: true,),leadingIcon: Icons.add,menuItemColor: getEnteColorScheme(context).fillFaint,- isTopBorderRadiusRemoved: _sharees.isNotEmpty,- isBottomBorderRadiusRemoved: true,+ isTopBorderRadiusRemoved:+ adminRoleEnabled ? true : _sharees.isNotEmpty,+ isBottomBorderRadiusRemoved: false,onTap: () async {// ignore: unawaited_futuresrouteToPage(context,AddParticipantPage([widget.collection],- const [ActionTypesToShow.addViewer],+ const [ActionTypesToShow.addCollaborator],),).then((value) => {@@ -115,19 +151,19 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {children.add(MenuItemWidget(captionedTextWidget: CaptionedTextWidget(- title: AppLocalizations.of(context).addCollaborator,+ title: AppLocalizations.of(context).addViewer,makeTextBold: true,),leadingIcon: Icons.add,menuItemColor: getEnteColorScheme(context).fillFaint,isTopBorderRadiusRemoved: true,+ isBottomBorderRadiusRemoved: true,onTap: () async {- // ignore: unawaited_futuresrouteToPage(context,AddParticipantPage([widget.collection],- const [ActionTypesToShow.addCollaborator],+ const [ActionTypesToShow.addViewer],),).then((value) => {diff --git a/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dartindex 9095e8c090..ce74a0c9fc 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/album_selection_action_widget.dart@@ -6,6 +6,7 @@ import "package:photos/generated/l10n.dart";import "package:photos/models/collection/collection.dart";import "package:photos/models/metadata/common_keys.dart";import "package:photos/models/selected_albums.dart";+import "package:photos/service_locator.dart";import "package:photos/services/collections_service.dart";import "package:photos/ui/actions/collection/collection_sharing_actions.dart";import "package:photos/ui/collections/collection_list_page.dart";@@ -59,10 +60,12 @@ class _AlbumSelectionActionWidgetStatereturn const SizedBox.shrink();}final List<SelectionActionButton> items = [];- final hasPinnedAlbum =- widget.selectedAlbums.albums.any((album) => album.isPinned);- final hasUnpinnedAlbum =- widget.selectedAlbums.albums.any((album) => !album.isPinned);+ final hasPinnedAlbum = widget.selectedAlbums.albums.any(+ (album) => album.isPinned,+ );+ final hasUnpinnedAlbum = widget.selectedAlbums.albums.any(+ (album) => !album.isPinned,+ );if (widget.sectionType == UISectionType.homeCollections ||widget.sectionType == UISectionType.outgoingCollections) {@@ -158,12 +161,16 @@ class _AlbumSelectionActionWidgetState}Future<void> _shareCollection() async {+ final actions = <ActionTypesToShow>[+ ActionTypesToShow.addViewer,+ ActionTypesToShow.addCollaborator,+ ];+ if (flagService.enableAdminRole) {+ actions.add(ActionTypesToShow.addAdmin);+ }await routeToPage(context,- AddParticipantPage(- widget.selectedAlbums.albums.toList(),- const [ActionTypesToShow.addViewer, ActionTypesToShow.addCollaborator],- ),+ AddParticipantPage(widget.selectedAlbums.albums.toList(), actions),);widget.selectedAlbums.clearAll();}@@ -173,8 +180,9 @@ class _AlbumSelectionActionWidgetStatefinal List<Collection> nonEmptyCollection = [];final List errors = [];- final List<Collection> selectedAlbums =- widget.selectedAlbums.albums.toList(growable: false);+ final List<Collection> selectedAlbums = widget.selectedAlbums.albums.toList(+ growable: false,+ );for (final collection in selectedAlbums) {if (collection.type == CollectionType.favorites) {continue;@@ -193,10 +201,7 @@ class _AlbumSelectionActionWidgetState}}if (errors.isNotEmpty) {- await showGenericErrorDialog(- context: context,- error: errors.first,- );+ await showGenericErrorDialog(context: context, error: errors.first);}if (nonEmptyCollection.isNotEmpty) {@@ -220,11 +225,7 @@ class _AlbumSelectionActionWidgetStatecontinue;}- await updateOrder(- context,- collection,- collection.isPinned ? 1 : 1,- );+ await updateOrder(context, collection, collection.isPinned ? 1 : 1);}if (hasFavorites) {_showFavToast();@@ -238,11 +239,7 @@ class _AlbumSelectionActionWidgetStatecontinue;}- await updateOrder(- context,- collection,- collection.isPinned ? 0 : 0,- );+ await updateOrder(context, collection, collection.isPinned ? 0 : 0);}if (hasFavorites) {_showFavToast();@@ -342,8 +339,9 @@ class _AlbumSelectionActionWidgetState),],title: AppLocalizations.of(context).leaveSharedAlbum,- body: AppLocalizations.of(context)- .photosAddedByYouWillBeRemovedFromTheAlbum,+ body: AppLocalizations.of(+ context,+ ).photosAddedByYouWillBeRemovedFromTheAlbum,);if (actionResult?.action != null && mounted) {if (actionResult!.action == ButtonAction.error) {@@ -359,8 +357,9 @@ class _AlbumSelectionActionWidgetStatevoid _selectionChangedListener() {if (mounted) {- hasFavorites = widget.selectedAlbums.albums- .any((album) => album.type == CollectionType.favorites);+ hasFavorites = widget.selectedAlbums.albums.any(+ (album) => album.type == CollectionType.favorites,+ );setState(() {});}}diff --git a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dartindex 3c9e2315d3..e5889a8789 100644--- a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart+++ b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart@@ -43,6 +43,7 @@ class FlagService {bool get disableCFWorker => flags.disableCFWorker;bool get internalUser => flags.internalUser || kDebugMode;+ bool get enableAdminRole => internalUser;bool get betaUser => flags.betaUser;diff --git a/mobile/packages/sharing/lib/models/user.dart b/mobile/packages/sharing/lib/models/user.dartindex 30785b0504..d52c417169 100644--- a/mobile/packages/sharing/lib/models/user.dart+++ b/mobile/packages/sharing/lib/models/user.dart@@ -22,6 +22,8 @@ class User {bool get isCollaborator =>role != null && role?.toUpperCase() == 'COLLABORATOR';+ bool get isAdmin => role != null && role?.toUpperCase() == 'ADMIN';+Map<String, dynamic> toMap() {// ignore: deprecated_member_use_from_same_packagereturn {'id': id, 'email': email, 'name': name, "role": role};diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsxindex ec076e56de..8e8fa9d194 100644--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx@@ -114,6 +114,8 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({setBlockingLoad,onRemotePull,}) => {+ const settings = useSettingsSnapshot();+ const { isInternalUser, isAdminRoleEnabled } = settings;const { onGenericError } = useBaseContext();const { showLoadingBar, hideLoadingBar } = usePhotosAppContext();@@ -145,7 +147,14 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({return <></>;}+ const currentSharee = collection.sharees.find(+ (sharee) => sharee.id == user.id,+ );+ const isOwner = user.id == collection.owner?.id;+ const isAdmin = currentSharee?.role == "ADMIN";+ const canManageParticipants = isOwner || (isAdminRoleEnabled && isAdmin);const isSharedIncoming = collectionSummary.type == "sharedIncoming";+ const showEmailSection = !isSharedIncoming || canManageParticipants;return (<SidebarDrawer anchor="right" {...{ open, onClose }}>@@ -154,13 +163,36 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({onClose={onClose}onRootClose={onClose}title={- isSharedIncoming- ? t("sharing_details")- : t("share_album")+ canManageParticipants+ ? t("share_album")+ : t("sharing_details")}caption={collection.name}/><Stack sx={{ py: "20px", px: "8px", gap: "24px" }}>+ {showEmailSection ? (+ <EmailShare+ onRootClose={onClose}+ {...{+ user,+ collection,+ emailByUserID,+ shareSuggestionEmails,+ onRemotePull,+ wrap,+ }}+ />+ ) : null}+ {isOwner ? (+ <PublicShare+ onRootClose={onClose}+ {...{+ collection,+ setBlockingLoad,+ onRemotePull,+ }}+ />+ ) : null}{isSharedIncoming ? (<SharingDetails{...{@@ -170,29 +202,7 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({emailByUserID,}}/>- ) : (- <>- <EmailShare- onRootClose={onClose}- {...{- user,- collection,- emailByUserID,- shareSuggestionEmails,- wrap,- onRemotePull,- }}- />- <PublicShare- onRootClose={onClose}- {...{- collection,- setBlockingLoad,- onRemotePull,- }}- />- </>- )}+ ) : null}</Stack></Stack></SidebarDrawer>@@ -210,15 +220,32 @@ const SharingDetails: React.FC<SharingDetailsProps> = ({collectionSummary,emailByUserID,}) => {+ const settings = useSettingsSnapshot();+ const { isInternalUser, isAdminRoleEnabled } = settings;const isOwner = user.id == collection.owner?.id;+ const currentSharee = collection.sharees.find(+ (sharee) => sharee.id == user.id,+ );+ const isAdmin = currentSharee?.role == "ADMIN";const ownerEmail = isOwner ? user?.email : collection.owner?.email;const collaborators = collection.sharees- .filter((sharee) => sharee.role == "COLLABORATOR")+ .filter(+ (sharee) =>+ sharee.role == "COLLABORATOR" ||+ (!isAdminRoleEnabled && sharee.role == "ADMIN"),+ ).map((sharee) => sharee.email).filter((email) => email !== undefined);+ const admins = isAdminRoleEnabled+ ? collection.sharees+ .filter((sharee) => sharee.role == "ADMIN")+ .map((sharee) => sharee.email)+ .filter((email) => email !== undefined)+ : [];+const viewers = collection.sharees.filter((sharee) => sharee.role == "VIEWER").map((sharee) => sharee.email)@@ -227,6 +254,27 @@ const SharingDetails: React.FC<SharingDetailsProps> = ({const userOrEmail = (email: string) =>email == user.email ? t("you") : email;+ if (isAdminRoleEnabled && !isOwner && isAdmin) {+ return (+ <Stack>+ <RowButtonGroupTitle icon={<AdminPanelSettingsIcon />}>+ {t("owner")}+ </RowButtonGroupTitle>+ <RowButtonGroup>+ <RowLabel+ startIcon={+ <Avatar+ email={ownerEmail}+ {...{ user, emailByUserID }}+ />+ }+ label={ownerEmail ?? ""}+ />+ </RowButtonGroup>+ </Stack>+ );+ }+return (<><Stack>@@ -245,6 +293,31 @@ const SharingDetails: React.FC<SharingDetailsProps> = ({/></RowButtonGroup></Stack>+ {isAdminRoleEnabled && admins.length > 0 && (+ <Stack>+ <RowButtonGroupTitle icon={<AdminPanelSettingsIcon />}>+ {t("admins", { defaultValue: "Admins" })}+ </RowButtonGroupTitle>+ <RowButtonGroup>+ {admins.map((email, index) => (+ <React.Fragment key={email}>+ <RowLabel+ startIcon={+ <Avatar+ email={email}+ {...{ user, emailByUserID }}+ />+ }+ label={userOrEmail(email)}+ />+ {index != admins.length - 1 && (+ <RowButtonDivider />+ )}+ </React.Fragment>+ ))}+ </RowButtonGroup>+ </Stack>+ )}{collectionSummary.attributes.has("sharedIncomingCollaborator") &&collaborators.length > 0 && (<Stack>@@ -326,6 +399,14 @@ const EmailShare: React.FC<EmailShareProps> = ({const { show: showManageEmail, props: manageEmailVisibilityProps } =useModalVisibility();+ const settings = useSettingsSnapshot();+ const {+ customDomain,+ embedURL: embedBaseURL,+ isInternalUser,+ isAdminRoleEnabled,+ } = settings;+const [participantRole, setParticipantRole] =// Initial value is arbitrary, it always gets reset before// `showAddParticipant` is called.@@ -341,7 +422,18 @@ const EmailShare: React.FC<EmailShareProps> = ({showAddParticipant();}, [showAddParticipant]);+ const showAddAdmin = useCallback(() => {+ setParticipantRole("ADMIN");+ showAddParticipant();+ }, [showAddParticipant]);+const participantCount = collection.sharees.length;+ const currentSharee = collection.sharees.find(+ (sharee) => sharee.id == user.id,+ );+ const isOwner = user.id == collection.owner?.id;+ const isAdmin = currentSharee?.role == "ADMIN";+ const canManageParticipants = isOwner || (isAdminRoleEnabled && isAdmin);return (<>@@ -368,20 +460,36 @@ const EmailShare: React.FC<EmailShareProps> = ({endIcon={<ChevronRightIcon />}onClick={showManageEmail}/>+ {canManageParticipants ? <RowButtonDivider /> : null}+ </>+ ) : null}+ {canManageParticipants ? (+ <>+ <RowButton+ startIcon={<AddIcon />}+ onClick={showAddViewer}+ label={t("add_viewers")}+ /><RowButtonDivider />+ <RowButton+ startIcon={<AddIcon />}+ onClick={showAddCollaborator}+ label={t("add_collaborators")}+ />+ {isAdminRoleEnabled ? (+ <>+ <RowButtonDivider />+ <RowButton+ startIcon={<AddIcon />}+ onClick={showAddAdmin}+ label={t("add_admins", {+ defaultValue: "Add admins",+ })}+ />+ </>+ ) : null}</>) : null}- <RowButton- startIcon={<AddIcon />}- onClick={showAddViewer}- label={t("add_viewers")}- />- <RowButtonDivider />- <RowButton- startIcon={<AddIcon />}- onClick={showAddCollaborator}- label={t("add_collaborators")}- /></RowButtonGroup></Stack><AddParticipant@@ -407,6 +515,8 @@ const EmailShare: React.FC<EmailShareProps> = ({participantCount,wrap,onRemotePull,+ canManageParticipants,+ adminRoleEnabled: isAdminRoleEnabled,}}/></>@@ -495,19 +605,31 @@ const AddParticipant: React.FC<AddParticipantProps> = ({onRemotePull,}) => {const eligibleEmails = useMemo(() => {+ const ownerEmail = collection.owner?.email;return shareSuggestionEmails.filter((email) =>email != user.email &&+ email != ownerEmail &&!collection?.sharees?.find((value) => value.email == email),);- }, [user.email, shareSuggestionEmails, collection.sharees]);+ }, [+ user.email,+ shareSuggestionEmails,+ collection.sharees,+ collection.owner?.email,+ ]);const handleRootClose = () => {onClose();onRootClose();};- const title = role == "VIEWER" ? t("add_viewers") : t("add_collaborators");+ const title =+ role == "VIEWER"+ ? t("add_viewers")+ : role == "COLLABORATOR"+ ? t("add_collaborators")+ : t("add_admins", { defaultValue: "Add admins" });const collectionShare: AddParticipantFormProps["onSubmit"] = async (emailOrEmails,@@ -720,6 +842,8 @@ type ManageEmailShareProps = ModalVisibilityProps & {onRootClose: () => void;participantCount: number;wrap: (f: () => Promise<void>) => () => void;+ canManageParticipants: boolean;+ adminRoleEnabled: boolean;} & Pick<CollectionShareProps,| "user"@@ -740,6 +864,8 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({participantCount,wrap,onRemotePull,+ canManageParticipants,+ adminRoleEnabled,}) => {const { show: showAddParticipant, props: addParticipantVisibilityProps } =useModalVisibility();@@ -764,14 +890,20 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({showAddParticipant();}, [showAddParticipant]);+ const showAddAdmin = useCallback(() => {+ setParticipantRole("ADMIN");+ showAddParticipant();+ }, [showAddParticipant]);+const selectAndManageParticipant = useCallback((email: string) => {+ if (!canManageParticipants || email == user.email) return;setSelectedParticipant(collection.sharees.find((sharee) => sharee.email == email),);showManageParticipant();},- [collection, showManageParticipant],+ [collection, showManageParticipant, canManageParticipants, user.email],);const handleRootClose = () => {@@ -785,10 +917,32 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({const isOwner = user.id == collection.owner?.id;const collaborators = collection.sharees- .filter((sharee) => sharee.role == "COLLABORATOR")+ .filter(+ (sharee) =>+ sharee.role == "COLLABORATOR" ||+ (!adminRoleEnabled && sharee.role == "ADMIN"),+ ).map((sharee) => sharee.email).filter((email) => email !== undefined);+ const admins = adminRoleEnabled+ ? collection.sharees+ .filter((sharee) => sharee.role == "ADMIN")+ .map((sharee) => sharee.email)+ .filter((email) => email !== undefined)+ : [];+ const currentSharee = collection.sharees.find(+ (sharee) => sharee.email == user.email,+ );+ if (+ adminRoleEnabled &&+ currentSharee?.role == "ADMIN" &&+ user.email &&+ !admins.includes(user.email)+ ) {+ admins.unshift(user.email);+ }+const viewers = collection.sharees.filter((sharee) => sharee.role == "VIEWER").map((sharee) => sharee.email)@@ -820,40 +974,124 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({/></RowButtonGroup></Stack>+ {adminRoleEnabled &&+ (admins.length > 0 || canManageParticipants) ? (+ <Stack>+ <RowButtonGroupTitle+ icon={<AdminPanelSettingsIcon />}+ >+ {t("admins", { defaultValue: "Admins" })}+ </RowButtonGroupTitle>+ <RowButtonGroup>+ {admins.map((item, index) => {+ const isSelf = item == user.email;+ return (+ <React.Fragment key={item}>+ <RowButton+ fontWeight="regular"+ onClick={+ canManageParticipants &&+ !isSelf+ ? () =>+ selectAndManageParticipant(+ item,+ )+ : undefined+ }+ label={+ isSelf+ ? t("you")+ : item ?? ""+ }+ startIcon={+ <Avatar+ email={item}+ {...{+ user,+ emailByUserID,+ }}+ />+ }+ endIcon={+ canManageParticipants &&+ !isSelf ? (+ <ChevronRightIcon />+ ) : undefined+ }+ />+ {(index < admins.length - 1 ||+ canManageParticipants) && (+ <RowButtonDivider />+ )}+ </React.Fragment>+ );+ })}+ {canManageParticipants ? (+ <RowButton+ startIcon={<AddIcon />}+ onClick={showAddAdmin}+ label={+ admins?.length+ ? t("add_more")+ : t("add_admins", {+ defaultValue: "Add admins",+ })+ }+ />+ ) : null}+ </RowButtonGroup>+ </Stack>+ ) : null}<Stack><RowButtonGroupTitle icon={<ModeEditIcon />}>{t("collaborators")}</RowButtonGroupTitle><RowButtonGroup>- {collaborators.map((item) => (- <React.Fragment key={item}>- <RowButton- fontWeight="regular"- onClick={() =>- selectAndManageParticipant(item)- }- label={item}- startIcon={- <Avatar- email={item}- {...{ user, emailByUserID }}- />- }- endIcon={<ChevronRightIcon />}- />- <RowButtonDivider />+ {collaborators.map((item, index) => (+ <React.Fragment key={item}>+ <RowButton+ fontWeight="regular"+ onClick={+ canManageParticipants &&+ item != user.email+ ? () =>+ selectAndManageParticipant(+ item,+ )+ : undefined+ }+ label={item}+ startIcon={+ <Avatar+ email={item}+ {...{ user, emailByUserID }}+ />+ }+ endIcon={+ canManageParticipants &&+ item != user.email ? (+ <ChevronRightIcon />+ ) : undefined+ }+ />+ {(index < collaborators.length - 1 ||+ canManageParticipants) && (+ <RowButtonDivider />+ )}</React.Fragment>))}- <RowButton- startIcon={<AddIcon />}- onClick={showAddCollaborator}- label={- collaborators?.length- ? t("add_more")- : t("add_collaborators")- }- />+ {canManageParticipants ? (+ <RowButton+ startIcon={<AddIcon />}+ onClick={showAddCollaborator}+ label={+ collaborators?.length+ ? t("add_more")+ : t("add_collaborators")+ }+ />+ ) : null}</RowButtonGroup></Stack><Stack>@@ -861,34 +1099,50 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({{t("viewers")}</RowButtonGroupTitle><RowButtonGroup>- {viewers.map((item) => (- <React.Fragment key={item}>- <RowButton- fontWeight="regular"- onClick={() =>- selectAndManageParticipant(item)- }- label={item}- startIcon={- <Avatar- email={item}- {...{ user, emailByUserID }}- />- }- endIcon={<ChevronRightIcon />}- />- <RowButtonDivider />+ {viewers.map((item, index) => (+ <React.Fragment key={item}>+ <RowButton+ fontWeight="regular"+ onClick={+ canManageParticipants &&+ item != user.email+ ? () =>+ selectAndManageParticipant(+ item,+ )+ : undefined+ }+ label={item}+ startIcon={+ <Avatar+ email={item}+ {...{ user, emailByUserID }}+ />+ }+ endIcon={+ canManageParticipants &&+ item != user.email ? (+ <ChevronRightIcon />+ ) : undefined+ }+ />+ {(index < viewers.length - 1 ||+ canManageParticipants) && (+ <RowButtonDivider />+ )}</React.Fragment>))}- <RowButton- startIcon={<AddIcon />}- onClick={showAddViewer}- label={- viewers?.length- ? t("add_more")- : t("add_viewers")- }- />+ {canManageParticipants ? (+ <RowButton+ startIcon={<AddIcon />}+ onClick={showAddViewer}+ label={+ viewers?.length+ ? t("add_more")+ : t("add_viewers")+ }+ />+ ) : null}</RowButtonGroup></Stack></Stack>@@ -907,7 +1161,13 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({/><ManageParticipant{...manageParticipantVisibilityProps}- {...{ onRootClose, wrap, collection, onRemotePull }}+ {...{+ onRootClose,+ wrap,+ collection,+ onRemotePull,+ adminRoleEnabled,+ }}participant={selectedParticipant}/></>@@ -924,6 +1184,7 @@ type ManageParticipantProps = ModalVisibilityProps & {* when {@link open} is `true`, but the types don't reflect this.*/participant: CollectionUser | undefined;+ adminRoleEnabled: boolean;} & Pick<CollectionShareProps, "collection" | "onRemotePull">;const ManageParticipant: React.FC<ManageParticipantProps> = ({@@ -934,6 +1195,7 @@ const ManageParticipant: React.FC<ManageParticipantProps> = ({participant,wrap,onRemotePull,+ adminRoleEnabled,}) => {const { showMiniDialog } = useBaseContext();@@ -970,11 +1232,19 @@ const ManageParticipant: React.FC<ManageParticipantProps> = ({/>);buttonText = t("confirm_convert_to_viewer");- } else {+ } else if (newRole == "COLLABORATOR") {message = t("change_permission_to_collaborator", {selectedEmail,});buttonText = t("confirm_convert_to_collaborator");+ } else {+ message = t("change_permission_to_admin", {+ selectedEmail,+ defaultValue: `Make ${selectedEmail} an admin?`,+ });+ buttonText = t("confirm_convert_to_admin", {+ defaultValue: "Make admin",+ });}showMiniDialog({@@ -1042,6 +1312,24 @@ const ManageParticipant: React.FC<ManageParticipantProps> = ({</Typography><RowButtonGroup>+ {adminRoleEnabled ? (+ <>+ <RowButton+ fontWeight="regular"+ onClick={createOnRoleChange("ADMIN")}+ label={t("admin", {+ defaultValue: "Admin",+ })}+ startIcon={<AdminPanelSettingsIcon />}+ endIcon={+ participant.role === "ADMIN" && (+ <DoneIcon />+ )+ }+ />+ <RowButtonDivider />+ </>+ ) : null}<RowButtonfontWeight="regular"onClick={createOnRoleChange("COLLABORATOR")}diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.tsindex db81444cc9..c6b402600f 100644--- a/web/packages/media/collection.ts+++ b/web/packages/media/collection.ts@@ -185,6 +185,9 @@ export type CollectionType = (typeof collectionTypes)[number];* - "COLLABORATOR" - Can additionally add files from the collection, and remove* files that they added from the collection (i.e., files they "own").*+ * - "ADMIN" - Can manage participants (invite/remove) similar to the owner, but+ * cannot delete the collection or remove the owner.+ ** - "OWNER" - The owner of the collection. Can remove any file, including those* added by other users, from the collection.*@@ -194,6 +197,7 @@ export type CollectionType = (typeof collectionTypes)[number];export type CollectionParticipantRole =| "VIEWER"| "COLLABORATOR"+ | "ADMIN"| "OWNER"| "UNKNOWN";@@ -201,7 +205,7 @@ export type CollectionParticipantRole =* A subset of {@link CollectionParticipantRole} that are applicable when* sharing a collection with another Ente user.*/-export type CollectionNewParticipantRole = "VIEWER" | "COLLABORATOR";+export type CollectionNewParticipantRole = "VIEWER" | "COLLABORATOR" | "ADMIN";/*** Information about the user associated with a collection, either as an owner,diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.tsindex bc0b318027..2b71b32ce8 100644--- a/web/packages/new/photos/services/settings.ts+++ b/web/packages/new/photos/services/settings.ts@@ -44,6 +44,10 @@ export interface Settings {* `true` if the current user is an internal user.*/isInternalUser: boolean;+ /**+ * `true` if admin role management features are enabled.+ */+ isAdminRoleEnabled: boolean;/*** `true` if maps are enabled.@@ -103,6 +107,7 @@ export interface Settings {const createDefaultSettings = (): Settings => ({isInternalUser: false,+ isAdminRoleEnabled: false,mapEnabled: false,cfUploadProxyDisabled: false,castURL: "https://cast.ente.io",@@ -192,7 +197,9 @@ type FeatureFlags = z.infer<typeof FeatureFlags>;const syncSettingsSnapshotWithLocalStorage = () => {const flags = savedRemoteFeatureFlags();const settings = createDefaultSettings();- settings.isInternalUser = flags?.internalUser || false;+ settings.isInternalUser = flags?.internalUser || isDevBuild;+ settings.isAdminRoleEnabled =+ (flags?.internalUser ?? false) || isDevBuild;settings.mapEnabled = flags?.mapEnabled || false;settings.cfUploadProxyDisabled = savedCFProxyDisabled();if (flags?.castUrl) settings.castURL = flags.castUrl;