Commit 19b1cd5e authored by Florent Chehab's avatar Florent Chehab

Moderation fully connected !

parent 43103ecb
Pipeline #27309 passed with stages
in 2 minutes and 36 seconds
......@@ -11,6 +11,7 @@ import orange from '@material-ui/core/colors/orange';
import green from '@material-ui/core/colors/green';
import MyComponent from '../../MyComponent';
import isModerationRequired from '../../../utils/isModerationRequired';
import {
serverModerationStatusFetchData,
......@@ -75,6 +76,7 @@ const styles = theme => ({
class GenericModule extends MyComponent {
state = {
editorOpen: false,
dataToSave: null,
historyOpen: false,
pendingModerationOpen: false,
rawModelDataForEditor: this.props.rawModelData,
......@@ -86,7 +88,7 @@ class GenericModule extends MyComponent {
};
handleCloseEditor = () => {
this.setState({ editorOpen: false });
this.setState({ editorOpen: false, dataToSave: null });
};
handleCloseHistory = () => {
......@@ -131,6 +133,11 @@ class GenericModule extends MyComponent {
this.handleOpenEditor();
}
handleApproveModeration = (modelDataInModeration) => {
this.setState({ dataToSave: modelDataInModeration });
this.handleClosePendingModeration();
}
renderTitle = (rawModelData) => (
<div>
{renderTitle(rawModelData, this.props.classes, this.props.buildTitle)}
......@@ -144,8 +151,23 @@ class GenericModule extends MyComponent {
</div>
)
userCanModerate() {
const userData = this.getFetchedData('userDataEl');
const serverModerationStatus = this.getFetchedData('serverModerationStatus');
const { rawModelData } = this.props;
return !isModerationRequired(
serverModerationStatus.activated,
serverModerationStatus.moderator_level,
rawModelData.model_config.moderation_level,
rawModelData.obj_moderation_level,
userData.owner_level
)
}
myRender() {
const { classes } = this.props;
const userCanModerate = this.userCanModerate();
return (
<div>
<this.props.editor
......@@ -154,6 +176,7 @@ class GenericModule extends MyComponent {
modelData={this.props.parseRawModelData(this.state.rawModelDataForEditor)}
userData={this.props.userDataEl}
forceSave={this.state.forceSave}
dataToSave={this.state.dataToSave}
/>
<History
factory={this}
......@@ -166,9 +189,11 @@ class GenericModule extends MyComponent {
open={this.state.pendingModerationOpen}
handleClosePendingModeration={this.handleClosePendingModeration}
handleEditPendingModeration={this.handleEditPendingModeration}
handleApproveModeration={this.handleApproveModeration}
userCanModerate={userCanModerate}
/>
<Paper className={classes.root} square={true}>
{renderFirstRow.bind(this)()}
{renderFirstRow.bind(this)(userCanModerate)}
{this.renderCore(this.props.rawModelData, this.props.coreClasses)}
</Paper>
</div>
......
......@@ -60,13 +60,25 @@ class PendingModeration extends React.Component {
>
Éditer à partir de cette version
</Button>
{
this.props.userCanModerate ? <div></div> : <Typography variant='caption' align='center'>Vous n'avez pas les droits nécessaires pour modérer cet élément.</Typography>
}
<Button
variant='outlined'
color="primary"
disabled={!this.props.userCanModerate}
className={this.props.classes.editButton}
onClick={() => this.props.handleApproveModeration(rawModelData)}
>
Valider cette version
</Button>
<Divider />
</div>
)
}
renderPendingModeration() {
let rawModelData = this.newFactory.props.rawModelData.pending_moderation[0].new_object;
let rawModelData = this.props.factory.props.rawModelData.pending_moderation[0].new_object;
// we have to copy the original ID
rawModelData.id = this.newFactory.props.rawModelData.id;
return (
......@@ -111,6 +123,7 @@ PendingModeration.propTypes = {
classes: PropTypes.object.isRequired,
factory: PropTypes.object.isRequired,
handleEditPendingModeration: PropTypes.func.isRequired,
userCanModerate: PropTypes.bool.isRequired,
};
PendingModeration.defaultProps = {
......
......@@ -88,6 +88,18 @@ class Editor extends MyComponent {
return false;
}
performSave(data) {
this.setState({
notification: {
open: true,
message: "Enregistrement en cours",
isLoading: true,
duration: null
}
})
this.props.saveData(data);
}
handleSaveEditor() {
const formHasError = this.formHasError();
const formFieldsHaveError = this.formFieldsHaveError();
......@@ -96,15 +108,7 @@ class Editor extends MyComponent {
const { modelData } = this.props;
if (this.props.forceSave || this.hasChangesToSave(formData, modelData)) {
const tmp = Object.assign({}, this.props.modelData, formData)
this.setState({
notification: {
open: true,
message: "Enregistrement en cours",
isLoading: true,
duration: null
}
})
this.props.saveData(tmp);
this.performSave(tmp);
} else {
this.setState({
notification: {
......@@ -133,6 +137,14 @@ class Editor extends MyComponent {
}
myComponentDidUpdate() {
// usefull for handling moderation
const { dataToSave } = this.props;
if (dataToSave) {
this.props.handleCloseEditor();
this.performSave(dataToSave);
}
// end of comment
const { savingHasError } = this.props;
if (savingHasError.status) {
if (!this.state.alert.open) {
......
import isModerationRequired from '../../../../utils/isModerationRequired';
export default function getEditTooltipAndClass(readOnly, rawModelData, userLevel, serverModerationStatus, moderatorLevel) {
export default function getEditTooltipAndClass(readOnly, userCanModerate) {
if (readOnly) {
return {
editTooltip: "Ce contenu n'est pas concerné par l'édition.",
editClass: "disabled"
}
}
if (isModerationRequired(
serverModerationStatus,
moderatorLevel,
rawModelData.model_config.moderation_level,
rawModelData.obj_moderation_level,
userLevel
)) {
if (!userCanModerate) {
return {
editTooltip: "Vous pouvez éditer le contenu de ce module, mais votre contribution sera assujettie à la modération.",
editClass: "orange"
......
......@@ -16,7 +16,7 @@ import SettingsBackRestoreIcon from '@material-ui/icons/SettingsBackupRestore';
import Tooltip from '@material-ui/core/Tooltip';
export default function renderFirstRow() {
export default function renderFirstRow(userCanModerate) {
const { classes, theme } = this.props;
const { rawModelData } = this.props;
......@@ -30,10 +30,7 @@ export default function renderFirstRow() {
const { versionTooltip, versionClass } = getVersionTooltipAndClass(nbVersions);
const { moderTooltip, moderClass } = getModerationTooltipAndClass(nbPendingModeration, readOnly);
const userData = this.getFetchedData('userDataEl');
const serverModerationStatus = this.getFetchedData('serverModerationStatus');
const { editTooltip, editClass } = getEditTooltipAndClass(readOnly, rawModelData, userData.owner_level, serverModerationStatus.activated, serverModerationStatus.moderator_level);
const { editTooltip, editClass } = getEditTooltipAndClass(readOnly, userCanModerate);
return (
<Grid container spacing={8}>
......
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