Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added authorization requirements for posting and deleting reports #413

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/src/controllers/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const router = express.Router();
* Get all reports
*/
router.get('/', async (req, res) => {
if (!req.session.passport) return res.status(401).send('Unathenticated');
timobraz marked this conversation as resolved.
Show resolved Hide resolved
if (!req.session.passport.admin) return res.status(403).send('Unauthorized');
const reports = await getDocuments(COLLECTION_NAMES.REPORTS, {}); // get all reports in collection

res.json(reports);
Expand All @@ -34,6 +36,8 @@ router.post('/', async (req, res) => {
*/
router.delete('/', async (req, res) => {
let status;
if (!req.session.passport) return res.status(401).send('Unathenticated');
timobraz marked this conversation as resolved.
Show resolved Hide resolved
if (!req.session.passport.admin) return res.status(403).send('Unauthorized');
if (req.body.id) {
console.log(`Deleting report ${req.body.id}`);
status = await deleteDocument(COLLECTION_NAMES.REPORTS, {
Expand Down
Loading