feat: bitwise RBAC engine with channel-level permission overrides
Replace string-based role checks (role === 'admin') with a bitwise BigInt permission system. Adds computePermissions() resolution engine following Discord's model: @everyone base → role union → admin shortcut → channel overrides (role deny/allow → member deny/allow). Ready payload now filters channels by VIEW_CHANNEL and attaches per-user myPermissions to each server and channel. Includes channel_overrides table, @everyone role auto-creation, migration for existing servers, and override CRUD API.
This commit is contained in:
@@ -140,6 +140,16 @@ export const memberRoles = sqliteTable('member_roles', {
|
||||
pk: primaryKey({ columns: [table.serverId, table.userId, table.roleId] }),
|
||||
}));
|
||||
|
||||
export const channelOverrides = sqliteTable('channel_overrides', {
|
||||
channelId: text('channel_id').notNull().references(() => channels.id, { onDelete: 'cascade' }),
|
||||
targetType: text('target_type').notNull(), // 'role' | 'member'
|
||||
targetId: text('target_id').notNull(), // role ID or user ID
|
||||
allow: text('allow').notNull().default('0'), // BigInt decimal string
|
||||
deny: text('deny').notNull().default('0'), // BigInt decimal string
|
||||
}, (table) => ({
|
||||
pk: primaryKey({ columns: [table.channelId, table.targetType, table.targetId] }),
|
||||
}));
|
||||
|
||||
export const readStates = sqliteTable('read_states', {
|
||||
userId: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
|
||||
channelId: text('channel_id').notNull(),
|
||||
|
||||
Reference in New Issue
Block a user