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 — a role / permission matrix with a checkbox per cell, category grouping, and live WebSocket grant updates, in Delphi, C++ Builder and .NET.
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.
TsgcHTMLComponent_RolesPermissions
Bootstrap 5 table matrix + inline script
Delphi, C++ Builder, .NET
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);
The members you reach for most often.
AddRole(aId, aName) and AddPermission(aId, aName, aCategory) build the matrix axes; each role gets a coloured badge, each permission an optional category header.
SetGrant(aRoleId, aPermissionId, aGranted) / GetGrant read and write the checked cells, keyed by role + permission id.
LoadRolesFromDataSet, LoadPermissionsFromDataSet and LoadGrantsFromDataSet populate the matrix straight from a TDataSet.
Every checkbox toggle sends a JSON payload over the WebSocket channel and fires the DOM event sgcRolesPermissions:grantChanged.
ShowDescriptions, ShowCategories, Striped, Bordered, Compact and StickyHeader (with MaxHeight) style the table; ReadOnly disables every checkbox.
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.
| Online HelpFull API reference and usage guide for this component. | Open | |
| All sgcHTML ComponentsBrowse the full feature matrix of 80+ components. | Open | |
| Download Free TrialThe 30-day trial ships the 60.HTML demo projects. | Open | |
| PricingSingle, Team and Site licenses with full source code. | Open |