Commit 999628aa authored by Jesús Espino's avatar Jesús Espino Committed by George Goldberg
Browse files

MM-8853: Add manage_emojis permissions (#1257)

* MM-8853: Add manage_emojis permissions

* Adding permissions gate to the backstage interface
parent 5cd1b1af
......@@ -24,10 +24,6 @@ export default class CustomEmojiSettings extends AdminSettings {
config.ServiceSettings.EnableCustomEmoji = this.state.enableCustomEmoji;
config.ServiceSettings.EnableEmojiPicker = this.state.enableEmojiPicker;
if (this.props.license.IsLicensed === 'true') {
config.ServiceSettings.RestrictCustomEmojiCreation = this.state.restrictCustomEmojiCreation;
}
return config;
}
......@@ -35,7 +31,6 @@ export default class CustomEmojiSettings extends AdminSettings {
return {
enableCustomEmoji: config.ServiceSettings.EnableCustomEmoji,
enableEmojiPicker: config.ServiceSettings.EnableEmojiPicker,
restrictCustomEmojiCreation: config.ServiceSettings.RestrictCustomEmojiCreation,
};
}
......@@ -49,36 +44,6 @@ export default class CustomEmojiSettings extends AdminSettings {
}
renderSettings() {
let restrictSetting = null;
if (this.props.license.IsLicensed === 'true') {
restrictSetting = (
<DropdownSetting
id='restrictCustomEmojiCreation'
values={[
{value: 'all', text: Utils.localizeMessage('admin.customization.restrictCustomEmojiCreationAll', 'Allow everyone to create custom emoji')},
{value: 'admin', text: Utils.localizeMessage('admin.customization.restrictCustomEmojiCreationAdmin', 'Allow System and Team Admins to create custom emoji')},
{value: 'system_admin', text: Utils.localizeMessage('admin.customization.restrictCustomEmojiCreationSystemAdmin', 'Only allow System Admins to create custom emoji')},
]}
label={
<FormattedMessage
id='admin.customization.restrictCustomEmojiCreationTitle'
defaultMessage='Restrict Custom Emoji Creation:'
/>
}
helpText={
<FormattedMessage
id='admin.customization.restrictCustomEmojiCreationDesc'
defaultMessage='Restrict the creation of custom emoji to certain users.'
/>
}
value={this.state.restrictCustomEmojiCreation}
onChange={this.handleChange}
disabled={!this.state.enableCustomEmoji}
setByEnv={this.isSetByEnv('ServiceSettings.RestrictCustomEmojiCreation')}
/>
);
}
return (
<SettingsGroup>
<BooleanSetting
......@@ -117,7 +82,6 @@ export default class CustomEmojiSettings extends AdminSettings {
onChange={this.handleChange}
setByEnv={this.isSetByEnv('ServiceSettings.EnableCustomEmoji')}
/>
{restrictSetting}
</SettingsGroup>
);
}
......
......@@ -68,6 +68,7 @@ const GROUPS = [
'manage_webhooks',
'manage_oauth',
'manage_slash_commands',
'manage_emojis',
],
},
];
......
......@@ -4,48 +4,21 @@
import React from 'react';
import PropTypes from 'prop-types';
import Permissions from 'mattermost-redux/constants/permissions';
import {Client4} from 'mattermost-redux/client';
import DeleteEmoji from 'components/emoji/delete_emoji_modal.jsx';
import TeamPermissionGate from 'components/permissions_gates/team_permission_gate';
export default class EmojiListItem extends React.Component {
static propTypes = {
/*
* Emoji to display.
*/
emoji: PropTypes.object.isRequired,
/*
* Logged in user's ID.
*/
currentUserId: PropTypes.string.isRequired,
/*
* Emoji creator name to display.
*/
creatorDisplayName: PropTypes.string.isRequired,
/*
* Emoji creator username to display if different from creatorDisplayName.
*/
creatorUsername: PropTypes.string,
/*
* Set if logged in user is system admin.
*/
isSystemAdmin: PropTypes.bool,
/*
* Function to call when emoji is deleted.
*/
currentTeam: PropTypes.object,
onDelete: PropTypes.func,
actions: PropTypes.shape({
/**
* Delete a custom emoji.
*/
deleteCustomEmoji: PropTypes.func.isRequired,
}).isRequired,
}
......@@ -53,8 +26,8 @@ export default class EmojiListItem extends React.Component {
static defaultProps = {
emoji: {},
currentUserId: '',
currentTeam: {},
creatorDisplayName: '',
isSystemAdmin: false,
}
handleDelete = () => {
......@@ -75,9 +48,28 @@ export default class EmojiListItem extends React.Component {
}
let deleteButton = null;
if (this.props.isSystemAdmin || emoji.creator_id === this.props.currentUserId) {
if (emoji.creator_id === this.props.currentUserId) {
deleteButton = (
<TeamPermissionGate
teamId={this.props.currentTeam.id}
permissions={[Permissions.MANAGE_EMOJIS]}
>
<DeleteEmoji onDelete={this.handleDelete}/>
</TeamPermissionGate>
);
} else {
deleteButton = (
<DeleteEmoji onDelete={this.handleDelete}/>
<TeamPermissionGate
teamId={this.props.currentTeam.id}
permissions={[Permissions.MANAGE_EMOJIS]}
>
<TeamPermissionGate
teamId={this.props.currentTeam.id}
permissions={[Permissions.MANAGE_OTHERS_EMOJIS]}
>
<DeleteEmoji onDelete={this.handleDelete}/>
</TeamPermissionGate>
</TeamPermissionGate>
);
}
......
......@@ -4,7 +4,8 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getUser, getCurrentUserId, isCurrentUserSystemAdmin} from 'mattermost-redux/selectors/entities/users';
import {getUser, getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {deleteCustomEmoji} from 'mattermost-redux/actions/emojis';
......@@ -21,7 +22,7 @@ function mapStateToProps(state, ownProps) {
creatorDisplayName: getDisplayNameByUser(creator),
creatorUsername: creator.username,
currentUserId: getCurrentUserId(state),
isSystemAdmin: isCurrentUserSystemAdmin(state),
currentTeam: getCurrentTeam(state),
};
}
......
......@@ -6,32 +6,23 @@ import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import {Link} from 'react-router-dom';
import Permissions from 'mattermost-redux/constants/permissions';
import * as Utils from 'utils/utils.jsx';
import TeamPermissionGate from 'components/permissions_gates/team_permission_gate';
import EmojiList from './emoji_list';
export default class EmojiPage extends React.Component {
static propTypes = {
/**
* Non-UI team name for the current team.
*/
teamId: PropTypes.string.isRequired,
teamName: PropTypes.string.isRequired,
/**
* UI team name for the current team.
*/
teamDisplayName: PropTypes.string.isRequired,
/**
* Title of the app or site.
*/
siteName: PropTypes.string,
/**
* Function to scroll list to top.
*/
scrollToTop: PropTypes.func.isRequired,
actions: PropTypes.shape({
loadRolesIfNeeded: PropTypes.func.isRequired
}).isRequired
}
static defaultProps = {
......@@ -42,6 +33,7 @@ export default class EmojiPage extends React.Component {
componentDidMount() {
this.updateTitle();
this.props.actions.loadRolesIfNeeded(['system_admin', 'team_admin', 'system_user', 'team_user']);
}
updateTitle = (props = this.props) => {
......@@ -64,20 +56,25 @@ export default class EmojiPage extends React.Component {
defaultMessage='Custom Emoji'
/>
</h1>
<Link
className='add-link'
to={'/' + this.props.teamName + '/emoji/add'}
<TeamPermissionGate
teamId={this.props.teamId}
permissions={[Permissions.MANAGE_EMOJIS]}
>
<button
type='button'
className='btn btn-primary'
<Link
className='add-link'
to={'/' + this.props.teamName + '/emoji/add'}
>
<FormattedMessage
id='emoji_list.add'
defaultMessage='Add Custom Emoji'
/>
</button>
</Link>
<button
type='button'
className='btn btn-primary'
>
<FormattedMessage
id='emoji_list.add'
defaultMessage='Add Custom Emoji'
/>
</button>
</Link>
</TeamPermissionGate>
<EmojiList scrollToTop={this.props.scrollToTop}/>
</div>
</div>
......
......@@ -2,8 +2,10 @@
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {loadRolesIfNeeded} from 'mattermost-redux/actions/roles';
import EmojiPage from './emoji_page.jsx';
......@@ -11,10 +13,19 @@ function mapStateToProps(state) {
const team = getCurrentTeam(state) || {};
return {
teamId: team.id,
teamName: team.name,
teamDisplayName: team.display_name,
siteName: state.entities.general.config.SiteName,
};
}
export default connect(mapStateToProps)(EmojiPage);
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
loadRolesIfNeeded,
}, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(EmojiPage);
......@@ -171,6 +171,8 @@
"admin.permissions.group.reactions.description": "Add and delete reactions on posts.",
"admin.permissions.permission.manage_slash_commands.name": "Manage Slash Commands",
"admin.permissions.permission.manage_slash_commands.description": "Create, edit and delete custom slash commands.",
"admin.permissions.permission.manage_emojis.name": "Manage Custom Emojis",
"admin.permissions.permission.manage_emojis.description": "Create and delete custom emojis.",
"admin.permissions.permission.create_public_channel.name": "Create Channels",
"admin.permissions.permission.create_public_channel.description": "Create new public channels.",
"admin.permissions.permission.create_private_channel.name": "Create Channels",
......
......@@ -97,6 +97,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_tree sh
"manage_webhooks",
"manage_oauth",
"manage_slash_commands",
"manage_emojis",
],
},
]
......@@ -213,6 +214,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_tree sh
"manage_webhooks",
"manage_oauth",
"manage_slash_commands",
"manage_emojis",
],
},
]
......@@ -329,6 +331,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_tree sh
"manage_webhooks",
"manage_oauth",
"manage_slash_commands",
"manage_emojis",
],
},
]
......@@ -445,6 +448,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_tree sh
"manage_webhooks",
"manage_oauth",
"manage_slash_commands",
"manage_emojis",
],
},
]
......@@ -565,6 +569,7 @@ exports[`components/admin_console/permission_schemes_settings/permission_tree sh
"manage_webhooks",
"manage_oauth",
"manage_slash_commands",
"manage_emojis",
],
},
]
......
......@@ -562,6 +562,8 @@ export const PermissionsScope = {
[Permissions.READ_USER_ACCESS_TOKEN]: 'system_scope',
[Permissions.REVOKE_USER_ACCESS_TOKEN]: 'system_scope',
[Permissions.MANAGE_JOBS]: 'system_scope',
[Permissions.MANAGE_EMOJIS]: 'team_scope',
[Permissions.MANAGE_OTHERS_EMOJIS]: 'team_scope',
};
export const DefaultRolePermissions = {
......@@ -593,6 +595,7 @@ export const DefaultRolePermissions = {
Permissions.MANAGE_PRIVATE_CHANNEL_MEMBERS,
Permissions.DELETE_POST,
Permissions.EDIT_POST,
Permissions.MANAGE_EMOJIS,
],
channel_admin: [
Permissions.MANAGE_CHANNEL_ROLES,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment