VerifyTemAccess Middleware
This commit is contained in:
1 parent
95b832c1c6
commit
78a2e5d106
4 files changed
+17
-15
No files matched your search
@@ -8,9 +8,9 @@ import {
|
|||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
deleteChecksByTeamIdParamValidation,
|
deleteChecksByTeamIdParamValidation,
|
||||||
updateChecksTTLBodyValidation,
|
updateChecksTTLBodyValidation,
|
||||||
updateCheckStatusBodyValidation,
|
ackCheckBodyValidation,
|
||||||
updateAllChecksStatusBodyValidation,
|
ackAllChecksParamValidation,
|
||||||
updateCheckStatusParamValidation,
|
ackAllChecksBodyValidation,
|
||||||
} from "../validation/joi.js";
|
} from "../validation/joi.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import { getTokenFromHeaders } from "../utils/utils.js";
|
import { getTokenFromHeaders } from "../utils/utils.js";
|
||||||
@@ -114,7 +114,7 @@ class CheckController {
|
|||||||
|
|
||||||
ackCheck = async (req, res, next) => {
|
ackCheck = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
await updateCheckStatusBodyValidation.validateAsync(req.body);
|
await ackCheckBodyValidation.validateAsync(req.body);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(handleValidationError(error, SERVICE_NAME));
|
next(handleValidationError(error, SERVICE_NAME));
|
||||||
return;
|
return;
|
||||||
@@ -138,8 +138,8 @@ class CheckController {
|
|||||||
|
|
||||||
ackAllChecks = async (req, res, next) => {
|
ackAllChecks = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
await updateCheckStatusParamValidation.validateAsync(req.params);
|
await ackAllChecksParamValidation.validateAsync(req.params);
|
||||||
await updateAllChecksStatusBodyValidation.validateAsync(req.body);
|
await ackAllChecksBodyValidation.validateAsync(req.body);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(handleValidationError(error, SERVICE_NAME));
|
next(handleValidationError(error, SERVICE_NAME));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ const getChecksByMonitor = async ({
|
|||||||
const matchStage = {
|
const matchStage = {
|
||||||
monitorId: ObjectId.createFromHexString(monitorId),
|
monitorId: ObjectId.createFromHexString(monitorId),
|
||||||
...(typeof status !== "undefined" && { status }),
|
...(typeof status !== "undefined" && { status }),
|
||||||
...(typeof ack !== "undefined" && { ack: ack === "true" ? true : false }),
|
...(typeof ack !== "undefined" && { ack: ack === "true" }),
|
||||||
...(dateRangeLookup[dateRange] && {
|
...(dateRangeLookup[dateRange] && {
|
||||||
createdAt: {
|
createdAt: {
|
||||||
$gte: dateRangeLookup[dateRange],
|
$gte: dateRangeLookup[dateRange],
|
||||||
@@ -168,7 +168,7 @@ const getChecksByTeam = async ({
|
|||||||
const matchStage = {
|
const matchStage = {
|
||||||
teamId: ObjectId.createFromHexString(teamId),
|
teamId: ObjectId.createFromHexString(teamId),
|
||||||
status: status,
|
status: status,
|
||||||
...(typeof ack !== "undefined" && { ack: ack === "true" ? true : false }),
|
...(typeof ack !== "undefined" && { ack: ack === "true" }),
|
||||||
...(dateRangeLookup[dateRange] && {
|
...(dateRangeLookup[dateRange] && {
|
||||||
createdAt: {
|
createdAt: {
|
||||||
$gte: dateRangeLookup[dateRange],
|
$gte: dateRangeLookup[dateRange],
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import { verifyOwnership } from "../middleware/verifyOwnership.js";
|
import { verifyOwnership } from "../middleware/verifyOwnership.js";
|
||||||
|
import { verifyTeamAccess } from "../middleware/verifyTeamAccess.js";
|
||||||
import { isAllowed } from "../middleware/isAllowed.js";
|
import { isAllowed } from "../middleware/isAllowed.js";
|
||||||
import Monitor from "../db/models/Monitor.js";
|
import Monitor from "../db/models/Monitor.js";
|
||||||
|
import Check from "../db/models/Check.js";
|
||||||
|
|
||||||
class CheckRoutes {
|
class CheckRoutes {
|
||||||
constructor(checkController) {
|
constructor(checkController) {
|
||||||
@@ -20,7 +22,7 @@ class CheckRoutes {
|
|||||||
|
|
||||||
this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
|
this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
|
||||||
|
|
||||||
this.router.put("/:checkId", this.checkController.ackCheck);
|
this.router.put("/:checkId", verifyTeamAccess(Check, "checkId"), this.checkController.ackCheck);
|
||||||
|
|
||||||
this.router.put("/:path/:monitorId?", this.checkController.ackAllChecks);
|
this.router.put("/:path/:monitorId?", this.checkController.ackAllChecks);
|
||||||
|
|
||||||
|
|||||||
@@ -289,16 +289,16 @@ const createCheckBodyValidation = joi.object({
|
|||||||
message: joi.string().required(),
|
message: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateCheckStatusBodyValidation = joi.object({
|
const ackCheckBodyValidation = joi.object({
|
||||||
ack: joi.boolean(),
|
ack: joi.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateCheckStatusParamValidation = joi.object({
|
const ackAllChecksParamValidation = joi.object({
|
||||||
monitorId: joi.string().optional(),
|
monitorId: joi.string().optional(),
|
||||||
path: joi.string().valid("monitor", "team").required(),
|
path: joi.string().valid("monitor", "team").required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateAllChecksStatusBodyValidation = joi.object({
|
const ackAllChecksBodyValidation = joi.object({
|
||||||
ack: joi.boolean(),
|
ack: joi.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -669,9 +669,9 @@ export {
|
|||||||
getChecksQueryValidation,
|
getChecksQueryValidation,
|
||||||
getTeamChecksParamValidation,
|
getTeamChecksParamValidation,
|
||||||
getTeamChecksQueryValidation,
|
getTeamChecksQueryValidation,
|
||||||
updateCheckStatusBodyValidation,
|
ackCheckBodyValidation,
|
||||||
updateAllChecksStatusBodyValidation,
|
ackAllChecksParamValidation,
|
||||||
updateCheckStatusParamValidation,
|
ackAllChecksBodyValidation,
|
||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
deleteChecksByTeamIdParamValidation,
|
deleteChecksByTeamIdParamValidation,
|
||||||
updateChecksTTLBodyValidation,
|
updateChecksTTLBodyValidation,
|
||||||
|
|||||||
Reference in new issue
Block a user