Commit dc8e6107 authored by Alessandro Abluton's avatar Alessandro Abluton 🤖

working on permissions management

parent 08b3e90d
window.env = {
// MEDIA
// Online Simcaa.it
/* "PathImages": "http://www.simcaa.it/media/symbols/",
"PathImages": "http://www.simcaa.it/media/symbols/",
"WaterImages": "http://www.simcaa.it/media/specialchar/",
"CustomImage": "http://www.simcaa.it/demo/media/custom/",
"ApiImageUpload": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/imageupload",
"ApiSymbolUpload": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/imageuploadtmp",
"MediaImage": "http://www.simcaa.it/demo/media/images/",
"TmpImage": "http://www.simcaa.it/demo/media/tmp/",
*/
// Local
"PathImages": "http://10.0.0.132/media/symbols/",
"WaterImages": "http://10.0.0.132/media/watermark/",
"CustomImage": "http://10.0.0.132/media/custom/",
"ApiImageUpload": "http://10.0.0.132:8085/graphql/imageupload",
"ApiSymbolUpload": "http://10.0.0.132:8085/graphql/imageuploadtmp",
"MediaImage": "http://10.0.0.132/media/images/",
"TmpImage": "http://10.0.0.132/media/tmp/",
// "PathImages": "http://10.0.0.132/media/symbols/",
// "WaterImages": "http://10.0.0.132/media/watermark/",
// "CustomImage": "http://10.0.0.132/media/custom/",
// "ApiImageUpload": "http://10.0.0.132:8085/graphql/imageupload",
// "ApiSymbolUpload": "http://10.0.0.132:8085/graphql/imageuploadtmp",
// "MediaImage": "http://10.0.0.132/media/images/",
// "TmpImage": "http://10.0.0.132/media/tmp/",
// API SERVER
// Online Simcaa.it
/* "GraphQLServer": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/query",
"GraphQLServer": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/query",
"GraphQLServerNoAuth": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/query/noauth",
"GraphQLLogin": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/login",
"GraphQLCurrentUser": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/me",
......@@ -29,17 +29,17 @@ window.env = {
"RestApiCard": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/card",
"RestApiDuplicateProject": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/duplicateproject",
"RestApiDuplicateChapter": "http://www.simcaa.it/demo/apisimcaa-graphql/public/graphql/duplicatechapter",
*/
// Local
"GraphQLServer": "http://10.0.0.132:8085/graphql/query",
"GraphQLServerNoAuth": "http://10.0.0.132:8085/graphql/query/noauth",
"GraphQLLogin": "http://10.0.0.132:8085/graphql/login",
"GraphQLCurrentUser": "http://10.0.0.132:8085/graphql/me",
"GraphQLRefreshToken": "http://10.0.0.132:8085/graphql/jwtrefresh",
"RestApiCard": "http://10.0.0.132:8085/graphql/card",
"RestApiDuplicateProject": "http://10.0.0.132:8085/graphql/duplicateproject",
"RestApiDuplicateChapter": "http://10.0.0.132:8085/graphql/duplicatechapter",
// "GraphQLServer": "http://10.0.0.132:8085/graphql/query",
// "GraphQLServerNoAuth": "http://10.0.0.132:8085/graphql/query/noauth",
// "GraphQLLogin": "http://10.0.0.132:8085/graphql/login",
// "GraphQLCurrentUser": "http://10.0.0.132:8085/graphql/me",
// "GraphQLRefreshToken": "http://10.0.0.132:8085/graphql/jwtrefresh",
// "RestApiCard": "http://10.0.0.132:8085/graphql/card",
// "RestApiDuplicateProject": "http://10.0.0.132:8085/graphql/duplicateproject",
// "RestApiDuplicateChapter": "http://10.0.0.132:8085/graphql/duplicatechapter",
// CSS - remote
// "SemanticCSS": "http://10.0.0.132/includes/css/semantic.min.css",
......
import React, { Component, Fragment } from 'react'
import {Button, Form, Checkbox} from 'semantic-ui-react'
class EditUserForm extends Component{
constructor(props){
super(props)
}
handleChange(e,data){
}
render(){
console.log(this.props.permissions);
let fieldsLayout = this.props.permissions.map((perm,idx)=>{
return(
<Form.Field>
<label>Object.keys(perm)[0]</label>
<Checkbox toggle
key={idx}
checked={Object.values(perm)[0]}
onChange={this.handleChange}
/>
</Form.Field>
)
})
return(
<Form>
{fieldsLayout}
</Form>
)
}
}
export default EditUserForm
......@@ -25,6 +25,7 @@ class UsersTable extends React.Component {
}
render() {
const { t } = this.props
let rows = this.props.users.map((item,idx)=>{
return(
<Table.Row
......@@ -57,7 +58,7 @@ class UsersTable extends React.Component {
content= {t("POPUP_DEL")}
/>
<Popup
trigger={<Button circular icon={<Icon name='edit' size='large'/>} onClick={()=>this.props.openEdit(item)}/>}
trigger={<Button circular icon={<Icon name='edit' size='large'/>} onClick={()=>{this.props.openEdit(item)}}/>}
content= "Modifica dati"
/>
</Table.Cell>
......
import React, { Component, Fragment } from 'react'
import { Modal, Button, Icon, Popup } from 'semantic-ui-react'
import { Modal, Button, Icon, Popup, Tab } from 'semantic-ui-react'
import PositiveMessage from '../components/PositiveMessage'
import NegativeMessage from '../components/ErrorMessage'
import EditUserForm from '../components/EditUserForm'
import EditPermissionsForm from '../components/EditPermissionsForm'
import {apolloFetch, apolloFetchNoAuth} from '../../store/apolloFetchUtils'
import {connect} from 'react-redux'
import {saveUserTeams} from '../../store/actions/AdministrationActions'
......@@ -25,7 +25,8 @@ class EditUserParamsModal extends Component {
link_web: this.props.toUser.web_site,
role_id: this.props.toUser.role_id,
old_password: '',
new_password: ''
new_password: '',
activeIndex: 0
}
}
nameChange(e){
......@@ -44,8 +45,6 @@ class EditUserParamsModal extends Component {
this.setState({link_web: e.target.value, somethingModded: true})
}
roleChange(e,data){
console.log(e);
console.log(data);
this.setState({role: data.value, somethingModded: true})
}
oldPassChange(e){
......@@ -108,7 +107,33 @@ class EditUserParamsModal extends Component {
this.setState({loading: false, error: true, updated: false})
})
}
handleTabChange(e,{activeIndex}){
console.log(activeIndex);
this.setState({activeIndex})
}
render(){
const editParamsForm = <EditUserForm
name={this.state.name}
nameChange={()=>this.nameChange.bind(this)}
email={this.state.email}
emailChange={()=>this.emailChange.bind(this)}
username={this.state.username}
usernameChange={()=>this.usernameChange.bind(this)}
organization = {this.state.organization}
orgChange={()=>this.orgChange.bind(this)}
link_web = {this.state.link_web}
linkWebChange={()=>this.linkWebChange.bind(this)}
roles = {this.props.roles}
roleChange={()=>this.roleChange.bind(this)}
oldPassChange={()=>this.oldPassChange.bind(this)}
newPassChange={()=>this.newPassChange.bind(this)}
toUser={this.props.toUser}
/>
const editPermissionsForm = <EditPermissionsForm permissions={this.props.toUser.user_permissions}/>
const panes=[
{menuItem: 'Parametri', render: ()=><Tab.Pane>{editParamsForm}</Tab.Pane>},
{menuItem: 'Permessi', render: ()=><Tab.Pane>{editPermissionsForm}</Tab.Pane>}
]
return(
<Modal closeIcon="close" open={this.props.openModal} onClose={this.props.closeModal}>
<Modal.Header>
......@@ -117,23 +142,7 @@ class EditUserParamsModal extends Component {
content="Modifica dei parametri dell'utente, basta digitare il nuovo valore per uno o più parametri e poi cliccare su Modifica. "/>
</Modal.Header>
<Modal.Content>
<EditUserForm
name={this.state.name}
nameChange={()=>this.nameChange.bind(this)}
email={this.state.email}
emailChange={()=>this.emailChange.bind(this)}
username={this.state.username}
usernameChange={()=>this.usernameChange.bind(this)}
organization = {this.state.organization}
orgChange={()=>this.orgChange.bind(this)}
link_web = {this.state.link_web}
linkWebChange={()=>this.linkWebChange.bind(this)}
roles = {this.props.roles}
roleChange={()=>this.roleChange.bind(this)}
oldPassChange={()=>this.oldPassChange.bind(this)}
newPassChange={()=>this.newPassChange.bind(this)}
toUser={this.props.toUser}
/>
<Tab panes={panes} activeIndex={this.state.activeIndex} onTabChange={this.handleTabChange.bind(this)}/>
<PositiveMessage header="Tutto ok!" message="Utente modificato correttamente :)" hidden={!this.state.updated}/>
<NegativeMessage header="Errore!" message="Non è stato possibile modificare i parametri dell'utente" hidden={!this.state.error}/>
</Modal.Content>
......
......@@ -103,6 +103,7 @@ export function saveUserTeams(){
name
username
email
user_permissions
organization
web_site
role_id
......@@ -112,6 +113,10 @@ export function saveUserTeams(){
`
apolloFetchNoAuth({query})
.then((data)=>{
console.log(data);
data.data.user_teams.data.map((el)=>{
el.user_permissions = JSON.parse(el.user_permissions)
})
dispatch({
type: "SAVE_ADMIN_USER_TEAMS",
user_teams: data.data.user_teams.data
......
......@@ -24,6 +24,7 @@ export function modalReducer(state = { }, action) {
});
return newState
case "OPEN_MODAL_EDIT_USER_PARAMS":
console.log(action.toUser);
newState = Object.assign({},state,{
openModal: true,
modalContent: "edit_user_params",
......
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