refactor: events to a pure stream instead of being part of topics
NOTE: tests are passing, but the client is broken
This commit is contained in:
parent
c34069066d
commit
a5707e2f81
31 changed files with 934 additions and 686 deletions
30
utils/object_helpers.ts
Normal file
30
utils/object_helpers.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
export function flatten(obj: Record<string, any>, path?: string, result?: Record<string, any>) {
|
||||
result = result ?? {};
|
||||
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (typeof value === 'object') {
|
||||
flatten(value, (path ?? '') + key + '.', result);
|
||||
} else {
|
||||
result[(path ?? '') + key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function expand(obj: Record<string, any>) {
|
||||
const result: Record<string, any> = {};
|
||||
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
const elements = key.split('.');
|
||||
|
||||
let current = result;
|
||||
for (const element of elements.slice(0, elements.length - 1)) {
|
||||
current[element] = current[element] ?? {};
|
||||
current = current[element];
|
||||
}
|
||||
current[elements[elements.length - 1]] = value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
import { getCookies } from '@std/http/cookie';
|
||||
import { SESSIONS } from '../models/session.ts';
|
||||
import { verifyTotp } from './totp.ts';
|
||||
import { USERS } from '../models/user.ts';
|
||||
import { USER, USERS } from '../models/user.ts';
|
||||
import * as CANNED_RESPONSES from './canned_responses.ts';
|
||||
import { EVENT } from '../models/event.ts';
|
||||
|
||||
export type PRECHECK = (req: Request, meta: Record<string, any>) => Promise<Response | undefined> | Response | undefined;
|
||||
export type PRECHECK_TABLE = Record<string, PRECHECK[]>;
|
||||
|
|
@ -41,3 +42,7 @@ export function require_user(
|
|||
return CANNED_RESPONSES.permission_denied();
|
||||
}
|
||||
}
|
||||
|
||||
export function user_has_write_permission_for_event(user: USER, event: EVENT) {
|
||||
return user.permissions.includes('events.create.' + event.type) || (Deno.env.get('DENO_ENV') === 'test' && event.type === 'test');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue