Skip to content

Commit

Permalink
expect a 403 error on privs edit modal
Browse files Browse the repository at this point in the history
  • Loading branch information
the-good-boy committed Jul 4, 2023
1 parent 9c5864d commit 5d567d5
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/client/components/pages/parts/privs-edit-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class PrivsEditModal extends React.Component {
},
method: 'POST'
});

if (!response.ok) {
if (response.status === 403) {
throw new Error(response.statusText);
}
const {error} = await response.json();
throw new Error(error ?? response.statusText);
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/helpers/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class NotAuthorizedError extends PathError {
static detailedMessage(req) {
return [
`You do not have permission to access the following path:
${req.path}`,
${req.originalUrl}`,
'Please make sure you have the privileges to access the route!'
];
}
Expand Down
7 changes: 3 additions & 4 deletions src/server/helpers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,10 @@ export function isAuthorized(flag) {
return async (req, res, next) => {
try {
const {Editor} = req.app.locals.orm;
const latestPrivs = await Editor.query({where: {id: req.user.id}})
.fetch({require: true})
.then(editor => editor.get('privs'));
const editor = await Editor.query({where: {id: req.user.id}})
.fetch({require: true});
/* eslint-disable no-bitwise */
if (latestPrivs & flag) {
if (editor.get('privs') & flag) {
return next();
}
throw new error.NotAuthorizedError(
Expand Down
2 changes: 1 addition & 1 deletion test/src/server/routes/entity/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import chaiHttp from 'chai-http';
chai.use(chaiHttp);
const {expect} = chai;

describe('Edition routes', () => {
describe('Edition routes with entity editing priv', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';
let agent;
Expand Down
2 changes: 1 addition & 1 deletion test/src/server/routes/entity/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import chaiHttp from 'chai-http';
chai.use(chaiHttp);
const {expect} = chai;

describe('Publisher routes', () => {
describe('Publisher routes with entity editing priv', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';
let agent;
Expand Down
2 changes: 1 addition & 1 deletion test/src/server/routes/entity/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import chaiHttp from 'chai-http';
chai.use(chaiHttp);
const {expect} = chai;

describe('Series routes', () => {
describe('Series routes with entity editing priv', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';
let agent;
Expand Down
2 changes: 1 addition & 1 deletion test/src/server/routes/entity/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import chaiHttp from 'chai-http';
chai.use(chaiHttp);
const {expect} = chai;

describe('Work routes', () => {
describe('Work routes with entity editing priv', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';
let agent;
Expand Down

0 comments on commit 5d567d5

Please sign in to comment.