removed group granularity, notifications should be on page level

pull/6998/head
Felipe Polo-Wood 3 weeks ago
parent 4ed4e5c0e1
commit 3316852d25

@ -19,7 +19,7 @@ exports.up = function (knex) {
table.index("email", "subscriber_email");
table.index("unsubscribe_token", "subscriber_unsubscribe_token");
})
// Create status_page_subscription table (links subscribers to status pages and components)
// Create status_page_subscription table (links subscribers to status pages)
.createTable("status_page_subscription", (table) => {
table.increments("id").primary();
table.integer("subscriber_id")
@ -36,13 +36,6 @@ exports.up = function (knex) {
.inTable("status_page")
.onDelete("CASCADE")
.onUpdate("CASCADE");
table.integer("group_id") // NULL means subscribe to all components on a status page
.unsigned()
.nullable()
.references("id")
.inTable("group")
.onDelete("CASCADE")
.onUpdate("CASCADE");
table.boolean("notify_incidents").defaultTo(true);
table.boolean("notify_maintenance").defaultTo(true);
table.boolean("notify_status_changes").defaultTo(false);
@ -51,11 +44,9 @@ exports.up = function (knex) {
table.timestamps(false, true);
table.index("status_page_id", "status_page_subscription_status_page_id");
table.index("group_id", "status_page_subscription_group_id");
table.index("verification_token", "status_page_subscription_verification_token");
// Prevent duplicate subscriptions
table.unique(["subscriber_id", "status_page_id", "group_id"]);
table.unique(["subscriber_id", "status_page_id"]);
})
);
};

@ -4,7 +4,7 @@ const { nanoid } = require("nanoid");
/**
* StatusPageSubscription model
* Links subscribers to status pages and components
* Links subscribers to status pages
*/
class StatusPageSubscription extends BeanModel {
/**
@ -43,7 +43,6 @@ class StatusPageSubscription extends BeanModel {
id: this.id,
subscriberId: this.subscriber_id,
statusPageId: this.status_page_id,
groupId: this.group_id,
notifyIncidents: !!this.notify_incidents,
notifyMaintenance: !!this.notify_maintenance,
notifyStatusChanges: !!this.notify_status_changes,
@ -64,16 +63,9 @@ class StatusPageSubscription extends BeanModel {
/**
* Get all subscriptions for a status page
* @param {number} statusPageId Status Page ID
* @param {number|null} groupId Group ID (optional)
* @returns {Promise<StatusPageSubscription[]>} Array of subscriptions
*/
static async getByStatusPage(statusPageId, groupId = null) {
if (groupId) {
return await R.find("status_page_subscription", " status_page_id = ? AND (group_id = ? OR group_id IS NULL) ", [
statusPageId,
groupId,
]);
}
static async getByStatusPage(statusPageId) {
return await R.find("status_page_subscription", " status_page_id = ? ", [statusPageId]);
}
@ -81,18 +73,10 @@ class StatusPageSubscription extends BeanModel {
* Check if status_page_subscription exists
* @param {number} subscriberId Subscriber ID
* @param {number} statusPageId Status Page ID
* @param {number|null} groupId Group ID (optional)
* @returns {Promise<StatusPageSubscription|null>} StatusPageSubscription or null
*/
static async exists(subscriberId, statusPageId, groupId = null) {
if (groupId) {
return await R.findOne("status_page_subscription", " subscriber_id = ? AND status_page_id = ? AND group_id = ? ", [
subscriberId,
statusPageId,
groupId,
]);
}
return await R.findOne("status_page_subscription", " subscriber_id = ? AND status_page_id = ? AND group_id IS NULL ", [
static async exists(subscriberId, statusPageId) {
return await R.findOne("status_page_subscription", " subscriber_id = ? AND status_page_id = ? ", [
subscriberId,
statusPageId,
]);

Loading…
Cancel
Save