RolesPermissions Component — sgcHTML | eSeGeCe

RolesPermissions

TsgcHTMLComponent_RolesPermissions — a role / permission matrix with a checkbox per cell, category grouping, and live WebSocket grant updates, in Delphi, C++ Builder and .NET.

TsgcHTMLComponent_RolesPermissions

Add roles and permissions, set the initial grants, then read the HTML property. Every checkbox toggle is sent to the server, which must authorize it before applying it.

Component class

TsgcHTMLComponent_RolesPermissions

Renders

Bootstrap 5 table matrix + inline script

Languages

Delphi, C++ Builder, .NET

Add roles, add permissions, grant, render it

Call AddRole and AddPermission to build the matrix axes, SetGrant for the initial checks, then read HTML.

uses
  sgcHTML_Enums, sgcHTML_Component_RolesPermissions;

var
  oMatrix: TsgcHTMLComponent_RolesPermissions;
begin
  oMatrix := TsgcHTMLComponent_RolesPermissions.Create(nil);
  try
    oMatrix.MatrixID := 'acl';
    oMatrix.StickyHeader := True;

    oMatrix.AddRole('admin', 'Administrator').Color := hcDanger;
    oMatrix.AddRole('editor', 'Editor');
    oMatrix.AddRole('viewer', 'Viewer');

    oMatrix.AddPermission('users.edit', 'Edit users', 'Users');
    oMatrix.AddPermission('users.delete', 'Delete users', 'Users');
    oMatrix.AddPermission('billing.view', 'View invoices', 'Billing');

    oMatrix.SetGrant('admin', 'users.edit', True);
    oMatrix.SetGrant('admin', 'users.delete', True);
    oMatrix.SetGrant('editor', 'users.edit', True);

    WebModule.Response := oMatrix.HTML;   // matrix table + inline script
  finally
    oMatrix.Free;
  end;
end;

// Server-side handler for a checkbox toggle received over WebSockets.
// ALWAYS verify the acting user is authorized before applying the change:
oMatrix.ProcessGrantChanged('editor', 'users.delete', True);
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_RolesPermissions.hpp

TsgcHTMLComponent_RolesPermissions *oMatrix = new TsgcHTMLComponent_RolesPermissions(NULL);
try
{
  oMatrix->MatrixID = "acl";
  oMatrix->StickyHeader = true;

  oMatrix->AddRole("admin", "Administrator")->Color = hcDanger;
  oMatrix->AddRole("editor", "Editor");
  oMatrix->AddRole("viewer", "Viewer");

  oMatrix->AddPermission("users.edit", "Edit users", "Users");
  oMatrix->AddPermission("users.delete", "Delete users", "Users");
  oMatrix->AddPermission("billing.view", "View invoices", "Billing");

  oMatrix->SetGrant("admin", "users.edit", true);
  oMatrix->SetGrant("admin", "users.delete", true);
  oMatrix->SetGrant("editor", "users.edit", true);

  String html = oMatrix->HTML;   // matrix table + inline script

  // Server-side handler for a checkbox toggle (verify authorization first):
  oMatrix->ProcessGrantChanged("editor", "users.delete", true);
}
__finally
{
  delete oMatrix;
}
using esegece.sgcWebSockets;

var matrix = new TsgcHTMLComponent_RolesPermissions();
matrix.MatrixID = "acl";
matrix.StickyHeader = true;

matrix.AddRole("admin", "Administrator").Color = TsgcHTMLColor.hcDanger;
matrix.AddRole("editor", "Editor");
matrix.AddRole("viewer", "Viewer");

matrix.AddPermission("users.edit", "Edit users", "Users");
matrix.AddPermission("users.delete", "Delete users", "Users");
matrix.AddPermission("billing.view", "View invoices", "Billing");

matrix.SetGrant("admin", "users.edit", true);
matrix.SetGrant("admin", "users.delete", true);
matrix.SetGrant("editor", "users.edit", true);

string html = matrix.HTML;   // matrix table + inline script

// Server-side handler for a checkbox toggle (verify authorization first):
matrix.ProcessGrantChanged("editor", "users.delete", true);

Key properties & methods

The members you reach for most often.

Roles & permissions

AddRole(aId, aName) and AddPermission(aId, aName, aCategory) build the matrix axes; each role gets a coloured badge, each permission an optional category header.

Grants

SetGrant(aRoleId, aPermissionId, aGranted) / GetGrant read and write the checked cells, keyed by role + permission id.

Dataset binding

LoadRolesFromDataSet, LoadPermissionsFromDataSet and LoadGrantsFromDataSet populate the matrix straight from a TDataSet.

Client changes

Every checkbox toggle sends a JSON payload over the WebSocket channel and fires the DOM event sgcRolesPermissions:grantChanged.

Presentation

ShowDescriptions, ShowCategories, Striped, Bordered, Compact and StickyHeader (with MaxHeight) style the table; ReadOnly disables every checkbox.

Security

This component renders UI only. ProcessGrantChanged must only be called after the host verifies, server-side, that the acting user may change that role/permission pair.

Keep exploring

Online HelpFull API reference and usage guide for this component.
All sgcHTML ComponentsBrowse the full feature matrix of 80+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.

Ready to Get Started?

Download the free trial and add a role/permission matrix to your Delphi, C++ Builder or .NET admin panel.