Skip to content
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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f592669
hide plus icon when user doesn't have both permission for create-c an…
cfunkles Apr 23, 2018
df6e91b
add helper to checkout two permissions set initial value for the room…
cfunkles Apr 23, 2018
badaefe
hide the plus icon in directory if user doesn't have both create-c an…
cfunkles Apr 23, 2018
bda88ac
get permissions for create channels and groups
cfunkles Apr 23, 2018
9e49bc9
check if user can add channel hide and groups, hide button based upon…
cfunkles Apr 23, 2018
dcdb454
prevent add user button from being hidden when user has permission ad…
cfunkles Apr 23, 2018
87999b1
Merge branch 'develop' into fix-permissions-bug-create-channels-add-u…
chuckAtCataworx Apr 25, 2018
f2232ae
Merge branch 'develop' into fix-permissions-bug-create-channels-add-u…
chuckAtCataworx Apr 25, 2018
7e5a44f
removed the if statement and use short hand if else syntax
cfunkles May 11, 2018
74a8d87
Merge branch 'develop' into fix-permissions-bug-create-channels-add-u…
chuckAtCataworx May 11, 2018
31e6e5b
Merge branch 'fix-permissions-bug-create-channels-add-users' of https…
cfunkles May 11, 2018
8853fb8
better code for disabling checkbox in create room feature if user doe…
cfunkles May 11, 2018
aee7a94
add missing simicolon
cfunkles May 11, 2018
975ef05
put canShowAddUsersButton into seperate function call function in eve…
cfunkles May 15, 2018
807b25e
move the canShowAddUsersButton function to define before it's called
cfunkles May 15, 2018
ae193fa
Merge branch 'develop' into fix-permissions-bug-create-channels-add-u…
chuckAtCataworx May 16, 2018
44cda3a
fix bug that prevents the viewing of the keyboard shortcuts button in…
cfunkles May 16, 2018
c9ad6ec
fix permissions
ggazzo May 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/client/defaultTabBars.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ RocketChat.TabBar.addButton({
});

RocketChat.TabBar.addButton({
groups: ['channel', 'privategroup', 'directmessage'],
groups: ['channel', 'group', 'direct'],
id: 'keyboard-shortcut-list',
i18nTitle: 'Keyboard_Shortcuts_Title',
icon: 'keyboard',
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-flextab/client/flexTabBar.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1 class="contextual-bar__header-title">{{_ label}}</h1>
<template name="RoomsActionTab">
<div class="rc-room-actions">
{{#each buttons}}
<div class="rc-room-actions__action tab-button {{active}} {{visible}} {{class}} js-action">
<div class="rc-room-actions__action tab-button {{active}} {{visible}} {{class}} js-action" data-id="{{id}}">
<button class="rc-tooltip rc-tooltip--down rc-room-actions__button" aria-label="{{title}}">
{{> icon block="tab-button-icon" icon=icon }}
</button>
Expand Down
81 changes: 44 additions & 37 deletions packages/rocketchat-ui-flextab/client/flexTabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,51 @@ const commonHelpers = {
}
}
};

function canShowAddUsersButton(rid) {
const canAddToChannel = RocketChat.authz.hasAllPermission(
'add-user-to-any-c-room', rid
);
const canAddToGroup = RocketChat.authz.hasAllPermission(
'add-user-to-any-p-room', rid
);
const canAddToJoinedRoom = RocketChat.authz.hasAllPermission(
'add-user-to-joined-room', rid
);
if (
!canAddToJoinedRoom &&
!canAddToChannel &&
Template.instance().tabBar.currentGroup() === 'channel'
) {
return false;
}
if (
!canAddToJoinedRoom &&
!canAddToGroup &&
Template.instance().tabBar.currentGroup() === 'group'
) {
return false;
}
return true;
}
const filterButtons = (button, anonymous, rid) => {
if (!Meteor.userId() && !anonymous) {
return false;
}
if (button.groups.indexOf(Template.instance().tabBar.currentGroup()) === -1) {
return false;
}
if (button.id === 'addUsers' && !canShowAddUsersButton(rid)) {
return false;
}
return true;
};
Template.flexTabBar.helpers({
headerData() {
return Template.instance().tabBar.getData();
},
...commonHelpers,
buttons() {
return RocketChat.TabBar.getButtons().filter(button => {
if (!Meteor.userId() && !this.anonymous) {
return false;
}
if (button.groups.indexOf(Template.instance().tabBar.currentGroup()) === -1) {
return false;
}
return true;
});
return RocketChat.TabBar.getButtons().filter(button => filterButtons(button, this.anonymous, this.data.rid));
},
opened() {
return Template.instance().tabBar.getState();
Expand Down Expand Up @@ -131,15 +160,7 @@ Template.RoomsActionTab.events({
'click .js-more'(e, instance) {
$(e.currentTarget).blur();
e.preventDefault();
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;
}
return true;
});
const buttons = RocketChat.TabBar.getButtons().filter(button => filterButtons(button, instance.anonymous, instance.data.rid));
const groups = [{items:(instance.small.get() ? buttons : buttons.slice(4)).map(item => {
item.name = TAPi18n.__(item.i18nTitle);
item.action = action;
Expand Down Expand Up @@ -188,31 +209,17 @@ Template.RoomsActionTab.helpers({
if (Template.instance().small.get()) {
return [];
}
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;
}
return true;
});
const buttons = RocketChat.TabBar.getButtons().filter(button => filterButtons(button, this.anonymous, this.data.rid));
return buttons.length <= 5 ? buttons : buttons.slice(0, 4);
},

moreButtons() {
if (Template.instance().small.get()) {
return true;
}
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;
}
return true;
});
const buttons = RocketChat.TabBar.getButtons().filter(button =>
filterButtons(button, this.anonymous, this.data.rid)
);
return buttons.length > 5;
}
});
6 changes: 3 additions & 3 deletions packages/rocketchat-ui/client/views/app/createChannel.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ <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>
<input type="checkbox" class="rc-switch__input" name="type" value="p" checked={{roomTypeIsP}} disabled="{{cantCreateBothTypes}}">
<span class="rc-switch__button">
<span class="rc-switch__button-inside"></span>
</span>
<span class="rc-switch__button-inside"></span>
</span>
<span class="rc-switch__text">
{{typeLabel}}
</span>
Expand Down
8 changes: 7 additions & 1 deletion packages/rocketchat-ui/client/views/app/createChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ 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'));
},
cantCreateBothTypes() {
return !RocketChat.authz.hasAllPermission(['create-c', 'create-p']);
},
roomTypeIsP() {
return Template.instance().type.get() === 'p';
},
createIsDisabled() {
const instance = Template.instance();
const invalid = instance.invalid.get();
Expand Down Expand Up @@ -258,7 +264,7 @@ Template.createChannel.onCreated(function() {
this.extensions_validations = {};
this.extensions_submits = {};
this.name = new ReactiveVar('');
this.type = new ReactiveVar('p');
this.type = new ReactiveVar(RocketChat.authz.hasAllPermission(['create-p']) ? 'p' : 'c');
this.readOnly = new ReactiveVar(false);
this.broadcast = new ReactiveVar(false);
this.inUse = new ReactiveVar(undefined);
Expand Down
4 changes: 3 additions & 1 deletion packages/rocketchat-ui/client/views/app/directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
</div>
</label>
</div>
<button class="rc-button rc-button--small rc-button--primary rc-directory-plus">{{> icon icon="plus" }}</button>
{{#if createChannelOrGroup}}
<button class="rc-button rc-button--small rc-button--primary rc-directory-plus">{{> icon icon="plus" }}</button>
{{/if}}
</div>
{{/header}}
<div class="rc-directory-content">
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-ui/client/views/app/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Template.directory.helpers({
} = Template.instance();

return key === searchSortBy.get() && sortDirection.get() !== 'asc' ? 'sort-up' : 'sort-down';
},
createChannelOrGroup() {
return RocketChat.authz.hasAtLeastOnePermission(['create-c', 'create-p']);
}
});

Expand Down
33 changes: 33 additions & 0 deletions tests/end-to-end/ui/04-main-elements-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,19 @@ describe('[Main Elements Render]', function() {

describe('Files Tab:', () => {
before(()=> {
if (flexTab.filesTab.isVisible()) {
this.shouldClose = undefined;
return flexTab.filesTab.click();
}
this.shouldClose = true;
flexTab.moreActions.click();
flexTab.operateFlexTab('files', true);
});

after(()=> {
if (!this.shouldClose) {
return;
}
flexTab.moreActions.click();
flexTab.operateFlexTab('files', false);
});
Expand All @@ -292,12 +300,21 @@ describe('[Main Elements Render]', function() {
});

describe('Mentions Tab:', () => {

before(()=> {
if (flexTab.mentionsTab.isVisible()) {
this.shouldClose = undefined;
return flexTab.mentionsTab.click();
}
this.shouldClose = true;
flexTab.moreActions.click();
flexTab.operateFlexTab('mentions', true);
});

after(()=> {
if (!this.shouldClose) {
return;
}
flexTab.moreActions.click();
flexTab.operateFlexTab('mentions', false);
});
Expand All @@ -309,11 +326,19 @@ describe('[Main Elements Render]', function() {

describe('Starred Messages Tab:', () => {
before(()=> {
if (flexTab.starredTab.isVisible()) {
this.shouldClose = undefined;
return flexTab.starredTab.click();
}
this.shouldClose = true;
flexTab.moreActions.click();
flexTab.operateFlexTab('starred', true);
});

after(()=> {
if (!this.shouldClose) {
return;
}
flexTab.moreActions.click();
flexTab.operateFlexTab('starred', false);
});
Expand All @@ -325,11 +350,19 @@ describe('[Main Elements Render]', function() {

describe('Pinned Messages Tab:', () => {
before(()=> {
if (flexTab.pinnedTab.isVisible()) {
this.shouldClose = undefined;
return flexTab.pinnedTab.click();
}
this.shouldClose = true;
flexTab.moreActions.click();
flexTab.operateFlexTab('pinned', true);
});

after(()=> {
if (!this.shouldClose) {
return;
}
flexTab.moreActions.click();
flexTab.operateFlexTab('pinned', false);
});
Expand Down
8 changes: 4 additions & 4 deletions tests/pageobjects/flex-tab.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ class FlexTab extends Page {
get notificationsSettings() { return browser.element('.push-notifications'); }

// Files Tab
get filesTab() { return browser.element('.rc-popover__item[data-id=uploaded-files-list]'); }
get filesTab() { return browser.element('.rc-popover__item[data-id=uploaded-files-list], .tab-button[data-id=uploaded-files-list]'); }
get fileItem() { return browser.element('.uploaded-files-list ul:first-child'); }
get filesTabContent() { return browser.element('.uploaded-files-list'); }
get fileDelete() { return browser.element('.uploaded-files-list ul:first-child .file-delete'); }
get fileDownload() { return browser.element('.uploaded-files-list ul:first-child .file-download'); }
get fileName() { return browser.element('.uploaded-files-list ul:first-child .room-file-item'); }

// Mentions Tab
get mentionsTab() { return browser.element('.rc-popover__item[data-id=mentions]'); }
get mentionsTab() { return browser.element('.rc-popover__item[data-id=mentions], .tab-button[data-id=mentions]'); }
get mentionsTabContent() { return browser.element('.mentioned-messages-list'); }

// Starred Tab
get starredTab() { return browser.element('.rc-popover__item[data-id=starred-messages]'); }
get starredTab() { return browser.element('.rc-popover__item[data-id=starred-messages], .tab-button[data-id=starred-messages]'); }
get starredTabContent() { return browser.element('.starred-messages-list'); }

// Pinned Tab
get pinnedTab() { return browser.element('.rc-popover__item[data-id=pinned-messages]'); }
get pinnedTab() { return browser.element('.rc-popover__item[data-id=pinned-messages], .tab-button[data-id=pinned-messages]'); }
get pinnedTabContent() { return browser.element('.pinned-messages-list'); }

get firstSetting() { return browser.element('.clearfix li:nth-child(1) .current-setting'); }
Expand Down