mirror of
https://github.com/spacedeck/spacedeck-open.git
synced 2025-12-16 09:57:30 +01:00
initial commit.
This commit is contained in:
23
middlewares/team_helpers.js
Normal file
23
middlewares/team_helpers.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
require('../models/schema');
|
||||
var config = require('config');
|
||||
|
||||
module.exports = (req, res, next) => {
|
||||
if (req.user) {
|
||||
var isAdmin = req.user.team.admins.indexOf(req.user._id) >= 0;
|
||||
var correctMethod = req.method == "GET" || (req.method == "DELETE" || req.method == "PUT" || req.method == "POST");
|
||||
|
||||
if (correctMethod && isAdmin) {
|
||||
next();
|
||||
} else {
|
||||
res.status(403, {
|
||||
"error": "not authorized"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.status(403, {
|
||||
"error": "not logged in"
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user