-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] UI was not disabling the actions when users has had no permissions to create channels or add users to rooms #10564
Changes from 8 commits
f592669
df6e91b
badaefe
bda88ac
9e49bc9
dcdb454
87999b1
f2232ae
7e5a44f
74a8d87
31e6e5b
8853fb8
aee7a94
975ef05
807b25e
ae193fa
44cda3a
c9ad6ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,15 +188,30 @@ Template.RoomsActionTab.helpers({ | |
if (Template.instance().small.get()) { | ||
return []; | ||
} | ||
let removedButton = false; | ||
const canAddToChannel = RocketChat.authz.hasAllPermission('add-user-to-any-c-room'); | ||
const canAddToGroup = RocketChat.authz.hasAllPermission('add-user-to-any-p-room'); | ||
const canAddToJoinedRoom = RocketChat.authz.hasAllPermission('add-user-to-joined-room'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this happen on create-channel as well? Need to make sure the room is created before he is able to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I think your comment on the createChannel.js file looks like you saw where that happens. I could take a look at how we use the add-user-to-joined-room permission. In this implementation the user needs the permissions 'add-user-to-any-c-room'('add-user-to-any-p-room' for groups) or 'add-user-to-joined-room' to view the 'add users' button. Perhaps it should only rely on the 'add-user-to-joined-room'? It is as simple as deleting the two const 'canAddToChannel' and 'canAddToGroup' then removing them from the if statement on line 202 and 206. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, checking the permissions page show that users do not have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a slight mistake in my comment in describing the behavior, I edited the comment to reflect the actual behavior of what is coded. Which is what I think should correctly handle the expected behavior. The mistake was saying you need both permissions to view, but corrected to say one or the other. |
||
const buttons = RocketChat.TabBar.getButtons().filter(button => { | ||
if (!Meteor.userId() && !this.anonymous) { | ||
return false; | ||
} | ||
if (button.groups.indexOf(Template.instance().tabBar.currentGroup()) === -1) { | ||
return false; | ||
} | ||
if (!canAddToJoinedRoom && !canAddToChannel && Template.instance().tabBar.currentGroup() === 'channel' && button.id === 'addUsers') { | ||
removedButton = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove ;) |
||
return false; | ||
} | ||
if (!canAddToJoinedRoom && !canAddToGroup && Template.instance().tabBar.currentGroup() === 'group' && button.id === 'addUsers') { | ||
removedButton = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove ;) |
||
return false; | ||
} | ||
return true; | ||
}); | ||
if (removedButton) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove ;) |
||
return buttons.length <= 5 ? buttons : buttons.slice(0, 3); | ||
} | ||
return buttons.length <= 5 ? buttons : buttons.slice(0, 4); | ||
}, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,12 @@ <h1 class="create-channel__title">{{_ "Create_A_New_Channel"}}</h1> | |
<div class="create-channel__switches"> | ||
<div class="rc-switch"> | ||
<label class="rc-switch__label" tabindex="-1"> | ||
<input type="checkbox" class="rc-switch__input" name="type" value="p" checked> | ||
<span class="rc-switch__button"> | ||
<span class="rc-switch__button-inside"></span> | ||
</span> | ||
{{#if canCreateBothTypes}} | ||
<input type="checkbox" class="rc-switch__input" name="type" value="p" checked> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chuckAtCataworx could you change this code to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of |
||
<span class="rc-switch__button"> | ||
<span class="rc-switch__button-inside"></span> | ||
</span> | ||
{{/if}} | ||
<span class="rc-switch__text"> | ||
{{typeLabel}} | ||
</span> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,9 @@ Template.createChannel.helpers({ | |
readOnlyDescription() { | ||
return t(Template.instance().readOnly.get() ? t('Only_authorized_users_can_write_new_messages') : t('All_users_in_the_channel_can_write_new_messages')); | ||
}, | ||
canCreateBothTypes() { | ||
return RocketChat.authz.hasAllPermission(['create-c', 'create-p']); | ||
}, | ||
createIsDisabled() { | ||
const instance = Template.instance(); | ||
const invalid = instance.invalid.get(); | ||
|
@@ -258,7 +261,11 @@ Template.createChannel.onCreated(function() { | |
this.extensions_validations = {}; | ||
this.extensions_submits = {}; | ||
this.name = new ReactiveVar(''); | ||
this.type = new ReactiveVar('p'); | ||
if (!RocketChat.authz.hasAllPermission(['create-p'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use this.type = new ReactiveVar(RocketChat.authz.hasAllPermission(['create-p']) ? 'p' : 'c') |
||
this.type = new ReactiveVar('c'); | ||
} else { | ||
this.type = new ReactiveVar('p'); | ||
} | ||
this.readOnly = new ReactiveVar(false); | ||
this.broadcast = new ReactiveVar(false); | ||
this.inUse = new ReactiveVar(undefined); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you dont need this variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this variable creates a potential issue. When the
add users
button isn't displayed, thenfiles list
gets duplicated. It stays in it's originalmore
section and takes the place of theadd users
button