mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 23:30:10 +00:00
Update import statements and add new data migration
This commit is contained in:
parent
f62930abb1
commit
16a65fcb4c
@ -59,9 +59,8 @@ export class Service extends DatabaseService<Model> {
|
|||||||
if (data.data.subscriberPhone) {
|
if (data.data.subscriberPhone) {
|
||||||
// check if this project has SMS enabled.
|
// check if this project has SMS enabled.
|
||||||
|
|
||||||
const isSMSEnabled: boolean = await ProjectService.isSMSNotificationsEnabled(
|
const isSMSEnabled: boolean =
|
||||||
projectId
|
await ProjectService.isSMSNotificationsEnabled(projectId);
|
||||||
);
|
|
||||||
|
|
||||||
if (!isSMSEnabled) {
|
if (!isSMSEnabled) {
|
||||||
throw new BadDataException(
|
throw new BadDataException(
|
||||||
|
@ -7,6 +7,7 @@ import DataMigrationBase from './DataMigrationBase';
|
|||||||
import MigrateDefaultUserNotificationRule from './MigrateDefaultUserNotificationRule';
|
import MigrateDefaultUserNotificationRule from './MigrateDefaultUserNotificationRule';
|
||||||
import MigrateDefaultUserNotificationSetting from './MigrateDefaultUserSettingNotification';
|
import MigrateDefaultUserNotificationSetting from './MigrateDefaultUserSettingNotification';
|
||||||
import MigrateToMeteredSubscription from './MigrateToMeteredSubscription';
|
import MigrateToMeteredSubscription from './MigrateToMeteredSubscription';
|
||||||
|
import MoveEnableSubscribersToEnableEmailSubscribersOnStatusPage from './MoveEnableSubscribersToEnableEmailSubscribersOnStatusPage';
|
||||||
import UpdateActiveMonitorCountToBillingProvider from './UpdateActiveMonitorCountToBillingProvider';
|
import UpdateActiveMonitorCountToBillingProvider from './UpdateActiveMonitorCountToBillingProvider';
|
||||||
import UpdateGlobalConfigFromEnv from './UpdateGlobalCongfigFromEnv';
|
import UpdateGlobalConfigFromEnv from './UpdateGlobalCongfigFromEnv';
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ const DataMigrations: Array<DataMigrationBase> = [
|
|||||||
new AddDefaultGlobalConfig(),
|
new AddDefaultGlobalConfig(),
|
||||||
new UpdateGlobalConfigFromEnv(),
|
new UpdateGlobalConfigFromEnv(),
|
||||||
new AddPostedAtToPublicNotes(),
|
new AddPostedAtToPublicNotes(),
|
||||||
|
new MoveEnableSubscribersToEnableEmailSubscribersOnStatusPage(),
|
||||||
];
|
];
|
||||||
|
|
||||||
export default DataMigrations;
|
export default DataMigrations;
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
import DataMigrationBase from './DataMigrationBase';
|
||||||
|
import LIMIT_MAX from 'Common/Types/Database/LimitMax';
|
||||||
|
import StatusPage from 'Model/Models/StatusPage';
|
||||||
|
import StatusPageService from 'CommonServer/Services/StatusPageService';
|
||||||
|
|
||||||
|
export default class MoveEnableSubscribersToEnableEmailSubscribersOnStatusPage extends DataMigrationBase {
|
||||||
|
public constructor() {
|
||||||
|
super('AddPostedAtToPublicNotes');
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async migrate(): Promise<void> {
|
||||||
|
// get all the users with email isVerified true.
|
||||||
|
|
||||||
|
const tempStatusPage = new StatusPage();
|
||||||
|
|
||||||
|
if(!tempStatusPage.getTableColumnMetadata("enableSubscribers")){
|
||||||
|
// this column does not exist, so we can skip this migration.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusPages: Array<StatusPage> =
|
||||||
|
await StatusPageService.findBy({
|
||||||
|
query: {},
|
||||||
|
select: {
|
||||||
|
_id: true,
|
||||||
|
enableSubscribers: true,
|
||||||
|
},
|
||||||
|
skip: 0,
|
||||||
|
limit: LIMIT_MAX,
|
||||||
|
props: {
|
||||||
|
isRoot: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const statusPage of statusPages) {
|
||||||
|
await StatusPageService.updateOneById({
|
||||||
|
id: statusPage.id!,
|
||||||
|
data: {
|
||||||
|
enableEmailSubscribers: statusPage.enableSubscribers!,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
isRoot: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async rollback(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ import './Jobs/PaymentProvider/PopulatePlanNameInProject';
|
|||||||
import './Jobs/Announcement/SendEmailToSubscribers';
|
import './Jobs/Announcement/SendEmailToSubscribers';
|
||||||
|
|
||||||
// Incidents
|
// Incidents
|
||||||
import './Jobs/Incident/SendEmailToSubscribers';
|
import './Jobs/Incident/SendNotificationToSubscribers';
|
||||||
import './Jobs/IncidentStateTimeline/SendEmailToSubscribers';
|
import './Jobs/IncidentStateTimeline/SendEmailToSubscribers';
|
||||||
|
|
||||||
// Incident Notes
|
// Incident Notes
|
||||||
|
@ -24,9 +24,11 @@ import Markdown from 'CommonServer/Types/Markdown';
|
|||||||
import Hostname from 'Common/Types/API/Hostname';
|
import Hostname from 'Common/Types/API/Hostname';
|
||||||
import Protocol from 'Common/Types/API/Protocol';
|
import Protocol from 'Common/Types/API/Protocol';
|
||||||
import DatabaseConfig from 'CommonServer/DatabaseConfig';
|
import DatabaseConfig from 'CommonServer/DatabaseConfig';
|
||||||
|
import SmsService from 'CommonServer/Services/SmsService';
|
||||||
|
import SMS from 'Common/Types/SMS/SMS';
|
||||||
|
|
||||||
RunCron(
|
RunCron(
|
||||||
'Incident:SendEmailToSubscribers',
|
'Incident:SendNotificationToSubscribers',
|
||||||
{ schedule: EVERY_MINUTE, runOnStartup: false },
|
{ schedule: EVERY_MINUTE, runOnStartup: false },
|
||||||
async () => {
|
async () => {
|
||||||
// get all scheduled events of all the projects.
|
// get all scheduled events of all the projects.
|
||||||
@ -176,6 +178,13 @@ RunCron(
|
|||||||
|
|
||||||
// Send email to Email subscribers.
|
// Send email to Email subscribers.
|
||||||
|
|
||||||
|
const resourcesAffectedString: string =
|
||||||
|
statusPageToResources[statuspage._id!]
|
||||||
|
?.map((r: StatusPageResource) => {
|
||||||
|
return r.displayName;
|
||||||
|
})
|
||||||
|
.join(', ') || 'None'
|
||||||
|
|
||||||
for (const subscriber of subscribers) {
|
for (const subscriber of subscribers) {
|
||||||
if (!subscriber._id) {
|
if (!subscriber._id) {
|
||||||
continue;
|
continue;
|
||||||
@ -206,11 +215,7 @@ RunCron(
|
|||||||
? 'true'
|
? 'true'
|
||||||
: 'false',
|
: 'false',
|
||||||
resourcesAffected:
|
resourcesAffected:
|
||||||
statusPageToResources[statuspage._id!]
|
resourcesAffectedString,
|
||||||
?.map((r: StatusPageResource) => {
|
|
||||||
return r.displayName;
|
|
||||||
})
|
|
||||||
.join(', ') || 'None',
|
|
||||||
incidentSeverity:
|
incidentSeverity:
|
||||||
incident.incidentSeverity?.name ||
|
incident.incidentSeverity?.name ||
|
||||||
' - ',
|
' - ',
|
||||||
@ -238,6 +243,32 @@ RunCron(
|
|||||||
logger.error(err);
|
logger.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subscriber.subscriberPhone) {
|
||||||
|
|
||||||
|
const sms: SMS = {
|
||||||
|
message: `
|
||||||
|
${statusPageName} - New Incident
|
||||||
|
Title: ${incident.title || ''}
|
||||||
|
Severity: ${incident.incidentSeverity?.name || ' - '}
|
||||||
|
Resources Affected: ${resourcesAffectedString}
|
||||||
|
Click here for more info: ${statusPageURL}
|
||||||
|
|
||||||
|
To unsubscribe, please click here: ${new URL(httpProtocol, host)
|
||||||
|
.addRoute(
|
||||||
|
'/api/status-page-subscriber/unsubscribe/' +
|
||||||
|
subscriber._id.toString()
|
||||||
|
)
|
||||||
|
.toString()}
|
||||||
|
`,
|
||||||
|
to: subscriber.subscriberPhone,
|
||||||
|
}
|
||||||
|
|
||||||
|
// send sms here.
|
||||||
|
SmsService.sendSms(sms, {
|
||||||
|
projectId: statuspage.projectId,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user