Komponent RolesPermissions — sgcHTML | eSeGeCe

RolesPermissions

TsgcHTMLComponent_RolesPermissions — matryca ról / uprawnień z polem wyboru dla każdej komórki, grupowaniem według kategorii i aktualizacjami nadań na żywo przez WebSocket, w Delphi, C++ Builder i .NET.

TsgcHTMLComponent_RolesPermissions

Dodaj role i uprawnienia, ustaw początkowe nadania, a następnie odczytaj właściwość HTML. Każde przełączenie pola wyboru jest wysyłane do serwera, który musi je autoryzować przed zastosowaniem.

Klasa komponentu

TsgcHTMLComponent_RolesPermissions

Renderuje

Matryca tabelaryczna Bootstrap 5 + wbudowany skrypt

Języki

Delphi, C++ Builder, .NET

Dodaj role, dodaj uprawnienia, nadaj, wyrenderuj

Wywołaj AddRole i AddPermission, aby zbudować osie matrycy, SetGrant dla początkowych zaznaczeń, a następnie odczytaj 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);

Kluczowe właściwości i metody

Składniki, po które sięgasz najczęściej.

Role i uprawnienia

AddRole(aId, aName) i AddPermission(aId, aName, aCategory) budują osie matrycy; każda rola otrzymuje kolorową plakietkę, każde uprawnienie opcjonalny nagłówek kategorii.

Nadania

SetGrant(aRoleId, aPermissionId, aGranted) / GetGrant odczytują i zapisują zaznaczone komórki, indeksowane po id roli i uprawnienia.

Wiązanie z zestawem danych

LoadRolesFromDataSet, LoadPermissionsFromDataSet i LoadGrantsFromDataSet wypełniają matrycę bezpośrednio z TDataSet.

Zmiany po stronie klienta

Każde przełączenie pola wyboru wysyła ładunek JSON kanałem WebSocket i wyzwala zdarzenie DOM sgcRolesPermissions:grantChanged.

Prezentacja

ShowDescriptions, ShowCategories, Striped, Bordered, Compact i StickyHeader (z MaxHeight) stylizują tabelę; ReadOnly wyłącza wszystkie pola wyboru.

Bezpieczeństwo

Ten komponent renderuje wyłącznie interfejs. ProcessGrantChanged można wywołać dopiero po zweryfikowaniu po stronie serwera, że działający użytkownik może zmienić tę parę rola/uprawnienie.

Poznawaj dalej

Pomoc onlinePełna dokumentacja API i przewodnik użytkowania tego komponentu.
Wszystkie komponenty sgcHTMLPrzejrzyj pełną matrycę funkcji 80+ komponentów.
Pobierz bezpłatną wersję próbną30-dniowa wersja próbna zawiera projekty demonstracyjne 60.HTML.
CennikLicencje Single, Team i Site z pełnym kodem źródłowym.

Gotowy, aby zacząć?

Pobierz bezpłatną wersję próbną i dodaj matrycę ról/uprawnień do panelu administracyjnego w Delphi, C++ Builder lub .NET.