fix(ci): repair Journey route registration and shared client behavior

Register the public view route, align generated entities and test fixtures, and share the scoped reads and access switches. Keep gallery and notification writes in order, and submit the email subscription from the dialog footer.
This commit is contained in:
Maurice
2026-11-30 17:32:50 +01:00
parent 6d14eb6677
commit 0c08a6dcb9
50 changed files with 531 additions and 417 deletions
@@ -21,9 +21,9 @@ export const JourneyShareSubscribersSchema = defineEntity({
class: JourneyShareSubscribers,
repository: () => JourneyShareSubscribersRepository,
uniques: [
{ properties: ['confirm_token'] },
{ properties: ['unsubscribe_token'] },
{ properties: ['shareToken', 'email'] },
{ properties: ['unsubscribe_token'] },
{ properties: ['confirm_token'] },
],
properties: {
id: p.integer().primary(),
@@ -133,6 +133,7 @@ export const PUBLIC_ROUTE_ALLOW_LIST: string[] = [
'JourneyPublicController.mapLayers',
'JourneyPublicController.photo',
'JourneyPublicController.unlock',
'JourneyPublicController.view',
// Share-token validated too: the comments and following a shared journey by email (#1702, #1669).
'JourneyPublicSocialController.addComment',
'JourneyPublicSocialController.listComments',
@@ -8,6 +8,7 @@ import type { JourneyShareSubscribersRepository } from '../../db/repositories/Jo
import type { JourneyShareTokensRepository } from '../../db/repositories/JourneyShareTokens.repository';
import type { JourneysRepository } from '../../db/repositories/Journeys.repository';
import { dbNow } from '../../db/types';
import { forEachInOrder } from '../../utils/for-each-in-order';
import { AddonsService } from '../addons/addons.service';
import { logError } from '../audit/audit-log.logger';
import { MailerService } from '../notifications/mailer/mailer.service';
@@ -80,7 +81,8 @@ export class JourneyDigestService {
const forgetBefore = dbNow(new Date(now.getTime() - UNCONFIRMED_KEEP_MS));
result.purged = await this.subscribersRepo.purgeUnconfirmed(forgetBefore);
const canMail = await this.mailer.isSmtpConfigured();
for (const journeyId of await this.entriesRepo.listJourneysToAnnounce()) {
const journeyIds = await this.entriesRepo.listJourneysToAnnounce();
await forEachInOrder(journeyIds, async (journeyId) => {
try {
const done = await this.announce(journeyId, now, canMail);
result.journeys += 1;
@@ -89,7 +91,7 @@ export class JourneyDigestService {
} catch (err) {
logError(`[journey-digest] journey ${journeyId}: ${message(err)}`);
}
}
});
return result;
}
@@ -107,8 +109,9 @@ export class JourneyDigestService {
/** Everyone on the journey, unless every new entry is their own. */
private async notifyPeople(journeyId: number, title: string, entries: JourneyEntryToAnnounce[]): Promise<number> {
let notified = 0;
for (const userId of await this.journeysRepo.listRecipientUserIds(journeyId)) {
if (!entries.some((e) => e.author_id !== userId)) continue;
const recipients = await this.journeysRepo.listRecipientUserIds(journeyId);
await forEachInOrder(recipients, async (userId) => {
if (!entries.some((e) => e.author_id !== userId)) return;
try {
await this.notifications.send({
event: 'journey_entry_published',
@@ -121,7 +124,7 @@ export class JourneyDigestService {
} catch (err) {
logError(`[journey-digest] notifying user ${userId}: ${message(err)}`);
}
}
});
return notified;
}
@@ -144,7 +147,7 @@ export class JourneyDigestService {
// what the password guards. They only hear that there is something new.
const named = link.password_hash ? [] : entries;
const mailed: number[] = [];
for (const follower of due) {
await forEachInOrder(due, async (follower) => {
const mail = digestMail(follower.locale, title, named, {
link: link.token,
unsubscribe: follower.unsubscribe_token,
@@ -152,7 +155,7 @@ export class JourneyDigestService {
if (await this.mailer.sendStandaloneEmail(follower.email, mail, unsubscribeUrl(follower.unsubscribe_token))) {
mailed.push(follower.id);
}
}
});
await this.subscribersRepo.markNotified(mailed, dbNow(now));
return mailed.length;
}
@@ -3,6 +3,7 @@ import { JourneyPhotos } from '../../db/entities/JourneyPhotos.entity';
import type { JourneyEntryPhotosRepository } from '../../db/repositories/JourneyEntryPhotos.repository';
import type { JourneyPhotoOffEntryRow, JourneyPhotosRepository } from '../../db/repositories/JourneyPhotos.repository';
import { getCountryFromCoords } from '../../utils/country-borders';
import { forEachInOrder } from '../../utils/for-each-in-order';
import { forbidden, notFound } from '../common/domain-error';
import { UnitOfWork } from '../database/unit-of-work';
import { MapsService } from '../maps/maps.service';
@@ -178,10 +179,10 @@ export class JourneyEntriesFromPhotosService {
const byPoint = new Map<string, string | null>();
const names: (string | null)[] = [];
let asked = 0;
for (const summary of summaries) {
await forEachInOrder(summaries, async (summary) => {
if (summary.lat === null || summary.lng === null) {
names.push(null);
continue;
return;
}
// About a kilometre: two groups of the same town share one lookup.
const key = `${summary.lat.toFixed(2)},${summary.lng.toFixed(2)}`;
@@ -196,7 +197,7 @@ export class JourneyEntriesFromPhotosService {
byPoint.set(key, found);
}
names.push(byPoint.get(key) ?? null);
}
});
return names;
}
@@ -232,7 +233,7 @@ export class JourneyEntriesFromPhotosService {
const claimed = new Set<number>();
const skipped: number[] = [];
const written: Array<{ entry: CreatedEntry; photoCount: number }> = [];
for (const group of request.groups) {
await forEachInOrder(request.groups, async (group) => {
const photos: LocalCapture[] = [];
for (const id of group.photoIds) {
const capture = captures.get(id);
@@ -243,7 +244,7 @@ export class JourneyEntriesFromPhotosService {
claimed.add(id);
photos.push(capture);
}
if (!photos.length) continue;
if (!photos.length) return;
const summary = summarizeCluster(photos);
const countryCode = countryOf(summary.lat, summary.lng);
const entry = await this.journeys.createEntry(
@@ -265,22 +266,22 @@ export class JourneyEntriesFromPhotosService {
);
if (!entry) throw forbidden('Not allowed');
const now = Date.now();
for (const [index, photoId] of summary.photoIds.entries()) {
await forEachInOrder(summary.photoIds, async (photoId, index) => {
await this.entryPhotosRepo.insertIgnore(entry.id, photoId, index, now);
}
});
written.push({ entry, photoCount: summary.photoIds.length });
}
});
return { written, skipped };
});
for (const { entry } of done.written) {
await forEachInOrder(done.written, async ({ entry }) => {
try {
await this.journeys.broadcastJourneyEvent(journeyId, 'journey:entry:created', { entry }, socketId);
} catch (err) {
// The drafts are committed. A failed notification cannot undo the write.
this.logger.warn(`draft entry event failed: ${err instanceof Error ? err.message : String(err)}`);
}
}
});
return {
entries: done.written.map(({ entry, photoCount }) => ({
id: entry.id,
+10
View File
@@ -0,0 +1,10 @@
/**
* Run one operation at a time, in input order. Used for writes sharing a
* transaction and external services that should not receive a burst.
*/
export function forEachInOrder<T>(
values: readonly T[],
visit: (value: T, index: number) => Promise<void>,
): Promise<void> {
return values.reduce((pending, value, index) => pending.then(() => visit(value, index)), Promise.resolve());
}