mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: Update CodeRepository.getRepository() to return a Promise
Update CodeRepository.getRepository() to return a Promise<CodeRepositoryModel> instead of a string. This change improves the functionality and flexibility of the CodeRepository class.
This commit is contained in:
@@ -94,6 +94,12 @@ RunCron(
|
||||
fromName: true,
|
||||
secure: true,
|
||||
},
|
||||
callSmsConfig: {
|
||||
_id: true,
|
||||
twilioAccountSID: true,
|
||||
twilioAuthToken: true,
|
||||
twilioPhoneNumber: true,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import QueryHelper from '../Types/Database/QueryHelper';
|
||||
import logger from '../Utils/Logger';
|
||||
import DatabaseService from './DatabaseService';
|
||||
import MailService from './MailService';
|
||||
import ProjectCallSMSConfigService from './ProjectCallSMSConfigService';
|
||||
import ProjectService from './ProjectService';
|
||||
import SmsService from './SmsService';
|
||||
import StatusPageService from './StatusPageService';
|
||||
import { FileRoute } from 'Common/ServiceRoute';
|
||||
import Hostname from 'Common/Types/API/Hostname';
|
||||
@@ -144,31 +146,86 @@ export class Service extends DatabaseService<Model> {
|
||||
onCreate: OnCreate<Model>,
|
||||
createdItem: Model
|
||||
): Promise<Model> {
|
||||
if (!createdItem.statusPageId) {
|
||||
return createdItem;
|
||||
}
|
||||
|
||||
const statusPageURL: string = await StatusPageService.getStatusPageURL(
|
||||
createdItem.statusPageId
|
||||
);
|
||||
|
||||
const statusPageName: string =
|
||||
onCreate.carryForward.pageTitle ||
|
||||
onCreate.carryForward.name ||
|
||||
'Status Page';
|
||||
|
||||
const host: Hostname = await DatabaseConfig.getHost();
|
||||
|
||||
const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol();
|
||||
|
||||
const unsubscribeLink: string = this.getUnsubscribeLink(
|
||||
URL.fromString(statusPageURL),
|
||||
createdItem.id!
|
||||
).toString();
|
||||
|
||||
if (
|
||||
createdItem.statusPageId &&
|
||||
createdItem.subscriberPhone &&
|
||||
createdItem._id &&
|
||||
createdItem.sendYouHaveSubscribedMessage
|
||||
) {
|
||||
const statusPage: StatusPage | null =
|
||||
await StatusPageService.findOneBy({
|
||||
query: {
|
||||
_id: createdItem.statusPageId.toString(),
|
||||
},
|
||||
select: {
|
||||
callSmsConfig: {
|
||||
_id: true,
|
||||
twilioAccountSID: true,
|
||||
twilioAuthToken: true,
|
||||
twilioPhoneNumber: true,
|
||||
},
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
ignoreHooks: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!statusPage) {
|
||||
return createdItem;
|
||||
}
|
||||
|
||||
SmsService.sendSms(
|
||||
{
|
||||
to: createdItem.subscriberPhone,
|
||||
message: `You have been subscribed to ${statusPageName}. To unsubscribe, click on the link: ${unsubscribeLink}`,
|
||||
},
|
||||
{
|
||||
projectId: createdItem.projectId,
|
||||
isSensitive: false,
|
||||
customTwilioConfig:
|
||||
ProjectCallSMSConfigService.toTwilioConfig(
|
||||
statusPage.callSmsConfig
|
||||
),
|
||||
}
|
||||
).catch((err: Error) => {
|
||||
logger.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
createdItem.statusPageId &&
|
||||
createdItem.subscriberEmail &&
|
||||
createdItem._id
|
||||
createdItem._id &&
|
||||
createdItem.sendYouHaveSubscribedMessage
|
||||
) {
|
||||
// Call mail service and send an email.
|
||||
|
||||
// get status page domain for this status page.
|
||||
// if the domain is not found, use the internal status page preview link.
|
||||
|
||||
const statusPageURL: string =
|
||||
await StatusPageService.getStatusPageURL(
|
||||
createdItem.statusPageId
|
||||
);
|
||||
|
||||
const statusPageName: string =
|
||||
onCreate.carryForward.pageTitle ||
|
||||
onCreate.carryForward.name ||
|
||||
'Status Page';
|
||||
|
||||
const host: Hostname = await DatabaseConfig.getHost();
|
||||
|
||||
const httpProtocol: Protocol =
|
||||
await DatabaseConfig.getHttpProtocol();
|
||||
|
||||
MailService.sendMail(
|
||||
{
|
||||
toEmail: createdItem.subscriberEmail,
|
||||
@@ -189,10 +246,7 @@ export class Service extends DatabaseService<Model> {
|
||||
.isPublicStatusPage
|
||||
? 'true'
|
||||
: 'false',
|
||||
unsubscribeUrl: this.getUnsubscribeLink(
|
||||
URL.fromString(statusPageURL),
|
||||
createdItem.id!
|
||||
).toString(),
|
||||
unsubscribeUrl: unsubscribeLink,
|
||||
},
|
||||
subject: 'You have been subscribed to ' + statusPageName,
|
||||
},
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import URL from "Common/Types/API/URL";
|
||||
import BadDataException from "Common/Types/Exception/BadDataException";
|
||||
import URL from 'Common/Types/API/URL';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
|
||||
export const OneUptimeURL: URL = URL.fromString(process.env['ONEUPTIME_URL'] || 'https://oneuptime.com');
|
||||
export const OneUptimeURL: URL = URL.fromString(
|
||||
process.env['ONEUPTIME_URL'] || 'https://oneuptime.com'
|
||||
);
|
||||
|
||||
export const RepositorySecretKey: string = process.env['ONEUPTIME_REPOSITORY_SECRET_KEY'] || '';
|
||||
export const RepositorySecretKey: string =
|
||||
process.env['ONEUPTIME_REPOSITORY_SECRET_KEY'] || '';
|
||||
|
||||
if(!RepositorySecretKey) {
|
||||
if (!RepositorySecretKey) {
|
||||
throw new BadDataException('Repository Secret Key is required');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import Logger from 'CommonServer/Utils/Logger';
|
||||
|
||||
Logger.info('OneUptime Copilot is starting...');
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import CodeRepositoryModel from 'Model/Models/CodeRepository';
|
||||
|
||||
export default class CodeRepository {
|
||||
|
||||
public static getRepository(): Promise<CodeRepositoryModel> {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public static getRepository(): Promise<CodeRepositoryModel> {}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,16 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
|
||||
required: true,
|
||||
placeholder: 'subscriber@company.com',
|
||||
},
|
||||
|
||||
{
|
||||
field: {
|
||||
sendYouHaveSubscribedMessage: true,
|
||||
},
|
||||
title: 'Send Subscription Email',
|
||||
description:
|
||||
'Send "You have subscribed to this status page" email to this subscriber?',
|
||||
fieldType: FormFieldSchemaType.Toggle,
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
field: {
|
||||
isUnsubscribed: true,
|
||||
|
||||
@@ -469,6 +469,35 @@ export default class StatusPageSubscriber extends BaseModel {
|
||||
})
|
||||
public isUnsubscribed?: boolean = undefined;
|
||||
|
||||
@ColumnAccessControl({
|
||||
create: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CreateStatusPageSubscriber,
|
||||
Permission.Public,
|
||||
],
|
||||
read: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.ReadStatusPageSubscriber,
|
||||
],
|
||||
update: [],
|
||||
})
|
||||
@TableColumn({
|
||||
isDefaultValueColumn: true,
|
||||
type: TableColumnType.Boolean,
|
||||
title: 'Send You Have Subscribed Message',
|
||||
description:
|
||||
'Send You Have Subscribed Message when subscriber is created?',
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.Boolean,
|
||||
default: true,
|
||||
})
|
||||
public sendYouHaveSubscribedMessage?: boolean = undefined;
|
||||
|
||||
@ColumnAccessControl({
|
||||
create: [
|
||||
Permission.ProjectOwner,
|
||||
|
||||
Reference in New Issue
Block a user