diff --git a/datastore/src/main/java/net/jami/datastore/dao/PolicyDao.java b/datastore/src/main/java/net/jami/datastore/dao/PolicyDao.java index a3649752a6c239a471b263b4a76befcede927da9..247182325f5f325e59a4ae6ebfbcef71baf48e02 100644 --- a/datastore/src/main/java/net/jami/datastore/dao/PolicyDao.java +++ b/datastore/src/main/java/net/jami/datastore/dao/PolicyDao.java @@ -4,7 +4,6 @@ import lombok.extern.slf4j.Slf4j; import net.jami.datastore.main.DataStore; import net.jami.jams.common.dao.StatementList; import net.jami.jams.common.dao.connectivity.SQLConnection; -import net.jami.jams.common.objects.user.Group; import net.jami.jams.common.objects.user.Policy; import java.sql.PreparedStatement; @@ -23,7 +22,7 @@ public class PolicyDao extends AbstractDao<Policy> { SQLConnection connection = DataStore.connectionPool.getConnection(); try { PreparedStatement ps = connection.getConnection().prepareStatement("INSERT INTO policies " + - "(groupName, username, policyData) VALUES (?, ?, ?)"); + "(name, policyData) VALUES (?, ?)"); ps = object.getInsert(ps); return ps.executeUpdate() != 0; } catch (Exception e) { @@ -36,19 +35,17 @@ public class PolicyDao extends AbstractDao<Policy> { @Override public boolean updateObject(StatementList update, StatementList constraints) { - String policyData = update.getStatements().get(0).getValue(); - String groupName = update.getStatements().get(1).getValue(); - String username = update.getStatements().get(2).getValue(); - String oldGroupName = constraints.getStatements().get(0).getValue(); + String name = update.getStatements().get(0).getValue(); + String policyData = update.getStatements().get(1).getValue(); + String oldName = constraints.getStatements().get(0).getValue(); SQLConnection connection = DataStore.connectionPool.getConnection(); try { - PreparedStatement ps = connection.getConnection().prepareStatement("UPDATE policies SET groupName = ?, username = ?, policyData = ? WHERE groupName = ?"); - ps.setString(1, groupName); - ps.setString(2, username); - ps.setString(3, policyData); - ps.setString(4, oldGroupName); + PreparedStatement ps = connection.getConnection().prepareStatement("UPDATE policies SET name = ?, policyData = ? WHERE name = ?"); + ps.setString(1, name); + ps.setString(2, policyData); + ps.setString(3, oldName); return ps.executeUpdate() != 0; } catch (Exception e) { log.error("An error has occurred while trying to update a blueprint: " + e.toString()); @@ -65,7 +62,7 @@ public class PolicyDao extends AbstractDao<Policy> { SQLConnection connection = DataStore.connectionPool.getConnection(); try { - PreparedStatement ps = connection.getConnection().prepareStatement("DELETE FROM policies WHERE groupName = ?"); + PreparedStatement ps = connection.getConnection().prepareStatement("DELETE FROM policies WHERE name = ?"); ps.setString(1, name); return ps.executeUpdate() != 0; } catch (SQLException e){ diff --git a/datastore/src/main/resources/db/migration/V16__Policy.sql b/datastore/src/main/resources/db/migration/V16__Policy.sql index e39fcab348df9de31ad9027260d2da908a852765..f3ef94d62790717a91fcb41a9309ee418247c939 100644 --- a/datastore/src/main/resources/db/migration/V16__Policy.sql +++ b/datastore/src/main/resources/db/migration/V16__Policy.sql @@ -1,3 +1,2 @@ -CREATE TABLE policies (groupName varchar(255), -username varchar(255), policyData varchar(5000), -PRIMARY KEY (groupName)); \ No newline at end of file +CREATE TABLE policies (name varchar(255), policyData varchar(5000), +PRIMARY KEY (name)); \ No newline at end of file diff --git a/datastore/src/test/resources/db/migration/V16__Policy.sql b/datastore/src/test/resources/db/migration/V16__Policy.sql index 1bf348d2975f653ace6693434d73806fc91b400f..f3ef94d62790717a91fcb41a9309ee418247c939 100644 --- a/datastore/src/test/resources/db/migration/V16__Policy.sql +++ b/datastore/src/test/resources/db/migration/V16__Policy.sql @@ -1,3 +1,2 @@ -CREATE TABLE policies (groupName bigint, -userid bigint, -PRIMARY KEY (groupName,userid)); \ No newline at end of file +CREATE TABLE policies (name varchar(255), policyData varchar(5000), +PRIMARY KEY (name)); \ No newline at end of file diff --git a/jams-common/src/main/java/net/jami/jams/common/objects/user/Policy.java b/jams-common/src/main/java/net/jami/jams/common/objects/user/Policy.java index d3de8331f5a1e79d87fb9a4cbbf32b619aadfefb..6f9c9226c72ad2817442cba2af31c3daec0607c5 100644 --- a/jams-common/src/main/java/net/jami/jams/common/objects/user/Policy.java +++ b/jams-common/src/main/java/net/jami/jams/common/objects/user/Policy.java @@ -17,23 +17,20 @@ import java.sql.ResultSet; @NoArgsConstructor @Getter @Setter -public class Policy extends X509Entity implements DatabaseObject { +public class Policy implements DatabaseObject { - private String groupName; - private String username; + private String name; private String policyData; public Policy(ResultSet rs) throws Exception { - this.groupName = rs.getString("groupName"); - this.username = rs.getString("username"); + this.name = rs.getString("name"); this.policyData = rs.getString("policyData"); } @Override public PreparedStatement getInsert(PreparedStatement ps) throws Exception { - ps.setString(1, groupName); - ps.setString(2, username); - ps.setString(3, policyData); + ps.setString(1, name); + ps.setString(2, policyData); return ps; } diff --git a/jams-react-client/src/views/Blueprint/EditBlueprintConfiguration.js b/jams-react-client/src/views/Blueprint/EditBlueprintConfiguration.js index b017d600e6c7848764c771991d6bf31e4ee286b4..43a79a0e501280725fd420bfd64e448756b869f7 100644 --- a/jams-react-client/src/views/Blueprint/EditBlueprintConfiguration.js +++ b/jams-react-client/src/views/Blueprint/EditBlueprintConfiguration.js @@ -30,7 +30,7 @@ import BuildOutlinedIcon from '@material-ui/icons/BuildOutlined'; import axios from "axios" import configApiCall from "../../api" -import { api_path_blueprint_configuration } from "../../globalUrls" +import { api_path_blueprints } from "../../globalUrls" import Snackbar from '@material-ui/core/Snackbar'; @@ -106,57 +106,72 @@ export default function EditBlueprintConfiguration(props) { const classes = useStyles(); const history = useHistory(); - const [blueprintName, setBlueprintName] = React.useState("") - const [uPnP, setUPnP] = React.useState(true) - const [turn, setTurn] = React.useState(true) - const [turnServerAddress, setTurnServerAddress] = React.useState("") - const [turnUsername, setTurnUsername] = React.useState("") - const [turnPassword, setTurnPassword] = React.useState("") - const [bootstrap, setBootstrap] = React.useState(true) - const [bootstrapName, setBootstrapName] = React.useState("") - const [dhtProxy, setDhtProxy] = React.useState("") - const [dhtProxyName, setDhtProxyName] = React.useState("") - const [pushNotifications, setPushNotifications] = React.useState(false) + const [videoEnabled, setVideoEnabled] = React.useState(false); + const [allowPeersFromContact, setAllowPeersFromContact] = React.useState(false); + const [autoAnswer, setAutoAnswer] = React.useState(false); + const [accountPeerDiscovery, setAccountPeerDiscovery] = React.useState(false); + + const [upnpEnabled, setUpnpEnabled] = React.useState(false) + const [turnEnabled, setTurnEnabled] = React.useState(false) + const [turnServer, setTurnServer] = React.useState("") + const [turnServerUserName, setTurnServerUserName] = React.useState("") + const [turnServerPassword, setTurnServerPassword] = React.useState("") + const [proxyEnabled, setProxyEnabled] = React.useState("") + const [proxyServer, setProxyServer] = React.useState("") + const [accountDhtProxyListUrl, setAccountDhtProxyListUrl] = React.useState("") const [open, setOpen] = React.useState(false) const [message, setMessage] = React.useState(false) const [severity, setSeverity] = React.useState("success") React.useEffect(()=>{ - setBlueprintName(props.blueprintName) - - axios(configApiCall(api_path_blueprint_configuration, 'GET', {"queryString": props.blueprintName}, null)).then((response) => { - response.data.map((blueprint) => { - setUPnP(blueprint["uPnP"]) - setTurn(blueprint["turn"]) - setTurnServerAddress(blueprint["turnServerAddress"]) - setTurnUsername(blueprint["turnUsername"]) - setTurnPassword(blueprint['turnPassword']) - setBootstrap(blueprint["bootstrap"]) - setBootstrapName(blueprint["bootstrapName"]) - setDhtProxy(blueprint["dhtProxy"]) - setDhtProxyName(blueprint["dhtProxyName"]) - setPushNotifications(blueprint["pushNotifications"]) - }) + axios(configApiCall(api_path_blueprints+"?name="+props.blueprintName, 'GET', null, null)).then((response) => { + let policyData = JSON.parse(response.data.policyData); + setVideoEnabled(policyData["videoEnabled"]); + setAllowPeersFromContact(policyData["allowPeersFromContact"]); + setAutoAnswer(policyData["autoAnswer"]); + setAccountPeerDiscovery(policyData["Account.peerDiscovery"]); + + setUpnpEnabled(policyData["upnpEnabled"]) + setTurnEnabled(policyData["turnEnabled"]) + setTurnServer(policyData["turnServer"]) + setTurnServerUserName(policyData["turnServerUserName"]) + setTurnServerPassword(policyData['turnServerPassword']) + setProxyEnabled(policyData["proxyEnabled"]) + setProxyServer(policyData["proxyServer"]) + setAccountDhtProxyListUrl(policyData["Account.dhtProxyListUrl"]) }).catch((error) => { console.log("Error fetching blueprint permissions : " + props.username + " " + error) }) }, []) - const handleUpdateConfiguration = () => { - const data = { - 'uPnP': uPnP, - 'turn': turn, - 'turnServerAddress': turnServerAddress, - 'turnUsername': turnUsername, - 'turnPassword': turnPassword, - 'bootstrap': bootstrap, - 'dhtProxy': dhtProxy, - 'dhtProxyName': dhtProxyName, - 'pushNotifications': pushNotifications + const handleUpdateConfiguration = (field, value) => { + let data = { + "videoEnabled": videoEnabled, + "allowPeersFromContact": allowPeersFromContact, + "allowPeersFromHistory": allowPeersFromContact, + "allowPeersFromTrusted": allowPeersFromContact, + "autoAnswer": autoAnswer, + "Account.peerDiscovery": accountPeerDiscovery, + "Account.accountDiscovery": accountPeerDiscovery, + "Account.accountPublish": accountPeerDiscovery, + "upnpEnabled": upnpEnabled, + "turnEnabled": turnEnabled, + "turnServer": turnServer, + "turnServerUserName": turnServerUserName, + "turnServerPassword": turnServerPassword, + "proxyEnabled": proxyEnabled, + "proxyServer": proxyServer, + "Account.dhtProxyListUrl": accountDhtProxyListUrl + } + + if(field === "accountDhtProxyListUrl"){ + data["Account.dhtProxyListUrl"] = value; + }else{ + data[field] = value; } - axios(configApiCall(api_path_blueprint_configuration, 'PUT', data, null)).then((response) => { + axios(configApiCall(api_path_blueprints+"?name="+props.blueprintName, 'PUT', data, null)).then((response) => { setOpen(false) setSeverity("success") setOpen(true) @@ -169,7 +184,7 @@ export default function EditBlueprintConfiguration(props) { }) } - const initUpdateConfiguration = useCallback(debounce((searchValue) => handleUpdateConfiguration(), 500), []) + //const initUpdateConfiguration = useCallback(debounce((field, value) => handleUpdateConfiguration(fields), 500), []) const handleClose = () => { setOpen(false) @@ -204,10 +219,10 @@ export default function EditBlueprintConfiguration(props) { <Grid item xs={12} sm={12} md={12}> <FormGroup row> <FormControlLabel - control={<Checkbox checked={uPnP} color="primary" onChange={e => { - setUPnP(e.target.checked); - handleUpdateConfiguration(); - }} name="uPnP" />} + control={<Checkbox checked={upnpEnabled} color="primary" onChange={e => { + setUpnpEnabled(e.target.checked); + handleUpdateConfiguration("upnpEnabled", e.target.checked); + }} name="upnpEnabled" />} label="UPnP" /> </FormGroup> @@ -215,10 +230,10 @@ export default function EditBlueprintConfiguration(props) { <Grid item xs={12} sm={12} md={12}> <FormGroup row> <FormControlLabel - control={<Checkbox checked={turn} color="primary" onChange={e => { - setTurn(e.target.checked); - handleUpdateConfiguration(); - }} name="turn" />} + control={<Checkbox checked={turnEnabled} color="primary" onChange={e => { + setTurnEnabled(e.target.checked); + handleUpdateConfiguration("turnEnabled", e.target.checked); + }} name="turnEnabled" />} label="TURN" /> </FormGroup> @@ -228,57 +243,57 @@ export default function EditBlueprintConfiguration(props) { <Grid item xs={12} sm={12} md={8}> <FormGroup row> <FormControl className={classes.margin} size="large"> - <InputLabel htmlFor="turnServerAddress">TURN Server address</InputLabel> + <InputLabel htmlFor="turnServer">TURN Server address</InputLabel> <Input - disabled={!turn} - id="turnServerAddress" - placeholder={turnServerAddress} + disabled={!turnEnabled} + id="turnServer" + placeholder={turnServer} startAdornment={ <InputAdornment position="start"> <DnsOutlinedIcon /> </InputAdornment> } onChange={e => { - setTurnServerAddress(e.target.value); - initUpdateConfiguration(); + setTurnServer(e.target.value); + handleUpdateConfiguration("turnServer", e.target.value); }} /> </FormControl> </FormGroup> <FormGroup row> <FormControl className={classes.margin} size="large"> - <InputLabel htmlFor="turnUsername">TURN username</InputLabel> + <InputLabel htmlFor="turnServerUserName">TURN server username</InputLabel> <Input - disabled={!turn} - id="turnUsername" - placeholder={turnUsername} + disabled={!turnEnabled} + id="turnServerUserName" + placeholder={turnServerUserName} startAdornment={ <InputAdornment position="start"> <AccountCircleIcon /> </InputAdornment> } onChange={e => { - setTurnUsername(e.target.value); - initUpdateConfiguration(); + setTurnServerUserName(e.target.value); + handleUpdateConfiguration("turnServerUserName", e.target.value); }} /> </FormControl> </FormGroup> <FormGroup row> <FormControl className={classes.margin} size="large"> - <InputLabel htmlFor="turnPassword">TURN password</InputLabel> + <InputLabel htmlFor="turnServerPassword">TURN server password</InputLabel> <Input - disabled={!turn} - id="turnPassword" - placeholder={turnPassword} + disabled={!turnEnabled} + id="turnServerPassword" + placeholder={turnServerPassword} startAdornment={ <InputAdornment position="start"> <VpnKeyOutlinedIcon /> </InputAdornment> } onChange={e => { - setTurnPassword(e.target.value); - initUpdateConfiguration(); + setTurnServerPassword(e.target.value); + handleUpdateConfiguration("turnServerPassword", e.target.value); }} /> </FormControl> @@ -287,11 +302,11 @@ export default function EditBlueprintConfiguration(props) { <Grid item xs={12} sm={12} md={12}> <FormGroup row> <FormControlLabel - control={<Checkbox checked={bootstrap} color="primary" onChange={e => { - setBootstrap(e.target.checked); - handleUpdateConfiguration(); - }} name="bootstrap" />} - label="Bootstrap" + control={<Checkbox checked={proxyEnabled} color="primary" onChange={e => { + setProxyEnabled(e.target.checked); + handleUpdateConfiguration("proxyEnabled", e.target.checked); + }} name="proxyEnabled" />} + label="Dht proxy" /> </FormGroup> </Grid> @@ -300,69 +315,43 @@ export default function EditBlueprintConfiguration(props) { <Grid item xs={12} sm={12} md={8}> <FormGroup row> <FormControl className={classes.margin} size="large"> - <InputLabel htmlFor="bootstrapName">Bootstrap servername name</InputLabel> + <InputLabel htmlFor="proxyServer">DHT proxy server name</InputLabel> <Input - disabled={!bootstrap} - id="bootstrapName" - placeholder={bootstrapName} + disabled={!proxyEnabled} + id="proxyServer" + placeholder={proxyServer} startAdornment={ <InputAdornment position="start"> - <StorageOutlinedIcon /> + <LanguageOutlinedIcon /> </InputAdornment> } onChange={e => { - setBootstrapName(e.target.value); - initUpdateConfiguration(); + setProxyServer(e.target.value); + handleUpdateConfiguration("proxyServer", e.target.value); }} /> </FormControl> </FormGroup> - </Grid> - <Grid item xs={12} sm={12} md={12}> - <FormGroup row> - <FormControlLabel - control={<Checkbox checked={dhtProxy} color="primary" onChange={e => { - setDhtProxy(e.target.checked); - handleUpdateConfiguration(); - }} name="dhtProxy" />} - label="Dht proxy" - /> - </FormGroup> - </Grid> - <Grid item xs={12} sm={12} md={4}> - </Grid> - <Grid item xs={12} sm={12} md={8}> <FormGroup row> <FormControl className={classes.margin} size="large"> - <InputLabel htmlFor="dhtProxyName">DHT proxy name</InputLabel> + <InputLabel htmlFor="accountDhtProxyListUrl">DHT proxy List URL</InputLabel> <Input - disabled={!dhtProxy} - id="dhtProxyName" - placeholder={dhtProxyName} + disabled={!proxyEnabled} + id="proxyServer" + placeholder={accountDhtProxyListUrl} startAdornment={ <InputAdornment position="start"> <LanguageOutlinedIcon /> </InputAdornment> } onChange={e => { - setDhtProxyName(e.target.value); - initUpdateConfiguration(); + setAccountDhtProxyListUrl(e.target.value); + handleUpdateConfiguration("accountDhtProxyListUrl", e.target.value); }} /> </FormControl> </FormGroup> </Grid> - <Grid item xs={12} sm={12} md={12}> - <FormGroup row> - <FormControlLabel - control={<Checkbox checked={pushNotifications} color="primary" onChange={e => { - setPushNotifications(e.target.checked); - handleUpdateConfiguration(); - }} name="pushNotifications" />} - label="Push notifications" - /> - </FormGroup> - </Grid> </Grid> </div> </CardBody> diff --git a/jams-react-client/src/views/Blueprint/EditBlueprintPermissions.js b/jams-react-client/src/views/Blueprint/EditBlueprintPermissions.js index 0c45eeaba9598172f63a77df0eb1f8255d463307..86fca19433e27089c2bea59caac36fe7247e00d7 100644 --- a/jams-react-client/src/views/Blueprint/EditBlueprintPermissions.js +++ b/jams-react-client/src/views/Blueprint/EditBlueprintPermissions.js @@ -23,7 +23,7 @@ import PriorityHighOutlinedIcon from '@material-ui/icons/PriorityHighOutlined'; import axios from "axios" import configApiCall from "../../api" -import { api_path_blueprint_permissions } from "../../globalUrls" +import { api_path_blueprints } from "../../globalUrls" import dashboardStyle from "assets/jss/material-dashboard-react/views/dashboardStyle.js"; @@ -95,51 +95,80 @@ export default function EditBlueprintPermissions(props) { const classes = useStyles(); const history = useHistory(); - const [blueprintName, setBlueprintName] = React.useState("") - const [acceptIncomingCalls, setAcceptIncomingCalls] = React.useState(false) - const [acceptOutgoingCalls, setAcceptOutgoingCalls] = React.useState(false) - const [autoAnswer, setAutoAnswer] = React.useState(false) - const [activateChat, setActivateChat] = React.useState(false) - const [manageContacts, setManageContacts] = React.useState(false) - const [restrictAccesParameters, setRestrictAccesParameters] = React.useState(false) - const [allowNewAccount, setAllowNewAccount] = React.useState(false) - const [allowConnection, setAllowConnection] = React.useState(false) + const [videoEnabled, setVideoEnabled] = React.useState(false); + const [allowPeersFromContact, setAllowPeersFromContact] = React.useState(false); + const [autoAnswer, setAutoAnswer] = React.useState(false); + const [accountPeerDiscovery, setAccountPeerDiscovery] = React.useState(false); + + const [upnpEnabled, setUpnpEnabled] = React.useState(false) + const [turnEnabled, setTurnEnabled] = React.useState(false) + const [turnServer, setTurnServer] = React.useState("") + const [turnServerUserName, setTurnServerUserName] = React.useState("") + const [turnServerPassword, setTurnServerPassword] = React.useState("") + const [proxyEnabled, setProxyEnabled] = React.useState("") + const [proxyServer, setProxyServer] = React.useState("") + const [accountDhtProxyListUrl, setAccountDhtProxyListUrl] = React.useState("") const [open, setOpen] = React.useState(false) const [message, setMessage] = React.useState(false) const [severity, setSeverity] = React.useState("success") React.useEffect(()=>{ - setBlueprintName(props.blueprintName) - axios(configApiCall(api_path_blueprint_permissions, 'GET', {"queryString": props.blueprintName}, null)).then((response) => { - response.data.map((blueprint) => { - setAcceptIncomingCalls(blueprint["acceptIncomingCalls"]) - setAcceptOutgoingCalls(blueprint["acceptOutgoingCalls"]) - setAutoAnswer(blueprint["autoAnswer"]) - setActivateChat(blueprint["activateChat"]) - setManageContacts(blueprint['manageContacts']) - setRestrictAccesParameters(blueprint["restrictAccesParameters"]) - setAllowNewAccount(blueprint["allowNewAccount"]) - setAllowConnection(blueprint["allowConnection"]) - }) + axios(configApiCall(api_path_blueprints+"?name="+props.blueprintName, 'GET', null, null)).then((response) => { + let policyData = JSON.parse(response.data.policyData); + setVideoEnabled(policyData["videoEnabled"]); + setAllowPeersFromContact(policyData["allowPeersFromContact"]); + setAutoAnswer(policyData["autoAnswer"]); + setAccountPeerDiscovery(policyData["Account.peerDiscovery"]); + + setUpnpEnabled(policyData["upnpEnabled"]); + setTurnEnabled(policyData["turnEnabled"]) + setTurnServer(policyData["turnServer"]); + setTurnServerUserName(policyData["turnServerUserName"]); + setTurnServerPassword(policyData['turnServerPassword']); + setProxyEnabled(policyData["proxyEnabled"]); + setProxyServer(policyData["proxyServer"]); + setAccountDhtProxyListUrl(policyData["Account.dhtProxyListUrl"]); }).catch((error) => { console.log("Error fetching blueprint permissions : " + props.blueprintName + " " + error) }) }, []) - const handleUpdatePermissions = () => { - const data = { - 'acceptIncomingCalls': acceptIncomingCalls, - 'acceptOutgoingCalls': acceptOutgoingCalls, - 'autoAnswer': autoAnswer, - 'activateChat': activateChat, - 'manageContacts': manageContacts, - 'restrictAccesParameters': restrictAccesParameters, - 'allowNewAccount': allowNewAccount, - 'allowConnection': allowConnection + const handleUpdatePermissions = (field, value) => { + let data = { + "videoEnabled": videoEnabled, + "allowPeersFromContact": allowPeersFromContact, + "allowPeersFromHistory": allowPeersFromContact, + "allowPeersFromTrusted": allowPeersFromContact, + "autoAnswer": autoAnswer, + "Account.peerDiscovery": accountPeerDiscovery, + "Account.accountDiscovery": accountPeerDiscovery, + "Account.accountPublish": accountPeerDiscovery, + "upnpEnabled": upnpEnabled, + "turnEnabled": turnEnabled, + "turnServer": turnServer, + "turnServerUserName": turnServerUserName, + "turnServerPassword": turnServerPassword, + "proxyEnabled": proxyEnabled, + "proxyServer": proxyServer, + "Account.dhtProxyListUrl": accountDhtProxyListUrl + } + + if(field === "allowPeersFromContact"){ + data["allowPeersFromContact"] = value; + data["allowPeersFromHistory"] = value; + data["allowPeersFromTrusted"] = value; + } + else if (field === "accountPeerDiscovery"){ + data["Account.peerDiscovery"] = value; + data["Account.accountDiscovery"] = value; + data["Account.accountPublish"] = value; + } + else { + data[field] = value; } - axios(configApiCall(api_path_blueprint_permissions, 'PUT', data, null)).then((response) => { + axios(configApiCall(api_path_blueprints+"?name="+props.blueprintName, 'PUT', data, null)).then((response) => { setOpen(false) setSeverity("success") setOpen(true) @@ -185,74 +214,38 @@ export default function EditBlueprintPermissions(props) { <Grid item xs={12} sm={12} md={6}> <FormGroup row> <FormControlLabel - control={<Checkbox checked={acceptIncomingCalls} color="primary" onChange={e => { - setAcceptIncomingCalls(e.target.checked); - handleUpdatePermissions(); - }} name="acceptIncomingCalls" />} - label="Accept incoming calls" + control={<Checkbox checked={videoEnabled} color="primary" onChange={e => { + setVideoEnabled(e.target.checked); + handleUpdatePermissions("videoEnabled", e.target.checked); + }} name="videoEnabled" />} + label="Allow videos calls" /> </FormGroup> <FormGroup row> <FormControlLabel - control={<Checkbox checked={acceptOutgoingCalls} color="primary" onChange={e => { - setAcceptOutgoingCalls(e.target.checked); - handleUpdatePermissions(); - }} name="acceptOutgoingCalls" />} - label="Accept outgoing calls" + control={<Checkbox checked={allowPeersFromContact} color="primary" onChange={e => { + setAllowPeersFromContact(e.target.checked); + handleUpdatePermissions("allowPeersFromContact", e.target.checked); + }} name="allowPeersFromContact" />} + label="Allow incomming calls from unknown contacts" /> </FormGroup> <FormGroup row> <FormControlLabel control={<Checkbox checked={autoAnswer} color="primary" onChange={e => { setAutoAnswer(e.target.checked); - handleUpdatePermissions(); + handleUpdatePermissions("autoAnswer", e.target.checked); }} name="autoAnswer" />} - label="Auto-answer" - /> - </FormGroup> - <FormGroup row> - <FormControlLabel - control={<Checkbox checked={activateChat} color="primary" onChange={e => { - setActivateChat(e.target.checked); - handleUpdatePermissions(); - }} name="activateChat" />} - label="Activate chat" - /> - </FormGroup> - <FormGroup row> - <FormControlLabel - control={<Checkbox checked={manageContacts} color="primary" onChange={e => { - setManageContacts(e.target.checked); - handleUpdatePermissions(); - }} name="manageContacts" />} - label="Manage contacts" - /> - </FormGroup> - <FormGroup row> - <FormControlLabel - control={<Checkbox checked={restrictAccesParameters} color="primary" onChange={e => { - setRestrictAccesParameters(e.target.checked); - handleUpdatePermissions(); - }} name="restrictAccesParameters" />} - label="Restrict acces to parameters with password" - /> - </FormGroup> - <FormGroup row> - <FormControlLabel - control={<Checkbox checked={allowNewAccount} color="primary" onChange={e => { - setAllowNewAccount(e.target.checked); - handleUpdatePermissions(); - }} name="allowNewAccount" />} - label="Allow new account creation" + label="Auto answer calls" /> </FormGroup> <FormGroup row> <FormControlLabel - control={<Checkbox checked={allowConnection} color="primary" onChange={e => { - setAllowConnection(e.target.checked); - handleUpdatePermissions(); - }} name="allowConnection" />} - label="Allow connection with other account" + control={<Checkbox checked={accountPeerDiscovery} color="primary" onChange={e => { + setAccountPeerDiscovery(e.target.checked); + handleUpdatePermissions("accountPeerDiscovery", e.target.checked); + }} name="accountPeerDiscovery" />} + label="Allow use of Jami in a local lan" /> </FormGroup> </Grid> diff --git a/jams-react-client/src/views/Blueprints/Blueprints.js b/jams-react-client/src/views/Blueprints/Blueprints.js index 5ebce451767545d2f04278461483386b2a00d4e9..199115554f5a03c39eba22cd4d84e00a3244139e 100644 --- a/jams-react-client/src/views/Blueprints/Blueprints.js +++ b/jams-react-client/src/views/Blueprints/Blueprints.js @@ -104,7 +104,7 @@ export default function Blueprints() { return Math.min(oldProgress + diff, 100); }); }, 500); - axios(configApiCall(api_path_blueprints+"?groupName=*", 'GET', null, null)).then((response)=> { + axios(configApiCall(api_path_blueprints+"?name=*", 'GET', null, null)).then((response)=> { let allBluePrints = response.data if(allBluePrints.length === 0) setZeroBlueprint(true); @@ -138,7 +138,7 @@ export default function Blueprints() { } const handleCheckBlueprintNameExists = (searchBlueprintNameValue) => { - axios(configApiCall(api_path_blueprints+"?groupName="+searchBlueprintNameValue, 'GET', null, null)).then((response)=>{ + axios(configApiCall(api_path_blueprints+"?name="+searchBlueprintNameValue, 'GET', null, null)).then((response)=>{ setBlueprintNameExits(false) }).catch((error) =>{ setBlueprintNameExits(true) @@ -152,9 +152,10 @@ export default function Blueprints() { }; const handleCreateBlueprint = () => { - axios(configApiCall(api_path_blueprints+"?groupName="+blueprintName+"&username=admin&policyData="+blueprintName, 'POST', null, null)).then((response)=>{ + + axios(configApiCall(api_path_blueprints+"?name="+blueprintName+"&policyData=", 'POST', null, null)).then((response)=>{ setOpen(false); - console.log("Successfully create " + blueprintName) + console.log("Successfully created" + blueprintName) }).catch((error) =>{ setOpen(false); console.log("Could not create " + blueprintName + " " + error) @@ -168,7 +169,7 @@ export default function Blueprints() { } const removeBlueprint = () => { - axios(configApiCall(api_path_blueprints+"?groupName="+removedBlueprint, 'DELETE', {"queryString": removedBlueprint}, null)).then((response)=>{ + axios(configApiCall(api_path_blueprints+"?name="+removedBlueprint, 'DELETE', {"queryString": removedBlueprint}, null)).then((response)=>{ console.log("Successfully create " + removedBlueprint) setOpenRemoveDialog(false); }).catch((error) =>{ @@ -190,6 +191,7 @@ export default function Blueprints() { <Button variant="contained" color="info" href="#contained-buttons" onClick={redirectToBlueprints} style={{color: "white"}}> <KeyboardReturnIcon /> return to blueprints </Button> + <h3>{selectedBlueprintName}</h3> <Blueprint blueprintName={selectedBlueprintName}/> </div> ) @@ -287,22 +289,21 @@ export default function Blueprints() { <span>No blueprint found</span> : blueprints.map(blueprint => - <GridItem xs={12} sm={12} md={2} key={blueprint.groupName}> + <GridItem xs={12} sm={12} md={2} key={blueprint.name}> <Card profile> <CardBody profile> - <a href="#" onClick={(e) => redirectToBlueprint(e, blueprint.groupName)}> - - <h3 className={classes.cardTitle}>{blueprint.groupName ? blueprint.groupName : 'No blueprint name'}</h3> + <a href="#" onClick={(e) => redirectToBlueprint(e, blueprint.name)}> + <h3 className={classes.cardTitle}>{blueprint.name ? blueprint.name : 'No blueprint name'}</h3> <strong>Description:</strong> - <p>{blueprint.policyData ? blueprint.policyData : 'No description'}</p> + <p>{'No description'}</p> <ul> <li><GroupIcon fontSize='small' style={{marginRight: "10px"}} /> {blueprint.usersCount ? blueprint.usersCount + ' user(s)' : 'No users count'}</li> </ul> </a> </CardBody> <CardFooter> - <IconButton color="secondary" onClick={ () => {handleRemoveBlueprint(blueprint.groupName)}}><DeleteOutlineIcon /></IconButton> + <IconButton color="secondary" onClick={ () => {handleRemoveBlueprint(blueprint.name)}}><DeleteOutlineIcon /></IconButton> </CardFooter> </Card> diff --git a/jams-server/src/main/java/net/jami/jams/server/servlets/api/admin/group/PolicyServlet.java b/jams-server/src/main/java/net/jami/jams/server/servlets/api/admin/group/PolicyServlet.java index 6ae76738e5830e196d056f323cc0c3ae1ca638b8..c854f9fea021150f1a559ff2699c6a229d2298e0 100644 --- a/jams-server/src/main/java/net/jami/jams/server/servlets/api/admin/group/PolicyServlet.java +++ b/jams-server/src/main/java/net/jami/jams/server/servlets/api/admin/group/PolicyServlet.java @@ -10,11 +10,11 @@ import net.jami.jams.common.annotations.ScopedServletMethod; import net.jami.jams.common.dao.StatementElement; import net.jami.jams.common.dao.StatementList; import net.jami.jams.common.objects.user.*; +import org.json.JSONObject; import java.io.IOException; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; +import java.util.Scanner; import static net.jami.jams.server.Server.dataStore; @@ -28,11 +28,11 @@ public class PolicyServlet extends HttpServlet { List<Policy> policies; - Policy singlePolicy; + String name = req.getParameter("name"); - if (!req.getParameter("groupName").equals("*")) { + if (!name.equals("*")) { StatementList statementList = new StatementList(); - StatementElement st = new StatementElement("groupName", "=", req.getParameter("groupName"), ""); + StatementElement st = new StatementElement("name", "=", name, ""); statementList.addStatement(st); resp.getOutputStream().write(JsonStream.serialize(dataStore.getPolicyDao().getObjects(statementList).get(0)).getBytes()); resp.setStatus(200); @@ -46,15 +46,20 @@ public class PolicyServlet extends HttpServlet { @Override @ScopedServletMethod(securityGroups = {AccessLevel.ADMIN}) protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException { + String name = req.getParameter("name"); + + Scanner s = new Scanner(req.getInputStream()).useDelimiter("\\A"); + String result = s.hasNext() ? s.next() : ""; + final JSONObject obj = new JSONObject(result); + final String jsonString = obj.toString(); + StatementList update = new StatementList(); - StatementElement st0 = new StatementElement("groupName", "=", req.getParameter("groupName"), ""); + StatementElement st0 = new StatementElement("name", "=", name, ""); update.addStatement(st0); - StatementElement st1 = new StatementElement("username", "=", req.getParameter("username"), ""); - update.addStatement(st1); - StatementElement st2 = new StatementElement("policyData", "=", req.getParameter("policyData"), ""); + StatementElement st2 = new StatementElement("policyData", "=", jsonString, ""); update.addStatement(st2); StatementList constraint = new StatementList(); - StatementElement st3 = new StatementElement("groupName", "=", req.getParameter("groupName"), ""); + StatementElement st3 = new StatementElement("name", "=", name, ""); constraint.addStatement(st3); if (dataStore.getPolicyDao().updateObject(update, constraint)) resp.setStatus(200); else resp.sendError(500, "could not update the group's name!"); @@ -63,9 +68,9 @@ public class PolicyServlet extends HttpServlet { @Override @ScopedServletMethod(securityGroups = {AccessLevel.ADMIN}) protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + String name = req.getParameter("name"); Policy policy = new Policy(); - policy.setGroupName(req.getParameter("groupName")); - policy.setUsername(req.getParameter("username")); + policy.setName(name); policy.setPolicyData(req.getParameter("policyData")); if (dataStore.getPolicyDao().storeObject(policy)) resp.setStatus(200); else resp.sendError(500, "Could not create a group successfully!"); @@ -74,7 +79,9 @@ public class PolicyServlet extends HttpServlet { @Override @ScopedServletMethod(securityGroups = {AccessLevel.ADMIN}) protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException { - StatementElement statementElement = new StatementElement("groupName", "=", req.getParameter("groupName"), ""); + String name = req.getParameter("name"); + + StatementElement statementElement = new StatementElement("name", "=", name, ""); StatementList constraint = new StatementList(); constraint.addStatement(statementElement); if (dataStore.getPolicyDao().deleteObject(constraint))