a3aff9fa49
- add `src/core/modules/` with registry, discovery (server), and public index - add `src/core/public-pages/` with registry, server component, and public index - add `src/core/users/permissions-registry.js` for runtime permission registration - expose `./modules`, `./public-pages`, and `./public-pages/server` package exports - rename `registerFeatureRoutes` to `registerApiRoutes` with backward-compatible alias - extend `seedDefaultRolesAndPermissions` to include module-registered permissions - update `initializeZen` and shared init to wire module discovery and registration - add `docs/MODULES.md` documenting the `@zen/module-*` authoring contract - update `docs/DEV.md` with references to module system docs
33 lines
951 B
JavaScript
33 lines
951 B
JavaScript
import { query } from '@zen/core/database';
|
|
export { PERMISSIONS, PERMISSION_DEFINITIONS, getPermissionGroups } from './constants.js';
|
|
export {
|
|
registerPermission,
|
|
registerPermissions,
|
|
getRegisteredPermissions,
|
|
getRegisteredPermissionKeys,
|
|
} from './permissions-registry.js';
|
|
|
|
export async function hasPermission(userId, permissionKey) {
|
|
const result = await query(
|
|
`SELECT 1
|
|
FROM zen_auth_user_roles ur
|
|
JOIN zen_auth_role_permissions rp ON rp.role_id = ur.role_id
|
|
WHERE ur.user_id = $1
|
|
AND rp.permission_key = $2
|
|
LIMIT 1`,
|
|
[userId, permissionKey]
|
|
);
|
|
return result.rows.length > 0;
|
|
}
|
|
|
|
export async function getUserPermissions(userId) {
|
|
const result = await query(
|
|
`SELECT DISTINCT rp.permission_key
|
|
FROM zen_auth_user_roles ur
|
|
JOIN zen_auth_role_permissions rp ON rp.role_id = ur.role_id
|
|
WHERE ur.user_id = $1`,
|
|
[userId]
|
|
);
|
|
return result.rows.map(r => r.permission_key);
|
|
}
|