PLT-4990 (WebApp): Separate channel management permissions. (#4865)

Этот коммит содержится в:
George Goldberg
2017-01-02 22:35:26 +00:00
коммит произвёл enahum
родитель 267257b680
Коммит e3b8511462
8 изменённых файлов: 230 добавлений и 94 удалений

Просмотреть файл

@@ -23,8 +23,12 @@ export default class PolicySettings extends AdminSettings {
getConfigFromState(config) {
config.TeamSettings.RestrictTeamInvite = this.state.restrictTeamInvite;
config.TeamSettings.RestrictPublicChannelCreation = this.state.restrictPublicChannelCreation;
config.TeamSettings.RestrictPrivateChannelCreation = this.state.restrictPrivateChannelCreation;
config.TeamSettings.RestrictPublicChannelManagement = this.state.restrictPublicChannelManagement;
config.TeamSettings.RestrictPrivateChannelManagement = this.state.restrictPrivateChannelManagement;
config.TeamSettings.RestrictPublicChannelDeletion = this.state.restrictPublicChannelDeletion;
config.TeamSettings.RestrictPrivateChannelDeletion = this.state.restrictPrivateChannelDeletion;
return config;
}
@@ -32,8 +36,12 @@ export default class PolicySettings extends AdminSettings {
getStateFromConfig(config) {
return {
restrictTeamInvite: config.TeamSettings.RestrictTeamInvite,
restrictPublicChannelCreation: config.TeamSettings.RestrictPublicChannelCreation,
restrictPrivateChannelCreation: config.TeamSettings.RestrictPrivateChannelCreation,
restrictPublicChannelManagement: config.TeamSettings.RestrictPublicChannelManagement,
restrictPrivateChannelManagement: config.TeamSettings.RestrictPrivateChannelManagement
restrictPrivateChannelManagement: config.TeamSettings.RestrictPrivateChannelManagement,
restrictPublicChannelDeletion: config.TeamSettings.RestrictPublicChannelDeletion,
restrictPrivateChannelDeletion: config.TeamSettings.RestrictPrivateChannelDeletion
};
}
@@ -74,46 +82,154 @@ export default class PolicySettings extends AdminSettings {
}
/>
<DropdownSetting
id='restrictPublicChannelManagement'
id='restrictPublicChannelCreation'
values={[
{value: Constants.PERMISSIONS_ALL, text: Utils.localizeMessage('admin.general.policy.permissionsAll', 'All team members')},
{value: Constants.PERMISSIONS_TEAM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsAdmin', 'Team and System Admins')},
{value: Constants.PERMISSIONS_SYSTEM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsSystemAdmin', 'System Admins')}
]}
label={
<FormattedMessage
id='admin.general.policy.restrictPublicChannelCreationTitle'
defaultMessage='Enable public channel creation for:'
/>
}
value={this.state.restrictPublicChannelCreation}
onChange={this.handleChange}
helpText={
<FormattedMessage
id='admin.general.policy.restrictPublicChannelCreationDescription'
defaultMessage='Set policy on who can create public channels.'
/>
}
/>
<DropdownSetting
id='restrictPublicChannelManagement'
values={[
{value: Constants.PERMISSIONS_ALL, text: Utils.localizeMessage('admin.general.policy.permissionsAllChannel', 'All channel members')},
{value: Constants.PERMISSIONS_TEAM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsAdmin', 'Team and System Admins')},
{value: Constants.PERMISSIONS_SYSTEM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsSystemAdmin', 'System Admins')}
]}
label={
<FormattedMessage
id='admin.general.policy.restrictPublicChannelManagementTitle'
defaultMessage='Enable public channel management permissions for:'
defaultMessage='Enable public channel renaming for:'
/>
}
value={this.state.restrictPublicChannelManagement}
onChange={this.handleChange}
helpText={
<FormattedHTMLMessage
<FormattedMessage
id='admin.general.policy.restrictPublicChannelManagementDescription'
defaultMessage='Set policy on who can create, delete, rename, and set the header or purpose for public channels.'
defaultMessage='Set policy on who can rename and set the header or purpose for public channels.'
/>
}
/>
<DropdownSetting
id='restrictPrivateChannelManagement'
id='restrictPublicChannelDeletion'
values={[
{value: Constants.PERMISSIONS_ALL, text: Utils.localizeMessage('admin.general.policy.permissionsAllChannel', 'All channel members')},
{value: Constants.PERMISSIONS_TEAM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsAdmin', 'Team and System Admins')},
{value: Constants.PERMISSIONS_SYSTEM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsSystemAdmin', 'System Admins')}
]}
label={
<FormattedMessage
id='admin.general.policy.restrictPublicChannelDeletionTitle'
defaultMessage='Enable public channel deletion for:'
/>
}
value={this.state.restrictPublicChannelDeletion}
onChange={this.handleChange}
helpText={
<FormattedMessage
id='admin.general.policy.restrictPublicChannelDeletionDescription'
defaultMessage='Set policy on who can delete public channels. Deleted channels can be recovered from the database using a {commandLineToolLink}.'
values={{
commandLineToolLink: (
<a href='https://docs.mattermost.com/administration/command-line-tools.html'>
<FormattedMessage
id='admin.general.policy.restrictPublicChannelDeletionCommandLineToolLink'
defaultMessage='command line tool'
/>
</a>
)
}}
/>
}
/>
<DropdownSetting
id='restrictPrivateChannelCreation'
values={[
{value: Constants.PERMISSIONS_ALL, text: Utils.localizeMessage('admin.general.policy.permissionsAll', 'All team members')},
{value: Constants.PERMISSIONS_TEAM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsAdmin', 'Team and System Admins')},
{value: Constants.PERMISSIONS_SYSTEM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsSystemAdmin', 'System Admins')}
]}
label={
<FormattedMessage
id='admin.general.policy.restrictPrivateChannelCreationTitle'
defaultMessage='Enable private group creation for:'
/>
}
value={this.state.restrictPrivateChannelCreation}
onChange={this.handleChange}
helpText={
<FormattedMessage
id='admin.general.policy.restrictPrivateChannelCreationDescription'
defaultMessage='Set policy on who can create private groups.'
/>
}
/>
<DropdownSetting
id='restrictPrivateChannelManagement'
values={[
{value: Constants.PERMISSIONS_ALL, text: Utils.localizeMessage('admin.general.policy.permissionsAllChannel', 'All channel members')},
{value: Constants.PERMISSIONS_TEAM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsAdmin', 'Team and System Admins')},
{value: Constants.PERMISSIONS_SYSTEM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsSystemAdmin', 'System Admins')}
]}
label={
<FormattedMessage
id='admin.general.policy.restrictPrivateChannelManagementTitle'
defaultMessage='Enable private group management permissions for:'
defaultMessage='Enable private group renaming for:'
/>
}
value={this.state.restrictPrivateChannelManagement}
onChange={this.handleChange}
helpText={
<FormattedHTMLMessage
<FormattedMessage
id='admin.general.policy.restrictPrivateChannelManagementDescription'
defaultMessage='Set policy on who can create, delete, rename, and set the header or purpose for private groups.'
defaultMessage='Set policy on who can rename and set the header or purpose for private groups.'
/>
}
/>
<DropdownSetting
id='restrictPrivateChannelDeletion'
values={[
{value: Constants.PERMISSIONS_ALL, text: Utils.localizeMessage('admin.general.policy.permissionsAllChannel', 'All channel members')},
{value: Constants.PERMISSIONS_TEAM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsAdmin', 'Team and System Admins')},
{value: Constants.PERMISSIONS_SYSTEM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsSystemAdmin', 'System Admins')}
]}
label={
<FormattedMessage
id='admin.general.policy.restrictPrivateChannelDeletionTitle'
defaultMessage='Enable private group deletion for:'
/>
}
value={this.state.restrictPrivateChannelDeletion}
onChange={this.handleChange}
helpText={
<FormattedMessage
id='admin.general.policy.restrictPrivateChannelDeletionDescription'
defaultMessage='Set policy on who can delete private groups. Deleted groups can be recovered from the database using a {commandLineToolLink}.'
values={{
commandLineToolLink: (
<a href='https://docs.mattermost.com/administration/command-line-tools.html'>
<FormattedMessage
id='admin.general.policy.restrictPrivateChannelDeletionCommandLineToolLink'
defaultMessage='command line tool'
/>
</a>
)
}}
/>
}
/>

Просмотреть файл

@@ -206,30 +206,6 @@ export default class ChannelHeader extends React.Component {
});
}
showManagementOptions(channel, isAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
return true;
}
if (channel.type === Constants.OPEN_CHANNEL) {
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;
}
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
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;
}
}
return true;
}
initWebrtc(contactId, isOnline) {
if (isOnline && !this.state.isBusy) {
GlobalActions.emitCloseRightHandSide();
@@ -521,7 +497,7 @@ export default class ChannelHeader extends React.Component {
</li>
);
if (this.showManagementOptions(channel, isAdmin, isSystemAdmin)) {
if (ChannelUtils.showManagementOptions(channel, isAdmin, isSystemAdmin)) {
dropdownContents.push(
<li
key='set_channel_header'
@@ -584,7 +560,9 @@ export default class ChannelHeader extends React.Component {
</a>
</li>
);
}
if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin)) {
if (!ChannelStore.isDefault(channel)) {
dropdownContents.push(deleteOption);
}

Просмотреть файл

@@ -9,6 +9,7 @@ import TeamStore from 'stores/team_store.jsx';
import Constants from 'utils/constants.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import * as ChannelUtils from 'utils/channel_utils.jsx';
import {joinChannel, searchMoreChannels} from 'actions/channel_actions.jsx';
import React from 'react';
@@ -151,14 +152,9 @@ export default class MoreChannels extends React.Component {
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
if (global.window.mm_license.IsLicensed === 'true') {
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
createNewChannelButton = null;
createChannelHelpText = null;
} else if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
createNewChannelButton = null;
createChannelHelpText = null;
}
if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) {
createNewChannelButton = null;
createChannelHelpText = null;
}
return (

Просмотреть файл

@@ -222,30 +222,6 @@ export default class Navbar extends React.Component {
});
}
showManagementOptions(channel, isAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
return true;
}
if (channel.type === Constants.OPEN_CHANNEL) {
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;
}
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
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;
}
}
return true;
}
toggleFavorite = (e) => {
e.preventDefault();
@@ -388,7 +364,7 @@ export default class Navbar extends React.Component {
</li>
);
if (this.showManagementOptions(channel, isAdmin, isSystemAdmin)) {
if (ChannelUtils.showManagementOptions(channel, isAdmin, isSystemAdmin)) {
setChannelHeaderOption = (
<li role='presentation'>
<a
@@ -444,7 +420,7 @@ export default class Navbar extends React.Component {
);
}
if (this.showManagementOptions(channel, isAdmin, isSystemAdmin) || this.state.userCount === 1) {
if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin) || this.state.userCount === 1) {
if (!ChannelStore.isDefault(channel)) {
deleteChannelOption = (
<li role='presentation'>

Просмотреть файл

@@ -6,6 +6,7 @@ import ReactDOM from 'react-dom';
import * as UserAgent from 'utils/user_agent.jsx';
import * as Utils from 'utils/utils.jsx';
import * as ChannelUtils from 'utils/channel_utils.jsx';
import Constants from 'utils/constants.jsx';
import UserStore from 'stores/user_store.jsx';
@@ -141,18 +142,12 @@ export default class NewChannelModal extends React.Component {
const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
if (global.window.mm_license.IsLicensed === 'true') {
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
createPublicChannelLink = null;
} else if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
createPublicChannelLink = null;
}
if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) {
createPublicChannelLink = null;
}
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
createPrivateChannelLink = null;
} else if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
createPrivateChannelLink = null;
}
if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isAdmin, isSystemAdmin)) {
createPrivateChannelLink = null;
}
var channelTerm = '';

Просмотреть файл

@@ -722,18 +722,12 @@ export default class Sidebar extends React.Component {
</OverlayTrigger>
);
if (global.window.mm_license.IsLicensed === 'true') {
if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
createPublicChannelIcon = null;
} else if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
createPublicChannelIcon = null;
}
if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) {
createPublicChannelIcon = null;
}
if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
createPrivateChannelIcon = null;
} else if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) {
createPrivateChannelIcon = null;
}
if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isAdmin, isSystemAdmin)) {
createPrivateChannelIcon = null;
}
let moreDirectChannelsModal;

Просмотреть файл

@@ -310,11 +310,22 @@
"admin.general.policy": "Policy",
"admin.general.policy.permissionsAdmin": "Team and System Admins",
"admin.general.policy.permissionsAll": "All team members",
"admin.general.policy.permissionsAllChannel": "All channel members",
"admin.general.policy.permissionsSystemAdmin": "System Admins",
"admin.general.policy.restrictPrivateChannelManagementDescription": "Set policy on who can create, delete, rename, and set the header or purpose for private groups.",
"admin.general.policy.restrictPrivateChannelManagementTitle": "Enable private group management permissions for:",
"admin.general.policy.restrictPublicChannelManagementDescription": "Set policy on who can create, delete, rename, and set the header or purpose for public channels.",
"admin.general.policy.restrictPublicChannelManagementTitle": "Enable public channel management permissions for:",
"admin.general.policy.restrictPublicChannelCreationTitle": "Enable public channel creation for:",
"admin.general.policy.restrictPublicChannelCreationDescription": "Set policy on who can create public channels.",
"admin.general.policy.restrictPublicChannelManagementTitle": "Enable public channel renaming for:",
"admin.general.policy.restrictPublicChannelManagementDescription": "Set policy on who can rename and set the header or purpose for public channels.",
"admin.general.policy.restrictPublicChannelDeletionTitle": "Enable public channel deletion for:",
"admin.general.policy.restrictPublicChannelDeletionDescription": "Set policy on who can delete public channels. Deleted channels can be recovered from the database using a {commandLineToolLink}.",
"admin.general.policy.restrictPublicChannelDeletionCommandLineToolLink": "command line tool",
"admin.general.policy.restrictPrivateChannelCreationTitle": "Enable private group creation for:",
"admin.general.policy.restrictPrivateChannelCreationDescription": "Set policy on who can create private groups.",
"admin.general.policy.restrictPrivateChannelManagementTitle": "Enable private group renaming for:",
"admin.general.policy.restrictPrivateChannelManagementDescription": "Set policy on who can rename and set the header or purpose for private groups.",
"admin.general.policy.restrictPrivateChannelDeletionTitle": "Enable private group deletion for:",
"admin.general.policy.restrictPrivateChannelDeletionDescription": "Set policy on who can delete private groups. Deleted groups can be recovered from the database using a {commandLineToolLink}.",
"admin.general.policy.restrictPrivateChannelDeletionCommandLineToolLink": "command line tool",
"admin.general.policy.teamInviteDescription": "Set policy on who can invite others to a team using <b>Invite New Member</b> to invite new users by email, or the <b>Get Team Invite Link</b> options from the Main Menu. If <b>Get Team Invite Link</b> is used to share a link, you can expire the invite code from <b>Team Settings</b> > <b>Invite Code</b> after the desired users join the team.",
"admin.general.policy.teamInviteTitle": "Enable sending team invites from:",
"admin.general.privacy": "Privacy",

Просмотреть файл

@@ -82,6 +82,76 @@ export function sortChannelsByDisplayName(a, b) {
return buildDisplayNameAndTypeComparable(a).localeCompare(buildDisplayNameAndTypeComparable(b), locale, {numeric: true});
}
export function showCreateOption(channelType, isAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
return true;
}
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) {
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) {
return false;
}
}
return true;
}
export function showManagementOptions(channel, isAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
return true;
}
if (channel.type === Constants.OPEN_CHANNEL) {
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;
}
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
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;
}
}
return true;
}
export function showDeleteOption(channel, isAdmin, isSystemAdmin) {
if (global.window.mm_license.IsLicensed !== 'true') {
return true;
}
if (channel.type === Constants.OPEN_CHANNEL) {
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;
}
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
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;
}
}
return true;
}
/*
* not exported helpers
*/