diff --git a/cloud/firestore/firestore.default.rules b/cloud/firestore/firestore.default.rules index 11fb8776..4058215a 100644 --- a/cloud/firestore/firestore.default.rules +++ b/cloud/firestore/firestore.default.rules @@ -17,10 +17,6 @@ service cloud.firestore { allow read, write: if false; } - match /event-family-tokens/{familyId} { - allow read, write: if false; - } - match /public-tokens/{publicSecretToken} { allow get: if true; allow list, write: if false; diff --git a/cloud/firestore/firestore.default.rules.spec.ts b/cloud/firestore/firestore.default.rules.spec.ts index be53c64f..6227ab28 100644 --- a/cloud/firestore/firestore.default.rules.spec.ts +++ b/cloud/firestore/firestore.default.rules.spec.ts @@ -147,16 +147,6 @@ const FIREBASE_MANAGED_COLLECTIONS = [ data: () => ({dayId: 'monday', feedbacks: []}), updatedData: () => ({dayId: 'tuesday', feedbacks: []}) }] - }, { - name: '/event-family-tokens/{familyId}', - docInitializations: [{ - name: 'default', - collection: '/event-family-tokens', - path: '/event-family-tokens/a-family', - newDocPath: '/event-family-tokens/another-family', - data: () => ({families: ['devoxx'], token: 'ffffffff-ffff-ffff-ffff-ffffffffffff'}), - updatedData: () => ({families: ['devoxx'], token: 'ffffffff-ffff-ffff-ffff-fffffffffff0'}) - }] }, { name: '/public-tokens/{tokenId}', docInitializations: [{ @@ -692,18 +682,6 @@ const COLLECTIONS: CollectionDescriptor[] = [{ get: false, update: false, createDoc: false, }, 'alice') } -}, { - name: "/event-family-tokens", - aroundTests: (_: UserContext) => ({ - beforeEach: [], - afterEach: [], - }), - tests: (userContext: UserContext) => { - ensureCollectionFollowAccessPermissions('/event-family-tokens/{familyId}', userContext, - { - read: false, write: false - }) - } }, { name: "/public-tokens", aroundTests: (_: UserContext) => ({ diff --git a/cloud/functions/src/functions/firestore/firestore-utils.ts b/cloud/functions/src/functions/firestore/firestore-utils.ts index c059af19..0f89555a 100644 --- a/cloud/functions/src/functions/firestore/firestore-utils.ts +++ b/cloud/functions/src/functions/firestore/firestore-utils.ts @@ -31,7 +31,7 @@ export async function getSecretTokenDoc(path: string) { export async function getOrganizerSpaceByToken( eventId: string, - tokenType: 'organizerSecretToken'|'familyToken', + tokenType: 'organizerSecretToken', secretToken: string ) { const organizerSpace: ConferenceOrganizerSpace = await getSecretTokenDoc(`events/${eventId}/organizer-space`); @@ -40,13 +40,6 @@ export async function getOrganizerSpaceByToken( throw new Error(`Invalid organizer token for eventId=${eventId}: ${secretToken}`); } - if(tokenType === 'familyToken') { - const familyTokenValid = await checkEventFamilyTokenIsValid(eventId, secretToken); - if(!familyTokenValid) { - throw new Error(`Invalid family token for eventId=${eventId}: ${secretToken}`); - } - } - return organizerSpace; } @@ -132,18 +125,3 @@ export async function checkEventLastUpdate( return { cachedHash, updatesDetected: true }; } - -export async function checkEventFamilyTokenIsValid(eventId: string, token: string) { - const listableEvent = (await db.collection("events").doc(eventId).get())?.data() as ListableEvent|undefined; - - if(!listableEvent || !listableEvent.eventFamily) { - return false; - } - - const familyTokenSnapshots = await db.collection("event-family-tokens") - .where('families', 'array-contains', listableEvent.eventFamily) - .where("token", '==', token) - .get() - - return !familyTokenSnapshots.empty; -} diff --git a/cloud/functions/src/functions/firestore/migrations/020-cleaningUnusedFirestoreDocs.ts b/cloud/functions/src/functions/firestore/migrations/020-cleaningUnusedFirestoreDocs.ts new file mode 100644 index 00000000..54533992 --- /dev/null +++ b/cloud/functions/src/functions/firestore/migrations/020-cleaningUnusedFirestoreDocs.ts @@ -0,0 +1,13 @@ +import {db} from "../../../firebase"; + + +export async function cleaningUnusedFirestoreDocs(): Promise<"OK"|"Error"> { + const eventFamilyTokensColl = await db.collection(`event-family-tokens`).get() + if(!eventFamilyTokensColl.empty) { + await Promise.all(eventFamilyTokensColl.docs.map(async eventFamilyToken => { + return eventFamilyToken.ref.delete() + })) + } + + return "OK" +} diff --git a/cloud/functions/src/functions/http/event/legacy/deprecatedAttendeesFeedbacks.ts b/cloud/functions/src/functions/http/event/legacy/deprecatedAttendeesFeedbacks.ts index d507eb6f..677793f2 100644 --- a/cloud/functions/src/functions/http/event/legacy/deprecatedAttendeesFeedbacks.ts +++ b/cloud/functions/src/functions/http/event/legacy/deprecatedAttendeesFeedbacks.ts @@ -18,14 +18,12 @@ export async function legacyAttendeesFeedbacks(request: functions.https.Request, const organizerSecretToken = extractSingleQueryParam(request, 'organizerSecretToken'); const talkIds = extractMultiQueryParam(request, 'talkIds'); - // deprecated - const familyToken = extractSingleQueryParam(request, 'familyToken'); const familyOrganizerSecretToken = extractSingleQueryParam(request, 'familyOrganizerSecretToken'); const eventId = extractSingleQueryParam(request, 'eventId'); if(!talkIds || !talkIds.length) { return sendResponseMessage(response, 400, `Missing [talkIds] (multi) query parameter !`) } if(!eventId) { return sendResponseMessage(response, 400, `Missing [eventId] query parameter !`) } - if(!organizerSecretToken && !familyToken && !familyOrganizerSecretToken) { return sendResponseMessage(response, 400, `Missing either [organizerSecretToken] or [familyToken] or [familyOrganizerSecretToken] query parameter !`) } + if(!organizerSecretToken && !familyOrganizerSecretToken) { return sendResponseMessage(response, 400, `Missing either [organizerSecretToken] or [familyOrganizerSecretToken] query parameter !`) } const eventDescriptor = await getEventDescriptor(eventId); if(familyOrganizerSecretToken) { @@ -48,13 +46,11 @@ export async function legacyAttendeesFeedbacks(request: functions.https.Request, // } try { - const organizerSpace = await match([organizerSecretToken, familyToken, familyOrganizerSecretToken]) - .with([ P.nullish, P.nullish, P.nullish ], async ([_1, _2]) => { throw new Error(`Unexpected state: (undefined,undefined)`); }) - .with([ P.not(P.nullish), P.any, P.any ], async ([organizerSecretToken, _]) => { + const organizerSpace = await match([organizerSecretToken, familyOrganizerSecretToken]) + .with([ P.nullish, P.nullish ], async ([_1, _2]) => { throw new Error(`Unexpected state: (undefined,undefined)`); }) + .with([ P.not(P.nullish), P.any ], async ([organizerSecretToken, _]) => { return getOrganizerSpaceByToken(eventId, 'organizerSecretToken', organizerSecretToken); - }).with([ P.any, P.not(P.nullish), P.any ], async ([_, familyToken]) => { - return getOrganizerSpaceByToken(eventId, 'familyToken', familyToken); - }).with([ P.any, P.any, P.not(P.nullish) ], async ([_1, _2, familyOrganizerSecretToken]) => { + }).with([ P.any, P.not(P.nullish) ], async ([_1]) => { return getSecretTokenDoc(`/events/${eventId}/organizer-space`); }).run() diff --git a/cloud/functions/src/functions/http/event/legacy/deprecatedEventStats.ts b/cloud/functions/src/functions/http/event/legacy/deprecatedEventStats.ts index 17ea8ea4..e60451ea 100644 --- a/cloud/functions/src/functions/http/event/legacy/deprecatedEventStats.ts +++ b/cloud/functions/src/functions/http/event/legacy/deprecatedEventStats.ts @@ -12,11 +12,10 @@ import * as express from "express"; export async function deprecatedEventStats(request: functions.https.Request, response: express.Response) { const organizerSecretToken = extractSingleQueryParam(request, 'organizerSecretToken'); - const familyToken = extractSingleQueryParam(request, 'familyToken'); const eventId = extractSingleQueryParam(request, 'eventId'); if(!eventId) { return sendResponseMessage(response, 400, `Missing [eventId] query parameter !`) } - if(!organizerSecretToken && !familyToken) { return sendResponseMessage(response, 400, `Missing either [organizerSecretToken] or [familyToken] query parameter !`) } + if(!organizerSecretToken) { return sendResponseMessage(response, 400, `Missing either [organizerSecretToken] or [familyToken] query parameter !`) } const { cachedHash, updatesDetected } = await checkEventLastUpdate(eventId, [ root => root.favorites, @@ -27,12 +26,10 @@ export async function deprecatedEventStats(request: functions.https.Request, res } try { - const organizerSpace = await match([organizerSecretToken, familyToken]) - .with([ P.nullish, P.nullish ], async ([_1, _2]) => { throw new Error(`Unexpected state: (undefined,undefined)`); }) - .with([ P.not(P.nullish), P.any ], async ([organizerSecretToken, _]) => { + const organizerSpace = await match([organizerSecretToken]) + .with([ P.nullish ], async ([_1]) => { throw new Error(`Unexpected state: (undefined,undefined)`); }) + .with([ P.not(P.nullish) ], async ([organizerSecretToken]) => { return getOrganizerSpaceByToken(eventId, 'organizerSecretToken', organizerSecretToken); - }).with([ P.any, P.not(P.nullish) ], async ([_, familyToken]) => { - return getOrganizerSpaceByToken(eventId, 'familyToken', familyToken); }).run() const talksStats = await eventTalkStatsFor(eventId); diff --git a/cloud/functions/src/functions/http/migrateFirestoreSchema.ts b/cloud/functions/src/functions/http/migrateFirestoreSchema.ts index be655be5..ccf15b12 100644 --- a/cloud/functions/src/functions/http/migrateFirestoreSchema.ts +++ b/cloud/functions/src/functions/http/migrateFirestoreSchema.ts @@ -28,6 +28,7 @@ const MIGRATIONS: Migration[] = [ { name: "migrateFamilyEventsStatsAccessTokenTypes", exec: async () => (await import("../firestore/migrations/017-migrateSomePublicTokenTypes")).migrateFamilyEventsStatsAccessTokenTypes() }, { name: "introduceTalkAssets", exec: async () => (await import("../firestore/migrations/018-introduceTalkAssets")).introduceTalkAssets() }, { name: "introduceFormattingsFeature", exec: async () => (await import("../firestore/migrations/019-introduceFormattingsFeature")).introduceFormattingsFeature() }, + { name: "cleaningUnusedFirestoreDocs", exec: async () => (await import("../firestore/migrations/020-cleaningUnusedFirestoreDocs")).cleaningUnusedFirestoreDocs() }, ]; export type MigrationResult = "OK"|"Error";