mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-15 23:00:45 +08:00
feat: add unified IM access policies
This commit is contained in:
parent
075d2713c1
commit
840e5aa857
89 changed files with 5573 additions and 1676 deletions
35
test/channels/access-policy-fixture.mjs
Normal file
35
test/channels/access-policy-fixture.mjs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
export { COMMAND_PERMISSION_DENIED_MESSAGE } from '../../src/channels/shared/inbound-access.mjs';
|
||||
|
||||
function scope(users = []) {
|
||||
return {
|
||||
mode: 'allowlist',
|
||||
open: {
|
||||
defaultCanExecuteCommands: false,
|
||||
commandPermissionOverrides: [],
|
||||
},
|
||||
allowlist: {
|
||||
users: users.map(({ id, canExecuteCommands = false }) => ({
|
||||
id,
|
||||
canExecuteCommands,
|
||||
})),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function directAccessPolicy({
|
||||
users = [],
|
||||
privilegedIds = [],
|
||||
} = {}) {
|
||||
const privileged = new Set(privilegedIds);
|
||||
const settings = {
|
||||
direct: scope(users),
|
||||
group: scope(),
|
||||
};
|
||||
return {
|
||||
getSettings: () => settings,
|
||||
isPrivileged: (senderIds) => (
|
||||
(Array.isArray(senderIds) ? senderIds : [senderIds])
|
||||
.some((senderId) => privileged.has(senderId))
|
||||
),
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue