RolesPermissions
TsgcHTMLComponent_RolesPermissions — Delphi、C++ Builder、.NET で、セルごとにチェックボックスを備え、カテゴリーグループ化とライブ WebSocket 権限更新を伴う、ロール / 権限マトリックスです。
TsgcHTMLComponent_RolesPermissions — Delphi、C++ Builder、.NET で、セルごとにチェックボックスを備え、カテゴリーグループ化とライブ WebSocket 権限更新を伴う、ロール / 権限マトリックスです。
ロールと権限を追加し、初期の権限付与を設定してから、HTML プロパティを読み取ります。チェックボックスの切り替えはすべてサーバーに送信され、サーバー側で認可されてから適用されます。
TsgcHTMLComponent_RolesPermissions
Bootstrap 5 のテーブルマトリックス + インラインスクリプト
Delphi, C++ Builder, .NET
AddRole と AddPermission を呼び出してマトリックスの軸を構築し、初期のチェックには SetGrant を使用してから、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);
最もよく使うメンバーです。
AddRole(aId, aName) と AddPermission(aId, aName, aCategory) はマトリックスの軸を構築します。各ロールには色付きバッジが、各権限には任意のカテゴリーヘッダーが付きます。
SetGrant(aRoleId, aPermissionId, aGranted) / GetGrant は、ロール + 権限 id をキーにチェック済みセルを読み書きします。
LoadRolesFromDataSet、LoadPermissionsFromDataSet、LoadGrantsFromDataSet は、TDataSet から直接マトリックスにデータを投入します。
チェックボックスの切り替えはすべて、WebSocket チャンネル経由で JSON ペイロードを送信し、DOM イベント sgcRolesPermissions:grantChanged を発火させます。
ShowDescriptions、ShowCategories、Striped、Bordered、Compact、StickyHeader(MaxHeight と併用)はテーブルのスタイルを設定します。ReadOnly はすべてのチェックボックスを無効にします。
このコンポーネントは UI のみをレンダリングします。ProcessGrantChanged は、ホスト側でその操作を行うユーザーがロール / 権限のペアを変更できることをサーバー側で検証した後にのみ呼び出す必要があります。