Commit ee9a98b3 authored by Florent Chehab's avatar Florent Chehab

Obj moderation level is now managed

parent d85a5f7f
Pipeline #27271 passed with stages
in 2 minutes and 42 seconds
{
"staff": {
"level": 3,
"label": "Administrateurs et administratrices du site"
},
"DRI": {
"level": 2,
"label": "Membres de la DRI"
},
"moderator": {
"level": 1,
"label": "Modérateurs et modératrices"
},
"authenticated_user": {
"level": 0,
"label": "Utilisateurs et utilisatrices authentifiées"
}
}
\ No newline at end of file
OBJ_MODERATION_PERMISSIONS = {
"staff": 3,
"DRI": 2,
"moderator": 1,
"authenticated_user": 0
}
import json
from os.path import join, realpath, dirname
current_dir = dirname(realpath(__file__))
with open(join(current_dir, 'OBJ_MODERATION_PERMISSIONS.json'), 'r') as f:
tmp = json.load(f)
OBJ_MODERATION_PERMISSIONS = {}
for key in tmp:
OBJ_MODERATION_PERMISSIONS[key] = tmp[key]['level']
DEFAULT_OBJ_MODERATION_LV = OBJ_MODERATION_PERMISSIONS["authenticated_user"]
......@@ -92,6 +92,7 @@ class GenericModule extends MyComponent {
open={this.state.fullScreenDialogOpen}
handleClose={this.handleCloseFullScreenDialog}
modelData={this.props.modelData}
userData={this.props.userDataEl}
/>
<Paper className={classes.root} square={true}>
{renderFirstRow.bind(this)()}
......
......@@ -68,7 +68,8 @@ class UniversitySemestersDates extends MyComponent {
parse(rawModelData) {
// reverse serialization
const semestersDates = this.getFetchedData('universitiesSemestersDatesEl');
let { autumn_begin, autumn_end, spring_begin, spring_end, comment, useful_links, id, university } = semestersDates;
let { autumn_begin, autumn_end, spring_begin, spring_end,
comment, useful_links, id, university, obj_moderation_level } = semestersDates;
const modelData = {
autumn_begin: convertDateStrToDate(autumn_begin),
......@@ -78,6 +79,7 @@ class UniversitySemestersDates extends MyComponent {
useful_links,
comment,
university,
obj_moderation_level,
id,
}
......
......@@ -14,6 +14,8 @@ import Slide from '@material-ui/core/Slide';
import MyComponent from '../../../MyComponent';
import Alert from './Alert';
import dateToDateStr from '../../../../utils/dateToDateStr';
import getObjModerationLevel from '../../../../utils/getObjModerationLevels';
import SelectField from './fields/SelectField';
function Transition(props) {
return <Slide direction="up" {...props} />;
......@@ -74,6 +76,26 @@ class Editor extends MyComponent {
return (<div>No editor set</div>)
}
renderObjModerationLevelField() {
const { modelData } = this.props;
const possibleObjModeration = getObjModerationLevel(this.getFetchedData('userData').owner_level, true);
if (possibleObjModeration.length > 1) {
return (
<SelectField label={"Niveau de modération pour ce module"}
required={true}
value={modelData.obj_moderation_level}
options={possibleObjModeration}
onChange={(data) => this.setFormDataAndError('obj_moderation_level', data)}
/>
)
} else {
return (
<Typography variant='caption'>Votre statut ne vous permet pas modifier le niveau local de modération pour ce module.</Typography>
)
}
}
myRender() {
const { classes } = this.props;
return (
......@@ -102,7 +124,7 @@ class Editor extends MyComponent {
</Toolbar>
</AppBar>
<Paper className={classes.paper}>
{this.renderEditor()}
{this.props.open ? this.renderEditor() : <div></div>}
</Paper>
</Dialog>
</div>
......
......@@ -12,6 +12,7 @@ import DateField from './fields/DateField';
import UsefulLinksField from './fields/UsefulLinksField';
import MarkdownField from './fields/MarkdownField';
import {
universitiesSemestersDatesElSaveData,
universitiesSemestersDatesElSavingHasError
......@@ -25,8 +26,6 @@ const styles = theme => ({
class UniversitySemestersDatesEditor extends Editor {
handleSaveEditor() {
const tmp = Object.assign({}, this.props.modelData, this.formData)
console.log(tmp);
console.log(this.props);
this.props.saveData(tmp);
}
......@@ -35,8 +34,8 @@ class UniversitySemestersDatesEditor extends Editor {
return (
<div>
{this.renderObjModerationLevelField()}
<DateField label={"Date de début du semestre de printemps"}
required={true}
selectedDate={modelData.spring_begin}
onChange={(data) => this.setFormDataAndError('spring_begin', data, 'date')}
/>
......
......@@ -80,7 +80,7 @@ class DateField extends PureComponent {
DateField.defaultProps = {
required: false,
label: 'mon label',
selectedDate: Date(),
selectedDate: null,
onChange: (date) => console.log('Nouvelle date sélectionnée : ', date),
}
......
import React from 'react';
import PropTypes from 'prop-types';
import withStyles from '@material-ui/core/styles/withStyles';
import compose from 'recompose/compose';
import FieldWrapper from './FieldWrapper';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
const styles = theme => ({
})
class SelectField extends React.Component {
state = {
value: this.props.value,
hasError: this.hasError(this.props.value)
};
hasError(value) {
if (this.props.required && !value) {
return true;
} else {
return false;
}
}
handleChangeValue = (value) => {
const newState = {
value,
hasError: this.hasError(value)
}
this.setState(newState);
this.props.onChange({
data: newState.value,
hasError: newState.hasError
})
}
render() {
const { classes } = this.props;
return (
<FieldWrapper
required={this.props.required}
hasError={this.state.hasError}
label={this.props.label}
>
<Select
value={this.state.value}
onChange={(e) => this.handleChangeValue(e.target.value)}
>
{
this.props.options.map((el, ind) => (
<MenuItem disabled={false || el.disabled} value={el.value}>{el.label}</MenuItem>
))
}
</Select>
</FieldWrapper>
)
}
}
SelectField.defaultProps = {
required: false,
value: null,
label: 'mon label',
onChange: (data) => console.log('Nouvelle sélection : ', data),
}
SelectField.propTypes = {
required: PropTypes.bool,
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
options: PropTypes.arrayOf(PropTypes.shape({
label: PropTypes.string.isRequired,
value: PropTypes.oneOfType([PropTypes.number.isRequired, PropTypes.string.isRequired]),
disabled: PropTypes.bool
})),
label: PropTypes.string,
onChange: PropTypes.func.isRequired,
};
export default compose(
withStyles(styles, { withTheme: true }),
)(SelectField);
\ No newline at end of file
......@@ -6,7 +6,7 @@ import compose from 'recompose/compose';
import FieldWrapper from './FieldWrapper';
import TextField from '@material-ui/core/TextField';
import { TextField as MuiTextField } from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
const styles = theme => ({
......@@ -36,10 +36,15 @@ class TextField extends React.Component {
value = value.substring(0, maxLength + 1);
}
this.setState({
const newState = {
value,
hasError: this.hasError(value)
});
}
this.setState(newState);
this.props.onChange({
data: newState.value,
hasError: newState.hasError
})
}
......@@ -59,7 +64,7 @@ class TextField extends React.Component {
:
<div></div>
}
<TextField
<MuiTextField
placeholder={"Le champ est vide"}
fullWidth={true}
value={this.state.value}
......@@ -77,13 +82,15 @@ TextField.defaultProps = {
value: '',
label: 'mon label',
maxLength: 0,
onChange: (data) => console.log('Nouveau texte : ', data),
}
TextField.propTypes = {
required: PropTypes.bool,
value: PropTypes.string,
label: PropTypes.string,
maxLength: PropTypes.number
maxLength: PropTypes.number,
onChange: PropTypes.func.isRequired,
};
......
import React from 'react';
import PropTypes from 'prop-types';
import withStyles from '@material-ui/core/styles/withStyles';
import Grid from '@material-ui/core/Grid';
import compose from 'recompose/compose';
......@@ -200,6 +201,15 @@ UsefulLinksField.defaultProps = {
usefulLinks: Array(),
}
UsefulLinksField.propTypes = {
required: PropTypes.bool.isRequired,
usefulLinks: PropTypes.arrayOf(PropTypes.shape({
url: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
})),
label: PropTypes.string,
};
export default compose(
withStyles(styles, { withTheme: true }),
)(UsefulLinksField);
\ No newline at end of file
import OBJ_MODERATION_PERMISSIONS from "../../../backend/permissions/OBJ_MODERATION_PERMISSIONS.json";
export default function getObjModerationLevel(userLevel, restrict = false) {
let out = Array();
for (let key in OBJ_MODERATION_PERMISSIONS) {
const label = OBJ_MODERATION_PERMISSIONS[key].label;
const value = OBJ_MODERATION_PERMISSIONS[key].level;
if (!restrict || (restrict && value <= userLevel)) {
out.push({
label,
value,
disabled: value > userLevel
});
}
}
return out;
}
\ No newline at end of file
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