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

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