fix(roles): replace hardcoded permission toggles with real role-based permissions
- Remove placeholder _defaultPermissions (same 5 toggles for every role) - Add GetPermissionsForRole() mapping each role to its actual backend authorization capabilities: - SuperAdmin: full platform access (6 permissions) - Admin: user/shop/report/audit management (5 permissions) - Merchant: full shop owner access (6 permissions) - MerchantAdmin: shop admin without settings (6 permissions) - MerchantStaff: POS + payment only (6 permissions, 4 disabled) - Support: read-only system access (5 permissions) - PremiumUser/User: customer-level access (4-5 permissions) - Toggles are now read-only (disabled) reflecting enforced policies - No conflict between system roles and shop roles confirmed Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -130,18 +130,21 @@ else
|
||||
</div>
|
||||
}
|
||||
|
||||
@* 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. *@
|
||||
<div style="font-size:12px;font-weight:700;color:var(--admin-text-tertiary);text-transform:uppercase;letter-spacing:0.05em;">
|
||||
Quyền hạn
|
||||
</div>
|
||||
@foreach (var perm in _defaultPermissions)
|
||||
@foreach (var perm in GetPermissionsForRole(selected.Name))
|
||||
{
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;padding:10px 12px;background:var(--admin-bg-interactive);border-radius:10px;">
|
||||
<div style="display:flex;flex-direction:column;">
|
||||
<span style="font-size:13px;font-weight:500;">@perm.Label</span>
|
||||
<span style="font-size:11px;color:var(--admin-text-tertiary);">@perm.Desc</span>
|
||||
</div>
|
||||
<MudSwitch T="bool" Value="perm.Allowed" Color="Color.Primary" />
|
||||
<MudSwitch T="bool" Value="perm.Granted" Color="@(perm.Granted ? Color.Success : Color.Default)" Disabled="true" />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -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);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user