RolesPermissions コンポーネント — sgcHTML | eSeGeCe

RolesPermissions

TsgcHTMLComponent_RolesPermissions — Delphi、C++ Builder、.NET で、セルごとにチェックボックスを備え、カテゴリーグループ化とライブ WebSocket 権限更新を伴う、ロール / 権限マトリックスです。

TsgcHTMLComponent_RolesPermissions

ロールと権限を追加し、初期の権限付与を設定してから、HTML プロパティを読み取ります。チェックボックスの切り替えはすべてサーバーに送信され、サーバー側で認可されてから適用されます。

コンポーネントクラス

TsgcHTMLComponent_RolesPermissions

レンダリング内容

Bootstrap 5 のテーブルマトリックス + インラインスクリプト

ファミリー

認証

言語

Delphi, C++ Builder, .NET

ロールを追加し、権限を追加し、付与し、レンダリングする

AddRoleAddPermission を呼び出してマトリックスの軸を構築し、初期のチェックには 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);

主なプロパティとメソッド

最もよく使うメンバーです。

Roles & permissions

AddRole(aId, aName)AddPermission(aId, aName, aCategory) はマトリックスの軸を構築します。各ロールには色付きバッジが、各権限には任意のカテゴリーヘッダーが付きます。

Grants

SetGrant(aRoleId, aPermissionId, aGranted) / GetGrant は、ロール + 権限 id をキーにチェック済みセルを読み書きします。

Dataset binding

LoadRolesFromDataSetLoadPermissionsFromDataSetLoadGrantsFromDataSet は、TDataSet から直接マトリックスにデータを投入します。

Client changes

チェックボックスの切り替えはすべて、WebSocket チャンネル経由で JSON ペイロードを送信し、DOM イベント sgcRolesPermissions:grantChanged を発火させます。

Presentation

ShowDescriptionsShowCategoriesStripedBorderedCompactStickyHeaderMaxHeight と併用)はテーブルのスタイルを設定します。ReadOnly はすべてのチェックボックスを無効にします。

Security

このコンポーネントは UI のみをレンダリングします。ProcessGrantChanged は、ホスト側でその操作を行うユーザーがロール / 権限のペアを変更できることをサーバー側で検証した後にのみ呼び出す必要があります。

さらに詳しく

オンラインヘルプこのコンポーネントの完全な API リファレンスと使用ガイドです。
すべての sgcHTML コンポーネント80 以上のコンポーネントの全機能マトリックスを閲覧できます。
無料体験版のダウンロード30 日間の体験版には 60.HTML デモプロジェクトが付属します。
価格完全なソースコード付きの Single、Team、Site ライセンス。

始める準備はできましたか?

無料体験版をダウンロードして、Delphi、C++ Builder、.NET の管理パネルにロール / 権限マトリックスを追加しましょう。