From 3cd9c152c24f7ee1e68721261ddb48ef21c88228 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 11 May 2019 19:45:24 +0100 Subject: [PATCH 1/2] Check permission to invite before showing invite buttons/disable them Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- res/css/views/rooms/_MemberList.scss | 5 +++++ src/components/views/rooms/MemberInfo.js | 3 ++- src/components/views/rooms/MemberList.js | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/res/css/views/rooms/_MemberList.scss b/res/css/views/rooms/_MemberList.scss index cac97cb60d..c8d61c7cc5 100644 --- a/res/css/views/rooms/_MemberList.scss +++ b/res/css/views/rooms/_MemberList.scss @@ -87,6 +87,11 @@ limitations under the License. } } +.mx_MemberList_invite.mx_AccessibleButton_disabled { + background-color: grey; + cursor: not-allowed; +} + .mx_MemberList_invite span { background-image: url('$(res)/img/feather-customised/user-add.svg'); background-repeat: no-repeat; diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index 35161dedf7..a8eb508497 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -589,6 +589,7 @@ module.exports = withMatrixClient(React.createClass({ can.kick = me.powerLevel >= powerLevels.kick; can.ban = me.powerLevel >= powerLevels.ban; + can.invite = me.powerLevel >= powerLevels.invite; can.mute = me.powerLevel >= editPowerLevel; can.modifyLevel = me.powerLevel >= editPowerLevel && (isMe || me.powerLevel > them.powerLevel); can.modifyLevelMax = me.powerLevel; @@ -727,7 +728,7 @@ module.exports = withMatrixClient(React.createClass({ ); } - if (!member || !member.membership || member.membership === 'leave') { + if (this.state.can.invite && (!member || !member.membership || member.membership === 'leave')) { const roomId = member && member.roomId ? member.roomId : RoomViewStore.getRoomId(); const onInviteUserButton = async () => { try { diff --git a/src/components/views/rooms/MemberList.js b/src/components/views/rooms/MemberList.js index 8350001d01..5718276768 100644 --- a/src/components/views/rooms/MemberList.js +++ b/src/components/views/rooms/MemberList.js @@ -449,10 +449,23 @@ module.exports = React.createClass({ const cli = MatrixClientPeg.get(); const room = cli.getRoom(this.props.roomId); let inviteButton; + if (room && room.getMyMembership() === 'join') { + // assume we can invite until proven false + let canInvite = true; + + const plEvent = room.currentState.getStateEvents("m.room.power_levels", ""); + const me = room.getMember(cli.getUserId()); + if (plEvent && me) { + const content = plEvent.getContent(); + if (content && content.invite > me.powerLevel) { + canInvite = false; + } + } + const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); inviteButton = - + { _t('Invite to this room') } ; } From fd07b5c4767bdca3e49cbdfb68cbe9b08479b6a4 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 14 May 2019 23:03:02 +0100 Subject: [PATCH 2/2] use scss variable for grey Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- res/css/views/rooms/_MemberList.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/css/views/rooms/_MemberList.scss b/res/css/views/rooms/_MemberList.scss index c8d61c7cc5..0b9c7e2368 100644 --- a/res/css/views/rooms/_MemberList.scss +++ b/res/css/views/rooms/_MemberList.scss @@ -88,7 +88,7 @@ limitations under the License. } .mx_MemberList_invite.mx_AccessibleButton_disabled { - background-color: grey; + background-color: $greyed-fg-color;; cursor: not-allowed; }