-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add some comments and remove a useless log * add PATCH route on scenes * fix custom events that were not cancellable * add UI to rename scenes
- Loading branch information
Showing
9 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
|
||
import request from "supertest"; | ||
|
||
import Vfs from "../../../../../vfs"; | ||
import UserManager from "../../../../../auth/UserManager"; | ||
|
||
describe("PATCH /api/v1/scenes/:scene", function(){ | ||
let vfs:Vfs, userManager:UserManager, ids :number[]; | ||
this.beforeEach(async function(){ | ||
let locals = await createIntegrationContext(this); | ||
vfs = locals.vfs; | ||
userManager = locals.userManager; | ||
ids = await Promise.all([ | ||
vfs.createScene("foo", {0:"admin"}), | ||
vfs.createScene("bar", {0:"admin"}), | ||
]); | ||
}); | ||
|
||
this.afterEach(async function(){ | ||
await cleanIntegrationContext(this); | ||
}); | ||
|
||
describe("rename a scene", function(){ | ||
it("get scene info", async function(){ | ||
await request(this.server).patch("/api/v1/scenes/foo") | ||
.send({name: "foofoo"}) | ||
.expect(200); | ||
}); | ||
|
||
it("forces unique names", async function(){ | ||
await request(this.server).patch("/api/v1/scenes/foo") | ||
.send({name: "bar"}) | ||
.expect(409); | ||
}) | ||
|
||
it("is admin-protected", async function(){ | ||
await userManager.grant("foo", "any", "write"); | ||
await userManager.grant("foo", "default", "write"); | ||
await request(this.server).patch("/api/v1/scenes/foo") | ||
.send({name: "foofoo"}) | ||
.expect(401); | ||
}); | ||
|
||
it("is access-protected (obfuscated as 404)", async function(){ | ||
await userManager.grant("foo", "default", "none"); | ||
await request(this.server).patch("/api/v1/scenes/foo") | ||
.send({name: "foofoo"}) | ||
.expect(404); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import { ConflictError } from "../../../../../utils/errors"; | ||
import { getUserId, getVfs } from "../../../../../utils/locals"; | ||
import { Request, Response } from "express"; | ||
|
||
|
||
|
||
/** | ||
* Patches a scene's properties | ||
* @param req | ||
* @param res | ||
* @returns {Promise<void>} | ||
*/ | ||
export default async function patchScene(req :Request, res :Response){ | ||
let vfs = getVfs(req); | ||
let user_id = getUserId(req); | ||
let {scene} = req.params; | ||
let {name} = req.body; | ||
//Ensure all or none of the changes are comitted | ||
let result = await getVfs(req).isolate(async (vfs)=>{ | ||
let {id} = await vfs.getScene(scene, user_id); | ||
if(name && name !== scene){ | ||
try{ | ||
await vfs.renameScene(id, name); | ||
}catch(e:any){ | ||
if(e.code == "SQLITE_CONSTRAINT" && /UNIQUE constraint failed: scenes.scene_name/.test(e.message)){ | ||
throw new ConflictError(`A scene named ${name} already exists`); | ||
}else{ | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
return await vfs.getScene(id, user_id); | ||
}); | ||
res.status(200).send(result); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters