Started fixing suborg swapping
This commit is contained in:
@@ -2,7 +2,7 @@ module shuffle
|
|||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
//replace github.com/frikky/shuffle-shared => ../../../../git/shuffle-shared
|
replace github.com/frikky/shuffle-shared => ../../../../git/shuffle-shared
|
||||||
|
|
||||||
//replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi
|
//replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi
|
||||||
|
|
||||||
|
|||||||
+44
-15
@@ -976,39 +976,68 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) {
|
|||||||
}
|
}
|
||||||
err = shuffle.SetUser(ctx, &userInfo, true)
|
err = shuffle.SetUser(ctx, &userInfo, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error patching User for activeOrg: %s", err)
|
log.Printf("[INFO] Error patching User for activeOrg: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Remove this dependency by updating users' orgs when org itself is updated
|
|
||||||
org, err := shuffle.GetOrg(ctx, userInfo.ActiveOrg.Id)
|
org, err := shuffle.GetOrg(ctx, userInfo.ActiveOrg.Id)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userInfo.ActiveOrg = shuffle.OrgMini{
|
userInfo.ActiveOrg = shuffle.OrgMini{
|
||||||
Id: org.Id,
|
Id: org.Id,
|
||||||
Name: org.Name,
|
Name: org.Name,
|
||||||
|
CreatorOrg: org.CreatorOrg,
|
||||||
|
Role: userInfo.ActiveOrg.Role,
|
||||||
|
Image: org.Image,
|
||||||
}
|
}
|
||||||
|
|
||||||
userInfo.ActiveOrg.Users = []shuffle.UserMini{}
|
userInfo.ActiveOrg.Users = []shuffle.UserMini{}
|
||||||
}
|
}
|
||||||
|
|
||||||
userInfo.ActiveOrg.Users = []shuffle.UserMini{}
|
userInfo.ActiveOrg.Users = []shuffle.UserMini{}
|
||||||
currentOrg, err := json.Marshal(userInfo.ActiveOrg)
|
userOrgs := []shuffle.OrgMini{}
|
||||||
|
for _, item := range userInfo.Orgs {
|
||||||
|
if item == userInfo.ActiveOrg.Id {
|
||||||
|
userOrgs = append(userOrgs, userInfo.ActiveOrg)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
org, err := shuffle.GetOrg(ctx, item)
|
||||||
|
if err == nil {
|
||||||
|
userOrgs = append(userOrgs, shuffle.OrgMini{
|
||||||
|
Id: org.Id,
|
||||||
|
Name: org.Name,
|
||||||
|
CreatorOrg: org.CreatorOrg,
|
||||||
|
Image: org.Image,
|
||||||
|
})
|
||||||
|
// Role: "admin",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
returnValue := shuffle.HandleInfo{
|
||||||
|
Success: true,
|
||||||
|
Username: userInfo.Username,
|
||||||
|
Admin: parsedAdmin,
|
||||||
|
Id: userInfo.Id,
|
||||||
|
Orgs: userOrgs,
|
||||||
|
ActiveOrg: userInfo.ActiveOrg,
|
||||||
|
Cookies: []shuffle.SessionCookie{
|
||||||
|
shuffle.SessionCookie{
|
||||||
|
Key: "session_token",
|
||||||
|
Value: userInfo.Session,
|
||||||
|
Expiration: expiration.Unix(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
returnData, err := json.Marshal(returnValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
currentOrg = []byte("{}")
|
log.Printf("[WARNING] Failed marshalling info: %s", err)
|
||||||
|
resp.WriteHeader(401)
|
||||||
|
resp.Write([]byte(`{"success": false}`))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
returnData := fmt.Sprintf(`{
|
|
||||||
"success": true,
|
|
||||||
"username": "%s",
|
|
||||||
"admin": %s,
|
|
||||||
"tutorials": [],
|
|
||||||
"id": "%s",
|
|
||||||
"orgs": [%s],
|
|
||||||
"active_org": %s,
|
|
||||||
"cookies": [{"key": "session_token", "value": "%s", "expiration": %d}]
|
|
||||||
}`, userInfo.Username, parsedAdmin, userInfo.Id, currentOrg, currentOrg, userInfo.Session, expiration.Unix())
|
|
||||||
|
|
||||||
resp.WriteHeader(200)
|
resp.WriteHeader(200)
|
||||||
resp.Write([]byte(returnData))
|
resp.Write([]byte(returnData))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ const App = (message, props) => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(responseJson => {
|
.then(responseJson => {
|
||||||
if (responseJson.success === true) {
|
if (responseJson.success === true) {
|
||||||
//console.log(responseJson.success)
|
console.log(responseJson)
|
||||||
setUserData(responseJson)
|
setUserData(responseJson)
|
||||||
setIsLoggedIn(true)
|
setIsLoggedIn(true)
|
||||||
//console.log("Cookies: ", cookies)
|
//console.log("Cookies: ", cookies)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -29,6 +29,7 @@ const Admin = (props) => {
|
|||||||
const [firstRequest, setFirstRequest] = React.useState(true);
|
const [firstRequest, setFirstRequest] = React.useState(true);
|
||||||
const [orgRequest, setOrgRequest] = React.useState(true);
|
const [orgRequest, setOrgRequest] = React.useState(true);
|
||||||
const [modalUser, setModalUser] = React.useState({});
|
const [modalUser, setModalUser] = React.useState({});
|
||||||
|
const [orgName, setOrgName] = React.useState("")
|
||||||
const [modalOpen, setModalOpen] = React.useState(false);
|
const [modalOpen, setModalOpen] = React.useState(false);
|
||||||
|
|
||||||
const [cloudSyncModalOpen, setCloudSyncModalOpen] = React.useState(false);
|
const [cloudSyncModalOpen, setCloudSyncModalOpen] = React.useState(false);
|
||||||
@@ -367,6 +368,45 @@ const Admin = (props) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 setting new password")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert.success("Successfully updated password!")
|
||||||
|
setSelectedUserModalOpen(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
setOrgName("")
|
||||||
|
setModalOpen(false)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.catch(error => {
|
||||||
|
alert.error("Err: " + error.toString())
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const onPasswordChange = () => {
|
const onPasswordChange = () => {
|
||||||
const data = { "username": selectedUser.username, "newpassword": newPassword }
|
const data = { "username": selectedUser.username, "newpassword": newPassword }
|
||||||
const url = globalUrl + '/api/v1/users/passwordchange';
|
const url = globalUrl + '/api/v1/users/passwordchange';
|
||||||
@@ -1773,14 +1813,20 @@ const Admin = (props) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogTitle><span style={{ color: "white" }}>
|
<DialogTitle><span style={{ color: "white" }}>
|
||||||
{curTab === 1 ? "Add user" : "Add environment"}
|
{curTab === 1 ? "Add user" : curTab === 7 ? "Add Sub-Organization" : "Add environment"}
|
||||||
</span></DialogTitle>
|
</span></DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
{curTab === 1 && isCloud ?
|
{curTab === 1 && isCloud ?
|
||||||
<Typography variant="body1" style={{marginBottom: 10}}>
|
<Typography variant="body1" style={{marginBottom: 10}}>
|
||||||
We'll send an email to invite them to your organization.
|
We'll send an email to invite them to your organization.
|
||||||
</Typography>
|
</Typography>
|
||||||
: null}
|
:
|
||||||
|
curTab === 7 ?
|
||||||
|
<Typography variant="body1" style={{marginBottom: 10}}>
|
||||||
|
The organization created will become a child of your current organization, and be available to you.
|
||||||
|
</Typography>
|
||||||
|
:
|
||||||
|
null }
|
||||||
{curTab === 1 ?
|
{curTab === 1 ?
|
||||||
<div>
|
<div>
|
||||||
Username
|
Username
|
||||||
@@ -1830,6 +1876,31 @@ const Admin = (props) => {
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
: curTab === 7 ?
|
||||||
|
<div>
|
||||||
|
Name
|
||||||
|
<TextField
|
||||||
|
color="primary"
|
||||||
|
style={{ backgroundColor: theme.palette.inputColor }}
|
||||||
|
autoFocus
|
||||||
|
InputProps={{
|
||||||
|
style: {
|
||||||
|
height: "50px",
|
||||||
|
color: "white",
|
||||||
|
fontSize: "1em",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
required
|
||||||
|
fullWidth={true}
|
||||||
|
placeholder={`${selectedOrganization.name} Copycat Inc.`}
|
||||||
|
id="orgname"
|
||||||
|
margin="normal"
|
||||||
|
variant="outlined"
|
||||||
|
onChange={(event) => {
|
||||||
|
setOrgName(event.target.value)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
: curTab === 5 ?
|
: curTab === 5 ?
|
||||||
<div>
|
<div>
|
||||||
Environment Name
|
Environment Name
|
||||||
@@ -1867,6 +1938,8 @@ const Admin = (props) => {
|
|||||||
} else {
|
} else {
|
||||||
submitUser(modalUser)
|
submitUser(modalUser)
|
||||||
}
|
}
|
||||||
|
} else if (curTab === 7) {
|
||||||
|
createSubOrg(selectedOrganization.id, orgName)
|
||||||
} else if (curTab === 5) {
|
} else if (curTab === 5) {
|
||||||
submitEnvironment(modalUser)
|
submitEnvironment(modalUser)
|
||||||
}
|
}
|
||||||
@@ -2334,13 +2407,13 @@ const Admin = (props) => {
|
|||||||
style={{minWidth: 150, maxWidth: 150, overflow: "hidden"}}
|
style={{minWidth: 150, maxWidth: 150, overflow: "hidden"}}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
{categories.map(data => {
|
{categories.map((data, index) => {
|
||||||
if (data.apps.length === 0) {
|
if (data.apps.length === 0) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItem>
|
<ListItem key={index}>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={data.name}
|
primary={data.name}
|
||||||
style={{minWidth: 150, maxWidth: 150}}
|
style={{minWidth: 150, maxWidth: 150}}
|
||||||
@@ -2633,12 +2706,11 @@ const Admin = (props) => {
|
|||||||
style={{}}
|
style={{}}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
disabled
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setModalOpen(true)
|
setModalOpen(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Add organization
|
Add suborganization
|
||||||
</Button>
|
</Button>
|
||||||
<Divider style={{marginTop: 20, marginBottom: 20, backgroundColor: theme.palette.inputColor}}/>
|
<Divider style={{marginTop: 20, marginBottom: 20, backgroundColor: theme.palette.inputColor}}/>
|
||||||
<List>
|
<List>
|
||||||
@@ -2772,13 +2844,13 @@ const Admin = (props) => {
|
|||||||
<div style={{padding: 15}}>
|
<div style={{padding: 15}}>
|
||||||
{organizationView}
|
{organizationView}
|
||||||
{authenticationView}
|
{authenticationView}
|
||||||
{appCategoryView}
|
|
||||||
{usersView}
|
{usersView}
|
||||||
{environmentView}
|
{environmentView}
|
||||||
{schedulesView}
|
{schedulesView}
|
||||||
{filesView}
|
{filesView}
|
||||||
{hybridTab}
|
{hybridTab}
|
||||||
{organizationsTab}
|
{organizationsTab}
|
||||||
|
{appCategoryView}
|
||||||
</div>
|
</div>
|
||||||
</Paper>
|
</Paper>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -932,7 +932,11 @@ const Apps = (props) => {
|
|||||||
console.log("Error in dropzone: ", e)
|
console.log("Error in dropzone: ", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
reader.readAsText(files[0]);
|
reader.readAsText(files[0]);
|
||||||
|
} catch(error) {
|
||||||
|
alert.error("Failed to read file")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user