[CLAUDE] Phase1.2: CRUD Master + Permission Matrix + FE admin pages
Backend:
- Domain/Master: Supplier (+ SupplierType 5 loai), Project, Department (AuditableEntity)
- Domain/Identity: MenuItem, Permission, MenuKeys const (12 menu)
- EF Configurations voi unique Code + query filter IsDeleted
- DbSets + IApplicationDbContext interface update
- Application: PagedResult + PagedRequest generic
- Application/Master CQRS CRUD 3 entity (Create/Update/Delete/Get/List voi paging search sort)
- Application/Permissions: GetMyMenuTree (union OR role, filter tree), ListMenuItems, ListPermissionsByRole, UpsertPermission (guard admin khong tu giam quyen), ListRoles
- Api/Authorization: MenuPermissionRequirement + Handler (Admin bypass, query DB)
- Program.cs: register 48 policy {menu}.{action} tu MenuKeys x Actions
- Api/Controllers: Suppliers, Projects, Departments, Menus, Roles, Permissions
- DbInitializer: seed 12 menu + admin full CRUD permissions
- Migration AddMasterData + AddPermissions
Frontend (fe-admin):
- Types: menuKeys.ts const, menu.ts (MenuNode/Role/Permission), master.ts (Supplier/Project/Department + SupplierType const-object)
- AuthContext: load menu from /menus/me, cache localStorage, refreshMenu()
- usePermission hook + PermissionGuard component (wrap button)
- UI kit them: Dialog (modal overlay), Textarea, Select
- Generic: DataTable (column config, sortable, loading, empty) + Pagination
- PageHeader component
- apiError helper extract message tu ProblemDetails
- Layout rewrite: render menu dong tu AuthContext.menu (MenuGroup collapsible + NavLink + lucide icon map)
- Pages: master/Suppliers, master/Projects, master/Departments (CRUD + search + sort + paging + Dialog form)
- Page system/Permissions: ma tran Role x MenuKey x CRUD checkbox (tick tu dong PUT upsert)
- App.tsx them 4 route moi
Bug fix:
- MenuPermissionHandler: EF expression tree khong support switch expression -> tach switch ra ngoai AnyAsync
- TS erasableSyntaxOnly khong cho enum -> SupplierType const-object pattern (typeof[keyof])
E2E verified via Vite proxy:
- GET /menus/me -> 6 root + 6 child nodes (12 menus)
- GET /roles -> 12 roles
- POST/GET/PUT/DELETE /suppliers -> full CRUD, soft delete OK
- tsc -b fe-admin pass
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
14
src/Backend/SolutionErp.Domain/Identity/MenuItem.cs
Normal file
14
src/Backend/SolutionErp.Domain/Identity/MenuItem.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace SolutionErp.Domain.Identity;
|
||||
|
||||
public class MenuItem
|
||||
{
|
||||
public string Key { get; set; } = string.Empty; // PK, PascalCase
|
||||
public string Label { get; set; } = string.Empty; // Tiếng Việt display
|
||||
public string? ParentKey { get; set; } // NULL nếu root
|
||||
public int Order { get; set; }
|
||||
public string? Icon { get; set; } // lucide-react icon name
|
||||
|
||||
public MenuItem? Parent { get; set; }
|
||||
public List<MenuItem> Children { get; set; } = new();
|
||||
public List<Permission> Permissions { get; set; } = new();
|
||||
}
|
||||
29
src/Backend/SolutionErp.Domain/Identity/MenuKeys.cs
Normal file
29
src/Backend/SolutionErp.Domain/Identity/MenuKeys.cs
Normal file
@ -0,0 +1,29 @@
|
||||
namespace SolutionErp.Domain.Identity;
|
||||
|
||||
// Nguồn duy nhất (single source of truth) cho menu key — dùng ở cả BE (policy) và seed.
|
||||
// FE có `src/lib/menuKeys.ts` đồng bộ tay.
|
||||
public static class MenuKeys
|
||||
{
|
||||
public const string Dashboard = "Dashboard";
|
||||
public const string Master = "Master";
|
||||
public const string Suppliers = "Suppliers";
|
||||
public const string Projects = "Projects";
|
||||
public const string Departments = "Departments";
|
||||
public const string Contracts = "Contracts";
|
||||
public const string Forms = "Forms";
|
||||
public const string Reports = "Reports";
|
||||
public const string System = "System";
|
||||
public const string Users = "Users";
|
||||
public const string Roles = "Roles";
|
||||
public const string Permissions = "Permissions";
|
||||
|
||||
public static readonly string[] All =
|
||||
[
|
||||
Dashboard,
|
||||
Master, Suppliers, Projects, Departments,
|
||||
Contracts, Forms, Reports,
|
||||
System, Users, Roles, Permissions,
|
||||
];
|
||||
|
||||
public static readonly string[] Actions = ["Read", "Create", "Update", "Delete"];
|
||||
}
|
||||
15
src/Backend/SolutionErp.Domain/Identity/Permission.cs
Normal file
15
src/Backend/SolutionErp.Domain/Identity/Permission.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace SolutionErp.Domain.Identity;
|
||||
|
||||
public class Permission
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid RoleId { get; set; }
|
||||
public string MenuKey { get; set; } = string.Empty;
|
||||
public bool CanRead { get; set; }
|
||||
public bool CanCreate { get; set; }
|
||||
public bool CanUpdate { get; set; }
|
||||
public bool CanDelete { get; set; }
|
||||
|
||||
public Role? Role { get; set; }
|
||||
public MenuItem? Menu { get; set; }
|
||||
}
|
||||
11
src/Backend/SolutionErp.Domain/Master/Department.cs
Normal file
11
src/Backend/SolutionErp.Domain/Master/Department.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using SolutionErp.Domain.Common;
|
||||
|
||||
namespace SolutionErp.Domain.Master;
|
||||
|
||||
public class Department : AuditableEntity
|
||||
{
|
||||
public string Code { get; set; } = string.Empty; // vd "CCM", "PRO", "FIN"
|
||||
public string Name { get; set; } = string.Empty; // vd "Phòng Kiểm soát Chi phí"
|
||||
public Guid? ManagerUserId { get; set; } // TPB — Trưởng Phòng ban
|
||||
public string? Note { get; set; }
|
||||
}
|
||||
14
src/Backend/SolutionErp.Domain/Master/Project.cs
Normal file
14
src/Backend/SolutionErp.Domain/Master/Project.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using SolutionErp.Domain.Common;
|
||||
|
||||
namespace SolutionErp.Domain.Master;
|
||||
|
||||
public class Project : AuditableEntity
|
||||
{
|
||||
public string Code { get; set; } = string.Empty; // vd "FLOCK 01"
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public DateTime? StartDate { get; set; }
|
||||
public DateTime? EndDate { get; set; }
|
||||
public Guid? ManagerUserId { get; set; } // PM — Giám đốc Dự án
|
||||
public decimal? BudgetTotal { get; set; } // Tổng ngân sách dự án (tham chiếu cho CCM check)
|
||||
public string? Note { get; set; }
|
||||
}
|
||||
16
src/Backend/SolutionErp.Domain/Master/Supplier.cs
Normal file
16
src/Backend/SolutionErp.Domain/Master/Supplier.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using SolutionErp.Domain.Common;
|
||||
|
||||
namespace SolutionErp.Domain.Master;
|
||||
|
||||
public class Supplier : AuditableEntity
|
||||
{
|
||||
public string Code { get; set; } = string.Empty; // Mã NCC (viết tắt, dùng trong mã HĐ)
|
||||
public string Name { get; set; } = string.Empty; // Tên công ty đầy đủ
|
||||
public SupplierType Type { get; set; }
|
||||
public string? TaxCode { get; set; } // Mã số thuế
|
||||
public string? Phone { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Address { get; set; }
|
||||
public string? ContactPerson { get; set; } // Người liên hệ
|
||||
public string? Note { get; set; }
|
||||
}
|
||||
10
src/Backend/SolutionErp.Domain/Master/SupplierType.cs
Normal file
10
src/Backend/SolutionErp.Domain/Master/SupplierType.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace SolutionErp.Domain.Master;
|
||||
|
||||
public enum SupplierType
|
||||
{
|
||||
NhaCungCap = 1, // NCC — Nhà cung cấp
|
||||
NhaThauPhu = 2, // NTP — Nhà thầu phụ
|
||||
ToDoi = 3, // TĐ — Tổ đội
|
||||
DonViDichVu = 4, // ĐVDV — Đơn vị dịch vụ
|
||||
ChuDauTu = 5, // CĐT — Chủ đầu tư (đặc biệt, bypass quy trình CCM)
|
||||
}
|
||||
Reference in New Issue
Block a user