Skip to content

Commit

Permalink
fix(published): if inactive, check user for authz
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneRifle committed Nov 29, 2023
1 parent 6e7b27b commit 3ec84ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/server/checker/CheckerController.ts
Expand Up @@ -119,10 +119,22 @@ export class CheckerController {
res
) => {
const { id } = req.params
const { user } = req.session
try {
const checker = await this.service.retrievePublished(id)
if (!checker || !checker.isActive) {
if (!checker) {
res.status(404).json({ message: 'Not Found' })
} else if (!checker.isActive) {
if (!user) {
res.status(404).json({ message: 'Not Found' })
} else {
try {
await this.service.findAndCheckAuth(id, user)
res.json(checker)
} catch {
res.status(404).json({ message: 'Not Found' })
}
}
} else {
res.json(checker)
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/checker/CheckerService.ts
Expand Up @@ -201,7 +201,7 @@ export class CheckerService {
}
}

private findAndCheckAuth: (
findAndCheckAuth: (
id: string,
user: User,
transactionOptions?: { transaction?: Transaction }
Expand Down
1 change: 1 addition & 0 deletions src/server/checker/__test__/CheckerController.spec.ts
Expand Up @@ -33,6 +33,7 @@ describe('CheckerController', () => {
listCollaborators: jest.fn(),
addCollaborator: jest.fn(),
deleteCollaborator: jest.fn(),
findAndCheckAuth: jest.fn(),
}
const controller = new CheckerController({ service })

Expand Down

0 comments on commit 3ec84ac

Please sign in to comment.