mirror of
https://github.com/mollersuite/monofile.git
synced 2024-10-06 20:16:25 -07:00
change file owner
This commit is contained in:
parent
abedda18e3
commit
cfd55d7230
|
@ -48,15 +48,67 @@ adminRoutes.post("/reset", parser, (req,res) => {
|
||||||
if (!acc.admin) return
|
if (!acc.admin) return
|
||||||
if (typeof req.body.target !== "string" || typeof req.body.password !== "string" || !req.body.password) {
|
if (typeof req.body.target !== "string" || typeof req.body.password !== "string" || !req.body.password) {
|
||||||
res.status(404)
|
res.status(404)
|
||||||
|
res.send()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let targetAccount = Accounts.getFromUsername(req.body.target)
|
let targetAccount = Accounts.getFromUsername(req.body.target)
|
||||||
if (!targetAccount) {
|
if (!targetAccount) {
|
||||||
res.status(404)
|
res.status(404)
|
||||||
|
res.send()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Accounts.password.set ( targetAccount.id, req.body.password )
|
Accounts.password.set ( targetAccount.id, req.body.password )
|
||||||
|
res.send()
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
adminRoutes.post("/transfer", parser, (req,res) => {
|
||||||
|
|
||||||
|
if (!auth.validate(req.cookies.auth)) {
|
||||||
|
ServeError(res, 401, "not logged in")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let acc = Accounts.getFromToken(req.cookies.auth) as Accounts.Account
|
||||||
|
|
||||||
|
if (!acc) return
|
||||||
|
if (!acc.admin) return
|
||||||
|
if (typeof req.body.target !== "string" || typeof req.body.password !== "string" || !req.body.password) {
|
||||||
|
res.status(404)
|
||||||
|
res.send()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let targetFile = files.getFilePointer(req.body.target)
|
||||||
|
if (!targetFile) {
|
||||||
|
res.status(404)
|
||||||
|
res.send()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let newOwner = Accounts.getFromUsername(req.body.owner || "")
|
||||||
|
|
||||||
|
// clear old owner
|
||||||
|
|
||||||
|
if (targetFile.owner) {
|
||||||
|
let oldOwner = Accounts.getFromId(targetFile.owner)
|
||||||
|
if (oldOwner) {
|
||||||
|
Accounts.files.deindex(oldOwner.id, req.body.target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newOwner) {
|
||||||
|
Accounts.files.index(newOwner.id, req.body.target)
|
||||||
|
}
|
||||||
|
targetFile.owner = newOwner ? newOwner.id : undefined;
|
||||||
|
|
||||||
|
files.writeFile(req.body.target, targetFile).then(() => {
|
||||||
|
res.send()
|
||||||
|
}).catch(() => {
|
||||||
|
res.status(500)
|
||||||
|
res.send()
|
||||||
|
}) // wasting a reassignment but whatee
|
||||||
|
|
||||||
})
|
})
|
|
@ -38,3 +38,41 @@ export function pwdReset(optPicker) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function chgOwner(optPicker) {
|
||||||
|
optPicker.picker("Transfer file ownership",[
|
||||||
|
{
|
||||||
|
name: "File ID",
|
||||||
|
icon: "/static/assets/icons/file.svg",
|
||||||
|
id: "file",
|
||||||
|
inputSettings: {
|
||||||
|
password: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "New owner",
|
||||||
|
icon: "/static/assets/icons/person.svg",
|
||||||
|
id: "owner",
|
||||||
|
inputSettings: {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Transfer file ownership",
|
||||||
|
icon: "/static/assets/icons/update.svg",
|
||||||
|
description: "This will transfer the file to this user",
|
||||||
|
id: true
|
||||||
|
}
|
||||||
|
]).then((exp) => {
|
||||||
|
if (exp && exp.selected) {
|
||||||
|
fetch(`/admin/transfer`,{method:"POST", body:JSON.stringify({
|
||||||
|
owner: exp.owner,
|
||||||
|
target: exp.file
|
||||||
|
})}).then((response) => {
|
||||||
|
|
||||||
|
if (response.status != 200) {
|
||||||
|
optPicker.picker(`${response.status} ${response.statusText}`,[])
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
|
@ -196,7 +196,7 @@
|
||||||
<p>Elevate account to admin</p>
|
<p>Elevate account to admin</p>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button>
|
<button on:click={() => admOpts.chgOwner(optPicker)}>
|
||||||
<img src="/static/assets/icons/link.svg" alt="change file owner">
|
<img src="/static/assets/icons/link.svg" alt="change file owner">
|
||||||
<p>Change file owner</p>
|
<p>Change file owner</p>
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in a new issue