The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
fix(notifications): list the paddle region request for admins while any trip has Tours on
Mauricec289541c43c2
diff --git a/server/src/db/repositories/TripAddonOverrides.repository.ts b/server/src/db/repositories/TripAddonOverrides.repository.tsindex f5f76ae68..ed608bb2f 100644--- a/server/src/db/repositories/TripAddonOverrides.repository.ts+++ b/server/src/db/repositories/TripAddonOverrides.repository.ts@@ -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 ondiff --git a/server/src/nest/addons/addons.service.ts b/server/src/nest/addons/addons.service.tsindex abd7832a9..ed3f15eff 100644--- a/server/src/nest/addons/addons.service.ts+++ b/server/src/nest/addons/addons.service.ts@@ -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' };diff --git a/server/src/nest/notifications/notification-preferences.service.ts b/server/src/nest/notifications/notification-preferences.service.tsindex 591c5619e..5a3e71be9 100644--- a/server/src/nest/notifications/notification-preferences.service.ts+++ b/server/src/nest/notifications/notification-preferences.service.ts@@ -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 scopeconst 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 {diff --git a/server/tests/helpers/notifications.ts b/server/tests/helpers/notifications.tsindex e3c748858..7471ab9a0 100644--- a/server/tests/helpers/notifications.ts+++ b/server/tests/helpers/notifications.ts@@ -111,13 +111,18 @@ export function everyFeatureOn(overrides: Partial<Pick<AddonsService,- 'isAddonEnabled' | 'isEnabledForUserAnywhere' | 'isWandererAvailable' | 'enabledPhotoProviderIds'+ | 'isAddonEnabled'+ | 'isEnabledForUserAnywhere'+ | 'isEnabledAnywhere'+ | 'isWandererAvailable'+ | 'enabledPhotoProviderIds'>> = {},): AddonsService {return {isAddonEnabled: async () => true,isEnabledForUserAnywhere: async () => true,+ isEnabledAnywhere: async () => true,isWandererAvailable: async () => true,enabledPhotoProviderIds: async () => ['immich', 'synologyphotos'],...overrides,diff --git a/server/tests/unit/db/repositories/TripAddonOverrides.repository.test.ts b/server/tests/unit/db/repositories/TripAddonOverrides.repository.test.tsindex 357405921..4fbb2bc1f 100644--- a/server/tests/unit/db/repositories/TripAddonOverrides.repository.test.ts+++ b/server/tests/unit/db/repositories/TripAddonOverrides.repository.test.ts@@ -130,4 +130,14 @@ describe('TripAddonOverridesRepository', () => {await deleteRows(t, Trips, { id: trip.id });expect(await countRows(t, TripAddonOverrides, { trip: trip.id })).toBe(0);});++ it('TAOREPO-010: anyEnabled sees any trip that switched the addon on, and none that switched it off', async () => {+ const { trip } = await ownerAndTrip();+ const { trip: other } = await ownerAndTrip();+ await repo.upsertOverride(trip.id, 'tours', false);+ expect(await repo.anyEnabled('tours')).toBe(false);+ await repo.upsertOverride(other.id, 'tours', true);+ expect(await repo.anyEnabled('tours')).toBe(true);+ expect(await repo.anyEnabled('roadtrip')).toBe(false);+ });});diff --git a/server/tests/unit/nest/notification-preferences.service.test.ts b/server/tests/unit/nest/notification-preferences.service.test.tsindex 998675e95..fee7fb768 100644--- a/server/tests/unit/nest/notification-preferences.service.test.ts+++ b/server/tests/unit/nest/notification-preferences.service.test.ts@@ -502,6 +502,27 @@ describe('listed events follow the features that are on', () => {}});+ it('NPREF-LIST-004: the admin matrix lists the paddle region request while any trip has Tours on, not only on a trip of the admin', async () => {+ const { user: admin } = createAdmin(testDb);+ const all = { ...features };+ Object.assign(features, {+ isAddonEnabled: async (id: string) => id !== 'tours',+ isEnabledForUserAnywhere: async () => false,+ isEnabledAnywhere: async (id: string) => id === 'tours',+ });+ try {+ expect((await svc.getPreferencesMatrix(admin.id, 'admin', 'admin')).event_types).toContain(+ 'paddle_region_requested',+ );+ Object.assign(features, { isEnabledAnywhere: async () => false });+ expect((await svc.getPreferencesMatrix(admin.id, 'admin', 'admin')).event_types).not.toContain(+ 'paddle_region_requested',+ );+ } finally {+ Object.assign(features, all);+ }+ });+it('NPREF-LIST-002: the flight events are listed only while live flight status is on', async () => {const flights = ['flight_departed', 'flight_delayed', 'flight_landed'];const { user } = createUser(testDb);diff --git a/server/tests/unit/nest/trip-addons.service.test.ts b/server/tests/unit/nest/trip-addons.service.test.tsindex a133474f5..7346880fa 100644--- a/server/tests/unit/nest/trip-addons.service.test.ts+++ b/server/tests/unit/nest/trip-addons.service.test.ts@@ -132,6 +132,19 @@ describe('TripAddonsService: routes without a trip', () => {expect(await addons.isEnabledForUserAnywhere(owner.id, 'no_such_addon')).toBe(false);});+ it('TRIPADDON-SVC-015: isEnabledAnywhere opens for any trip that switched the addon on, whoever owns it', async () => {+ const { owner, trip } = await ownedTrip();+ await setAddonEnabled(orm(), 'tours', false);+ expect(await addons.isEnabledAnywhere('tours')).toBe(false);+ await svc.setTripOverride(trip.id, owner.id, 'tours', true);+ expect(await addons.isEnabledAnywhere('tours')).toBe(true);+ await setAddonEnabled(orm(), 'vacay', false);+ expect(await addons.isEnabledAnywhere('vacay')).toBe(false);+ expect(await addons.isEnabledAnywhere('no_such_addon')).toBe(false);+ await setAddonEnabled(orm(), 'roadtrip', true);+ expect(await addons.isEnabledAnywhere('roadtrip')).toBe(true);+ });+it('TRIPADDON-SVC-013: tripsWithAddon keeps the trips the addon applies to, in their order, each as isEnabledForTrip says', async () => {const { owner, trip: off } = await ownedTrip();const on = await makeTrip(orm(), owner.id);