feat(page-data): add private and public dataset API (phase 1-3)
Extract UserDataSpaceService for shared SQLite access, wire logged-in Page Data routes, and add public insert plus password-token read/update/delete with policy storage, rate limits, and regression tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
buildEffectiveDataset,
|
||||
normalizePageAccessPolicy,
|
||||
policyAllowsAction,
|
||||
} from './page-access-policy.mjs';
|
||||
|
||||
test('normalizePageAccessPolicy validates access mode and datasets', () => {
|
||||
const policy = normalizePageAccessPolicy(
|
||||
{
|
||||
pageId: 'page-1',
|
||||
ownerUserId: 'user-1',
|
||||
accessMode: 'public',
|
||||
datasets: {
|
||||
registrations: {
|
||||
insert: true,
|
||||
columns: { insert: ['name', 'phone'] },
|
||||
},
|
||||
},
|
||||
},
|
||||
{ fallbackPageId: 'page-1', fallbackOwnerUserId: 'user-1' },
|
||||
);
|
||||
assert.equal(policy.accessMode, 'public');
|
||||
assert.equal(policy.datasets.registrations.insert, true);
|
||||
assert.equal(policy.datasets.registrations.read, false);
|
||||
});
|
||||
|
||||
test('buildEffectiveDataset intersects registry actions with policy permissions', () => {
|
||||
const effective = buildEffectiveDataset(
|
||||
{
|
||||
name: 'registrations',
|
||||
table: 'form_registrations',
|
||||
description: '报名',
|
||||
actions: ['read', 'insert', 'update', 'soft_delete'],
|
||||
columns: {
|
||||
read: ['id', 'name', 'phone', 'secret'],
|
||||
insert: ['name', 'phone', 'secret'],
|
||||
update: ['status'],
|
||||
soft_delete: ['id'],
|
||||
},
|
||||
},
|
||||
{
|
||||
read: false,
|
||||
insert: true,
|
||||
update: false,
|
||||
softDelete: false,
|
||||
columns: { insert: ['name', 'phone'] },
|
||||
},
|
||||
);
|
||||
assert.deepEqual(effective.actions, ['insert']);
|
||||
assert.deepEqual(effective.columns.insert, ['name', 'phone']);
|
||||
});
|
||||
|
||||
test('policyAllowsAction respects per-dataset flags', () => {
|
||||
const policy = normalizePageAccessPolicy({
|
||||
pageId: 'page-1',
|
||||
ownerUserId: 'user-1',
|
||||
accessMode: 'password',
|
||||
datasets: {
|
||||
ledger: { read: true, insert: true, update: true, softDelete: true, columns: {} },
|
||||
},
|
||||
});
|
||||
assert.equal(policyAllowsAction(policy, 'ledger', 'read'), true);
|
||||
assert.equal(policyAllowsAction(policy, 'ledger', 'insert'), true);
|
||||
assert.equal(policyAllowsAction(policy, 'missing', 'read'), false);
|
||||
});
|
||||
Reference in New Issue
Block a user