From 8cdd9c3b2d8f235784d904ec10dd593c57206e2b Mon Sep 17 00:00:00 2001 From: Kelrap Date: Thu, 18 Jul 2024 17:17:28 -0400 Subject: [PATCH] Lets students add subrooms to spaces --- lib/pages/chat_list/chat_list.dart | 7 +------ .../pangea_room_extension.dart | 2 ++ .../user_permissions_extension.dart | 16 ++-------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 803b773e1..9abe76a91 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -819,8 +819,7 @@ class ChatListController extends State label: space.nameIncludingParents(context), // If user is not admin of space, button is grayed out textStyle: TextStyle( - color: (firstSelectedRoom == null || - (firstSelectedRoom.isSpace && !space.isRoomAdmin)) + color: (firstSelectedRoom == null) ? Theme.of(context).colorScheme.outline : Theme.of(context).colorScheme.surfaceTint, ), @@ -838,10 +837,6 @@ class ChatListController extends State if (firstSelectedRoom == null) { throw L10n.of(context)!.nonexistentSelection; } - // If user is not admin of the would-be parent space, does not allow - if (firstSelectedRoom.isSpace && !space.isRoomAdmin) { - throw L10n.of(context)!.cantAddSpaceChild; - } if (space.canSendDefaultStates) { for (final roomId in selectedRoomIds) { diff --git a/lib/pangea/extensions/pangea_room_extension/pangea_room_extension.dart b/lib/pangea/extensions/pangea_room_extension/pangea_room_extension.dart index fbec662a7..f0094f994 100644 --- a/lib/pangea/extensions/pangea_room_extension/pangea_room_extension.dart +++ b/lib/pangea/extensions/pangea_room_extension/pangea_room_extension.dart @@ -291,6 +291,8 @@ extension PangeaRoom on Room { bool get canDelete => _canDelete; + /// Determines whether user has permission to add child room to this + /// Can add child if, and only if, is admin of child bool canIAddSpaceChild(Room? room, {bool spaceMode = false}) { return _canIAddSpaceChild(room, spaceMode: spaceMode); } diff --git a/lib/pangea/extensions/pangea_room_extension/user_permissions_extension.dart b/lib/pangea/extensions/pangea_room_extension/user_permissions_extension.dart index b94db5c57..a61b459c6 100644 --- a/lib/pangea/extensions/pangea_room_extension/user_permissions_extension.dart +++ b/lib/pangea/extensions/pangea_room_extension/user_permissions_extension.dart @@ -88,20 +88,8 @@ extension UserPermissionsRoomExtension on Room { return false; } - final isSpaceAdmin = isRoomAdmin; - final isChildRoomAdmin = room?.isRoomAdmin ?? true; - - // if user is not admin of child room, return false - if (!isChildRoomAdmin) return false; - - // if the child room is a space, or will be a space, - // then the user must be an admin of the parent space - if (room?.isSpace ?? spaceMode) return isSpaceAdmin; - - // otherwise, the user can add the child room to the parent - // if they're the admin of the parent or if the parent creation - // of group chats - return isSpaceAdmin || (pangeaRoomRules?.isCreateRooms ?? false); + // Can add child if, and only if, admin of child + return room?.isRoomAdmin ?? true; } bool get _canIAddSpaceParents =>