import React, { useState, useEffect } from 'react';
import { makeStyles } from '@material-ui/styles';
import { useTheme } from '@material-ui/core/styles';
import {Link} from 'react-router-dom';
import {Paper, Card, Tooltip, FormControlLabel, Typography, Switch, Select, MenuItem, Divider, TextField, Button, Tabs, Tab, Grid, List, ListItem, ListItemText, ListItemAvatar, ListItemSecondaryAction, IconButton, Avatar, Zoom, Dialog, DialogTitle, DialogActions, DialogContent, CircularProgress } from '@material-ui/core';
import {Edit as EditIcon, FileCopy as FileCopyIcon, Publish as PublishIcon, SelectAll as SelectAllIcon, OpenInNew as OpenInNewIcon, CloudDownload as CloudDownloadIcon, Description as DescriptionIcon, Polymer as PolymerIcon, CheckCircle as CheckCircleIcon, Close as CloseIcon, Apps as AppsIcon, Image as ImageIcon, Delete as DeleteIcon, Cached as CachedIcon, AccessibilityNew as AccessibilityNewIcon, Lock as LockIcon, Eco as EcoIcon, Schedule as ScheduleIcon, Cloud as CloudIcon, Business as BusinessIcon} from '@material-ui/icons';
import { useAlert } from "react-alert";
import Dropzone from '../components/Dropzone';
import HandlePayment from './HandlePayment'
import OrgHeader from '../components/OrgHeader'
const useStyles = makeStyles({
notchedOutline: {
borderColor: "#f85a3e !important"
},
})
const Admin = (props) => {
const { globalUrl, userdata } = props;
var upload = ""
var to_be_copied = ""
const theme = useTheme();
const classes = useStyles();
const [firstRequest, setFirstRequest] = React.useState(true);
const [orgRequest, setOrgRequest] = React.useState(true);
const [modalUser, setModalUser] = React.useState({});
const [orgName, setOrgName] = React.useState("")
const [modalOpen, setModalOpen] = React.useState(false);
const [cloudSyncModalOpen, setCloudSyncModalOpen] = React.useState(false);
const [cloudSyncApikey, setCloudSyncApikey] = React.useState("");
const [loading, setLoading] = React.useState(false);
const [selectedOrganization, setSelectedOrganization] = React.useState({});
const [organizationFeatures, setOrganizationFeatures] = React.useState({});
const [loginInfo, setLoginInfo] = React.useState("");
const [curTab, setCurTab] = React.useState(0);
const [users, setUsers] = React.useState([]);
const [organizations, setOrganizations] = React.useState([]);
const [orgSyncResponse, setOrgSyncResponse] = React.useState("");
const [userSettings, setUserSettings] = React.useState({});
const [environments, setEnvironments] = React.useState([]);
const [authentication, setAuthentication] = React.useState([]);
const [schedules, setSchedules] = React.useState([])
const [files, setFiles] = React.useState([])
const [selectedUser, setSelectedUser] = React.useState({})
const [newPassword, setNewPassword] = React.useState("");
const [selectedUserModalOpen, setSelectedUserModalOpen] = React.useState(false)
const [selectedAuthentication, setSelectedAuthentication] = React.useState({})
const [selectedAuthenticationModalOpen, setSelectedAuthenticationModalOpen] = React.useState(false)
const [authenticationFields, setAuthenticationFields] = React.useState([])
const [showArchived, setShowArchived] = React.useState(false)
const [isDropzone, setIsDropzone] = React.useState(false);
useEffect(() => {
if (isDropzone) {
//redirectOpenApi();
setIsDropzone(false);
}
}, [isDropzone]);
const isCloud = window.location.host === "localhost:3002" || window.location.host === "shuffler.io"
const getApps = () => {
fetch(globalUrl+"/api/v1/apps", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
}
return response.json()
})
.then((responseJson) => {
console.log("apps: ", responseJson)
//setApps(responseJson)
//setFilteredApps(responseJson)
//if (responseJson.length > 0) {
// setSelectedApp(responseJson[0])
// if (responseJson[0].actions !== null && responseJson[0].actions.length > 0) {
// setSelectedAction(responseJson[0].actions[0])
// } else {
// setSelectedAction({})
// }
//}
})
.catch(error => {
alert.error(error.toString())
});
}
const categories = [
{
"name": "Ticketing",
"apps": [
"TheHive",
"Service-Now",
"SecureWorks",
],
"categories": ["tickets", "ticket", "ticketing"]
},
]
/*
"SIEM",
"Active Directory",
"Firewalls",
"Proxies web",
"SIEM",
"SOAR",
"Mail",
"EDR",
"AV",
"MDM/MAM",
"DNS",
"Ticketing platform",
"TIP",
"Communication",
"DDOS protection",
"VMS",
]
*/
const alert = useAlert()
const deleteAuthentication = (data) => {
alert.info("Deleting auth " + data.label)
// Just use this one?
const url = globalUrl + '/api/v1/apps/authentication/' + data.id
console.log("URL: ", url)
fetch(url, {
method: 'DELETE',
credentials: "include",
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
console.log("RESP: ", responseJson)
if (responseJson["success"] === false) {
alert.error("Failed deleting auth")
} else {
// Need to wait because query in ES is too fast
setTimeout(() => {
getAppAuthentication()
}, 1000)
alert.success("Successfully deleted authentication!")
}
}),
)
.catch(error => {
console.log("Error in userdata: ", error)
});
}
const deleteSchedule = (data) => {
// FIXME - add some check here ROFL
console.log("INPUT: ", data)
// Just use this one?
const url = globalUrl + '/api/v1/workflows/' + data["workflow_id"] + "/schedule/" + data.id
console.log("URL: ", url)
fetch(url, {
method: 'DELETE',
credentials: "include",
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
console.log("RESP: ", responseJson)
if (responseJson["success"] === false) {
alert.error("Failed stopping schedule")
} else {
setTimeout(() => {
getSchedules()
}, 1500)
alert.success("Successfully stopped schedule!")
}
}),
)
.catch(error => {
console.log("Error in userdata: ", error)
});
}
const handleStopOrgSync = (org_id) => {
if (org_id === undefined || org_id === null) {
alert.error("Couldn't get org "+org_id)
return
}
const data = {}
const url = globalUrl + '/api/v1/orgs/' + org_id + "/stop_sync";
fetch(url, {
mode: 'cors',
method: 'POST',
body: JSON.stringify(data),
credentials: 'include',
crossDomain: true,
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
})
.then(response => {
if (response.status === 200) {
console.log("Cloud sync success?")
alert.success("Successfully stopped cloud sync")
} else {
console.log("Cloud sync fail?")
alert.error("Failed stopping sync. Try again, and contact support if this persists.")
}
return response.json()
})
.then((responseJson) => {
setTimeout(() => {
handleGetOrg(org_id)
}, 1000)
})
.catch(error => {
alert.error("Err: " + error.toString())
})
}
const enableCloudSync = (apikey, organization, disableSync) => {
setOrgSyncResponse("")
const data = {
apikey: apikey,
organization: organization,
disable: disableSync,
}
const url = globalUrl + '/api/v1/cloud/setup';
fetch(url, {
mode: 'cors',
method: 'POST',
body: JSON.stringify(data),
credentials: 'include',
crossDomain: true,
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
})
.then(response => {
setLoading(false)
if (response.status === 200) {
console.log("Cloud sync success?")
} else {
console.log("Cloud sync fail?")
}
return response.json()
//setTimeout(() => {
//}, 1000)
})
.then((responseJson) => {
console.log("RESP: ", responseJson)
if (responseJson.success === false && responseJson.reason !== undefined) {
setOrgSyncResponse(responseJson.reason)
alert.error("Failed to handle sync: "+responseJson.reason)
} else if (!responseJson.success) {
alert.error("Failed to handle sync.")
} else {
getOrgs()
if (disableSync) {
alert.success("Successfully disabled sync!")
setOrgSyncResponse("Successfully disabled syncronization")
} else {
alert.success("Cloud Syncronization successfully set up!")
setOrgSyncResponse("Successfully started syncronization. Cloud features you now have access to can be seen below.")
}
selectedOrganization.cloud_sync = !selectedOrganization.cloud_sync
setSelectedOrganization(selectedOrganization)
setCloudSyncApikey("")
handleGetOrg(userdata.active_org.id)
}
})
.catch(error => {
setLoading(false)
alert.error("Err: " + error.toString())
})
}
const saveAuthentication = (authentication) => {
const data = authentication
const url = globalUrl + '/api/v1/apps/authentication';
fetch(url, {
mode: 'cors',
method: 'PUT',
body: JSON.stringify(data),
credentials: 'include',
crossDomain: true,
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
alert.error("Failed changing authentication")
} else {
//alert.success("Successfully password!")
setSelectedUserModalOpen(false)
getAppAuthentication()
}
}),
)
.catch(error => {
alert.error("Err: " + error.toString())
});
}
const editAuthenticationConfig = (id) => {
const data = {
"id": id,
"action": "assign_everywhere",
}
const url = globalUrl + '/api/v1/apps/authentication/'+id+"/config";
fetch(url, {
mode: 'cors',
method: 'POST',
body: JSON.stringify(data),
credentials: 'include',
crossDomain: true,
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
alert.error("Failed overwriting appauth in workflows")
} else {
alert.success("Successfully updated auth everywhere!")
setSelectedUserModalOpen(false)
setTimeout(() => {
getAppAuthentication()
}, 1000)
}
}),
)
.catch(error => {
alert.error("Err: " + error.toString())
});
}
const createSubOrg = (currentOrgId, name) => {
const data = { "name": name, "org_id": currentOrgId}
console.log(data)
const url = globalUrl + `/api/v1/orgs/${currentOrgId}/create_sub_org`
fetch(url, {
mode: 'cors',
method: 'POST',
body: JSON.stringify(data),
credentials: 'include',
crossDomain: true,
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
if (responseJson.reason !== undefined) {
alert.error(responseJson.reason)
} else {
alert.error("Failed creating suborg")
}
} else {
alert.success("Successfully created suborg!")
setSelectedUserModalOpen(false)
}
setOrgName("")
setModalOpen(false)
}),
)
.catch(error => {
alert.error("Err: " + error.toString())
});
}
const onPasswordChange = () => {
const data = { "username": selectedUser.username, "newpassword": newPassword }
const url = globalUrl + '/api/v1/users/passwordchange';
fetch(url, {
mode: 'cors',
method: 'POST',
body: JSON.stringify(data),
credentials: 'include',
crossDomain: true,
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
if (responseJson.reason !== undefined) {
alert.error(responseJson.reason)
} else {
alert.error("Failed setting new password")
}
} else {
alert.success("Successfully updated password!")
setSelectedUserModalOpen(false)
}
}),
)
.catch(error => {
alert.error("Err: " + error.toString())
});
}
const deleteUser = (data) => {
// Just use this one?
const userId = data.id
const url = globalUrl + '/api/v1/users/' + userId
fetch(url, {
method: 'DELETE',
credentials: "include",
headers: {
'Content-Type': 'application/json',
},
})
.then(response => {
if (response.status === 200) {
getUsers()
}
return response.json()
})
.then((responseJson) => {
if (!responseJson.success && responseJson.reason !== undefined) {
alert.error("Failed to deactivate user: "+responseJson.reason)
} else {
alert.success("Deactivated user "+data.id)
}
})
.catch(error => {
console.log("Error in userdata: ", error)
});
}
const handleGetOrg = (orgId) => {
if (orgId.length === 0) {
alert.error("Organization ID not defined. Please contact us on https://shuffler.io if this persists logout.")
return
}
// Just use this one?
var baseurl = globalUrl
const url = baseurl + '/api/v1/orgs/'+orgId
fetch(url, {
method: 'GET',
credentials: "include",
headers: {
'Content-Type': 'application/json',
},
})
.then(response => {
if (response.status === 401) {
}
return response.json()
})
.then(responseJson => {
if (responseJson["success"] === false) {
alert.error("Failed getting org: ", responseJson.readon)
} else {
if (responseJson.sync_features === undefined || responseJson.sync_features === null) {
responseJson.sync_features = {}
}
setSelectedOrganization(responseJson)
var lists = {
"active": {
"triggers": [],
"features": [],
"sync": [],
},
"inactive": {
"triggers": [],
"features": [],
"sync": [],
},
}
// FIXME: Set up features
//Object.keys(responseJson.sync_features).map(function(key, index) {
// //console.log(responseJson.sync_features[key])
//})
//setOrgName(responseJson.name)
//setOrgDescription(responseJson.description)
setOrganizationFeatures(lists)
}
})
.catch(error => {
console.log("Error getting org: ", error)
alert.error("Error getting current organization")
});
}
const inviteUser = (data) => {
console.log("INPUT: ", data)
setLoginInfo("")
// Just use this one?
var data = { "username": data.Username, "type": "invite", "org_id": selectedOrganization.id}
var baseurl = globalUrl
const url = baseurl + '/api/v1/users/register_org';
fetch(url, {
method: 'POST',
credentials: "include",
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
setLoginInfo("Error: " + responseJson.reason)
} else {
setLoginInfo("")
setModalOpen(false)
setTimeout(() => {
getUsers()
}, 1000)
}
}),
)
.catch(error => {
console.log("Error in userdata: ", error)
});
}
const submitUser = (data) => {
console.log("INPUT: ", data)
setLoginInfo("")
// Just use this one?
var data = { "username": data.Username, "password": data.Password }
var baseurl = globalUrl
const url = baseurl + '/api/v1/users/register';
fetch(url, {
method: 'POST',
credentials: "include",
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
setLoginInfo("Error: " + responseJson.reason)
} else {
setLoginInfo("")
setModalOpen(false)
setTimeout(() => {
getUsers()
}, 1000)
}
}),
)
.catch(error => {
console.log("Error in userdata: ", error)
});
}
// Horrible frontend fix for environments
const setDefaultEnvironment = (environment) => {
// FIXME - add more checks to this
alert.info("Setting default env to " + environment.name)
var newEnv = []
for (var key in environments) {
if (environments[key].id == environment.id) {
if (environments[key].archived) {
alert.error("Can't set archived to default")
return
}
environments[key].default = true
} else if (environments[key].default == true && environments[key].id !== environment.id) {
environments[key].default = false
}
newEnv.push(environments[key])
}
// Just use this one?
const url = globalUrl + '/api/v1/setenvironments';
fetch(url, {
method: 'PUT',
credentials: "include",
body: JSON.stringify(newEnv),
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
alert.error(responseJson.reason)
setTimeout(() => {
getEnvironments()
}, 1500)
} else {
setLoginInfo("")
setModalOpen(false)
setTimeout(() => {
getEnvironments()
}, 1500)
}
}),
)
.catch(error => {
console.log("Error in backend data: ", error)
})
}
const flushQueue = (name) => {
// Just use this one?
const url = globalUrl + '/api/v1/flush_queue';
fetch(url, {
method: 'DELETE',
credentials: "include",
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
alert.error(responseJson.reason)
getEnvironments()
} else {
setLoginInfo("")
setModalOpen(false)
getEnvironments()
}
}),
)
.catch(error => {
console.log("Error when deleting: ", error)
})
}
const deleteEnvironment = (environment) => {
// FIXME - add some check here ROFL
//const name = environment.name
//alert.info("Modifying environment " + name)
//var newEnv = []
//for (var key in environments) {
// if (environments[key].Name == name) {
// if (environments[key].default) {
// alert.error("Can't modify the default environment")
// return
// }
// if (environments[key].type === "cloud" && !environments[key].archived) {
// alert.error("Can't modify cloud environments")
// return
// }
// environments[key].archived = !environments[key].archived
// }
// newEnv.push(environments[key])
//}
const id = environment.id
//alert.info("Modifying environment " + environment.Name)
var newEnv = []
for (var key in environments) {
if (environments[key].id == id) {
if (environments[key].default) {
alert.error("Can't modify the default environment")
return
}
if (environments[key].type === "cloud" && !environments[key].archived) {
alert.error("Can't modify cloud environments")
return
}
environments[key].archived = !environments[key].archived
}
newEnv.push(environments[key])
}
// Just use this one?
const url = globalUrl + '/api/v1/setenvironments';
fetch(url, {
method: 'PUT',
credentials: "include",
body: JSON.stringify(newEnv),
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
alert.error(responseJson.reason)
getEnvironments()
} else {
setLoginInfo("")
setModalOpen(false)
getEnvironments()
}
}),
)
.catch(error => {
console.log("Error when deleting: ", error)
})
}
const submitEnvironment = (data) => {
// FIXME - add some check here ROFL
environments.push({
"name": data.environment,
"type": "onprem",
})
// Just use this one?
var baseurl = globalUrl
const url = baseurl + '/api/v1/setenvironments';
fetch(url, {
method: 'PUT',
credentials: "include",
body: JSON.stringify(environments),
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
setLoginInfo("Error in input: " + responseJson.reason)
getEnvironments()
} else {
setLoginInfo("")
setModalOpen(false)
getEnvironments()
}
}),
)
.catch(error => {
console.log("Error in userdata: ", error)
});
}
const handleFileUpload = (file_id, file) => {
//console.log("FILE: ", file_id, file)
fetch(`${globalUrl}/api/v1/files/${file_id}/upload`, {
method: 'POST',
credentials: "include",
body: file,
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
return
}
return response.json()
})
.then((responseJson) => {
//console.log("RESPONSE: ", responseJson)
//setFiles(responseJson)
})
.catch(error => {
//alert.error(error.toString())
});
}
const handleCreateFile = (filename, file) => {
const data = {
"filename": filename,
"org_id": selectedOrganization.id,
"workflow_id": "global",
}
fetch(globalUrl + "/api/v1/files/create", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
body: JSON.stringify(data),
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
return
}
return response.json()
})
.then((responseJson) => {
//console.log("RESP: ", responseJson)
if (responseJson.success) {
handleFileUpload(responseJson.id, file)
} else {
alert.error("Failed to upload file ", filename)
}
})
.catch(error => {
alert.error(error.toString())
});
}
const getFiles = () => {
fetch(globalUrl + "/api/v1/files", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
return
}
return response.json()
})
.then((responseJson) => {
//console.log(responseJson)
setFiles(responseJson)
})
.catch(error => {
alert.error(error.toString())
});
}
const downloadFile = (file) => {
fetch(globalUrl + "/api/v1/files/"+file.id+"/content", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
return ""
}
return response.text()
})
.then((respdata) => {
if (respdata.length === 0) {
alert.error("Failed getting file")
return
}
var blob = new Blob( [ respdata ], {
type: 'application/octet-stream'
})
var url = URL.createObjectURL( blob )
var link = document.createElement( 'a' )
link.setAttribute( 'href', url )
link.setAttribute( 'download', `${file.filename}` )
var event = document.createEvent( 'MouseEvents' )
event.initMouseEvent( 'click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null)
link.dispatchEvent( event )
//return response.json()
})
.then((responseJson) => {
//console.log(responseJson)
//setSchedules(responseJson)
})
.catch(error => {
alert.error(error.toString())
});
}
const getSchedules = () => {
fetch(globalUrl + "/api/v1/workflows/schedules", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
return
}
return response.json()
})
.then((responseJson) => {
setSchedules(responseJson)
})
.catch(error => {
alert.error(error.toString())
});
}
const getAppAuthentication = () => {
fetch(globalUrl + "/api/v1/apps/authentication", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
return
}
return response.json()
})
.then((responseJson) => {
if (responseJson.success) {
//console.log(responseJson.data)
//console.log(responseJson)
setAuthentication(responseJson.data)
} else {
alert.error("Failed getting authentications")
}
})
.catch(error => {
alert.error(error.toString())
});
}
const getEnvironments = () => {
fetch(globalUrl + "/api/v1/getenvironments", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
return
}
return response.json()
})
.then((responseJson) => {
setEnvironments(responseJson)
})
.catch(error => {
alert.error(error.toString())
});
}
const getOrgs = () => {
fetch(globalUrl + "/api/v1/orgs", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for apps :O!")
return
}
return response.json()
})
.then((responseJson) => {
setOrganizations(responseJson)
})
.catch(error => {
alert.error(error.toString())
});
}
const getUsers = () => {
fetch(globalUrl + "/api/v1/getusers", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
// Ahh, this happens because they're not admin
// window.location.pathname = "/workflows"
return
}
return response.json()
})
.then((responseJson) => {
setUsers(responseJson)
})
.catch(error => {
alert.error(error.toString())
});
}
const getSettings = () => {
fetch(globalUrl+"/api/v1/getsettings", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 when getting settings :O!")
}
return response.json()
})
.then((responseJson) => {
setUserSettings(responseJson)
})
.catch(error => {
console.log(error)
});
}
const views = {
0: "organization",
1: "users",
2: "app_auth",
3: "files",
4: "schedules",
5: "environments",
6: "categories",
}
const setConfig = (event, newValue) => {
//console.log("Value: ", newValue)
setCurTab(parseInt(newValue))
if (newValue === 1) {
document.title = "Shuffle - admin - users"
getUsers()
} else if (newValue === 2) {
document.title = "Shuffle - admin - app authentication"
getAppAuthentication()
} else if (newValue === 3) {
document.title = "Shuffle - admin - files"
getFiles()
} else if (newValue === 4) {
document.title = "Shuffle - admin - schedules"
getSchedules()
} else if (newValue === 5) {
document.title = "Shuffle - admin - environments"
getEnvironments()
} else if (newValue === 6) {
document.title = "Shuffle - admin - orgs"
getOrgs()
} else {
document.title = "Shuffle - admin"
}
if (newValue === 6) {
console.log("Should get apps for categories.")
}
//var theURL = window.location.pathname
//FIXME: Add url edits
//var theURL = window.location
//theURL.replace(`/${views[curTab]}`, `/${views[newValue]}`)
//window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
//console.log(newpath)
//window.location.pathame = newpath
setModalUser({})
}
if (firstRequest) {
setFirstRequest(false)
document.title = "Shuffle - admin"
if (!isCloud) {
getUsers()
} else {
getSettings()
}
if (props.match.params.key !== undefined) {
//const tmpitem = views[props.match.params.key]
setConfig("", props.match.params.key)
}
}
if (selectedOrganization.id === undefined && userdata !== undefined && userdata.active_org !== undefined && orgRequest) {
setOrgRequest(false)
handleGetOrg(userdata.active_org.id)
}
const paperStyle = {
maxWidth: 1250,
margin: "auto",
color: "white",
backgroundColor: theme.palette.surfaceColor,
marginBottom: 10,
padding: 20,
}
const changeModalData = (field, value) => {
modalUser[field] = value
}
const setUser = (userId, field, value) => {
const data = { "user_id": userId }
data[field] = value
fetch(globalUrl + "/api/v1/users/updateuser", {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(data),
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for WORKFLOW EXECUTION :O!")
} else {
getUsers()
}
return response.json()
})
.then((responseJson) => {
if (!responseJson.success && responseJson.reason !== undefined) {
alert.error("Failed setting user: " + responseJson.reason)
} else {
alert.success("Set the user field " + field + " to " + value)
}
})
.catch(error => {
console.log(error)
});
}
const generateApikey = (user) => {
const userId = user.id
const data = { "user_id": userId }
fetch(globalUrl + "/api/v1/generateapikey", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(data),
credentials: "include",
})
.then((response) => {
if (response.status !== 200) {
console.log("Status not 200 for WORKFLOW EXECUTION :O!")
} else {
getUsers()
}
return response.json()
})
.then((responseJson) => {
console.log("RESP: ", responseJson)
if (!responseJson.success && responseJson.reason !== undefined) {
alert.error("Failed getting new: " + responseJson.reason)
} else {
alert.success("Got new API key")
}
})
.catch(error => {
console.log(error)
});
}
const editAuthenticationModal = selectedAuthenticationModalOpen ?
: null
const editUserModal =
const GridItem = (props) => {
const [expanded, setExpanded] = React.useState(false)
const primary = props.data.primary
const secondary = props.data.secondary
const primaryIcon = props.data.icon
const secondaryIcon = props.data.active ?