Message Editing and Deleting permissions (#4692)

Этот коммит содержится в:
Amit Yadav
2017-01-18 18:38:31 +05:30
коммит произвёл Joram Wilander
родитель 8f0175e15c
Коммит 99cf08ac38
20 изменённых файлов: 575 добавлений и 32 удалений

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

@@ -6,6 +6,8 @@ import React from 'react';
import AdminSettings from './admin_settings.jsx';
import SettingsGroup from './settings_group.jsx';
import DropdownSetting from './dropdown_setting.jsx';
import RadioSetting from './radio_setting.jsx';
import PostEditSetting from './post_edit_setting.jsx';
import Constants from 'utils/constants.jsx';
import * as Utils from 'utils/utils.jsx';
@@ -22,6 +24,9 @@ export default class PolicySettings extends AdminSettings {
}
getConfigFromState(config) {
config.ServiceSettings.RestrictPostDelete = this.state.restrictPostDelete;
config.ServiceSettings.AllowEditPost = this.state.allowEditPost;
config.ServiceSettings.PostEditTimeLimit = this.parseIntNonZero(this.state.postEditTimeLimit, Constants.DEFAULT_POST_EDIT_TIME_LIMIT);
config.TeamSettings.RestrictTeamInvite = this.state.restrictTeamInvite;
config.TeamSettings.RestrictPublicChannelCreation = this.state.restrictPublicChannelCreation;
config.TeamSettings.RestrictPrivateChannelCreation = this.state.restrictPrivateChannelCreation;
@@ -35,6 +40,9 @@ export default class PolicySettings extends AdminSettings {
getStateFromConfig(config) {
return {
restrictPostDelete: config.ServiceSettings.RestrictPostDelete,
allowEditPost: config.ServiceSettings.AllowEditPost,
postEditTimeLimit: config.ServiceSettings.PostEditTimeLimit,
restrictTeamInvite: config.TeamSettings.RestrictTeamInvite,
restrictPublicChannelCreation: config.TeamSettings.RestrictPublicChannelCreation,
restrictPrivateChannelCreation: config.TeamSettings.RestrictPrivateChannelCreation,
@@ -241,6 +249,47 @@ export default class PolicySettings extends AdminSettings {
/>
}
/>
<RadioSetting
id='restrictPostDelete'
values={[
{value: Constants.PERMISSIONS_DELETE_POST_ALL, text: Utils.localizeMessage('admin.general.policy.permissionsDeletePostAll', 'Message authors can delete their own messages, and Administrators can delete any message')},
{value: Constants.PERMISSIONS_DELETE_POST_TEAM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsDeletePostAdmin', 'Team Admins and System Admins')},
{value: Constants.PERMISSIONS_DELETE_POST_SYSTEM_ADMIN, text: Utils.localizeMessage('admin.general.policy.permissionsDeletePostSystemAdmin', 'System Admins')}
]}
label={
<FormattedMessage
id='admin.general.policy.restrictPostDeleteTitle'
defaultMessage='Allow which users to delete messages:'
/>
}
value={this.state.restrictPostDelete}
onChange={this.handleChange}
helpText={
<FormattedHTMLMessage
id='admin.general.policy.restrictPostDeleteDescription'
defaultMessage='Set policy on who has permission to delete messages.'
/>
}
/>
<PostEditSetting
id='allowEditPost'
timeLimitId='postEditTimeLimit'
label={
<FormattedMessage
id='admin.general.policy.allowEditPostTitle'
defaultMessage='Allow users to edit their messages:'
/>
}
value={this.state.allowEditPost}
timeLimitValue={this.state.postEditTimeLimit}
onChange={this.handleChange}
helpText={
<FormattedHTMLMessage
id='admin.general.policy.allowEditPostDescription'
defaultMessage='Set policy on the length of time authors have to edit their messages after posting.'
/>
}
/>
</SettingsGroup>
);
}

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

@@ -0,0 +1,99 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import Setting from './setting.jsx';
import Constants from 'utils/constants.jsx';
import * as Utils from 'utils/utils.jsx';
export default class PostEditSetting extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleTimeLimitChange = this.handleTimeLimitChange.bind(this);
}
handleChange(e) {
this.props.onChange(this.props.id, e.target.value);
}
handleTimeLimitChange(e) {
this.props.onChange(this.props.timeLimitId, e.target.value);
}
render() {
return (
<Setting
label={this.props.label}
inputId={this.props.id}
helpText={this.props.helpText}
>
<div className='radio'>
<label>
<input
type='radio'
value={Constants.ALLOW_EDIT_POST_ALWAYS}
name={this.props.id}
checked={this.props.value === Constants.ALLOW_EDIT_POST_ALWAYS}
onChange={this.handleChange}
disabled={this.props.disabled}
/>
{Utils.localizeMessage('admin.general.policy.allowEditPostAlways', 'Any time')}
</label>
</div>
<div className='radio'>
<label>
<input
type='radio'
value={Constants.ALLOW_EDIT_POST_NEVER}
name={this.props.id}
checked={this.props.value === Constants.ALLOW_EDIT_POST_NEVER}
onChange={this.handleChange}
disabled={this.props.disabled}
/>
{Utils.localizeMessage('admin.general.policy.allowEditPostNever', 'Never')}
</label>
</div>
<div className='radio form-inline'>
<label>
<input
type='radio'
value={Constants.ALLOW_EDIT_POST_TIME_LIMIT}
name={this.props.id}
checked={this.props.value === Constants.ALLOW_EDIT_POST_TIME_LIMIT}
onChange={this.handleChange}
disabled={this.props.disabled}
/>
<input
type='text'
value={this.props.timeLimitValue}
className='form-control'
name={this.props.timeLimitId}
onChange={this.handleTimeLimitChange}
disabled={this.props.disabled || this.props.value !== Constants.ALLOW_EDIT_POST_TIME_LIMIT}
/>
<span> {Utils.localizeMessage('admin.general.policy.allowEditPostTimeLimit', 'seconds after posting')}</span>
</label>
</div>
</Setting>
);
}
}
PostEditSetting.defaultProps = {
isDisabled: false
};
PostEditSetting.propTypes = {
id: React.PropTypes.string.isRequired,
timeLimitId: React.PropTypes.string.isRequired,
label: React.PropTypes.node.isRequired,
value: React.PropTypes.string.isRequired,
timeLimitValue: React.PropTypes.number.isRequired,
onChange: React.PropTypes.func.isRequired,
disabled: React.PropTypes.bool,
helpText: React.PropTypes.node
};

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

@@ -0,0 +1,63 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import Setting from './setting.jsx';
export default class RadioSetting extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.props.onChange(this.props.id, e.target.value);
}
render() {
const options = [];
for (const {value, text} of this.props.values) {
options.push(
<div className='radio'>
<label>
<input
type='radio'
value={value}
name={this.props.id}
checked={value === this.props.value}
onChange={this.handleChange}
disabled={this.props.disabled}
/>
{text}
</label>
</div>
);
}
return (
<Setting
label={this.props.label}
inputId={this.props.id}
helpText={this.props.helpText}
>
{options}
</Setting>
);
}
}
RadioSetting.defaultProps = {
isDisabled: false
};
RadioSetting.propTypes = {
id: React.PropTypes.string.isRequired,
values: React.PropTypes.array.isRequired,
label: React.PropTypes.node.isRequired,
value: React.PropTypes.string.isRequired,
onChange: React.PropTypes.func.isRequired,
disabled: React.PropTypes.bool,
helpText: React.PropTypes.node
};