mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-26 23:45:57 +00:00
chore: delete maintenance mode notification
This commit is contained in:
parent
d7148c997a
commit
3f4ed487eb
@ -32,7 +32,6 @@ export type InstanceFields<TExtra = {}> = BaseFields & {
|
||||
cname: string
|
||||
dev: boolean
|
||||
cname_active: boolean
|
||||
notifyMaintenanceMode: boolean
|
||||
volume: string
|
||||
idleTtl: number
|
||||
} & TExtra
|
||||
|
||||
@ -13,7 +13,6 @@ export type UpdateInstancePayload = {
|
||||
| 'version'
|
||||
| 'dev'
|
||||
| 'cname'
|
||||
| 'notifyMaintenanceMode'
|
||||
>
|
||||
>
|
||||
}
|
||||
@ -52,7 +51,6 @@ export const UpdateInstancePayloadSchema: JSONSchemaType<UpdateInstancePayload>
|
||||
},
|
||||
dev: { type: 'boolean', nullable: true },
|
||||
cname: { type: 'string', nullable: true },
|
||||
notifyMaintenanceMode: { type: 'boolean', nullable: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -21,7 +21,6 @@ export type UserFields<TExtra = {}> = BaseFields & {
|
||||
verified: boolean
|
||||
isLegacy: boolean
|
||||
subscription: SubscriptionType
|
||||
notifyMaintenanceMode: boolean
|
||||
isStatsRole: boolean
|
||||
} & TExtra
|
||||
|
||||
|
||||
@ -32,7 +32,6 @@ __export(lib_exports, {
|
||||
HandleMigrateRegions: () => HandleMigrateRegions,
|
||||
HandleMirrorData: () => HandleMirrorData,
|
||||
HandleNotifyDiscordAfterCreate: () => HandleNotifyDiscordAfterCreate,
|
||||
HandleNotifyMaintenanceMode: () => HandleNotifyMaintenanceMode,
|
||||
HandleProcessNotification: () => HandleProcessNotification,
|
||||
HandleProcessSingleNotification: () => HandleProcessSingleNotification,
|
||||
HandleSesError: () => HandleSesError,
|
||||
@ -100,7 +99,6 @@ var HandleInstanceCreate = (c) => {
|
||||
record.set("version", version);
|
||||
record.set("dev", true);
|
||||
record.set("syncAdmin", true);
|
||||
record.set("notifyMaintenanceMode", true);
|
||||
const form = new RecordUpsertForm($app, record);
|
||||
form.submit();
|
||||
return c.json(200, { instance: record });
|
||||
@ -214,8 +212,7 @@ var HandleInstanceUpdate = (c) => {
|
||||
secrets: null,
|
||||
syncAdmin: null,
|
||||
dev: null,
|
||||
cname: null,
|
||||
notifyMaintenanceMode: null
|
||||
cname: null
|
||||
}
|
||||
});
|
||||
c.bind(data);
|
||||
@ -223,16 +220,7 @@ var HandleInstanceUpdate = (c) => {
|
||||
data = JSON.parse(JSON.stringify(data));
|
||||
const id = c.pathParam("id");
|
||||
const {
|
||||
fields: {
|
||||
subdomain,
|
||||
maintenance,
|
||||
version,
|
||||
secrets,
|
||||
syncAdmin,
|
||||
dev,
|
||||
cname,
|
||||
notifyMaintenanceMode
|
||||
}
|
||||
fields: { subdomain, maintenance, version, secrets, syncAdmin, dev, cname }
|
||||
} = data;
|
||||
log(
|
||||
`vars`,
|
||||
@ -244,8 +232,7 @@ var HandleInstanceUpdate = (c) => {
|
||||
secrets,
|
||||
syncAdmin,
|
||||
dev,
|
||||
cname,
|
||||
notifyMaintenanceMode
|
||||
cname
|
||||
})
|
||||
);
|
||||
const record = dao.findRecordById("instances", id);
|
||||
@ -264,8 +251,7 @@ var HandleInstanceUpdate = (c) => {
|
||||
secrets,
|
||||
syncAdmin,
|
||||
dev,
|
||||
cname,
|
||||
notifyMaintenanceMode
|
||||
cname
|
||||
});
|
||||
const form = new RecordUpsertForm($app, record);
|
||||
form.loadData(sanitized);
|
||||
@ -428,37 +414,6 @@ var mkNotifier = (log, dao) => (channel, template, user_id, context = {}) => {
|
||||
dao.saveRecord(emailNotification);
|
||||
};
|
||||
|
||||
// src/lib/handlers/instance/model/HandleNotifyMaintenanceMode.ts
|
||||
var HandleNotifyMaintenanceMode = (e) => {
|
||||
const dao = e.dao || $app.dao();
|
||||
const newModel = e.model;
|
||||
const oldModel = newModel.originalCopy();
|
||||
const log = mkLog(`maintenance-mode`);
|
||||
const audit = mkAudit(log, dao);
|
||||
const notify = mkNotifier(log, dao);
|
||||
try {
|
||||
const isMaintenance = newModel.get("maintenance");
|
||||
if (!isMaintenance) return;
|
||||
if (isMaintenance === oldModel.get(`maintenance`)) return;
|
||||
log(`switched`);
|
||||
const uid = newModel.get(`uid`);
|
||||
const user = dao.findRecordById("users", uid);
|
||||
const shouldNotify = user.getBool(`notifyMaintenanceMode`) && newModel.getBool(`notifyMaintenanceMode`);
|
||||
log({ shouldNotify });
|
||||
if (!shouldNotify) return;
|
||||
const instanceId = newModel.getId();
|
||||
const subdomain = newModel.getString(`subdomain`);
|
||||
const address = user.getString(`email`);
|
||||
log({ instanceId, subdomain, address });
|
||||
notify(`email`, `maintenance-mode`, uid, {
|
||||
subdomain,
|
||||
instanceId
|
||||
});
|
||||
} catch (e2) {
|
||||
audit(`ERROR`, `Failed to enqueue template with ${e2}`);
|
||||
}
|
||||
};
|
||||
|
||||
// src/lib/handlers/lemon/api/HandleLemonSqueezySale.ts
|
||||
var HandleLemonSqueezySale = (c) => {
|
||||
const dao = $app.dao();
|
||||
@ -3147,7 +3102,6 @@ var HandleVersionsRequest = (c) => {
|
||||
HandleMigrateRegions,
|
||||
HandleMirrorData,
|
||||
HandleNotifyDiscordAfterCreate,
|
||||
HandleNotifyMaintenanceMode,
|
||||
HandleProcessNotification,
|
||||
HandleProcessSingleNotification,
|
||||
HandleSesError,
|
||||
|
||||
@ -26,8 +26,6 @@ routerAdd(
|
||||
onModelBeforeCreate((e) => {
|
||||
return require(`${__hooks}/mothership`).HandleInstanceVersionValidation(e);
|
||||
}, "instances");
|
||||
onModelAfterUpdate((e) => {
|
||||
}, "instances");
|
||||
onModelAfterCreate((e) => {
|
||||
}, "instances");
|
||||
onAfterBootstrap((e) => {
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((db) => {
|
||||
const dao = new Dao(db)
|
||||
const collection = dao.findCollectionByNameOrId("etae8tuiaxl6xfv")
|
||||
|
||||
// remove
|
||||
collection.schema.removeField("rofy4mta")
|
||||
|
||||
return dao.saveCollection(collection)
|
||||
}, (db) => {
|
||||
const dao = new Dao(db)
|
||||
const collection = dao.findCollectionByNameOrId("etae8tuiaxl6xfv")
|
||||
|
||||
// add
|
||||
collection.schema.addField(new SchemaField({
|
||||
"system": false,
|
||||
"id": "rofy4mta",
|
||||
"name": "notifyMaintenanceMode",
|
||||
"type": "bool",
|
||||
"required": false,
|
||||
"presentable": false,
|
||||
"unique": false,
|
||||
"options": {}
|
||||
}))
|
||||
|
||||
return dao.saveCollection(collection)
|
||||
})
|
||||
@ -47,7 +47,6 @@ export const HandleInstanceCreate = (c: echo.Context) => {
|
||||
record.set('version', version)
|
||||
record.set('dev', true)
|
||||
record.set('syncAdmin', true)
|
||||
record.set('notifyMaintenanceMode', true)
|
||||
|
||||
const form = new RecordUpsertForm($app, record)
|
||||
form.submit()
|
||||
|
||||
@ -17,7 +17,6 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
|
||||
syncAdmin: null,
|
||||
dev: null,
|
||||
cname: null,
|
||||
notifyMaintenanceMode: null,
|
||||
},
|
||||
}) as {
|
||||
id: string
|
||||
@ -29,7 +28,6 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
|
||||
syncAdmin: boolean | null
|
||||
dev: boolean | null
|
||||
cname: string | null
|
||||
notifyMaintenanceMode: boolean | null
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,16 +39,7 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
|
||||
|
||||
const id = c.pathParam('id')
|
||||
const {
|
||||
fields: {
|
||||
subdomain,
|
||||
maintenance,
|
||||
version,
|
||||
secrets,
|
||||
syncAdmin,
|
||||
dev,
|
||||
cname,
|
||||
notifyMaintenanceMode,
|
||||
},
|
||||
fields: { subdomain, maintenance, version, secrets, syncAdmin, dev, cname },
|
||||
} = data
|
||||
|
||||
log(
|
||||
@ -64,7 +53,6 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
|
||||
syncAdmin,
|
||||
dev,
|
||||
cname,
|
||||
notifyMaintenanceMode,
|
||||
}),
|
||||
)
|
||||
|
||||
@ -87,7 +75,6 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
|
||||
syncAdmin,
|
||||
dev,
|
||||
cname,
|
||||
notifyMaintenanceMode,
|
||||
})
|
||||
|
||||
const form = new RecordUpsertForm($app, record)
|
||||
|
||||
@ -27,10 +27,6 @@ onModelBeforeCreate((e) => {
|
||||
return require(`${__hooks}/mothership`).HandleInstanceVersionValidation(e)
|
||||
}, 'instances')
|
||||
|
||||
onModelAfterUpdate((e) => {
|
||||
// return require(`${__hooks}/mothership`).HandleNotifyMaintenanceMode(e)
|
||||
}, 'instances')
|
||||
|
||||
onModelAfterCreate((e) => {
|
||||
// return require(`${__hooks}/mothership`).HandleNotifyDiscordAfterCreate(e)
|
||||
}, 'instances')
|
||||
|
||||
@ -7,4 +7,3 @@ export * from './bootstrap/HandleMigrateRegions'
|
||||
export * from './model/HandleInstanceBeforeUpdate'
|
||||
export * from './model/HandleInstanceVersionValidation'
|
||||
export * from './model/HandleNotifyDiscordAfterCreate'
|
||||
export * from './model/HandleNotifyMaintenanceMode'
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
import { mkLog } from '$util/Logger'
|
||||
import { mkAudit } from '$util/mkAudit'
|
||||
import { mkNotifier } from '$util/mkNotifier'
|
||||
|
||||
export const HandleNotifyMaintenanceMode = (e: core.ModelEvent) => {
|
||||
const dao = e.dao || $app.dao()
|
||||
|
||||
const newModel = e.model as models.Record
|
||||
const oldModel = newModel.originalCopy()
|
||||
|
||||
const log = mkLog(`maintenance-mode`)
|
||||
const audit = mkAudit(log, dao)
|
||||
const notify = mkNotifier(log, dao)
|
||||
try {
|
||||
// Bail out if we aren't in maintenance mode
|
||||
const isMaintenance = newModel.get('maintenance')
|
||||
// log({ isMaintenance })
|
||||
if (!isMaintenance) return
|
||||
|
||||
// Bail out if the maintenance mode flag has not changed
|
||||
if (isMaintenance === oldModel.get(`maintenance`)) return
|
||||
|
||||
log(`switched`)
|
||||
const uid = newModel.get(`uid`)
|
||||
const user = dao.findRecordById('users', uid)
|
||||
|
||||
// Bail out if the user has notifications disabled globally or for the instance
|
||||
const shouldNotify =
|
||||
user.getBool(`notifyMaintenanceMode`) &&
|
||||
newModel.getBool(`notifyMaintenanceMode`)
|
||||
log({ shouldNotify })
|
||||
if (!shouldNotify) return
|
||||
|
||||
// Send the email warning about maintenance mode
|
||||
const instanceId = newModel.getId()
|
||||
const subdomain = newModel.getString(`subdomain`)
|
||||
const address = user.getString(`email`)
|
||||
log({ instanceId, subdomain, address })
|
||||
notify(`email`, `maintenance-mode`, uid, {
|
||||
subdomain,
|
||||
instanceId,
|
||||
})
|
||||
} catch (e) {
|
||||
audit(`ERROR`, `Failed to enqueue template with ${e}`)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user