Skip to content

Bug: Can't display role names in content manager #19

@Link2Twenty

Description

@Link2Twenty

Describe the bug

When using @strapi-community/plugin-api-permissions (^1.0.0-alpha.3), the roles relationship select dropdown in the Content Manager only displays the document/entry ID instead of the role name. Attempting to configure the view and setting the entry title to name does not resolve the issue.

role list with role IDs

To Reproduce

  1. Install and enable the plugin-api-permissions plugin.
  2. Navigate to the Content Manager and open a user record (or create a new one).
  3. Open the role relationship dropdown.

Expected behaviour

The dropdown should display the human-readable name property of the roles rather than fallback IDs.

Environment

  • OS: Ubuntu
  • Node version: 24.x
  • Package Manager: npm 11.x

Additional context

The issue stems from RBAC permissions. Because the role collection is hidden from the Content Manager by default, the relevant explorer permissions are not registered or exposed. This prevents the Content Manager API from fetching the populated relation fields authorized under the current admin user session.

Adding an alias mapping to the plugin's bootstrap function resolves this by registering the plugin's role CRUD actions under the Content Manager explorer actions and rebuilding the Super Admin permissions capability map.

Here is a working workaround implemented in my local register / bootstrap flow:

const permissionService = strapi.admin?.services?.permission;

if (permissionService?.actionProvider) {
  const aliasMappings = [
    {
      pluginAction: "plugin::api-permissions.roles.read",
      cmAction: "plugin::content-manager.explorer.read",
    },
    {
      pluginAction: "plugin::api-permissions.roles.create",
      cmAction: "plugin::content-manager.explorer.create",
    },
    {
      pluginAction: "plugin::api-permissions.roles.update",
      cmAction: "plugin::content-manager.explorer.update",
    },
    {
      pluginAction: "plugin::api-permissions.roles.delete",
      cmAction: "plugin::content-manager.explorer.delete",
    },
  ];

  for (const { pluginAction, cmAction } of aliasMappings) {
    const main = permissionService.actionProvider.get(cmAction);
    const alias = permissionService.actionProvider.get(pluginAction);

    if (main) {
      if (!main.subjects) main.subjects = [];

      if (!main.subjects.includes("plugin::api-permissions.role")) {
        main.subjects.push("plugin::api-permissions.role");
      }
    }

    if (alias) {
      if (!alias.aliases) alias.aliases = [];

      const exists = alias.aliases.some(({ actionId, subjects }) => {
        return actionId === cmAction && subjects?.includes("plugin::api-permissions.role");
      });

      if (!exists) {
        alias.aliases.push({ actionId: cmAction, subjects: ["plugin::api-permissions.role"] });
      }
    }
  }
}

try {
  const roleService = strapi.service("admin::role");
  await roleService?.resetSuperAdminPermissions?.();
} catch (err) {
  strapi.log.error("Failed to sync Super Admin permissions for API Roles:", err);
}

With this mapping applied, the dropdown populates correctly once the view configuration is adjusted:

role list with role names

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions