Feature: Roles & Permissions #11
Labels
No labels
area:api
area:core
area:docs
area:infra
area:ux
dependencies
documentation
duplicate
good first issue
help wanted
invalid
question
rust
status:complete
status:partial
status:planned
type:bug
type:design
type:feature
type:infra
type:refactor
type:research
type:ux
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
icub3d/decentcom#11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Migrated from GitHub issue icub3d/decentcom#11
Original Author: @icub3d
Original Date: 2026-04-15T14:15:33Z
Feature: Roles & Permissions
Overview
A role-based permission system that controls what members can do within a server and within individual channels. Roles are ordered by hierarchy, each carrying a set of boolean permission flags. Channel-level overrides allow fine-grained control. Two built-in roles (
@everyoneand@admin) provide sensible defaults.Background
The design docs specify a Discord-style role system (see
docs/design/server-model.md, "Roles and Permissions" section). Roles are central to moderation (kick, ban), channel management, and membership management features that follow. The permission model must be in place before invites (#12) and membership management (#13) can enforce access control.Phase 1 features (auth, channels, messages, gateway) exist but have no authorization layer beyond "is the user authenticated." This feature adds that layer.
Requirements
@everyoneand@adminroles on instance initialization@everyonebase, merged with all assigned roles (union), then channel overrides applied@adminrole has all permissions and cannot be deleted or have permissions removed@adminDesign
API / Interface Changes
REST endpoints (all under
/api/v1/):/roles/rolesmanage_roles/roles/:role_idmanage_roles/roles/:role_idmanage_roles/members/:pubkey/roles/:role_idmanage_roles/members/:pubkey/roles/:role_idmanage_roles/channels/:channel_id/overridesmanage_channels/channels/:channel_id/overrides/:role_idmanage_channels/channels/:channel_id/overrides/:role_idmanage_channelsGateway events:
ROLE_CREATE— new role createdROLE_UPDATE— role modified (permissions, name, position, color)ROLE_DELETE— role removedMEMBER_ROLE_ADD— role assigned to memberMEMBER_ROLE_REMOVE— role removed from memberTauri IPC: No new IPC commands needed; the React app calls REST endpoints directly.
Data Model Changes
New tables:
Permission bitfield flags:
send_messagesread_messagesmanage_messagesmanage_channelsmanage_roleskick_membersban_membersmanage_invitesmanage_serverattach_filesadd_reactionsmention_everyoneview_audit_logadministratorComponent Changes
Server (
server/):server/src/models/role.rs— Role, MemberRole, ChannelPermissionOverride structs; permission bitfield constants and helpersserver/src/models/permissions.rs— Permission computation logic (merge roles, apply overrides)server/src/store/role_store.rs—RoleStoretrait added to the storage trait hierarchyserver/src/store/sqlite/role_store.rs— SQLite implementation ofRoleStoreserver/src/routes/roles.rs— REST handlers for role CRUD and assignmentserver/src/routes/channels.rs— Extended with permission override endpointsserver/src/middleware/permissions.rs— Axum middleware/extractor that computes effective permissions for the authenticated user and injects them into request extensionsserver/src/gateway/events.rs— New event types for role changesserver/src/routes/messages.rs— Add permission checks (send_messages, read_messages)server/src/routes/channels.rs— Add permission checks (manage_channels)Client (
client/):client/src/api/roles.ts— API client functions for role endpointsclient/src/stores/roles.ts— Zustand slice for roles stateclient/src/components/settings/RoleEditor.tsx— Role creation/editing UI with permission togglesclient/src/components/settings/RoleList.tsx— Ordered role list with drag-to-reorderclient/src/components/settings/ChannelPermissions.tsx— Channel-level override editorclient/src/hooks/usePermissions.ts— Hook that computes effective permissions for the current user in a given channelDatabase migrations:
server/migrations/NNNN_create_roles.sqlImplementation Notes
UserPermissionsextractor live inserver/src/permissions.rs(notmodels/permissions.rsas originally planned, matching the actual module layout).ChannelPermissionOverridestructs are inserver/src/storage/models.rs.RoleStoretrait is inserver/src/storage/traits.rs; SQLite impl inserver/src/storage/sqlite/roles.rs.server/migrations/002_roles.sql(fixed IDs:"everyone","admin").@admininserver/src/auth/handlers.rs(best-effort; minor TOCTOU acceptable for v1).UserPermissionsextractor (replacesAuthUser); message handlers calleffective_permissionswith channel_id for channel-scoped checks.server/src/roles/handlers.rsand mounted byserver/src/roles/mod.rs.ROLE_CREATE,ROLE_UPDATE,ROLE_DELETE,MEMBER_ROLE_ADD, andMEMBER_ROLE_REMOVEinshared/src/gateway.rs.client/src/api/roles.tsandclient/src/stores/roles.ts;usePermissionsis inclient/src/hooks/usePermissions.ts.client/src/components/settings/RoleList.tsx,client/src/components/settings/RoleEditor.tsx, andclient/src/components/settings/ChannelPermissions.tsx.Task List
Server
server/src/permissions.rsserver/src/storage/models.rsRoleStoretrait to the storage trait hierarchyroles,member_roles, andchannel_permission_overridestablesRoleStorefor the SQLite backend@everyoneand@admin(seeded in migration; first user gets @admin via auth handler)POST/GET/PATCH/DELETE /roles)PUT/DELETE /members/:pubkey/roles/:role_id)UserPermissionsextractor resolves base permissions; channel overrides applied per-handler)Client
client/src/api/roles.tsusePermissionshook for computing effective permissionsTest List
Open Questions