Skip to content

fix: replace dead camelCase permission keys with OrgPermission enum in role seed (ISSUE-162)#164

Closed
GitAddRemote wants to merge 1 commit into
mainfrom
fix/ISSUE-162-role-seed-permissions
Closed

fix: replace dead camelCase permission keys with OrgPermission enum in role seed (ISSUE-162)#164
GitAddRemote wants to merge 1 commit into
mainfrom
fix/ISSUE-162-role-seed-permissions

Conversation

@GitAddRemote
Copy link
Copy Markdown
Owner

Summary

  • Replaces all invented camelCase permission keys in roles.seed.ts (e.g. canViewOrganization, canInviteUsers) with correct OrgPermission enum values (can_view_org_inventory, etc.) — the keys the backend actually enforces
  • Makes seedRoles() upsert permissions on existing roles rather than skipping them, so re-running pnpm seed heals a broken database without data loss
  • Fixes ISSUE-162

Root Cause

Two disconnected permission systems were never reconciled. roles.seed.ts used camelCase keys invented outside the OrgPermission enum; the backend only checks snake_case OrgPermission keys. Every user assigned Owner, Admin, Member, or Viewer had zero valid permissions, causing 403s on all inventory endpoints.

Permission Matrix (post-fix)

Role can_view can_edit can_admin can_view_shared
Owner
Admin
Inventory Manager
Member
Viewer

Test plan

  • Run pnpm seed against an existing database — all four roles should log ✓ Updated permissions for role
  • Verify database: SELECT name, permissions FROM role ORDER BY name — all roles show OrgPermission snake_case keys
  • Log in as the demo user (Owner role) and switch to org view — inventory loads without 403
  • Re-run pnpm seed a second time — idempotent, no errors

🤖 Generated with Claude Code

…n role seed (ISSUE-162)

- Replace all camelCase permission keys in roles.seed.ts with correct
  OrgPermission enum values (can_view_org_inventory, etc.)
- Import OrgPermission from permissions.constants.ts as single source of truth
- Make seedRoles() upsert permissions on existing roles so re-running
  the seeder heals a broken database rather than silently skipping
- Owner and Admin get full inventory access; Member gets view+shared;
  Viewer gets view-only
Copilot AI review requested due to automatic review settings May 16, 2026 16:34
@GitAddRemote GitAddRemote added bug Something isn't working backend Backend services and logic database Schema, migrations, indexing security Security, auth, and permissions labels May 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes ISSUE-162 where default roles were seeded with invented camelCase permission keys that the backend never enforced, leaving Owner/Admin/Member/Viewer users with effectively zero valid permissions. The seed now uses the real OrgPermission enum values, and seedRoles() heals existing roles by upserting their permissions instead of skipping them.

Changes:

  • Replace camelCase permission keys in defaultRoles with OrgPermission enum values across Owner/Admin/Member/Viewer.
  • Make seedRoles() update permissions on already-existing roles instead of leaving them untouched.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
backend/src/database/seeds/roles.seed.ts Imports OrgPermission and rewrites every role's permissions object using enum-keyed booleans.
backend/src/database/seeds/database-seeder.service.ts Changes the "role already exists" branch to overwrite permissions from the seed and log an update.
Comments suppressed due to low confidence (1)

backend/src/database/seeds/roles.seed.ts:38

  • Role description fields still reference organization/user/role/settings management (e.g., "Can delete organization and manage all settings", "Can manage users and settings"), but the actual permissions now only cover inventory-related capabilities. These descriptions are misleading to anyone reading them in the DB or UI; consider updating them to accurately reflect the inventory-focused permissions that are actually granted.
    description:
      'Full access to organization. Can delete organization and manage all settings.',
    permissions: {
      [OrgPermission.CAN_VIEW_ORG_INVENTORY]: true,
      [OrgPermission.CAN_EDIT_ORG_INVENTORY]: true,
      [OrgPermission.CAN_ADMIN_ORG_INVENTORY]: true,
      [OrgPermission.CAN_VIEW_MEMBER_SHARED_ITEMS]: true,
    },
  },
  {
    name: 'Admin',
    description: 'Administrative access. Can manage users and settings.',
    permissions: {
      [OrgPermission.CAN_VIEW_ORG_INVENTORY]: true,
      [OrgPermission.CAN_EDIT_ORG_INVENTORY]: true,
      [OrgPermission.CAN_ADMIN_ORG_INVENTORY]: true,
      [OrgPermission.CAN_VIEW_MEMBER_SHARED_ITEMS]: true,
    },
  },
  {
    name: 'Member',
    description: 'Standard member access. Can view and participate.',
    permissions: {
      [OrgPermission.CAN_VIEW_ORG_INVENTORY]: true,
      [OrgPermission.CAN_EDIT_ORG_INVENTORY]: false,
      [OrgPermission.CAN_ADMIN_ORG_INVENTORY]: false,
      [OrgPermission.CAN_VIEW_MEMBER_SHARED_ITEMS]: true,
    },
  },
  {
    name: 'Viewer',
    description: 'Read-only access. Can only view information.',

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 4 to 46
export const defaultRoles: Partial<Role>[] = [
{
name: 'Owner',
description:
'Full access to organization. Can delete organization and manage all settings.',
permissions: {
// Organization management
canDeleteOrganization: true,
canEditOrganization: true,
canViewOrganization: true,

// User management
canInviteUsers: true,
canRemoveUsers: true,
canEditUserRoles: true,
canViewUsers: true,

// Role management
canCreateRoles: true,
canEditRoles: true,
canDeleteRoles: true,
canViewRoles: true,

// Settings
canManageSettings: true,
canViewSettings: true,
[OrgPermission.CAN_VIEW_ORG_INVENTORY]: true,
[OrgPermission.CAN_EDIT_ORG_INVENTORY]: true,
[OrgPermission.CAN_ADMIN_ORG_INVENTORY]: true,
[OrgPermission.CAN_VIEW_MEMBER_SHARED_ITEMS]: true,
},
},
{
name: 'Admin',
description: 'Administrative access. Can manage users and settings.',
permissions: {
// Organization management
canEditOrganization: true,
canViewOrganization: true,

// User management
canInviteUsers: true,
canRemoveUsers: true,
canEditUserRoles: true,
canViewUsers: true,

// Role management
canViewRoles: true,

// Settings
canManageSettings: true,
canViewSettings: true,
[OrgPermission.CAN_VIEW_ORG_INVENTORY]: true,
[OrgPermission.CAN_EDIT_ORG_INVENTORY]: true,
[OrgPermission.CAN_ADMIN_ORG_INVENTORY]: true,
[OrgPermission.CAN_VIEW_MEMBER_SHARED_ITEMS]: true,
},
},
{
name: 'Member',
description: 'Standard member access. Can view and participate.',
permissions: {
// Organization management
canViewOrganization: true,

// User management
canViewUsers: true,

// Role management
canViewRoles: true,

// Settings
canViewSettings: true,
[OrgPermission.CAN_VIEW_ORG_INVENTORY]: true,
[OrgPermission.CAN_EDIT_ORG_INVENTORY]: false,
[OrgPermission.CAN_ADMIN_ORG_INVENTORY]: false,
[OrgPermission.CAN_VIEW_MEMBER_SHARED_ITEMS]: true,
},
},
{
name: 'Viewer',
description: 'Read-only access. Can only view information.',
permissions: {
// Organization management
canViewOrganization: true,

// User management
canViewUsers: true,

// Settings
canViewSettings: true,
[OrgPermission.CAN_VIEW_ORG_INVENTORY]: true,
[OrgPermission.CAN_EDIT_ORG_INVENTORY]: false,
[OrgPermission.CAN_ADMIN_ORG_INVENTORY]: false,
[OrgPermission.CAN_VIEW_MEMBER_SHARED_ITEMS]: false,
},
},
];
Comment on lines +96 to +98
existingRole.permissions = roleData.permissions ?? {};
await this.rolesRepository.save(existingRole);
this.logger.info(` ✓ Updated permissions for role: ${roleData.name}`);
@GitAddRemote GitAddRemote deleted the fix/ISSUE-162-role-seed-permissions branch May 16, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend services and logic bug Something isn't working database Schema, migrations, indexing security Security, auth, and permissions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants