From 558b292c25b3eb9be5e1aea816bdc6d45b4bd0ee Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 Sep 2021 09:41:58 +0100 Subject: [PATCH 1/2] Adapt and re-use the RolesRoomSettingsTab for Spaces --- .../views/dialogs/SpaceSettingsDialog.tsx | 8 ++ .../tabs/room/RolesRoomSettingsTab.tsx | 92 ++++++++++++------- src/i18n/strings/en_EN.json | 25 +++-- 3 files changed, 83 insertions(+), 42 deletions(-) diff --git a/src/components/views/dialogs/SpaceSettingsDialog.tsx b/src/components/views/dialogs/SpaceSettingsDialog.tsx index fe836ebc5c..46821b751b 100644 --- a/src/components/views/dialogs/SpaceSettingsDialog.tsx +++ b/src/components/views/dialogs/SpaceSettingsDialog.tsx @@ -29,10 +29,12 @@ import SpaceSettingsVisibilityTab from "../spaces/SpaceSettingsVisibilityTab"; import SettingsStore from "../../../settings/SettingsStore"; import { UIFeature } from "../../../settings/UIFeature"; import AdvancedRoomSettingsTab from "../settings/tabs/room/AdvancedRoomSettingsTab"; +import RolesRoomSettingsTab from "../settings/tabs/room/RolesRoomSettingsTab"; export enum SpaceSettingsTab { General = "SPACE_GENERAL_TAB", Visibility = "SPACE_VISIBILITY_TAB", + Roles = "SPACE_ROLES_TAB", Advanced = "SPACE_ADVANCED_TAB", } @@ -62,6 +64,12 @@ const SpaceSettingsDialog: React.FC = ({ matrixClient: cli, space, onFin "mx_SpaceSettingsDialog_visibilityIcon", , ), + new Tab( + SpaceSettingsTab.Roles, + _td("Roles & Permissions"), + "mx_RoomSettingsDialog_rolesIcon", + , + ), SettingsStore.getValue(UIFeature.AdvancedSettings) ? new Tab( SpaceSettingsTab.Advanced, diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx index 9225bc6b94..d27910517d 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx @@ -28,36 +28,31 @@ import { compare } from "../../../../../utils/strings"; import ErrorDialog from '../../../dialogs/ErrorDialog'; import PowerSelector from "../../../elements/PowerSelector"; -const plEventsToLabels = { - // These will be translated for us later. - [EventType.RoomAvatar]: _td("Change room avatar"), - [EventType.RoomName]: _td("Change room name"), - [EventType.RoomCanonicalAlias]: _td("Change main address for the room"), - [EventType.RoomHistoryVisibility]: _td("Change history visibility"), - [EventType.RoomPowerLevels]: _td("Change permissions"), - [EventType.RoomTopic]: _td("Change topic"), - [EventType.RoomTombstone]: _td("Upgrade the room"), - [EventType.RoomEncryption]: _td("Enable room encryption"), - [EventType.RoomServerAcl]: _td("Change server ACLs"), +interface IEventShowOpts { + isState?: boolean; + hideForSpace?: boolean; +} - // TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111) - "im.vector.modular.widgets": _td("Modify widgets"), -}; +interface IPowerLevelDescriptor { + desc: string; + defaultValue: number; + hideForSpace?: boolean; +} -const plEventsToShow = { +const plEventsToShow: Record = { // If an event is listed here, it will be shown in the PL settings. Defaults will be calculated. [EventType.RoomAvatar]: { isState: true }, [EventType.RoomName]: { isState: true }, [EventType.RoomCanonicalAlias]: { isState: true }, - [EventType.RoomHistoryVisibility]: { isState: true }, + [EventType.RoomHistoryVisibility]: { isState: true, hideForSpace: true }, [EventType.RoomPowerLevels]: { isState: true }, [EventType.RoomTopic]: { isState: true }, - [EventType.RoomTombstone]: { isState: true }, - [EventType.RoomEncryption]: { isState: true }, - [EventType.RoomServerAcl]: { isState: true }, + [EventType.RoomTombstone]: { isState: true, hideForSpace: true }, + [EventType.RoomEncryption]: { isState: true, hideForSpace: true }, + [EventType.RoomServerAcl]: { isState: true, hideForSpace: true }, // TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111) - "im.vector.modular.widgets": { isState: true }, + "im.vector.modular.widgets": { isState: true, hideForSpace: true }, }; // parse a string as an integer; if the input is undefined, or cannot be parsed @@ -145,7 +140,7 @@ export default class RolesRoomSettingsTab extends React.Component { private onPowerLevelsChanged = (inputValue: string, powerLevelKey: string) => { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); - const plEvent = room.currentState.getStateEvents('m.room.power_levels', ''); + const plEvent = room.currentState.getStateEvents(EventType.RoomPowerLevels, ''); let plContent = plEvent ? (plEvent.getContent() || {}) : {}; // Clone the power levels just in case @@ -173,7 +168,7 @@ export default class RolesRoomSettingsTab extends React.Component { parentObj[keyPath[keyPath.length - 1]] = value; } - client.sendStateEvent(this.props.roomId, "m.room.power_levels", plContent).catch(e => { + client.sendStateEvent(this.props.roomId, EventType.RoomPowerLevels, plContent).catch(e => { console.error(e); Modal.createTrackedDialog('Power level requirement change failed', '', ErrorDialog, { @@ -189,7 +184,7 @@ export default class RolesRoomSettingsTab extends React.Component { private onUserPowerLevelChanged = (value: string, powerLevelKey: string) => { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); - const plEvent = room.currentState.getStateEvents('m.room.power_levels', ''); + const plEvent = room.currentState.getStateEvents(EventType.RoomPowerLevels, ''); let plContent = plEvent ? (plEvent.getContent() || {}) : {}; // Clone the power levels just in case @@ -199,7 +194,7 @@ export default class RolesRoomSettingsTab extends React.Component { if (!plContent['users']) plContent['users'] = {}; plContent['users'][powerLevelKey] = value; - client.sendStateEvent(this.props.roomId, "m.room.power_levels", plContent).catch(e => { + client.sendStateEvent(this.props.roomId, EventType.RoomPowerLevels, plContent).catch(e => { console.error(e); Modal.createTrackedDialog('Power level change failed', '', ErrorDialog, { @@ -215,11 +210,31 @@ export default class RolesRoomSettingsTab extends React.Component { render() { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); - const plEvent = room.currentState.getStateEvents('m.room.power_levels', ''); - const plContent = plEvent ? (plEvent.getContent() || {}) : {}; - const canChangeLevels = room.currentState.mayClientSendStateEvent('m.room.power_levels', client); + const isSpaceRoom = room.isSpaceRoom(); - const powerLevelDescriptors = { + const plEvent = room.currentState.getStateEvents(EventType.RoomPowerLevels, ''); + const plContent = plEvent ? (plEvent.getContent() || {}) : {}; + const canChangeLevels = room.currentState.mayClientSendStateEvent(EventType.RoomPowerLevels, client); + + const plEventsToLabels = { + // These will be translated for us later. + [EventType.RoomAvatar]: isSpaceRoom ? _td("Change space avatar") : _td("Change room avatar"), + [EventType.RoomName]: isSpaceRoom ? _td("Change space name") : _td("Change room name"), + [EventType.RoomCanonicalAlias]: isSpaceRoom + ? _td("Change main address for the space") + : _td("Change main address for the room"), + [EventType.RoomHistoryVisibility]: _td("Change history visibility"), + [EventType.RoomPowerLevels]: _td("Change permissions"), + [EventType.RoomTopic]: isSpaceRoom ? _td("Change description") : _td("Change topic"), + [EventType.RoomTombstone]: _td("Upgrade the room"), + [EventType.RoomEncryption]: _td("Enable room encryption"), + [EventType.RoomServerAcl]: _td("Change server ACLs"), + + // TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111) + "im.vector.modular.widgets": isSpaceRoom ? null : _td("Modify widgets"), + }; + + const powerLevelDescriptors: Record = { "users_default": { desc: _t('Default role'), defaultValue: 0, @@ -227,6 +242,7 @@ export default class RolesRoomSettingsTab extends React.Component { "events_default": { desc: _t('Send messages'), defaultValue: 0, + hideForSpace: true, }, "invite": { desc: _t('Invite users'), @@ -247,10 +263,12 @@ export default class RolesRoomSettingsTab extends React.Component { "redact": { desc: _t('Remove messages sent by others'), defaultValue: 50, + hideForSpace: true, }, "notifications.room": { desc: _t('Notify everyone'), defaultValue: 50, + hideForSpace: true, }, }; @@ -361,6 +379,9 @@ export default class RolesRoomSettingsTab extends React.Component { const powerSelectors = Object.keys(powerLevelDescriptors).map((key, index) => { const descriptor = powerLevelDescriptors[key]; + if (isSpaceRoom && descriptor.hideForSpace) { + return null; + } const keyPath = key.split('.'); let currentObj = plContent; @@ -382,14 +403,18 @@ export default class RolesRoomSettingsTab extends React.Component { onChange={this.onPowerLevelsChanged} /> ; - }); + }).filter(Boolean); // hide the power level selector for enabling E2EE if it the room is already encrypted if (client.isRoomEncrypted(this.props.roomId)) { - delete eventsLevels["m.room.encryption"]; + delete eventsLevels[EventType.RoomEncryption]; } const eventPowerSelectors = Object.keys(eventsLevels).map((eventType, i) => { + if (isSpaceRoom && plEventsToShow[eventType].hideForSpace) { + return null; + } + let label = plEventsToLabels[eventType]; if (label) { label = _t(label); @@ -408,7 +433,7 @@ export default class RolesRoomSettingsTab extends React.Component { /> ); - }); + }).filter(Boolean); return (
@@ -418,7 +443,10 @@ export default class RolesRoomSettingsTab extends React.Component { { bannedUsersSection }
{ _t("Permissions") } -

{ _t('Select the roles required to change various parts of the room') }

+

{ isSpaceRoom + ? _t('Select the roles required to change various parts of the space') + : _t('Select the roles required to change various parts of the room') + }

{ powerSelectors } { eventPowerSelectors }
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index f3ae9424e0..7c74334862 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1421,16 +1421,6 @@ "Notification sound": "Notification sound", "Set a new custom sound": "Set a new custom sound", "Browse": "Browse", - "Change room avatar": "Change room avatar", - "Change room name": "Change room name", - "Change main address for the room": "Change main address for the room", - "Change history visibility": "Change history visibility", - "Change permissions": "Change permissions", - "Change topic": "Change topic", - "Upgrade the room": "Upgrade the room", - "Enable room encryption": "Enable room encryption", - "Change server ACLs": "Change server ACLs", - "Modify widgets": "Modify widgets", "Failed to unban": "Failed to unban", "Unban": "Unban", "Banned by %(displayName)s": "Banned by %(displayName)s", @@ -1439,6 +1429,20 @@ "An error occurred changing the room's power level requirements. Ensure you have sufficient permissions and try again.": "An error occurred changing the room's power level requirements. Ensure you have sufficient permissions and try again.", "Error changing power level": "Error changing power level", "An error occurred changing the user's power level. Ensure you have sufficient permissions and try again.": "An error occurred changing the user's power level. Ensure you have sufficient permissions and try again.", + "Change space avatar": "Change space avatar", + "Change room avatar": "Change room avatar", + "Change space name": "Change space name", + "Change room name": "Change room name", + "Change main address for the space": "Change main address for the space", + "Change main address for the room": "Change main address for the room", + "Change history visibility": "Change history visibility", + "Change permissions": "Change permissions", + "Change description": "Change description", + "Change topic": "Change topic", + "Upgrade the room": "Upgrade the room", + "Enable room encryption": "Enable room encryption", + "Change server ACLs": "Change server ACLs", + "Modify widgets": "Modify widgets", "Default role": "Default role", "Send messages": "Send messages", "Invite users": "Invite users", @@ -1453,6 +1457,7 @@ "Banned users": "Banned users", "Send %(eventType)s events": "Send %(eventType)s events", "Permissions": "Permissions", + "Select the roles required to change various parts of the space": "Select the roles required to change various parts of the space", "Select the roles required to change various parts of the room": "Select the roles required to change various parts of the room", "Are you sure you want to add encryption to this public room?": "Are you sure you want to add encryption to this public room?", "It's not recommended to add encryption to public rooms.Anyone can find and join public rooms, so anyone can read messages in them. You'll get none of the benefits of encryption, and you won't be able to turn it off later. Encrypting messages in a public room will make receiving and sending messages slower.": "It's not recommended to add encryption to public rooms.Anyone can find and join public rooms, so anyone can read messages in them. You'll get none of the benefits of encryption, and you won't be able to turn it off later. Encrypting messages in a public room will make receiving and sending messages slower.", From d46181385c89c317fb2713d348973a424963b4cd Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 Sep 2021 13:05:04 +0100 Subject: [PATCH 2/2] Also default to PL invite=50 for private space creation --- src/components/views/spaces/SpaceCreateMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/spaces/SpaceCreateMenu.tsx b/src/components/views/spaces/SpaceCreateMenu.tsx index 1762b3a964..59c970c7d0 100644 --- a/src/components/views/spaces/SpaceCreateMenu.tsx +++ b/src/components/views/spaces/SpaceCreateMenu.tsx @@ -56,7 +56,7 @@ export const createSpace = async ( power_level_content_override: { // Only allow Admins to write to the timeline to prevent hidden sync spam events_default: 100, - ...isPublic ? { invite: 0 } : {}, + invite: isPublic ? 0 : 50, }, room_alias_name: isPublic && alias ? alias.substr(1, alias.indexOf(":") - 1) : undefined, topic,