change file owner

This commit is contained in:
May 2023-06-28 22:08:24 -07:00
parent abedda18e3
commit cfd55d7230
3 changed files with 91 additions and 1 deletions

View file

@ -48,15 +48,67 @@ adminRoutes.post("/reset", parser, (req,res) => {
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 targetAccount = Accounts.getFromUsername(req.body.target)
if (!targetAccount) {
res.status(404)
res.send()
return
}
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
})

View file

@ -34,6 +34,44 @@ export function pwdReset(optPicker) {
optPicker.picker(`${response.status} ${response.statusText}`,[])
}
})
}
})
}
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}`,[])
}
})
}
})

View file

@ -196,7 +196,7 @@
<p>Elevate account to admin</p>
</button>
<button>
<button on:click={() => admOpts.chgOwner(optPicker)}>
<img src="/static/assets/icons/link.svg" alt="change file owner">
<p>Change file owner</p>
</button>