mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
Managed mode: hand place search, routing, plugins and docs to the operator
On a managed install the operator runs place search and routing, the plugin runtime, the integrations and the documentation, so the admin and the users no longer see switches and guides for them: - The place search and routing card, the transit provider and the search log are gone from the admin settings (desktop and mobile). places_provider is a managed-locked setting, and the transit provider, search log and wanderer routes refuse writes there. Share place details stays the admin's, as a card of its own, hidden when TREK_PLACES_CONTRIBUTE switches it off. - File types and trip reminders move to the right column, so the columns stay balanced. - Plugins disappear from the admin and the user settings, wanderer from Tours. - The Help & Docs page and its links are not offered. The help center stays and leaves out guides about what the operator runs (keys, OIDC, backups, storage, releases, plugins, document sync) and about integrations that are off. - Mapbox GL is offered only with the operator's token, Amap tiles only where the operator set Amap up. - The mobile admin no longer shows OIDC and the WebAuthn relying party fields, matching the desktop tab. For every install: - Notification matrices list only events the install can raise: no plugin row without the plugin runtime, no Vacay, collection, photo, Synology, wanderer or packing rows while those are off. On a managed install the release and replica alerts are left out. - The journey entry editor offers External photos only where a photo provider is switched on, as the phone already did. - app-config is asked again after a failed answer. A page opened while the server restarted kept every default for the session, which on a managed install brought back the operator's settings.
This commit is contained in:
@@ -114,6 +114,12 @@ export class AddonsService {
|
||||
return this.writeFlag('ski_routing_enabled', enabled);
|
||||
}
|
||||
|
||||
/** The photo providers users can connect: none while the journey addon is off. */
|
||||
async enabledPhotoProviderIds(): Promise<string[]> {
|
||||
if (!(await this.isAddonEnabled(ADDON_IDS.JOURNEY))) return [];
|
||||
return (await this.photoProviders.listEnabled()).map((row) => row.id);
|
||||
}
|
||||
|
||||
/** wanderer may be used: Tours is on and the admin allowed it under Tours. */
|
||||
async isWandererAvailable(): Promise<boolean> {
|
||||
return (await this.isAddonEnabled(ADDON_IDS.TOURS)) && (await this.getToursWanderer()).enabled;
|
||||
|
||||
@@ -293,6 +293,7 @@ export class AdminController {
|
||||
|
||||
@Put('tours-wanderer')
|
||||
@ResponseContract(adminFeatureToggleResponseSchema)
|
||||
@ManagedForbidden('wanderer sends searches to a server the user picks, which the operator has not agreed to')
|
||||
async updateToursWanderer(@CurrentUser() user: User, @Body() body: AdminFeatureToggleDto, @Req() req: Request) {
|
||||
const result = await this.addons.updateToursWanderer(body.enabled);
|
||||
await this.audit.writeAudit({
|
||||
@@ -418,6 +419,7 @@ export class AdminController {
|
||||
}
|
||||
|
||||
@Put('place-shadow')
|
||||
@ManagedForbidden('place search belongs to the operator on a managed install')
|
||||
async updatePlaceShadow(@CurrentUser() user: User, @Body() body: AdminFeatureToggleDto, @Req() req: Request) {
|
||||
const result = await this.addons.updatePlaceShadow(body.enabled);
|
||||
await this.audit.writeAudit({
|
||||
@@ -491,6 +493,7 @@ export class AdminController {
|
||||
}
|
||||
|
||||
@Put('transit-provider')
|
||||
@ManagedForbidden('routing belongs to the operator on a managed install')
|
||||
async updateTransitProvider(@CurrentUser() user: User, @Body() body: AdminTransitProviderDto, @Req() req: Request) {
|
||||
const result = await this.addons.updateTransitProvider(body.provider, user.id);
|
||||
await this.audit.writeAudit({
|
||||
|
||||
@@ -89,7 +89,7 @@ export const APP_SETTINGS = {
|
||||
webauthn_origins: { schema: text, default: null, adminForm: true, managedLocked: true },
|
||||
// 'auto' (what every install had before Amap existed), 'google', 'amap' or
|
||||
// 'openstreetmap'; the maps domain validates it (isPlacesProviderChoice).
|
||||
places_provider: { schema: text, default: 'auto', adminForm: true, publicConfig: true },
|
||||
places_provider: { schema: text, default: 'auto', adminForm: true, publicConfig: true, managedLocked: true },
|
||||
|
||||
// Read by name elsewhere.
|
||||
oidc_issuer: { schema: text, default: null, env: (e) => e.oidc.issuer, publicConfig: true },
|
||||
|
||||
@@ -91,6 +91,9 @@ export const MANAGED_LOCKED_SETTING_KEYS = [
|
||||
'oidc_login',
|
||||
'oidc_registration',
|
||||
'openweather_api_key',
|
||||
// Place search and routing are the operator's on a managed install: the
|
||||
// services, their allowance and who answers come with the instance.
|
||||
'places_provider',
|
||||
'routing_base_url',
|
||||
'routing_valhalla_provider',
|
||||
// The operator issues a managed install its key through TREK_SERVICES_KEY.
|
||||
@@ -149,10 +152,6 @@ export const MANAGED_CUSTOMER_KEYS = [
|
||||
'passkey_login',
|
||||
'password_login',
|
||||
'password_registration',
|
||||
// WHICH provider answers place search stays the admin's call even when the
|
||||
// operator owns both credentials: it decides what their users see, not what
|
||||
// the operator is billed for — the keys above cover that.
|
||||
'places_provider',
|
||||
'require_mfa',
|
||||
'temperature_unit',
|
||||
'time_format',
|
||||
|
||||
@@ -64,6 +64,9 @@ export function collectManagedRoutes(app: INestApplication): ManagedRouteEntry[]
|
||||
*/
|
||||
export const MANAGED_ROUTE_ALLOW_LIST: string[] = [
|
||||
'AdminController.rotateJwtSecret',
|
||||
'AdminController.updatePlaceShadow',
|
||||
'AdminController.updateToursWanderer',
|
||||
'AdminController.updateTransitProvider',
|
||||
'AdminOidcController.get',
|
||||
'AdminOidcController.update',
|
||||
'AiAdminController.connection',
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { ADDON_IDS } from '../../addons';
|
||||
import { readEnv } from '../../app-config';
|
||||
import { AppSettings } from '../../db/entities/AppSettings.entity';
|
||||
import { NotificationChannelPreferences } from '../../db/entities/NotificationChannelPreferences.entity';
|
||||
import type { AppSettingsRepository } from '../../db/repositories/AppSettings.repository';
|
||||
import type { NotificationChannelPreferencesRepository } from '../../db/repositories/NotificationChannelPreferences.repository';
|
||||
import { AddonsService } from '../addons/addons.service';
|
||||
import { readAppSetting } from '../common/app-settings.registry';
|
||||
import { UnitOfWork } from '../database/unit-of-work';
|
||||
import { listChannels } from './channel-registry';
|
||||
@@ -60,6 +63,21 @@ const DEFAULT_KEY = (event: string, channel: string) => `notif_default_${event}_
|
||||
* 3-column composite primary key (`user`, `event_type`, `channel`) via
|
||||
* `em.upsert({ onConflictFields: [...] })`, per Task 0's R5 pin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The events this install can actually raise, for the preference matrices.
|
||||
* Plugin notifications need the plugin runtime; on a managed install the
|
||||
* release check and the storage replicas are the operator's, so their alerts
|
||||
* would be rows nobody there can act on.
|
||||
*/
|
||||
export function offeredEventTypes(): NotifEventType[] {
|
||||
const env = readEnv();
|
||||
return ALL_EVENT_TYPES.filter((e) => {
|
||||
if (e === 'plugin_notification') return env.plugins.enabled;
|
||||
if (e === 'version_available' || e === 'replica_failure') return !env.managed.enabled;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@Injectable()
|
||||
export class NotificationPreferencesService {
|
||||
constructor(
|
||||
@@ -68,8 +86,57 @@ export class NotificationPreferencesService {
|
||||
@InjectRepository(AppSettings) private readonly appSettings: AppSettingsRepository,
|
||||
@InjectRepository(NotificationChannelPreferences)
|
||||
private readonly channelPrefs: NotificationChannelPreferencesRepository,
|
||||
private readonly addons: AddonsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* The events the matrices list: what the install can raise at all
|
||||
* (offeredEventTypes), narrowed to the features that are switched on. A row
|
||||
* for vacation sharing on an install without Vacay, or for Synology without
|
||||
* the provider, is a switch that never does anything.
|
||||
*/
|
||||
private async listedEventTypes(): Promise<NotifEventType[]> {
|
||||
const photoProviders = await this.addons.enabledPhotoProviderIds();
|
||||
const addonOn = new Map<string, boolean>();
|
||||
const on = async (id: string) => {
|
||||
if (!addonOn.has(id)) addonOn.set(id, await this.addons.isAddonEnabled(id));
|
||||
return addonOn.get(id) === true;
|
||||
};
|
||||
const listed: NotifEventType[] = [];
|
||||
for (const event of offeredEventTypes()) {
|
||||
if (await this.featureOn(event, on, photoProviders)) listed.push(event);
|
||||
}
|
||||
return listed;
|
||||
}
|
||||
|
||||
private async featureOn(
|
||||
event: NotifEventType,
|
||||
on: (addonId: string) => Promise<boolean>,
|
||||
photoProviders: string[],
|
||||
): Promise<boolean> {
|
||||
switch (event) {
|
||||
case 'vacay_invite':
|
||||
case 'vacay_share':
|
||||
return on(ADDON_IDS.VACAY);
|
||||
case 'collection_invite':
|
||||
return on(ADDON_IDS.COLLECTIONS);
|
||||
case 'collab_message':
|
||||
return on(ADDON_IDS.COLLAB);
|
||||
case 'packing_tagged':
|
||||
return on(ADDON_IDS.PACKING);
|
||||
case 'paddle_region_requested':
|
||||
return on(ADDON_IDS.TOURS);
|
||||
case 'photos_shared':
|
||||
return photoProviders.length > 0;
|
||||
case 'synology_session_cleared':
|
||||
return photoProviders.includes('synologyphotos');
|
||||
case 'wanderer_source_hint':
|
||||
return this.addons.isWandererAvailable();
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Channels implemented for an event. In-app takes everything; external channels
|
||||
* decide for themselves (today: everything except `synology_session_cleared`).
|
||||
@@ -151,12 +218,12 @@ export class NotificationPreferencesService {
|
||||
return (NOTIFICATION_DEFAULTS as readonly string[]).includes(raw ?? '') ? (raw as NotificationDefault) : 'on';
|
||||
}
|
||||
|
||||
private userEventTypes(): NotifEventType[] {
|
||||
return ALL_EVENT_TYPES.filter((e) => !ADMIN_SCOPED_EVENTS.has(e));
|
||||
private async userEventTypes(): Promise<NotifEventType[]> {
|
||||
return (await this.listedEventTypes()).filter((e) => !ADMIN_SCOPED_EVENTS.has(e));
|
||||
}
|
||||
|
||||
async getInstanceDefaults(adminId: number): Promise<InstanceDefaultsMatrix> {
|
||||
const event_types = this.userEventTypes();
|
||||
const event_types = await this.userEventTypes();
|
||||
const implemented_combos = await this.allCombos();
|
||||
const defaults: InstanceDefaultsMatrix['defaults'] = {};
|
||||
for (const event of event_types) {
|
||||
@@ -171,7 +238,9 @@ export class NotificationPreferencesService {
|
||||
async setInstanceDefaults(
|
||||
defaults: Partial<Record<string, Partial<Record<string, NotificationDefault>>>>,
|
||||
): Promise<void> {
|
||||
const userEvents = new Set<string>(this.userEventTypes());
|
||||
// Every user event, not only the listed ones: a default set while an addon is
|
||||
// off is still the right default once it is switched on.
|
||||
const userEvents = new Set<string>(ALL_EVENT_TYPES.filter((e) => !ADMIN_SCOPED_EVENTS.has(e)));
|
||||
// The channel set is read before the transaction opens: listChannels() may
|
||||
// ask the plugin runtime, which is no work to hold the connection for.
|
||||
const combos = await this.allCombos();
|
||||
@@ -298,8 +367,8 @@ export class NotificationPreferencesService {
|
||||
// Filter event types by scope
|
||||
const event_types =
|
||||
scope === 'admin'
|
||||
? ALL_EVENT_TYPES.filter((e) => ADMIN_SCOPED_EVENTS.has(e))
|
||||
: ALL_EVENT_TYPES.filter((e) => !ADMIN_SCOPED_EVENTS.has(e));
|
||||
? (await this.listedEventTypes()).filter((e) => ADMIN_SCOPED_EVENTS.has(e))
|
||||
: (await this.listedEventTypes()).filter((e) => !ADMIN_SCOPED_EVENTS.has(e));
|
||||
|
||||
return {
|
||||
preferences,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { PushSubscriptions } from '../../db/entities/PushSubscriptions.entity';
|
||||
import { Settings } from '../../db/entities/Settings.entity';
|
||||
import { TodoItems } from '../../db/entities/TodoItems.entity';
|
||||
import { Trips } from '../../db/entities/Trips.entity';
|
||||
import { AddonsModule } from '../addons/addons.module';
|
||||
import { SchedulingModule } from '../scheduling/scheduling.module';
|
||||
import { StorageModule } from '../storage/storage.module';
|
||||
import { MailerModule } from './mailer/mailer.module';
|
||||
@@ -63,6 +64,7 @@ import { Module } from '@nestjs/common';
|
||||
PushSubscriptions,
|
||||
]),
|
||||
|
||||
AddonsModule,
|
||||
MailerModule,
|
||||
SchedulingModule,
|
||||
StorageModule,
|
||||
|
||||
Reference in New Issue
Block a user