完善公共事業費用與會計報表權限設定
- 新增 utility_fees 與 accounting 相關權限至 PermissionSeeder - 更新 RoleController 加入權限群組中文標題映射 - 為會計報表匯出功能加上權限保護 - 前端加入 Can 組件保護按鈕顯示 - 更新權限管理 Skill 文件,補充 UI 顯示設定步驟
This commit is contained in:
@@ -110,10 +110,31 @@ export default function ProductIndex() {
|
||||
- `canAny(permissions: string[])`: 檢查當前使用者是否擁有陣列中**任一**權限。
|
||||
- `hasRole(role: string)`: 檢查當前使用者是否擁有指定角色。
|
||||
|
||||
## 5. 配置權限群組名稱 (Backend UI Config)
|
||||
|
||||
為了讓新權限在「角色與權限」管理介面中顯示正確的中文分組標題,需修改 Controller 設定。
|
||||
|
||||
### 步驟:
|
||||
|
||||
1. 開啟 `app/Http/Controllers/Admin/RoleController.php`。
|
||||
2. 找到 `getGroupedPermissions` 方法。
|
||||
3. 在 `$groupDefinitions` 陣列中,新增 `{resource}` 對應的中文名稱。
|
||||
|
||||
### 範例:
|
||||
|
||||
```php
|
||||
$groupDefinitions = [
|
||||
'products' => '商品資料管理',
|
||||
// ...
|
||||
'utility_fees' => '公共事業費管理', // 新增此行
|
||||
];
|
||||
```
|
||||
|
||||
## 檢核清單
|
||||
|
||||
- [ ] `PermissionSeeder.php` 已新增權限字串。
|
||||
- [ ] `PermissionSeeder.php` 已將新權限分配給對應角色。
|
||||
- [ ] 已執行 `php artisan tenants:seed --class=PermissionSeeder` 更新資料庫。
|
||||
- [ ] `RoleController.php` 已新增權限群組的中文名稱映射。
|
||||
- [ ] 後端路由 (`routes/web.php`) 已加上 middleware 保護。
|
||||
- [ ] 前端頁面/按鈕已使用 `usePermission` 進行顯示控制。
|
||||
|
||||
@@ -179,6 +179,8 @@ class RoleController extends Controller
|
||||
'purchase_orders' => '採購單管理',
|
||||
'users' => '使用者管理',
|
||||
'roles' => '角色與權限',
|
||||
'utility_fees' => '公共事業費管理',
|
||||
'accounting' => '會計報表',
|
||||
];
|
||||
|
||||
$result = [];
|
||||
|
||||
@@ -63,6 +63,16 @@ class PermissionSeeder extends Seeder
|
||||
|
||||
// 系統日誌
|
||||
'system.view_logs',
|
||||
|
||||
// 公共事業費管理
|
||||
'utility_fees.view',
|
||||
'utility_fees.create',
|
||||
'utility_fees.edit',
|
||||
'utility_fees.delete',
|
||||
|
||||
// 會計報表
|
||||
'accounting.view',
|
||||
'accounting.export',
|
||||
];
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
@@ -90,7 +100,10 @@ class PermissionSeeder extends Seeder
|
||||
'vendors.view', 'vendors.create', 'vendors.edit', 'vendors.delete',
|
||||
'warehouses.view', 'warehouses.create', 'warehouses.edit', 'warehouses.delete',
|
||||
'users.view', 'users.create', 'users.edit',
|
||||
'users.view', 'users.create', 'users.edit',
|
||||
'system.view_logs',
|
||||
'utility_fees.view', 'utility_fees.create', 'utility_fees.edit', 'utility_fees.delete',
|
||||
'accounting.view', 'accounting.export',
|
||||
]);
|
||||
|
||||
// warehouse-manager 管理庫存與倉庫
|
||||
@@ -115,6 +128,8 @@ class PermissionSeeder extends Seeder
|
||||
'inventory.view',
|
||||
'vendors.view',
|
||||
'warehouses.view',
|
||||
'utility_fees.view',
|
||||
'accounting.view',
|
||||
]);
|
||||
|
||||
// 將現有使用者設為 super-admin(如果存在的話)
|
||||
|
||||
@@ -27,6 +27,7 @@ import { getDateRange, formatDateWithDayOfWeek } from "@/utils/format";
|
||||
import { Badge } from "@/Components/ui/badge";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import { Can } from "@/Components/Permission/Can";
|
||||
|
||||
interface Record {
|
||||
id: string;
|
||||
@@ -135,13 +136,15 @@ export default function AccountingReport({ records, summary, filters }: PageProp
|
||||
<p className="text-gray-500 mt-1">彙整採購支出與各項公用事業費用</p>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
onClick={handleExport}
|
||||
variant="outline"
|
||||
className="button-outlined-primary gap-2"
|
||||
>
|
||||
<Download className="h-4 w-4" /> 匯出 CSV 報表
|
||||
</Button>
|
||||
<Can permission="accounting.export">
|
||||
<Button
|
||||
onClick={handleExport}
|
||||
variant="outline"
|
||||
className="button-outlined-primary gap-2"
|
||||
>
|
||||
<Download className="h-4 w-4" /> 匯出 CSV 報表
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
|
||||
{/* Filters with Quick Date Range */}
|
||||
@@ -224,7 +227,7 @@ export default function AccountingReport({ records, summary, filters }: PageProp
|
||||
onClick={handleFilter}
|
||||
className="button-filled-primary h-9 px-6 gap-2"
|
||||
>
|
||||
<Filter className="h-4 w-4" /> 篩選
|
||||
<Filter className="h-4 w-4" /> 查詢
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -147,7 +147,9 @@ Route::middleware('auth')->group(function () {
|
||||
// 系統管理
|
||||
Route::middleware('permission:accounting.view')->prefix('accounting-report')->group(function () {
|
||||
Route::get('/', [AccountingReportController::class, 'index'])->name('accounting.report');
|
||||
Route::get('/export', [AccountingReportController::class, 'export'])->name('accounting.export');
|
||||
Route::get('/export', [AccountingReportController::class, 'export'])
|
||||
->middleware('permission:accounting.export')
|
||||
->name('accounting.export');
|
||||
});
|
||||
|
||||
// 系統管理
|
||||
|
||||
Reference in New Issue
Block a user