remove verify team access

This commit is contained in:
Alex Holliday committed 2026-01-15 18:33:03 +00:00
1 parent 75bcf9df58
commit 74a7f0a701
4 files changed
+8 -77

No files matched your search

@@ -26,7 +26,7 @@ export interface IMonitorsRepository {
findByTeamId(teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null>; findByTeamId(teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null>;
// update // update
updateById(monitorId: string, updates: Partial<Monitor>): Promise<Monitor>; updateById(monitorId: string, teamId: string, updates: Partial<Monitor>): Promise<Monitor>;
togglePauseById(monitorId: string, teamId: string): Promise<Monitor>; togglePauseById(monitorId: string, teamId: string): Promise<Monitor>;
// delete // delete
deleteById(monitorId: string, teamId: string): Promise<Monitor>; deleteById(monitorId: string, teamId: string): Promise<Monitor>;
@@ -96,9 +96,9 @@ class MongoMonitorsRepository implements IMonitorsRepository {
return count; return count;
}; };
updateById = async (monitorId: string, patch: Partial<Monitor>) => { updateById = async (monitorId: string, teamId: string, patch: Partial<Monitor>) => {
const updatedMonitor = await MonitorModel.findOneAndUpdate( const updatedMonitor = await MonitorModel.findOneAndUpdate(
{ _id: monitorId }, { _id: monitorId, teamId },
{ {
$set: { $set: {
...patch, ...patch,
+3 -72
View File
@@ -14,7 +14,6 @@ type DateRangeKey = "recent" | "day" | "week" | "month" | "all";
export interface IMonitorService { export interface IMonitorService {
readonly serviceName: string; readonly serviceName: string;
verifyTeamAccess(args: { teamId: string; monitorId: string }): Promise<void>;
// create // create
createMonitor(teamId: string, userId: string, body: Monitor): Promise<void>; createMonitor(teamId: string, userId: string, body: Monitor): Promise<void>;
@@ -60,7 +59,6 @@ export interface IMonitorService {
// other // other
sendTestEmail(args: { to: string }): Promise<string>; sendTestEmail(args: { to: string }): Promise<string>;
exportMonitorsToCSV(args: { teamId: string }): Promise<string>;
exportMonitorsToJSON(args: { teamId: string }): Promise<any[]>; exportMonitorsToJSON(args: { teamId: string }): Promise<any[]>;
} }
@@ -146,13 +144,6 @@ export class MonitorService implements IMonitorService {
return formatLookup[dateRange]; return formatLookup[dateRange];
}; };
verifyTeamAccess = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<void> => {
const monitor = await this.db.monitorModule.getMonitorById(monitorId);
if (!monitor?.teamId?.equals(teamId)) {
throw this.errorService.createAuthorizationError();
}
};
createMonitor = async (teamId: string, userId: string, body: Monitor): Promise<void> => { createMonitor = async (teamId: string, userId: string, body: Monitor): Promise<void> => {
const monitor = await this.monitorsRepository.create(body, teamId, userId); const monitor = await this.monitorsRepository.create(body, teamId, userId);
if (!monitor) { if (!monitor) {
@@ -255,8 +246,6 @@ export class MonitorService implements IMonitorService {
dateRange: string; dateRange: string;
normalize?: boolean; normalize?: boolean;
}): Promise<any> => { }): Promise<any> => {
await this.verifyTeamAccess({ teamId, monitorId });
const monitor = await this.monitorsRepository.findById(monitorId, teamId); const monitor = await this.monitorsRepository.findById(monitorId, teamId);
if (!monitor) { if (!monitor) {
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 }); throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
@@ -292,7 +281,6 @@ export class MonitorService implements IMonitorService {
}; };
getHardwareDetailsById = async ({ teamId, monitorId, dateRange }: { teamId: string; monitorId: string; dateRange: string }): Promise<any> => { getHardwareDetailsById = async ({ teamId, monitorId, dateRange }: { teamId: string; monitorId: string; dateRange: string }): Promise<any> => {
await this.verifyTeamAccess({ teamId, monitorId });
const monitor = await this.monitorsRepository.findById(monitorId, teamId); const monitor = await this.monitorsRepository.findById(monitorId, teamId);
if (!monitor) { if (!monitor) {
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 }); throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
@@ -324,7 +312,6 @@ export class MonitorService implements IMonitorService {
}; };
getPageSpeedDetailsById = async ({ teamId, monitorId, dateRange }: { teamId: string; monitorId: string; dateRange: string }): Promise<any> => { getPageSpeedDetailsById = async ({ teamId, monitorId, dateRange }: { teamId: string; monitorId: string; dateRange: string }): Promise<any> => {
await this.verifyTeamAccess({ teamId, monitorId });
const monitor = await this.monitorsRepository.findById(monitorId, teamId); const monitor = await this.monitorsRepository.findById(monitorId, teamId);
if (!monitor) { if (!monitor) {
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 }); throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
@@ -348,7 +335,6 @@ export class MonitorService implements IMonitorService {
}; };
}; };
getMonitorById = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<any> => { getMonitorById = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<any> => {
await this.verifyTeamAccess({ teamId, monitorId });
const monitor = await this.monitorsRepository.findById(monitorId, teamId); const monitor = await this.monitorsRepository.findById(monitorId, teamId);
return monitor; return monitor;
}; };
@@ -429,21 +415,18 @@ export class MonitorService implements IMonitorService {
}; };
editMonitor = async ({ teamId, monitorId, body }: { teamId: string; monitorId: string; body: Monitor }) => { editMonitor = async ({ teamId, monitorId, body }: { teamId: string; monitorId: string; body: Monitor }) => {
await this.verifyTeamAccess({ teamId, monitorId }); const editedMonitor = await this.monitorsRepository.updateById(monitorId, teamId, body);
const editedMonitor = await this.monitorsRepository.updateById(monitorId, body);
await this.jobQueue.updateJob(editedMonitor); await this.jobQueue.updateJob(editedMonitor);
return editedMonitor; return editedMonitor;
}; };
pauseMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => { pauseMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => {
await this.verifyTeamAccess({ teamId, monitorId });
const monitor = await this.monitorsRepository.togglePauseById(monitorId, teamId); const monitor = await this.monitorsRepository.togglePauseById(monitorId, teamId);
monitor.isActive === true ? await this.jobQueue.resumeJob(monitor) : await this.jobQueue.pauseJob(monitor); monitor.isActive === true ? await this.jobQueue.resumeJob(monitor) : await this.jobQueue.pauseJob(monitor);
return monitor; return monitor;
}; };
deleteMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => { deleteMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => {
await this.verifyTeamAccess({ teamId, monitorId });
const monitor = await this.monitorsRepository.deleteById(monitorId, teamId); const monitor = await this.monitorsRepository.deleteById(monitorId, teamId);
await this.jobQueue.deleteJob(monitor); await this.jobQueue.deleteJob(monitor);
await this.db.statusPageModule.deleteStatusPagesByMonitorId(monitor.id); await this.db.statusPageModule.deleteStatusPagesByMonitorId(monitor.id);
@@ -486,65 +469,13 @@ export class MonitorService implements IMonitorService {
return messageId; return messageId;
}; };
exportMonitorsToCSV = async ({ teamId }: { teamId: string }): Promise<string> => {
const monitors = await this.db.monitorModule.getMonitorsByTeamId({ teamId });
if (!monitors || monitors.length === 0) {
throw this.errorService.createNotFoundError("No monitors to export");
}
const csvData = monitors?.filteredMonitors?.map((monitor: any) => ({
name: monitor.name,
description: monitor.description,
type: monitor.type,
url: monitor.url,
interval: monitor.interval,
port: monitor.port,
ignoreTlsErrors: monitor.ignoreTlsErrors,
isActive: monitor.isActive,
}));
const csv = this.papaparse.unparse(csvData);
return csv;
};
exportMonitorsToJSON = async ({ teamId }: { teamId: string }): Promise<any[]> => { exportMonitorsToJSON = async ({ teamId }: { teamId: string }): Promise<any[]> => {
const monitors = await this.db.monitorModule.getMonitorsByTeamId({ teamId }); const monitors = await this.monitorsRepository.findByTeamId(teamId, {});
if (!monitors || monitors.length === 0) { if (!monitors || monitors.length === 0) {
throw this.errorService.createNotFoundError("No monitors to export"); throw this.errorService.createNotFoundError("No monitors to export");
} }
const json = monitors?.filteredMonitors return monitors;
?.map((monitor: any) => {
const initialType = monitor.type;
let parsedType;
if (initialType === "hardware") {
parsedType = "infrastructure";
} else if (initialType === "http") {
if (monitor.url.startsWith("https://")) {
parsedType = "https";
} else {
parsedType = "http";
}
} else if (initialType === "pagespeed") {
parsedType = initialType;
} else {
// Skip unsupported types
return;
}
return {
name: monitor.name,
url: monitor.url,
type: parsedType,
interval: monitor.interval,
n: monitor.statusWindowSize,
secret: monitor.secret,
};
})
.filter(Boolean);
return json;
}; };
} }
@@ -195,7 +195,7 @@ class StatusService {
// Return early if not enough data points // Return early if not enough data points
if (monitor.statusWindow.length < monitor.statusWindowSize) { if (monitor.statusWindow.length < monitor.statusWindowSize) {
const updated = await this.monitorsRepository.updateById(monitor.id, monitor); const updated = await this.monitorsRepository.updateById(monitor.id, monitor.teamId, monitor);
return { return {
monitor: updated, monitor: updated,
statusChanged: false, statusChanged: false,
@@ -285,7 +285,7 @@ class StatusService {
} }
monitor.status = newStatus; monitor.status = newStatus;
const updated = await this.monitorsRepository.updateById(monitor.id, monitor); const updated = await this.monitorsRepository.updateById(monitor.id, monitor.teamId, monitor);
return { return {
monitor: updated, monitor: updated,