Skip to content

Commit

Permalink
properly send a 404 error when an user requests an UI view on a scene…
Browse files Browse the repository at this point in the history
… he can't access
  • Loading branch information
sdumetz committed Jan 10, 2024
1 parent 4b37035 commit 62e8662
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions source/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UserManager from "./auth/UserManager.js";
import { BadRequestError, HTTPError } from "./utils/errors.js";
import { mkdir } from "fs/promises";

import {AppLocals, getHost, getUserManager} from "./utils/locals.js";
import {AppLocals, canRead, canWrite, getHost, getUserManager, isUser} from "./utils/locals.js";

import openDatabase from "./vfs/helpers/db.js";
import Vfs from "./vfs/index.js";
Expand Down Expand Up @@ -105,6 +105,8 @@ export default async function createServer(config = defaultConfig) :Promise<expr
res.set("Cache-Control", `max-age=${60*60*24*30*12}, public`);
next();
});

app.use("/ui/scenes/:scene/", canRead);

app.get("/ui/scenes/:scene/view", (req, res)=>{
let {scene} = req.params;
Expand All @@ -122,7 +124,7 @@ export default async function createServer(config = defaultConfig) :Promise<expr
});
});

app.get("/ui/scenes/:scene/edit",(req, res)=>{
app.get("/ui/scenes/:scene/edit", canWrite, (req, res)=>{
let {scene} = req.params;
let {lang} = req.query;
let host = getHost(req);
Expand Down
3 changes: 1 addition & 2 deletions source/server/templates/error.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@
padding: 1ch;
}
</style>

<script src="/js/corpus.js"></script>
<script src="/dist/js/corpus.js"></script>

0 comments on commit 62e8662

Please sign in to comment.