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);

주요 속성 및 메서드

가장 자주 사용하게 되는 멤버.

역할 및 권한

AddRole(aId, aName)AddPermission(aId, aName, aCategory)가 매트릭스 축을 구성합니다. 각 역할에는 색상 배지가, 각 권한에는 선택적 카테고리 헤더가 부여됩니다.

승인

SetGrant(aRoleId, aPermissionId, aGranted) / GetGrant는 역할 + 권한 id를 키로 하여 체크된 셀을 읽고 씁니다.

데이터셋 바인딩

LoadRolesFromDataSet, LoadPermissionsFromDataSetLoadGrantsFromDataSetTDataSet에서 곧바로 매트릭스를 채웁니다.

클라이언트 변경

모든 체크박스 토글은 WebSocket 채널을 통해 JSON 페이로드를 전송하고 DOM 이벤트 sgcRolesPermissions:grantChanged를 발생시킵니다.

표시

ShowDescriptions, ShowCategories, Striped, Bordered, CompactStickyHeader(MaxHeight와 함께)가 표의 스타일을 지정합니다. ReadOnly는 모든 체크박스를 비활성화합니다.

보안

이 컴포넌트는 UI만 렌더링합니다. ProcessGrantChanged는 호스트가 서버 측에서 해당 사용자가 그 역할/권한 조합을 변경할 권한이 있는지 확인한 후에만 호출해야 합니다.

계속 살펴보기

온라인 도움말이 찱포넌트의 전체 API 참조 및 사용 가이드입니다.
모든 sgcHTML 컴포넌트80개 이상의 컴포넌트 전체 기능 매트릭스를 둘러보십시오.
무료 체험판 다운로드30일 체험판에는 60.HTML 데모 프로젝트가 포함됩니다.
가격전체 소스 코드가 포함된 Single, Team 및 Site 라이선스.

시작할 준비가 되셨습니까?

무료 체험판을 다운로드하고 Delphi, C++ Builder 또는 .NET 관리자 패널에 역할/권한 매트릭스를 추가하십시오.