Skip to content

Commit

Permalink
feat: update incident feed event types for owner additions and enhanc…
Browse files Browse the repository at this point in the history
…e related services
  • Loading branch information
simlarsen committed Jan 14, 2025
1 parent 1fb84ea commit 9dcd295
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Common/Models/DatabaseModels/IncidentFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export enum IncidentFeedEventType {
PublicNote = "PublicNote",
SubscriberNotificationSent = "SubscriberNotificationSent",
OwnerNotificationSent = "OwnerNotificationSent",
OwnerAdded = "OwnerAdded",
OwnerUserAdded = "OwnerUserAdded",
OwnerTeamAdded = "OwnerTeamAdded",
IncidentCreated = "IncidentCreated",
IncidentStateChanged = "IncidentStateChanged",
PrivateNote = "PrivateNote",
Expand Down
50 changes: 50 additions & 0 deletions Common/Server/Services/IncidentOwnerTeamService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
import ObjectID from "../../Types/ObjectID";
import { OnCreate } from "../Types/Database/Hooks";
import DatabaseService from "./DatabaseService";
import Model from "Common/Models/DatabaseModels/IncidentOwnerTeam";
import IncidentFeedService from "./IncidentFeedService";
import { IncidentFeedEventType } from "../../Models/DatabaseModels/IncidentFeed";
import { Blue500 } from "../../Types/BrandColors";
import TeamService from "./TeamService";
import Team from "../../Models/DatabaseModels/Team";

export class Service extends DatabaseService<Model> {
public constructor() {
super(Model);
}

public override async onCreateSuccess(onCreate: OnCreate<Model>, createdItem: Model): Promise<Model> {
// add incident feed.

const incidentId: ObjectID | undefined = createdItem.incidentId;
const projectId: ObjectID | undefined = createdItem.projectId;
const teamId: ObjectID | undefined = createdItem.teamId;
const createdByUserId: ObjectID | undefined = createdItem.createdByUserId || onCreate.createBy.props.userId;


if (incidentId && teamId && projectId) {


const team: Team | null = await TeamService.findOneById({
id: teamId,
select: {
name: true
},
props: {
isRoot: true
}
})

if (team && team.name) {


await IncidentFeedService.createIncidentFeed({

incidentId: incidentId,
projectId: projectId,
incidentFeedEventType: IncidentFeedEventType.OwnerTeamAdded,
displayColor: Blue500,
feedInfoInMarkdown: `Team ${team.name} was added to the incident as the owner.`,
userId: createdByUserId || undefined,
});

}

}

return createdItem;

}
}

export default new Service();
50 changes: 50 additions & 0 deletions Common/Server/Services/IncidentOwnerUserService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
import ObjectID from "../../Types/ObjectID";
import DatabaseService from "./DatabaseService";
import Model from "Common/Models/DatabaseModels/IncidentOwnerUser";
import IncidentFeedService from "./IncidentFeedService";
import { IncidentFeedEventType } from "../../Models/DatabaseModels/IncidentFeed";
import { Blue500 } from "../../Types/BrandColors";
import User from "../../Models/DatabaseModels/User";
import UserService from "./UserService";
import { OnCreate } from "../Types/Database/Hooks";

export class Service extends DatabaseService<Model> {
public constructor() {
super(Model);
}


public override async onCreateSuccess(onCreate: OnCreate<Model>, createdItem: Model): Promise<Model> {
// add incident feed.

const incidentId: ObjectID | undefined = createdItem.incidentId;
const projectId: ObjectID | undefined = createdItem.projectId;
const userId: ObjectID | undefined = createdItem.userId;
const createdByUserId: ObjectID | undefined = createdItem.createdByUserId || onCreate.createBy.props.userId;


if (incidentId && userId && projectId) {


const user: User | null = await UserService.findOneById({
id: userId,
select: {
name: true,
email: true
},
props: {
isRoot: true
}
})

if (user && user.name) {

await IncidentFeedService.createIncidentFeed({
incidentId: incidentId,
projectId: projectId,
incidentFeedEventType: IncidentFeedEventType.OwnerUserAdded,
displayColor: Blue500,
feedInfoInMarkdown: `${user.name.toString()} (${user.email?.toString()}) was added to the incident as the owner.`,
userId: createdByUserId || undefined,
});

}

}

return createdItem;

}
}

export default new Service();
4 changes: 2 additions & 2 deletions Common/UI/Components/Feed/FeedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ const FeedItem: FunctionComponent<ComponentProps> = (

const getUserIcon: GetReactElementFunction = (): ReactElement => {
return <div>
{!props.user?.profilePictureFile && <Image
{!props.user?.profilePictureId && <Image
className="h-10 w-10 rounded-full"
imageUrl={Route.fromString(`${BlankProfilePic}`)}
/>}

{props.user?.profilePictureFile && <Image
{props.user?.profilePictureId && <Image
className="flex size-10 items-center justify-center rounded-full bg-gray-400 ring-8 ring-white"
imageUrl={FileUtil.getFileRoute(props.user!.profilePictureId as ObjectID)}
/>}
Expand Down
6 changes: 3 additions & 3 deletions Dashboard/src/Components/Incident/IncidentFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ const IncidentFeedElement: FunctionComponent<ComponentProps> = (
icon = IconProp.Lock;
}

if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerAdded){
if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerUserAdded){
icon = IconProp.User;
}

if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerAdded){
icon = IconProp.User;
if(incidentFeed.incidentFeedEventType === IncidentFeedEventType.OwnerTeamAdded){
icon = IconProp.Team;
}

return {
Expand Down
11 changes: 0 additions & 11 deletions Worker/Jobs/IncidentOwners/SendOwnerAddedNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import IncidentOwnerTeam from "Common/Models/DatabaseModels/IncidentOwnerTeam";
import IncidentOwnerUser from "Common/Models/DatabaseModels/IncidentOwnerUser";
import Monitor from "Common/Models/DatabaseModels/Monitor";
import User from "Common/Models/DatabaseModels/User";
import IncidentFeedService from "Common/Server/Services/IncidentFeedService";
import { IncidentFeedEventType } from "Common/Models/DatabaseModels/IncidentFeed";
import { Blue500 } from "Common/Types/BrandColors";

RunCron(
"IncidentOwner:SendOwnerAddedEmail",
Expand Down Expand Up @@ -212,14 +209,6 @@ RunCron(
eventType:
NotificationSettingEventType.SEND_INCIDENT_OWNER_ADDED_NOTIFICATION,
});

await IncidentFeedService.createIncidentFeed({
incidentId: incident.id!,
projectId: incident.projectId!,
incidentFeedEventType: IncidentFeedEventType.OwnerAdded,
displayColor: Blue500,
feedInfoInMarkdown: `User added as owner to this Incident: ${user.name} (${user.email})`,
});
}
}
},
Expand Down

0 comments on commit 9dcd295

Please sign in to comment.