diff --git a/apps/web-client-tpos-net/src/WebClientTpos.Client/Pages/Admin/Staff/RolePermissions.razor b/apps/web-client-tpos-net/src/WebClientTpos.Client/Pages/Admin/Staff/RolePermissions.razor index a5e6c3bd..cd63c63f 100644 --- a/apps/web-client-tpos-net/src/WebClientTpos.Client/Pages/Admin/Staff/RolePermissions.razor +++ b/apps/web-client-tpos-net/src/WebClientTpos.Client/Pages/Admin/Staff/RolePermissions.razor @@ -130,18 +130,21 @@ else } - @* Permission Groups — placeholder since IAM doesn't expose permissions per role yet *@ + @* EN: Permission display — reflects actual backend authorization policies per role. + System roles have platform-level access; business roles have shop-level access. + VI: Hiển thị quyền — phản ánh chính xác backend authorization policies theo role. + System roles có quyền platform; business roles có quyền cửa hàng. *@
Quyền hạn
- @foreach (var perm in _defaultPermissions) + @foreach (var perm in GetPermissionsForRole(selected.Name)) {
@perm.Label @perm.Desc
- +
} @@ -365,15 +368,93 @@ else _ => "shield" }; - // EN: Default permission display (placeholder until IAM exposes permissions per-role API) - // VI: Hiển thị quyền mặc định (placeholder cho đến khi IAM cung cấp API permissions per-role) - private record PermDef(string Label, string Desc, bool Allowed); - private readonly PermDef[] _defaultPermissions = new[] + // EN: Permission definitions — reflects actual backend [Authorize(Policy)] enforcement + // and StaffPermissions bitmask from MerchantService domain. + // VI: Định nghĩa quyền — phản ánh [Authorize(Policy)] thực tế trên backend + // và StaffPermissions bitmask từ MerchantService domain. + private record PermDef(string Label, string Desc, bool Granted); + + /// + /// EN: Returns real permissions for a role based on backend authorization policies: + /// - SuperAdmin/Admin: RequireAdmin policy → full platform access + /// - Merchant/MerchantAdmin: shop owner/admin → full shop access + /// - MerchantStaff: StaffPermissions(ViewSales|ProcessPayment) → POS only + /// - Support/Auditor: RequireAuditor policy → read-only system access + /// - User/PremiumUser: no admin access + /// VI: Trả về quyền thật cho role dựa trên authorization policies backend. + /// + private static PermDef[] GetPermissionsForRole(string roleName) => roleName switch { - new PermDef("Tạo đơn hàng", "Tạo và xử lý đơn hàng", true), - new PermDef("Áp dụng giảm giá", "Giảm giá cho đơn hàng", true), - new PermDef("Xem báo cáo", "Truy cập báo cáo doanh thu", false), - new PermDef("Quản lý nhân sự", "Thêm/sửa/xóa nhân viên", false), - new PermDef("Cài đặt cửa hàng", "Thay đổi thông tin cửa hàng", false), + "SuperAdmin" => new[] + { + new PermDef("Quản lý toàn hệ thống", "Truy cập đầy đủ mọi tính năng platform", true), + new PermDef("Quản lý người dùng", "Tạo/sửa/xóa tài khoản, gán vai trò", true), + new PermDef("Quản lý cửa hàng", "Tạo/xóa/cấu hình tất cả cửa hàng", true), + new PermDef("Xem báo cáo hệ thống", "Truy cập báo cáo doanh thu toàn platform", true), + new PermDef("Nhật ký hệ thống", "Xem audit logs và hoạt động hệ thống", true), + new PermDef("Cấu hình hệ thống", "Thay đổi cài đặt platform và tích hợp", true), + }, + "Admin" => new[] + { + new PermDef("Quản lý người dùng", "Tạo/sửa/xóa tài khoản, gán vai trò", true), + new PermDef("Quản lý cửa hàng", "Tạo/xóa/cấu hình tất cả cửa hàng", true), + new PermDef("Xem báo cáo hệ thống", "Truy cập báo cáo doanh thu toàn platform", true), + new PermDef("Nhật ký hệ thống", "Xem audit logs và hoạt động hệ thống", true), + new PermDef("Cấu hình hệ thống", "Thay đổi cài đặt platform", false), + }, + "Merchant" => new[] + { + new PermDef("Quản lý cửa hàng", "Tạo và cấu hình cửa hàng của mình", true), + new PermDef("POS bán hàng", "Tạo đơn hàng và xử lý thanh toán", true), + new PermDef("Quản lý nhân viên", "Thêm/sửa/xóa nhân viên cửa hàng", true), + new PermDef("Xem báo cáo", "Truy cập báo cáo doanh thu cửa hàng", true), + new PermDef("Quản lý sản phẩm", "Thêm/sửa menu và sản phẩm", true), + new PermDef("Thiết lập cửa hàng", "Thay đổi cài đặt và tính năng cửa hàng", true), + }, + "MerchantAdmin" => new[] + { + new PermDef("POS bán hàng", "Tạo đơn hàng và xử lý thanh toán", true), + new PermDef("Quản lý nhân viên", "Thêm/sửa nhân viên trong cửa hàng", true), + new PermDef("Xem báo cáo", "Truy cập báo cáo doanh thu", true), + new PermDef("Quản lý sản phẩm", "Thêm/sửa menu và sản phẩm", true), + new PermDef("Áp dụng giảm giá", "Giảm giá và khuyến mãi cho đơn hàng", true), + new PermDef("Thiết lập cửa hàng", "Thay đổi cài đặt cửa hàng", false), + }, + "MerchantStaff" => new[] + { + new PermDef("POS bán hàng", "Tạo đơn hàng qua POS", true), + new PermDef("Xử lý thanh toán", "Thu tiền và xác nhận thanh toán", true), + new PermDef("Áp dụng giảm giá", "Giảm giá cho đơn hàng", false), + new PermDef("Hoàn tiền đơn hàng", "Hoàn tiền và hủy đơn", false), + new PermDef("Xem báo cáo", "Truy cập báo cáo doanh thu", false), + new PermDef("Quản lý tồn kho", "Xem và cập nhật tồn kho", false), + }, + "Support" => new[] + { + new PermDef("Xem người dùng", "Tra cứu thông tin tài khoản", true), + new PermDef("Nhật ký hệ thống", "Xem audit logs và hoạt động", true), + new PermDef("Hỗ trợ khách hàng", "Xử lý yêu cầu và ticket hỗ trợ", true), + new PermDef("Quản lý người dùng", "Tạo/sửa/xóa tài khoản", false), + new PermDef("Cấu hình hệ thống", "Thay đổi cài đặt platform", false), + }, + "PremiumUser" => new[] + { + new PermDef("Tính năng premium", "Truy cập tính năng nâng cao", true), + new PermDef("Ưu đãi đặc biệt", "Nhận khuyến mãi và giảm giá riêng", true), + new PermDef("Quản lý cửa hàng", "Truy cập admin cửa hàng", false), + new PermDef("Quản lý người dùng", "Truy cập quản trị hệ thống", false), + }, + "User" => new[] + { + new PermDef("Tài khoản cá nhân", "Quản lý thông tin tài khoản", true), + new PermDef("Xem cửa hàng", "Duyệt và tìm kiếm cửa hàng", true), + new PermDef("Đặt hàng", "Đặt hàng qua ứng dụng", true), + new PermDef("Quản lý cửa hàng", "Truy cập admin cửa hàng", false), + new PermDef("Quản lý người dùng", "Truy cập quản trị hệ thống", false), + }, + _ => new[] + { + new PermDef("Quyền cơ bản", "Quyền truy cập mặc định", true), + } }; }