mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 06:37:33 +00:00
fix(notifications): list the paddle region request for admins while any trip has Tours on
The admin matrix decided a trip addon by the admin's own trips, so with Tours off for the instance and on for a member's trip the paddle region request still reached admins but had no row to switch it. Admin-scoped rows now follow the addon being on for the instance or any trip.
This commit is contained in:
@@ -95,6 +95,18 @@ export class TripAddonOverridesRepository extends TrekRepository<TripAddonOverri
|
||||
.execute();
|
||||
}
|
||||
|
||||
/** Whether any trip at all switched the addon on for itself. */
|
||||
async anyEnabled(addon_id: string): Promise<boolean> {
|
||||
const row = await this.kysely<OverridesKyselyDB>()
|
||||
.selectFrom('trip_addon_overrides')
|
||||
.select('trip_id')
|
||||
.where('addon_id', '=', addon_id)
|
||||
.where('enabled', '=', 1)
|
||||
.limit(1)
|
||||
.executeTakeFirst();
|
||||
return row !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether any trip the user owns or is a member of switched the addon on for
|
||||
* itself. Routes without a trip (a library, a search across trips) open on
|
||||
|
||||
@@ -110,6 +110,15 @@ export class AddonsService {
|
||||
return this.tripOverrides.anyEnabledForUser(userId, addon.id);
|
||||
}
|
||||
|
||||
/** For what the whole install can raise: on for the instance, or for any trip that switched it on. */
|
||||
async isEnabledAnywhere(addonId: string): Promise<boolean> {
|
||||
const addon = await this.addons.findById(addonId);
|
||||
if (!addon) return false;
|
||||
if (addon.enabled) return true;
|
||||
if (!isTripAddonRow(addon)) return false;
|
||||
return this.tripOverrides.anyEnabled(addon.id);
|
||||
}
|
||||
|
||||
async getBagTracking() {
|
||||
const value = await readAppSetting(this.appSettings, 'bag_tracking_enabled');
|
||||
return { enabled: value === 'true' };
|
||||
|
||||
@@ -97,13 +97,15 @@ export class NotificationPreferencesService {
|
||||
* the provider, is a switch that never does anything. For one user's own
|
||||
* matrix a trip addon counts as on while it is on in any of their trips, so a
|
||||
* trip that switched Collab on lists its chat row although the instance has it off.
|
||||
* For the admin's matrix it counts as on while it is on in any trip at all,
|
||||
* since an admin-scoped event fires from whichever trip has it.
|
||||
*/
|
||||
private async listedEventTypes(userId?: number): Promise<NotifEventType[]> {
|
||||
private async listedEventTypes(userId?: number, scope: 'user' | 'admin' = 'user'): Promise<NotifEventType[]> {
|
||||
const photoProviders = await this.addons.enabledPhotoProviderIds();
|
||||
const read = (id: string): Promise<boolean> =>
|
||||
userId !== undefined && TRIP_ADDON_IDS.has(id)
|
||||
? this.addons.isEnabledForUserAnywhere(userId, id)
|
||||
: this.addons.isAddonEnabled(id);
|
||||
const read = (id: string): Promise<boolean> => {
|
||||
if (userId === undefined || !TRIP_ADDON_IDS.has(id)) return this.addons.isAddonEnabled(id);
|
||||
return scope === 'admin' ? this.addons.isEnabledAnywhere(id) : this.addons.isEnabledForUserAnywhere(userId, id);
|
||||
};
|
||||
// One read per addon, shared by the events that hang off it.
|
||||
const addonOn = new Map<string, Promise<boolean>>();
|
||||
const on = (id: string): Promise<boolean> => {
|
||||
@@ -381,7 +383,7 @@ export class NotificationPreferencesService {
|
||||
// Filter event types by scope
|
||||
const event_types =
|
||||
scope === 'admin'
|
||||
? (await this.listedEventTypes(userId)).filter((e) => ADMIN_SCOPED_EVENTS.has(e))
|
||||
? (await this.listedEventTypes(userId, 'admin')).filter((e) => ADMIN_SCOPED_EVENTS.has(e))
|
||||
: (await this.listedEventTypes(userId)).filter((e) => !ADMIN_SCOPED_EVENTS.has(e));
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user