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는 호스트가 서버 측에서 해당 사용자가 그 역할/권한 조합을 변경할 권한이 있는지 확인한 후에만 호출해야 합니다.