From 459ffc47d6061f937b8c67362472dcaeafc84d07 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Tue, 24 Oct 2017 15:25:35 +0100 Subject: [PATCH] Prevent editing of UI requiring user privilege if user unprivileged --- src/components/structures/GroupView.js | 93 +++++++++++++++++--------- 1 file changed, 63 insertions(+), 30 deletions(-) diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index b2e49fb67a..52680ea5fa 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -481,6 +481,10 @@ export default React.createClass({ editing: true, profileForm: Object.assign({}, this.state.summary.profile), }); + dis.dispatch({ + action: 'ui_opacity', + sideOpacity: 0.3, + }); }, _onCancelClick: function() { @@ -488,6 +492,7 @@ export default React.createClass({ editing: false, profileForm: null, }); + dis.dispatch({action: 'ui_opacity'}); }, _onNameChange: function(value) { @@ -535,12 +540,16 @@ export default React.createClass({ _onSaveClick: function() { this.setState({saving: true}); - MatrixClientPeg.get().setGroupProfile(this.props.groupId, this.state.profileForm).then((result) => { + const savePromise = this.state.isUserPrivileged ? + MatrixClientPeg.get().setGroupProfile(this.props.groupId, this.state.profileForm) : + Promise.resolve(); + savePromise.then((result) => { this.setState({ saving: false, editing: false, summary: null, }); + dis.dispatch({action: 'ui_opacity'}); this._initGroupStore(this.props.groupId); }).catch((e) => { this.setState({ @@ -624,23 +633,40 @@ export default React.createClass({ }); }, + _getGroupSection: function() { + const groupSettingsSectionClasses = classnames({ + "mx_GroupView_group": this.state.editing, + "mx_GroupView_group_disabled": this.state.editing && !this.state.isUserPrivileged, + }); + + const header = this.state.editing ?

{ _t('Community Settings') }

:
; + return
+ { header } + { this._getLongDescriptionNode() } + { this._getRoomsNode() } +
; + }, + _getRoomsNode: function() { const RoomDetailList = sdk.getComponent('rooms.RoomDetailList'); const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const TintableSvg = sdk.getComponent('elements.TintableSvg'); - const addButton = this.state.editing ? - ( -
+ + const addRoomRow = this.state.editing ? + ( +
-
+
{ _t('Add rooms to this community') }
) :
; return

{ _t('Rooms') }

- { addButton } + { addRoomRow }
; @@ -790,7 +816,7 @@ export default React.createClass({ _getMemberSettingsSection: function() { return
-

{ _t("Community Member Settings") }

+

{ _t("Community Member Settings") }

+ const groupDescEditingClasses = classnames({ + "mx_GroupView_groupDesc": true, + "mx_GroupView_groupDesc_disabled": !this.state.isUserPrivileged, + }); + + return this.state.editing ? +

{ _t("Long Description (HTML)") }