Commit c18d6f96 authored by Florent Chehab's avatar Florent Chehab
Browse files

Adding DRI module possible

parent d3f940a2
...@@ -9,6 +9,7 @@ try: ...@@ -9,6 +9,7 @@ try:
from .isStaffOrReadOnly import IsStaffOrReadOnly # noqa: F401 from .isStaffOrReadOnly import IsStaffOrReadOnly # noqa: F401
from .readOnly import ReadOnly # noqa: F401 from .readOnly import ReadOnly # noqa: F401
from .isDriOrReadOnly import IsDriOrReadOnly # noqa: F401 from .isDriOrReadOnly import IsDriOrReadOnly # noqa: F401
from .isDriOrNoPost import IsDriOrNoPost # noqa: F401
from .default_viewset_permissions import DEFAULT_VIEWSET_PERMISSIONS # noqa: F401 from .default_viewset_permissions import DEFAULT_VIEWSET_PERMISSIONS # noqa: F401
from .__is_moderation_required import is_moderation_required # noqa: F401 from .__is_moderation_required import is_moderation_required # noqa: F401
except Exception: except Exception:
......
from rest_framework import permissions
from backend.utils import is_member
class IsDriOrNoPost(permissions.BasePermission):
"""
TODO
"""
def has_permission(self, request, view):
if request.method == 'POST':
return is_member("DRI", request.user) or request.user.is_staff
return True
from backend.permissions import IsOwner, IsStaffOrReadOnly, IsDriOrReadOnly, ReadOnly from backend.permissions import IsOwner, IsStaffOrReadOnly, IsDriOrReadOnly, ReadOnly, IsDriOrNoPost
from rest_framework.permissions import IsAdminUser from rest_framework.permissions import IsAdminUser
from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS
from general.api import get_api_config from general.api import get_api_config
...@@ -15,6 +15,8 @@ def get_viewset_permissions(viewset): ...@@ -15,6 +15,8 @@ def get_viewset_permissions(viewset):
permission = (IsStaffOrReadOnly,) permission = (IsStaffOrReadOnly,)
elif custom_permission == "IsDriOrReadOnly": elif custom_permission == "IsDriOrReadOnly":
permission = (IsDriOrReadOnly,) permission = (IsDriOrReadOnly,)
elif custom_permission == "IsDriOrNoPost":
permission = (IsDriOrNoPost,)
elif custom_permission == "IsStaff": elif custom_permission == "IsStaff":
permission = (IsAdminUser,) permission = (IsAdminUser,)
elif custom_permission == 'default': elif custom_permission == 'default':
......
...@@ -74,7 +74,17 @@ class UniversityDri extends MyComponent { ...@@ -74,7 +74,17 @@ class UniversityDri extends MyComponent {
} }
return ( return (
<GenericGroupModule groupTitle={"Informations émanant de la DRI"}> <GenericGroupModule
groupTitle={"Informations émanant de la DRI"}
editor={UniversityDriEditor}
invalidateGroup={this.props.invalidateData}
propsForEditor={{
modelData: { universities: [this.props.univId], importance_level: '-' },
parseRawModelData: parseRawModelData,
outsideData: outsideData,
__apiAttr: this.props.univId,
}}
>
{ {
univDriItems.map((rawModelData) => ( univDriItems.map((rawModelData) => (
<GenericModule <GenericModule
......
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import withStyles from '@material-ui/core/styles/withStyles'; import withStyles from '@material-ui/core/styles/withStyles';
import compose from 'recompose/compose';
import { connect } from "react-redux";
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import Paper from '@material-ui/core/Paper'; import Paper from '@material-ui/core/Paper';
import Tooltip from '@material-ui/core/Tooltip'; import Tooltip from '@material-ui/core/Tooltip';
...@@ -13,7 +16,7 @@ import AddIcon from '@material-ui/icons/Add'; ...@@ -13,7 +16,7 @@ import AddIcon from '@material-ui/icons/Add';
import green from '@material-ui/core/colors/green'; import green from '@material-ui/core/colors/green';
import MyComponent from '../../MyComponent';
const styles = theme => ({ const styles = theme => ({
root: { root: {
...@@ -38,21 +41,52 @@ const styles = theme => ({ ...@@ -38,21 +41,52 @@ const styles = theme => ({
class GenericGroupModule extends React.Component { class GenericGroupModule extends MyComponent {
state = {
editorOpen: false,
};
handleOpenEditor = () => {
this.setState({ editorOpen: true });
}
handleCloseEditor = (somethingWasSaved = false) => {
this.setState({ editorOpen: false });
if (somethingWasSaved) {
this.props.invalidateGroup();
}
};
render() { render() {
const { classes, theme, groupTitle } = this.props; const { classes, theme, groupTitle } = this.props;
return ( return (
<Paper className={classes.root}> <Paper className={classes.root}>
<this.props.editor
{...this.props.propsForEditor}
open={this.state.editorOpen}
handleCloseEditor={this.handleCloseEditor}
userData={this.props.userDataEl}
/>
<Grid container spacing={8} alignItems='center'> <Grid container spacing={8} alignItems='center'>
<Grid item xs> <Grid item xs>
<Typography variant='title' align='center' color="textSecondary"><em>{groupTitle}</em></Typography> <Typography variant='title' align='center' color="textSecondary"><em>{groupTitle}</em></Typography>
</Grid> </Grid>
<Grid item xs={2} style={{ textAlign: 'right' }}> <Grid item xs={2} style={{ textAlign: 'right' }}>
<Tooltip title="Ajouter un élément" placement="top"> <Tooltip title="Ajouter un élément" placement="top">
<div style={{ display: 'inline-block' }}> {/* Needed to fire events for the tooltip when below is disabled! */} <div style={{ display: 'inline-block' }}> {/* Needed to fire events for the tooltip when below is disabled! */}
<Button variant='fab' mini aria-label="Ajouter un élément" disabled={false} style={{ backgroundColor: green.A700 }} className={classes.button}> <Button
variant='fab'
mini
aria-label="Ajouter un élément"
disabled={false}
style={{ backgroundColor: green.A700 }}
className={classes.button}
onClick={this.handleOpenEditor}
>
<AddIcon /> <AddIcon />
</Button> </Button>
</div> </div>
...@@ -71,4 +105,23 @@ GenericGroupModule.propTypes = { ...@@ -71,4 +105,23 @@ GenericGroupModule.propTypes = {
groupTitle: PropTypes.string.isRequired, groupTitle: PropTypes.string.isRequired,
}; };
export default withStyles(styles, { withTheme: true })(GenericGroupModule);
const mapStateToProps = (state) => {
return {
userDataEl: state.userDataEl
};
};
const mapDispatchToProps = (dispatch) => {
return {
fetchData: {
userDataEl: () => dispatch(userDataElFetchData("")),
}
};
};
export default compose(
withStyles(styles, { withTheme: true }),
connect(mapStateToProps, mapDispatchToProps)
)(GenericGroupModule);
\ No newline at end of file
...@@ -108,8 +108,6 @@ class GenericModule extends MyComponent { ...@@ -108,8 +108,6 @@ class GenericModule extends MyComponent {
} }
}) })
} }
}; };
handleCloseEditor = (somethingWasSaved = false) => { handleCloseEditor = (somethingWasSaved = false) => {
......
...@@ -134,6 +134,7 @@ ...@@ -134,6 +134,7 @@
api_end_point: countryDri api_end_point: countryDri
api_attr: (?P<country_id>[a-zA-Z]+) api_attr: (?P<country_id>[a-zA-Z]+)
enforce_moderation_user_level: 'DRI' enforce_moderation_user_level: 'DRI'
viewset_permission: IsDriOrNoPost
versionned: true versionned: true
...@@ -179,6 +180,7 @@ ...@@ -179,6 +180,7 @@
api_end_point: universityDri api_end_point: universityDri
api_attr: (?P<univ_id>[0-9]+) api_attr: (?P<univ_id>[0-9]+)
enforce_moderation_user_level: 'DRI' enforce_moderation_user_level: 'DRI'
viewset_permission: IsDriOrNoPost
versionned: true versionned: true
......
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