diff --git a/src/backend/drivers/apps/AppDriver.js b/src/backend/drivers/apps/AppDriver.js index 553eefc64..3f6475953 100644 --- a/src/backend/drivers/apps/AppDriver.js +++ b/src/backend/drivers/apps/AppDriver.js @@ -330,14 +330,11 @@ export class AppDriver extends PuterDriver { } /** - * Paged app listing. Unlike `/query/app`, which answers only for apps named - * by the caller and so must not confirm ones it may not see, this is the - * listing surface a launcher reads: `protected` apps are filtered by the - * permission check below, and everything else is listable by design. Narrow - * it with `predicate: ['user-can-edit']` to the caller's own. + * Paged listing of the caller's own apps. Apps owned by anyone else are + * reachable only by name or uid, through `read` and `/query/app`. */ async select(args = {}) { - const { predicate, params = {} } = args; + const { params = {} } = args; const actor = requireContextActor(); this.#requireUserOrAppActor(actor); @@ -353,16 +350,12 @@ export class AppDriver extends PuterDriver { const includeTotal = args.includeTotal === true; const paginated = hasCursor || offset !== undefined || includeTotal; - const filters = {}; - // predicate: ['user-can-edit'] → scope to owner - const ownerScoped = - Array.isArray(predicate) && predicate[0] === 'user-can-edit'; - if (ownerScoped) { - filters.ownerUserId = actor.user.id; - } + // Always the caller's own. `predicate: ['user-can-edit']` asks for the + // same thing and is accepted for older clients. + const ownerUserId = actor.user.id; let apps = await this.appStore.list({ - ...filters, + ownerUserId, limit: paginated ? limit + 1 : limit, offset, afterId: payload?.id !== undefined ? Number(payload.id) : undefined, @@ -371,23 +364,18 @@ export class AppDriver extends PuterDriver { let cursor; if (paginated && apps.length > limit) { apps = apps.slice(0, limit); - // The cursor tracks the last fetched row, not the last visible - // one, so rows hidden by the permission filter below aren't - // re-scanned on the next page. cursor = sealCursor( { id: Number(apps[apps.length - 1].id) }, this.config.jwt_secret_v2, ); } - // Protected apps are filtered by one batched grant check; stats and - // the shared views are each one batched lookup across the page. - const visible = await this.services.app.filterReadable(apps, actor); + // Stats and the shared views are each one batched lookup per page. const [statsByUid, views] = await Promise.all([ - this.appStore.getAppsStats(visible.map((a) => a.uid)), - this.services.app.views(visible, actor), + this.appStore.getAppsStats(apps.map((a) => a.uid)), + this.services.app.views(apps, actor), ]); - const items = visible.map((app, i) => + const items = apps.map((app, i) => toAppReadView(app, views[i], { viewer: actor.user, stats: statsByUid.get(app.uid), @@ -396,14 +384,9 @@ export class AppDriver extends PuterDriver { ); if (!paginated) return items; - let total; - if (includeTotal) { - total = ownerScoped - ? await this.appStore.count({ ownerUserId: actor.user.id }) - : await this.appStore.count({ - visibleToUserId: actor.user?.id ?? null, - }); - } + const total = includeTotal + ? await this.appStore.count({ ownerUserId }) + : undefined; return { items, diff --git a/src/backend/drivers/apps/AppDriver.test.ts b/src/backend/drivers/apps/AppDriver.test.ts index ffae39e06..db94c8b75 100644 --- a/src/backend/drivers/apps/AppDriver.test.ts +++ b/src/backend/drivers/apps/AppDriver.test.ts @@ -509,7 +509,7 @@ describe('AppDriver.read', () => { // ── select ────────────────────────────────────────────────────────── describe('AppDriver.select', () => { - it('returns visible apps including those owned by other users', async () => { + it("returns only the caller's apps when no predicate is sent", async () => { const a = await makeUser(); const b = await makeUser(); const aName = uniqueName('a'); @@ -538,7 +538,7 @@ describe('AppDriver.select', () => { )) as Array>; const names = result.map((r) => r.name); expect(names).toContain(aName); - expect(names).toContain(bName); + expect(names).not.toContain(bName); }); it('predicate `user-can-edit` filters to actor-owned apps only', async () => { @@ -1670,11 +1670,10 @@ describe('AppDriver.select pagination', () => { expect(page.total).toBe(names.length); }); - it("hides other users' protected apps from paginated catalog listings", async () => { + it("pages through only the caller's apps, protected ones included", async () => { const a = await makeApps(3); - const [visible1, hidden, visible2] = a.names; const created = await withActor(a.actor, () => - driver.read({ id: { name: hidden } }), + driver.read({ id: { name: a.names[1] } }), ); const row = await server.stores.app.getByUid( (created as Record).uid as string, @@ -1685,20 +1684,29 @@ describe('AppDriver.select pagination', () => { ); await server.stores.app.invalidateByUid(row!.uid as string); - const b = await makeUser(); - const seen: string[] = []; - let cursor: string | null | undefined = null; - do { - const page = (await withActor(b.actor, () => - driver.select({ limit: 50, cursor }), - )) as { items: Array<{ name: string }>; cursor?: string }; - seen.push(...page.items.map((r) => r.name)); - cursor = page.cursor; - } while (cursor); + const listAll = async (actor: Actor) => { + const seen: string[] = []; + let total: number | undefined; + let cursor: string | null | undefined = null; + do { + const page = (await withActor(actor, () => + driver.select({ limit: 2, cursor, includeTotal: true }), + )) as { + items: Array<{ name: string }>; + cursor?: string; + total?: number; + }; + seen.push(...page.items.map((r) => r.name)); + total ??= page.total; + cursor = page.cursor; + } while (cursor); + return { seen, total }; + }; - expect(seen).toContain(visible1); - expect(seen).toContain(visible2); - expect(seen).not.toContain(hidden); + expect(await listAll(a.actor)).toEqual({ seen: a.names, total: 3 }); + + const b = await makeUser(); + expect(await listAll(b.actor)).toEqual({ seen: [], total: 0 }); }); }); @@ -2517,22 +2525,6 @@ describe('AppDriver.select query-count regression', () => { // -- select / read parity -- describe('AppDriver.select / read parity', () => { - const findViaBroadSelect = async ( - actor: Actor, - uid: string, - ): Promise | undefined> => { - let cursor: string | null | undefined = null; - do { - const page = (await withActor(actor, () => - driver.select({ limit: 50, cursor }), - )) as { items: Array>; cursor?: string }; - const found = page.items.find((r) => r.uid === uid); - if (found) return found; - cursor = page.cursor; - } while (cursor); - return undefined; - }; - it('every select item (minus stats) deep-equals the corresponding read', async () => { const { actor } = await makeUser(); const names: string[] = []; @@ -2640,7 +2632,7 @@ describe('AppDriver.select / read parity', () => { ).toBe(false); }); - it('dangling hosted app via select: owner keeps index_url, others do not', async () => { + it('dangling hosted app: owner keeps index_url in select, others do not in read', async () => { const owner = await makeUser(); const other = await makeUser(); const sub = uniqueName('qcdangsel'); @@ -2672,13 +2664,12 @@ describe('AppDriver.select / read parity', () => { ?.reason, ).toBe('hosted_backing_unavailable'); - const otherItem = await findViaBroadSelect( - other.actor, - created.uid as string, - ); - expect(otherItem?.index_url).toBeUndefined(); + const otherItem = (await withActor(other.actor, () => + driver.read({ uid: created.uid }), + )) as Record; + expect(otherItem.index_url).toBeUndefined(); expect( - (otherItem?.privateAccess as { hasAccess?: boolean } | undefined) + (otherItem.privateAccess as { hasAccess?: boolean } | undefined) ?.hasAccess, ).toBe(false); }); diff --git a/src/backend/stores/app/AppStore.js b/src/backend/stores/app/AppStore.js index 9ded273c1..6c4a79451 100644 --- a/src/backend/stores/app/AppStore.js +++ b/src/backend/stores/app/AppStore.js @@ -686,12 +686,7 @@ export class AppStore extends PuterStore { return apps; } - /** - * Count apps matching the same equality filters as `list`. - * `visibleToUserId` counts the public catalog for one caller — - * non-protected apps plus their own; apps visible only via explicit - * permission grants are not included. - */ + /** Count apps matching the same equality filters as `list`. */ async count(filters = {}) { const where = []; const params = []; @@ -704,12 +699,6 @@ export class AppStore extends PuterStore { where.push('`app_owner` = ?'); params.push(filters.appOwner); } - if (filters.visibleToUserId !== undefined) { - where.push( - '(`protected` IS NULL OR `protected` = false OR `owner_user_id` = ?)', - ); - params.push(filters.visibleToUserId); - } const whereClause = where.length ? `WHERE ${where.join(' AND ')}` : ''; const rows = await this.clients.db.read( diff --git a/src/backend/stores/app/AppStore.test.js b/src/backend/stores/app/AppStore.test.js index 1f89f4696..ab37ee9ac 100644 --- a/src/backend/stores/app/AppStore.test.js +++ b/src/backend/stores/app/AppStore.test.js @@ -1292,31 +1292,14 @@ describe('AppStore CRUD and cache invalidation', () => { ).toBe('Bumped'); }); - it('counts apps by owner, creator and per-caller visibility', async () => { + it('counts apps by owner and creator', async () => { const countOwner = 4600; - const viewer = 4601; const open = await createApp({}, { ownerUserId: countOwner }); await createApp({}, { ownerUserId: countOwner, appOwner: open.id }); - const hidden = await createApp({}, { ownerUserId: countOwner }); - await db.write('UPDATE `apps` SET `protected` = 1 WHERE `id` = ?', [ - hidden.id, - ]); + await createApp({}, { ownerUserId: countOwner }); expect(await appStore.count({ ownerUserId: countOwner })).toBe(3); expect(await appStore.count({ appOwner: open.id })).toBe(1); - - // The protected app is invisible to a stranger but visible to its - // owner. - const strangerView = await appStore.count({ - ownerUserId: countOwner, - visibleToUserId: viewer, - }); - expect(strangerView).toBe(2); - const ownerView = await appStore.count({ - ownerUserId: countOwner, - visibleToUserId: countOwner, - }); - expect(ownerView).toBe(3); }); // -- filetype association batch + recent opens ----------------------