Skip to content

Commit

Permalink
feat: make MessageMSTeamsRepository common.
Browse files Browse the repository at this point in the history
  • Loading branch information
nshandra committed Sep 5, 2024
1 parent 3f0bd6d commit 691685c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MessageRepository } from "domain/repositories/user-monitoring/common/Me
export class MessageMSTeamsRepository implements MessageRepository {
constructor(private webhook: MSTeamsWebhookOptions) {}

async sendMessage(message: string): Async<boolean> {
async sendMessage(messageType: string, message: string): Async<boolean> {
const httpProxy = this.webhook.proxy;
const url = this.webhook.ms_url;
const server_name = this.webhook.server_name;
Expand All @@ -18,7 +18,7 @@ export class MessageMSTeamsRepository implements MessageRepository {
}

const postData = JSON.stringify({
text: `[*AUTHORITIES-MONITORING* - ${server_name}] - ${message}`,
text: `[*${messageType}* - ${server_name}] - ${message}`,
});

const requestOptions = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Async } from "domain/entities/Async";

export interface MessageRepository {
sendMessage(message: string): Async<boolean>;
sendMessage(messageType: string, message: string): Async<boolean>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export class MonitorUsersByAuthorityUseCase {
log.info("Report: No changes.");
} else {
const messages = this.makeMessages(newUsers, usersLosingAuth);
const teamsStatus = await this.MessageRepository.sendMessage(messages);
const teamsStatus = await this.MessageRepository.sendMessage(
"AUTHORITIES-MONITORING",
messages
);
if (teamsStatus) {
log.info(`Message sent to MSTeams`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ export class MonitorUserGroupsUseCase {
log.info("Report: No changes.");
} else {
const messages = this.makeMessages(userGroupsChanges);
const teamsStatus = await this.MessageRepository.sendMessage(messages);
const teamsStatus = await this.MessageRepository.sendMessage(
"USERGROUPS-MONITORING",
messages
);
if (teamsStatus) {
log.info(`Message sent to MSTeams`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ export class MonitorUserTemplatesUseCase {
log.info("Report: No changes.");
} else {
const messages = this.makeMessages(userGroupsChanges);
const teamsStatus = await this.MessageRepository.sendMessage(messages);
const teamsStatus = await this.MessageRepository.sendMessage(
"USER-TEMPLATES-MONITORING",
messages
);
if (teamsStatus) {
log.info(`Message sent to MSTeams`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/commands/usermonitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { PermissionFixerUserD2Repository } from "data/user-monitoring/permission

import { AuthoritiesMonitoringConfigD2Repository } from "data/user-monitoring/authorities-monitoring/AuthoritiesMonitoringConfigD2Repository";
import { UserRolesD2Repository } from "data/user-monitoring/authorities-monitoring/UserRolesD2Repository";
import { MessageMSTeamsRepository } from "data/user-monitoring/authorities-monitoring/MessageMSTeamsRepository";
import { MessageMSTeamsRepository } from "data/user-monitoring/common/MessageMSTeamsRepository";
import { MSTeamsWebhookOptions } from "data/user-monitoring/entities/MSTeamsWebhookOptions";
import { MonitorUsersByAuthorityUseCase } from "domain/usecases/user-monitoring/authorities-monitoring/MonitorUsersByAuthorityUseCase";

Expand Down

0 comments on commit 691685c

Please sign in to comment.