Skip to main content

Permissions

The Permission entity defines granular access controls within the Wrkbelt platform. It is a core component of the role-based access control (RBAC) system, allowing for fine-grained control over user capabilities.

note

The permission system is designed to be extensible and will evolve with the platform. The permissions documented here represent the current set at the time of writing. As new features are added and the platform grows, additional permissions will be introduced and existing ones may be refined.

Schema Definition

type Permission = {
// Base Properties
_id: string; // MongoDB ObjectId
name: AllPermissions; // Required, Unique, Predefined permission types
description: string; // Required, Human-readable description

// Timestamps
createdAt: Date; // Auto-generated
updatedAt: Date; // Auto-updated
} & BaseEntity;

Field Descriptions

Base Properties

FieldTypeRequiredUniqueDescription
_idObjectIdYesYesUnique identifier for the permission
nameAllPermissionsYesYesPredefined permission type from AllPermissions enum
descriptionstringYesNoHuman-readable description of the permission

Timestamps

FieldTypeDescription
createdAtDateAutomatically set when the permission is created
updatedAtDateAutomatically updated when the permission changes

Current Permission Categories

User Management

PermissionDescription
VIEW_USERSView Users
CREATE_USERCreate User
UPDATE_USERUpdate User
DELETE_USERDelete User
INVITE_USERInvite User to signup
CREATE_ORG_MEMBERCreate an organization member

Permission Management

PermissionDescription
VIEW_PERMISSIONSView Permissions
CREATE_PERMISSIONCreate Permission
UPDATE_PERMISSIONUpdate Permission
DELETE_PERMISSIONDelete Permission

Role Management

PermissionDescription
VIEW_ROLESView Roles
CREATE_ROLECreate Role
UPDATE_ROLEUpdate Role
DELETE_ROLEDelete Role

Membership Management

PermissionDescription
VIEW_MEMBERSHIPSView Memberships
CREATE_MEMBERSHIPCreate Membership
UPDATE_MEMBERSHIPUpdate Membership
DELETE_MEMBERSHIPDelete Membership

Organization Management

PermissionDescription
VIEW_ORGANIZATIONSView Organizations
CREATE_ORGANIZATIONCreate Organization
UPDATE_ORGANIZATIONUpdate Organization
DELETE_ORGANIZATIONDelete Organization

File Management

PermissionDescription
VIEW_FILESView Files
VIEW_FILEView File
CREATE_FILECreate File
UPDATE_FILEUpdate File
DELETE_FILEDelete File
DOWNLOAD_FILEDownload File
UPLOAD_FILEUpload File
UPLOAD_MULTIPLE_FILESUpload Multiple Files

BrandKit Management

PermissionDescription
VIEW_BRANDKITView BrandKit
CREATE_BRANDKITCreate BrandKit
UPDATE_BRANDKITUpdate BrandKit
DELETE_BRANDKITDelete BrandKit

Relationships

Primary Relationships

  • Permission → Roles (Many-to-Many)
    • Permissions are assigned to roles
    • Each permission can be part of multiple roles
    • Relationship managed through Role entity's permissions array

Indirect Relationships

  • Permission → Users (Many-to-Many through Roles and Memberships)
    • Users receive permissions through their roles
    • Permissions are checked against the user's current organization context

Permission Design Principles

  1. Granularity

    • Each permission represents a single, specific action
    • Permissions are atomic and don't overlap in functionality
    • Complex operations may require multiple permissions
  2. Clarity

    • Permission names are self-descriptive
    • Each permission has a clear, human-readable description
    • Permissions are grouped by functional area
  3. Consistency

    • Similar operations across different resources use consistent naming
    • CRUD operations follow the pattern: VIEW*, CREATE*, UPDATE*, DELETE*
    • Special operations have unique, descriptive names

Security Considerations

  1. Permission Checking

    • Permissions should be checked at both API and UI levels
    • Checks should consider the user's current organization context
    • Failed permission checks should be logged for security auditing (⚠️TODO⚠️)
  2. Permission Assignment

    • Permissions can only be assigned to roles by authorized users
    • Some permissions may be restricted to system-level roles
    • Permission changes should be audited
  3. Permission Inheritance

    • Permissions are inherited through role assignments
    • Users may have different permissions in different organizations
    • Permission checks should aggregate all applicable roles

Usage Examples

Permission Checking

Wrkbelt provides isomorphic utility functions for checking permissions, available in @wrkbelt/shared/utils-core-logic:

// Check a single permission
const canCreateUser = hasPermission(userPermissions, AllPermissions.CREATE_USER);

// Check multiple permissions
const canManageUsers = hasPermissions(userPermissions, [AllPermissions.CREATE_USER, AllPermissions.UPDATE_USER, AllPermissions.DELETE_USER]);

These utility functions are isomorphic and can be used in both frontend and backend code, ensuring consistent permission checking across the application.

Manual Permission Checking

// Check if user has permission through their roles
const hasPermission = user.memberships.find((m) => m.organization_id === currentOrgId).roles.some((role) => role.permissions.includes(AllPermissions.CREATE_USER));

Permission Validation

// Ensure permission name is valid
if (!Object.values(AllPermissions).includes(permissionName)) {
throw new Error('Invalid permission name');
}