PLT-7206: Remove the "Delete Channel" option for private channels if you're the last channel member and policy setting restricts channel deletion (#7050)
* PLT-7206: UI changes. Removed last user in channel loophole, refactored code to clean it up, added differentiated support for public and private channels, added unit tests. Still need to implement server-side checks * PLT-7206: All helper methods in channel_utils.jsx now accept the same three boolean variables in the same order and use the same boolean logic to check their values. * PLT-7206: Added unit tests for showManagementOptions(...) * PLT-7206: Fixed test case descriptions * Added unit tests for showCreateOption(...) * PLT-7206: Added unit tests for canManageMembers(...) * PLT-7206: Removed last person in channel loophole from server-side code * PLT-7206: Reverted config.json * PLT-7206: Fixed double negatives in unit test names * PLT-7206: PR feedback - Removed confusing comment and unused variable
Этот коммит содержится в:
@@ -448,23 +448,14 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var memberCount int64
|
||||
if memberCount, err = app.GetChannelMemberCount(id); err != nil {
|
||||
c.Err = err
|
||||
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
// Allow delete if user is the only member left in channel
|
||||
if memberCount > 1 {
|
||||
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
|
||||
return
|
||||
}
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
err = app.DeleteChannel(channel, c.Session.UserId)
|
||||
|
||||
@@ -1476,9 +1476,8 @@ func TestDeleteChannel(t *testing.T) {
|
||||
t.Fatal("should have errored not system admin")
|
||||
}
|
||||
|
||||
// Only one left in channel, should be able to delete
|
||||
if _, err := Client.DeleteChannel(channel4.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
if _, err := Client.DeleteChannel(channel4.Id); err == nil {
|
||||
t.Fatal("Should not be able to delete channel, even though only one user is left")
|
||||
}
|
||||
|
||||
th.LoginSystemAdmin()
|
||||
|
||||
@@ -534,19 +534,12 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var memberCount int64
|
||||
if memberCount, err = app.GetChannelMemberCount(c.Params.ChannelId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
// Allow delete if there's only one member left in a private channel
|
||||
if memberCount > 1 && channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1064,15 +1064,13 @@ func TestDeleteChannel(t *testing.T) {
|
||||
|
||||
// last member of a public channel should have required permission to delete
|
||||
publicChannel6 = th.CreateChannelWithClient(th.Client, model.CHANNEL_OPEN)
|
||||
|
||||
_, resp = Client.DeleteChannel(publicChannel6.Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// last member of a private channel should be able to delete it regardless of required permissions
|
||||
// last member of a private channel should not be able to delete it if they don't have required permissions
|
||||
privateChannel7 = th.CreateChannelWithClient(th.Client, model.CHANNEL_PRIVATE)
|
||||
|
||||
_, resp = Client.DeleteChannel(privateChannel7.Id)
|
||||
CheckNoError(t, resp)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestRestoreChannel(t *testing.T) {
|
||||
|
||||
@@ -286,10 +286,9 @@ export default class ChannelHeader extends React.Component {
|
||||
</Popover>
|
||||
);
|
||||
let channelTitle = channel.display_name;
|
||||
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
|
||||
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
|
||||
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
|
||||
const isDirect = (this.state.channel.type === Constants.DM_CHANNEL);
|
||||
const isGroup = (this.state.channel.type === Constants.GM_CHANNEL);
|
||||
let webrtc;
|
||||
@@ -533,7 +532,7 @@ export default class ChannelHeader extends React.Component {
|
||||
/>
|
||||
);
|
||||
|
||||
if (ChannelUtils.canManageMembers(channel, isSystemAdmin, isTeamAdmin, isChannelAdmin)) {
|
||||
if (ChannelUtils.canManageMembers(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
dropdownContents.push(
|
||||
<li
|
||||
key='add_members'
|
||||
@@ -594,26 +593,7 @@ export default class ChannelHeader extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
const deleteOption = (
|
||||
<li
|
||||
key='delete_channel'
|
||||
role='presentation'
|
||||
>
|
||||
<ToggleModalButton
|
||||
id='channelDelete'
|
||||
role='menuitem'
|
||||
dialogType={DeleteChannelModal}
|
||||
dialogProps={{channel}}
|
||||
>
|
||||
<FormattedMessage
|
||||
id='channel_header.delete'
|
||||
defaultMessage='Delete Channel'
|
||||
/>
|
||||
</ToggleModalButton>
|
||||
</li>
|
||||
);
|
||||
|
||||
if (ChannelUtils.showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
|
||||
if (ChannelUtils.showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
dropdownContents.push(
|
||||
<li
|
||||
key='divider-2'
|
||||
@@ -679,8 +659,25 @@ export default class ChannelHeader extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, this.state.userCount)) {
|
||||
dropdownContents.push(deleteOption);
|
||||
if (ChannelUtils.showDeleteOptionForCurrentUser(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
dropdownContents.push(
|
||||
<li
|
||||
key='delete_channel'
|
||||
role='presentation'
|
||||
>
|
||||
<ToggleModalButton
|
||||
id='channelDelete'
|
||||
role='menuitem'
|
||||
dialogType={DeleteChannelModal}
|
||||
dialogProps={{channel}}
|
||||
>
|
||||
<FormattedMessage
|
||||
id='channel_header.delete'
|
||||
defaultMessage='Delete Channel'
|
||||
/>
|
||||
</ToggleModalButton>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
const canLeave = channel.type === Constants.PRIVATE_CHANNEL ? this.state.userCount > 1 : true;
|
||||
|
||||
@@ -95,7 +95,7 @@ export default class ChannelMembersDropdown extends React.Component {
|
||||
|
||||
// Checks if the current user has the power to remove this member from the channel.
|
||||
canRemoveMember() {
|
||||
return canManageMembers(this.props.channel, UserStore.isSystemAdminForCurrentUser(), TeamStore.isTeamAdminForCurrentTeam(), ChannelStore.isChannelAdminForCurrentChannel());
|
||||
return canManageMembers(this.props.channel, ChannelStore.isChannelAdminForCurrentChannel(), TeamStore.isTeamAdminForCurrentTeam(), UserStore.isSystemAdminForCurrentUser());
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -38,7 +38,7 @@ export default class ChannelMembersModal extends React.Component {
|
||||
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
|
||||
|
||||
let addMembersButton = null;
|
||||
if (canManageMembers(this.state.channel, isSystemAdmin, isTeamAdmin, isChannelAdmin) && this.state.channel.name !== Constants.DEFAULT_CHANNEL) {
|
||||
if (canManageMembers(this.state.channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) && this.state.channel.name !== Constants.DEFAULT_CHANNEL) {
|
||||
addMembersButton = (
|
||||
<a
|
||||
id='showInviteModal'
|
||||
|
||||
@@ -165,10 +165,10 @@ export default class MoreChannels extends React.Component {
|
||||
</p>
|
||||
);
|
||||
|
||||
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
|
||||
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
|
||||
if (!showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) {
|
||||
if (!showCreateOption(Constants.OPEN_CHANNEL, isTeamAdmin, isSystemAdmin)) {
|
||||
createNewChannelButton = null;
|
||||
createChannelHelpText = null;
|
||||
}
|
||||
|
||||
@@ -287,7 +287,6 @@ export default class Navbar extends React.Component {
|
||||
};
|
||||
|
||||
createDropdown(channel, channelTitle, isSystemAdmin, isTeamAdmin, isChannelAdmin, isDirect, isGroup, popoverContent) {
|
||||
const isAdmin = isSystemAdmin || isTeamAdmin;
|
||||
const infoIcon = Constants.INFO_ICON_SVG;
|
||||
|
||||
if (channel) {
|
||||
@@ -434,7 +433,7 @@ export default class Navbar extends React.Component {
|
||||
</li>
|
||||
);
|
||||
|
||||
if (ChannelUtils.canManageMembers(channel, isSystemAdmin, isTeamAdmin, isChannelAdmin)) {
|
||||
if (ChannelUtils.canManageMembers(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
manageMembersOption = (
|
||||
<li
|
||||
key='manage_members'
|
||||
@@ -492,7 +491,7 @@ export default class Navbar extends React.Component {
|
||||
</li>
|
||||
);
|
||||
|
||||
if (ChannelUtils.showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
|
||||
if (ChannelUtils.showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
setChannelHeaderOption = (
|
||||
<li role='presentation'>
|
||||
<a
|
||||
@@ -539,7 +538,7 @@ export default class Navbar extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, this.state.userCount)) {
|
||||
if (ChannelUtils.showDeleteOptionForCurrentUser(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
deleteChannelOption = (
|
||||
<li role='presentation'>
|
||||
<ToggleModalButton
|
||||
|
||||
@@ -192,13 +192,11 @@ export default class NewChannelModal extends React.PureComponent {
|
||||
</a>
|
||||
);
|
||||
|
||||
const isAdmin = this.props.isTeamAdmin || this.props.isSystemAdmin;
|
||||
|
||||
if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, this.props.isSystemAdmin)) {
|
||||
if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, this.props.isTeamAdmin, this.props.isSystemAdmin)) {
|
||||
createPublicChannelLink = null;
|
||||
}
|
||||
|
||||
if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isAdmin, this.props.isSystemAdmin)) {
|
||||
if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, this.props.isTeamAdmin, this.props.isSystemAdmin)) {
|
||||
createPrivateChannelLink = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ export default class PopoverListMembers extends React.Component {
|
||||
/>
|
||||
);
|
||||
|
||||
const manageMembers = canManageMembers(this.props.channel, isSystemAdmin, isTeamAdmin, isChannelAdmin);
|
||||
const manageMembers = canManageMembers(this.props.channel, isChannelAdmin, isTeamAdmin, isSystemAdmin);
|
||||
const isDefaultChannel = ChannelStore.isDefault(this.props.channel);
|
||||
|
||||
if ((manageMembers === false && isDefaultChannel === false) || isDefaultChannel) {
|
||||
|
||||
@@ -714,7 +714,7 @@ export default class Sidebar extends React.Component {
|
||||
/>
|
||||
);
|
||||
|
||||
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
|
||||
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
|
||||
let createPublicChannelIcon = (
|
||||
@@ -753,11 +753,11 @@ export default class Sidebar extends React.Component {
|
||||
</OverlayTrigger>
|
||||
);
|
||||
|
||||
if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) {
|
||||
if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isTeamAdmin, isSystemAdmin)) {
|
||||
createPublicChannelIcon = null;
|
||||
}
|
||||
|
||||
if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isAdmin, isSystemAdmin)) {
|
||||
if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isTeamAdmin, isSystemAdmin)) {
|
||||
createPrivateChannelIcon = null;
|
||||
}
|
||||
|
||||
|
||||
782
webapp/tests/utils/channel_utils.test.jsx
Обычный файл
782
webapp/tests/utils/channel_utils.test.jsx
Обычный файл
@@ -0,0 +1,782 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import * as Utils from 'utils/channel_utils.jsx';
|
||||
import Constants from 'utils/constants.jsx';
|
||||
|
||||
describe('Channel Utils', () => {
|
||||
describe('showDeleteOption', () => {
|
||||
test('all users can delete channels on unlicensed instances', () => {
|
||||
global.window.mm_license = {IsLicensed: 'false'};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(null, true, true, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('users cannot delete default channels', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
const channel = {name: Constants.DEFAULT_CHANNEL};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, true, true, true)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins can delete private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can delete private channels, user is not system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins can delete public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can delete public channels, user is not system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can delete private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can delete private channels, user is not system admin or team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can delete public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can delete public channels, user is not system admin or team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can delete private channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can delete public channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can delete public channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, true, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can delete private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, true, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can delete public channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can delete private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can delete public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can delete private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can delete public channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can delete private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('any member can delete public channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelDeletion: Constants.PERMISSIONS_ALL};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('any member can delete private channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelDeletion: Constants.PERMISSIONS_ALL};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showDeleteOptionForCurrentUser(channel, false, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('showManagementOptions', () => {
|
||||
test('all users can manage channel options on unlicensed instances', () => {
|
||||
global.window.mm_license = {IsLicensed: 'false'};
|
||||
expect(Utils.showManagementOptions(null, true, true, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can manage channel options in private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can manage channel options in private channels, user is not system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins can manage channel options in public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can manage channel options in public channels, user is not system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel options in private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel options in private channels, user is not system admin or team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel options in public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel options in public channels, user is not system admin or team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel options in private channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel options in public channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel options in public channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, true, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel options in private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, true, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel options in public channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel options in private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel options in public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel options in private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel options in public channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel options in private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('any member can manage channel options in public channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelManagement: Constants.PERMISSIONS_ALL};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('any member can manage channel options in private channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManagement: Constants.PERMISSIONS_ALL};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.showManagementOptions(channel, false, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('showCreateOption', () => {
|
||||
test('all users can create new channels on unlicensed instances', () => {
|
||||
global.window.mm_license = {IsLicensed: 'false'};
|
||||
expect(Utils.showCreateOption(null, true, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can create new private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelCreation: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.PRIVATE_CHANNEL, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can create new private channels, user is not system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelCreation: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.PRIVATE_CHANNEL, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins can create new public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can create new public channels, user is not system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can create new private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelCreation: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.PRIVATE_CHANNEL, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can create new private channels, user is not system admin or team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelCreation: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.PRIVATE_CHANNEL, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can create new public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can create new public channels, user is not system admin or team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can create new private channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelCreation: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.PRIVATE_CHANNEL, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can create new public channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can create new public channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can create new public channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can create new private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelCreation: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.PRIVATE_CHANNEL, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can create new public channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can create new private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelCreation: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.PRIVATE_CHANNEL, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('any member can create new public channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPublicChannelCreation: Constants.PERMISSIONS_ALL};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.OPEN_CHANNEL, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('any member can create new private channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelCreation: Constants.PERMISSIONS_ALL};
|
||||
|
||||
expect(Utils.showCreateOption(Constants.PRIVATE_CHANNEL, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canManageMembers', () => {
|
||||
test('all users can manage channel members on unlicensed instances', () => {
|
||||
global.window.mm_license = {IsLicensed: 'false'};
|
||||
expect(Utils.canManageMembers(null, true, true, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can manage channel members in private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins can manage channel members in private channels, user is not system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_SYSTEM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel members in private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel members in private channels, user is not system admin or team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('system admins or team admins can manage channel members in private channels, user is team admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_TEAM_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel members in private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, true, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel members in private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, true, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel members in private channels, user is system admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, false, true)).
|
||||
toEqual(true);
|
||||
});
|
||||
|
||||
test('channel, team, and system admins can manage channel members in private channels, user is channel admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_CHANNEL_ADMIN};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.PRIVATE_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, false, false)).
|
||||
toEqual(false);
|
||||
});
|
||||
|
||||
test('any member can manage channel members in public channels, user is not admin test', () => {
|
||||
global.window.mm_license = {IsLicensed: 'true'};
|
||||
global.window.mm_config = {RestrictPrivateChannelManageMembers: Constants.PERMISSIONS_ALL};
|
||||
|
||||
const channel = {
|
||||
name: 'fakeChannelName',
|
||||
type: Constants.OPEN_CHANNEL
|
||||
};
|
||||
expect(Utils.canManageMembers(channel, false, false, false)).
|
||||
toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -160,12 +160,12 @@ export function createOffTopicIntroMessage(channel, centeredIntro) {
|
||||
/>
|
||||
);
|
||||
|
||||
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
|
||||
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
|
||||
let setHeaderButton = createSetHeaderButton(channel);
|
||||
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
|
||||
if (!showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
setHeaderButton = null;
|
||||
}
|
||||
|
||||
@@ -199,20 +199,20 @@ export function createDefaultIntroMessage(channel, centeredIntro) {
|
||||
</a>
|
||||
);
|
||||
|
||||
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
|
||||
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
|
||||
if (global.window.mm_license.IsLicensed === 'true') {
|
||||
if (global.window.mm_config.RestrictTeamInvite === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
inviteModalLink = null;
|
||||
} else if (global.window.mm_config.RestrictTeamInvite === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
|
||||
} else if (global.window.mm_config.RestrictTeamInvite === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
|
||||
inviteModalLink = null;
|
||||
}
|
||||
}
|
||||
|
||||
let setHeaderButton = createSetHeaderButton(channel);
|
||||
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
|
||||
if (!showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
setHeaderButton = null;
|
||||
}
|
||||
|
||||
@@ -321,12 +321,12 @@ export function createStandardIntroMessage(channel, centeredIntro) {
|
||||
);
|
||||
}
|
||||
|
||||
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
|
||||
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
|
||||
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
|
||||
|
||||
let setHeaderButton = createSetHeaderButton(channel);
|
||||
if (!showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
|
||||
if (!showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
|
||||
setHeaderButton = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ export function getChannelDisplayName(channel) {
|
||||
return channel.display_name;
|
||||
}
|
||||
|
||||
export function showCreateOption(channelType, isAdmin, isSystemAdmin) {
|
||||
export function showCreateOption(channelType, isTeamAdmin, isSystemAdmin) {
|
||||
if (global.window.mm_license.IsLicensed !== 'true') {
|
||||
return true;
|
||||
}
|
||||
@@ -146,13 +146,13 @@ export function showCreateOption(channelType, isAdmin, isSystemAdmin) {
|
||||
if (channelType === Constants.OPEN_CHANNEL) {
|
||||
if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
} else if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
|
||||
} else if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
} else if (channelType === Constants.PRIVATE_CHANNEL) {
|
||||
if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
} else if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
|
||||
} else if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -160,88 +160,88 @@ export function showCreateOption(channelType, isAdmin, isSystemAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin) {
|
||||
export function showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) {
|
||||
if (global.window.mm_license.IsLicensed !== 'true') {
|
||||
// policies are only enforced in enterprise editions
|
||||
return true;
|
||||
}
|
||||
|
||||
if (channel.type === Constants.OPEN_CHANNEL) {
|
||||
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) {
|
||||
return false;
|
||||
}
|
||||
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
|
||||
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, userCount) {
|
||||
export function showDeleteOptionForCurrentUser(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) {
|
||||
if (global.window.mm_license.IsLicensed !== 'true') {
|
||||
// policies are only enforced in enterprise editions
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ChannelStore.isDefault(channel)) {
|
||||
// can't delete default channels, no matter who you are
|
||||
return false;
|
||||
}
|
||||
|
||||
if (channel.type === Constants.OPEN_CHANNEL) {
|
||||
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) {
|
||||
return false;
|
||||
}
|
||||
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
|
||||
if (userCount === 1) {
|
||||
return true;
|
||||
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function canManageMembers(channel, isSystemAdmin, isTeamAdmin, isChannelAdmin) {
|
||||
export function canManageMembers(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) {
|
||||
if (global.window.mm_license.IsLicensed !== 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (channel.type === Constants.PRIVATE_CHANNEL) {
|
||||
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_TEAM_ADMIN && !isTeamAdmin && !isSystemAdmin) {
|
||||
return false;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isTeamAdmin && !isSystemAdmin) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Ссылка в новой задаче
Block a user