Skip to content

Commit

Permalink
Merge branch 'owners-in-form'
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed May 16, 2023
2 parents b72dcc6 + 51d28b0 commit 4b5ea13
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 45 deletions.
63 changes: 63 additions & 0 deletions CommonServer/Services/IncidentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import CreateBy from '../Types/Database/CreateBy';
import BadDataException from 'Common/Types/Exception/BadDataException';
import IncidentState from 'Model/Models/IncidentState';
import IncidentStateService from './IncidentStateService';
import IncidentOwnerTeamService from './IncidentOwnerTeamService';
import IncidentOwnerTeam from 'Model/Models/IncidentOwnerTeam';
import IncidentOwnerUser from 'Model/Models/IncidentOwnerUser';
import IncidentOwnerUserService from './IncidentOwnerUserService';
import Typeof from 'Common/Types/Typeof';

export class Service extends DatabaseService<Model> {
public constructor(postgresDatabase?: PostgresDatabase) {
Expand Down Expand Up @@ -90,9 +95,67 @@ export class Service extends DatabaseService<Model> {
}
);

// add owners.

if (
onCreate.createBy.miscDataProps &&
(onCreate.createBy.miscDataProps['ownerTeams'] ||
onCreate.createBy.miscDataProps['ownerUsers'])
) {
await this.addOwners(
createdItem.projectId,
createdItem.id,
(onCreate.createBy.miscDataProps[
'ownerUsers'
] as Array<ObjectID>) || [],
(onCreate.createBy.miscDataProps[
'ownerTeams'
] as Array<ObjectID>) || [],
onCreate.createBy.props
);
}

return createdItem;
}

public async addOwners(
projectId: ObjectID,
incidentId: ObjectID,
userIds: Array<ObjectID>,
teamIds: Array<ObjectID>,
props: DatabaseCommonInteractionProps
): Promise<void> {
for (let teamId of teamIds) {
if (typeof teamId === Typeof.String) {
teamId = new ObjectID(teamId.toString());
}

const teamOwner: IncidentOwnerTeam = new IncidentOwnerTeam();
teamOwner.incidentId = incidentId;
teamOwner.projectId = projectId;
teamOwner.teamId = teamId;

await IncidentOwnerTeamService.create({
data: teamOwner,
props: props,
});
}

for (let userId of userIds) {
if (typeof userId === Typeof.String) {
userId = new ObjectID(userId.toString());
}
const teamOwner: IncidentOwnerUser = new IncidentOwnerUser();
teamOwner.incidentId = incidentId;
teamOwner.projectId = projectId;
teamOwner.userId = userId;
await IncidentOwnerUserService.create({
data: teamOwner,
props: props,
});
}
}

public async changeIncidentState(
projectId: ObjectID,
incidentId: ObjectID,
Expand Down
63 changes: 63 additions & 0 deletions CommonServer/Services/MonitorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import MonitorType from 'Common/Types/Monitor/MonitorType';
import Probe from 'Model/Models/Probe';
import ActiveMonitoringMeteredPlan from '../Types/Billing/MeteredPlan/ActiveMonitoringMeteredPlan';
import { IsBillingEnabled } from '../Config';
import MonitorOwnerUserService from './MonitorOwnerUserService';
import MonitorOwnerUser from 'Model/Models/MonitorOwnerUser';
import MonitorOwnerTeamService from './MonitorOwnerTeamService';
import MonitorOwnerTeam from 'Model/Models/MonitorOwnerTeam';
import Typeof from 'Common/Types/Typeof';

export class Service extends DatabaseService<Model> {
public constructor(postgresDatabase?: PostgresDatabase) {
Expand Down Expand Up @@ -111,9 +116,67 @@ export class Service extends DatabaseService<Model> {
);
}

// add owners.

if (
onCreate.createBy.miscDataProps &&
(onCreate.createBy.miscDataProps['ownerTeams'] ||
onCreate.createBy.miscDataProps['ownerUsers'])
) {
await this.addOwners(
createdItem.projectId,
createdItem.id,
(onCreate.createBy.miscDataProps[
'ownerUsers'
] as Array<ObjectID>) || [],
(onCreate.createBy.miscDataProps[
'ownerTeams'
] as Array<ObjectID>) || [],
onCreate.createBy.props
);
}

return createdItem;
}

public async addOwners(
projectId: ObjectID,
monitorId: ObjectID,
userIds: Array<ObjectID>,
teamIds: Array<ObjectID>,
props: DatabaseCommonInteractionProps
): Promise<void> {
for (let teamId of teamIds) {
if (typeof teamId === Typeof.String) {
teamId = new ObjectID(teamId.toString());
}

const teamOwner: MonitorOwnerTeam = new MonitorOwnerTeam();
teamOwner.monitorId = monitorId;
teamOwner.projectId = projectId;
teamOwner.teamId = teamId;

await MonitorOwnerTeamService.create({
data: teamOwner,
props: props,
});
}

for (let userId of userIds) {
if (typeof userId === Typeof.String) {
userId = new ObjectID(userId.toString());
}
const teamOwner: MonitorOwnerUser = new MonitorOwnerUser();
teamOwner.monitorId = monitorId;
teamOwner.projectId = projectId;
teamOwner.userId = userId;
await MonitorOwnerUserService.create({
data: teamOwner,
props: props,
});
}
}

public async addDefaultProbesToMonitor(
projectId: ObjectID,
monitorId: ObjectID
Expand Down
67 changes: 66 additions & 1 deletion CommonServer/Services/ScheduledMaintenanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import BadDataException from 'Common/Types/Exception/BadDataException';
import ScheduledMaintenanceState from 'Model/Models/ScheduledMaintenanceState';
import ScheduledMaintenanceStateService from './ScheduledMaintenanceStateService';
import { LIMIT_PER_PROJECT } from 'Common/Types/Database/LimitMax';
import ScheduledMaintenanceOwnerUserService from './ScheduledMaintenanceOwnerUserService';
import ScheduledMaintenanceOwnerUser from 'Model/Models/ScheduledMaintenanceOwnerUser';
import Typeof from 'Common/Types/Typeof';
import ScheduledMaintenanceOwnerTeamService from './ScheduledMaintenanceOwnerTeamService';
import ScheduledMaintenanceOwnerTeam from 'Model/Models/ScheduledMaintenanceOwnerTeam';

export class Service extends DatabaseService<Model> {
public constructor(postgresDatabase?: PostgresDatabase) {
Expand Down Expand Up @@ -52,7 +57,7 @@ export class Service extends DatabaseService<Model> {
}

protected override async onCreateSuccess(
_onCreate: OnCreate<Model>,
onCreate: OnCreate<Model>,
createdItem: Model
): Promise<Model> {
// create new scheduled maintenance state timeline.
Expand All @@ -72,9 +77,69 @@ export class Service extends DatabaseService<Model> {
},
});

if (
createdItem.projectId &&
createdItem.id &&
onCreate.createBy.miscDataProps &&
(onCreate.createBy.miscDataProps['ownerTeams'] ||
onCreate.createBy.miscDataProps['ownerUsers'])
) {
await this.addOwners(
createdItem.projectId!,
createdItem.id!,
(onCreate.createBy.miscDataProps[
'ownerUsers'
] as Array<ObjectID>) || [],
(onCreate.createBy.miscDataProps[
'ownerTeams'
] as Array<ObjectID>) || [],
onCreate.createBy.props
);
}

return createdItem;
}

public async addOwners(
projectId: ObjectID,
scheduledMaintenanceId: ObjectID,
userIds: Array<ObjectID>,
teamIds: Array<ObjectID>,
props: DatabaseCommonInteractionProps
): Promise<void> {
for (let teamId of teamIds) {
if (typeof teamId === Typeof.String) {
teamId = new ObjectID(teamId.toString());
}

const teamOwner: ScheduledMaintenanceOwnerTeam =
new ScheduledMaintenanceOwnerTeam();
teamOwner.scheduledMaintenanceId = scheduledMaintenanceId;
teamOwner.projectId = projectId;
teamOwner.teamId = teamId;

await ScheduledMaintenanceOwnerTeamService.create({
data: teamOwner,
props: props,
});
}

for (let userId of userIds) {
if (typeof userId === Typeof.String) {
userId = new ObjectID(userId.toString());
}
const teamOwner: ScheduledMaintenanceOwnerUser =
new ScheduledMaintenanceOwnerUser();
teamOwner.scheduledMaintenanceId = scheduledMaintenanceId;
teamOwner.projectId = projectId;
teamOwner.userId = userId;
await ScheduledMaintenanceOwnerUserService.create({
data: teamOwner,
props: props,
});
}
}

public async changeAttachedMonitorStates(
item: Model,
props: DatabaseCommonInteractionProps
Expand Down
74 changes: 73 additions & 1 deletion CommonServer/Services/StatusPageService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PostgresDatabase from '../Infrastructure/PostgresDatabase';
import DatabaseService from './DatabaseService';
import DatabaseService, { OnCreate } from './DatabaseService';
import DatabaseCommonInteractionProps from 'Common/Types/Database/DatabaseCommonInteractionProps';
import ObjectID from 'Common/Types/ObjectID';
import PositiveNumber from 'Common/Types/PositiveNumber';
Expand All @@ -13,12 +13,84 @@ import { ExpressRequest } from '../Utils/Express';
import JSONWebToken from '../Utils/JsonWebToken';
import JSONWebTokenData from 'Common/Types/JsonWebTokenData';
import logger from '../Utils/Logger';
import Typeof from 'Common/Types/Typeof';
import StatusPageOwnerTeam from 'Model/Models/StatusPageOwnerTeam';
import StatusPageOwnerTeamService from './StatusPageOwnerTeamService';
import StatusPageOwnerUser from 'Model/Models/StatusPageOwnerUser';
import StatusPageOwnerUserService from './StatusPageOwnerUserService';

export class Service extends DatabaseService<StatusPage> {
public constructor(postgresDatabase?: PostgresDatabase) {
super(StatusPage, postgresDatabase);
}

protected override async onCreateSuccess(
onCreate: OnCreate<StatusPage>,
createdItem: StatusPage
): Promise<StatusPage> {
// add owners.

if (
createdItem.projectId &&
createdItem.id &&
onCreate.createBy.miscDataProps &&
(onCreate.createBy.miscDataProps['ownerTeams'] ||
onCreate.createBy.miscDataProps['ownerUsers'])
) {
await this.addOwners(
createdItem.projectId!,
createdItem.id!,
(onCreate.createBy.miscDataProps[
'ownerUsers'
] as Array<ObjectID>) || [],
(onCreate.createBy.miscDataProps[
'ownerTeams'
] as Array<ObjectID>) || [],
onCreate.createBy.props
);
}

return createdItem;
}

public async addOwners(
projectId: ObjectID,
statusPageId: ObjectID,
userIds: Array<ObjectID>,
teamIds: Array<ObjectID>,
props: DatabaseCommonInteractionProps
): Promise<void> {
for (let teamId of teamIds) {
if (typeof teamId === Typeof.String) {
teamId = new ObjectID(teamId.toString());
}

const teamOwner: StatusPageOwnerTeam = new StatusPageOwnerTeam();
teamOwner.statusPageId = statusPageId;
teamOwner.projectId = projectId;
teamOwner.teamId = teamId;

await StatusPageOwnerTeamService.create({
data: teamOwner,
props: props,
});
}

for (let userId of userIds) {
if (typeof userId === Typeof.String) {
userId = new ObjectID(userId.toString());
}
const teamOwner: StatusPageOwnerUser = new StatusPageOwnerUser();
teamOwner.statusPageId = statusPageId;
teamOwner.projectId = projectId;
teamOwner.userId = userId;
await StatusPageOwnerUserService.create({
data: teamOwner,
props: props,
});
}
}

public async hasReadAccess(
statusPageId: ObjectID,
props: DatabaseCommonInteractionProps,
Expand Down
23 changes: 13 additions & 10 deletions CommonUI/src/Components/Forms/BasicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,25 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(

props.onSubmit(values);
} else if (props.steps && props.steps.length > 0) {
const currentStepIndex: number = props.steps.findIndex(
const steps: Array<FormStep<T>> = props.steps.filter(
(step: FormStep<T>) => {
if (!step.showIf) {
return true;
}

return step.showIf(refCurrentValue.current);
}
);

const currentStepIndex: number = steps.findIndex(
(step: FormStep<T>) => {
return step.id === currentFormStepId;
}
);

if (currentStepIndex > -1) {
setCurrentFormStepId(
(
props.steps.filter((step: FormStep<T>) => {
if (!step.showIf) {
return true;
}

return step.showIf(refCurrentValue.current);
})[currentStepIndex + 1] as FormStep<T>
).id
(steps[currentStepIndex + 1] as FormStep<T>).id
);
}
}
Expand Down
Loading

0 comments on commit 4b5ea13

Please sign in to comment.