| .. | ||
| access_denied_page.dart | ||
| permission_button.dart | ||
| permission_info_widget.dart | ||
| permission_widgets.dart | ||
| README.md | ||
سیستم مدیریت دسترسیها
این سیستم برای مدیریت دسترسیهای کاربران در سطح کسب و کار طراحی شده است.
ویژگیها
- دسترسیهای جزئی: پشتیبانی از دسترسیهای بسیار جزئی برای هر بخش
- مدیریت خودکار: فیلتر کردن منو و دکمهها بر اساس دسترسیها
- کامپوننتهای آماده: ویجتهای آماده برای بررسی دسترسیها
- امنیت کامل: بررسی دسترسیها در هر سطح
دسترسیهای موجود
اشخاص (People)
people: add, view, edit, deletepeople_receipts: add, view, edit, delete, draftpeople_payments: add, view, edit, delete, draft
کالا و خدمات (Products & Services)
products: add, view, edit, deleteprice_lists: add, view, edit, deletecategories: add, view, edit, deleteproduct_attributes: add, view, edit, delete
بانکداری (Banking)
bank_accounts: add, view, edit, deletecash: add, view, edit, deletepetty_cash: add, view, edit, deletechecks: add, view, edit, delete, collect, transfer, returnwallet: view, chargetransfers: add, view, edit, delete, draft
فاکتورها و هزینهها (Invoices & Expenses)
invoices: add, view, edit, delete, draftexpenses_income: add, view, edit, delete, draft
حسابداری (Accounting)
accounting_documents: add, view, edit, delete, draftchart_of_accounts: add, view, edit, deleteopening_balance: view, edit
انبارداری (Warehouse)
warehouses: add, view, edit, deletewarehouse_transfers: add, view, edit, delete, draft
تنظیمات (Settings)
settings: business, print, history, usersstorage: view, deletesms: history, templatesmarketplace: view, buy, invoices
نحوه استفاده
1. بررسی دسترسی در AuthStore
final authStore = Provider.of<AuthStore>(context);
// بررسی دسترسی کلی
if (authStore.canReadSection('people')) {
// نمایش لیست اشخاص
}
// بررسی دسترسی خاص
if (authStore.hasBusinessPermission('people', 'add')) {
// نمایش دکمه اضافه کردن
}
// بررسی دسترسیهای خاص
if (authStore.canCollectChecks()) {
// نمایش دکمه وصول چک
}
2. استفاده از کامپوننتهای آماده
PermissionButton
PermissionButton(
section: 'people',
action: 'add',
authStore: authStore,
child: IconButton(
onPressed: () => _addPerson(),
icon: const Icon(Icons.add),
tooltip: 'اضافه کردن شخص',
),
)
PermissionWidget
PermissionWidget(
section: 'settings',
action: 'view',
authStore: authStore,
child: Card(
child: ListTile(
title: Text('تنظیمات'),
onTap: () => _openSettings(),
),
),
)
AccessDeniedPage
if (!authStore.canReadSection('people')) {
return AccessDeniedPage(
message: 'شما دسترسی لازم برای مشاهده لیست اشخاص را ندارید',
);
}
3. فیلتر کردن منو
منوی کسب و کار به صورت خودکار بر اساس دسترسیهای کاربر فیلتر میشود:
// در BusinessShell
final menuItems = _getFilteredMenuItems(allMenuItems);
4. API Endpoint
// دریافت اطلاعات کسب و کار و دسترسیها
final businessData = await businessService.getBusinessWithPermissions(businessId);
await authStore.setCurrentBusiness(businessData);
مثال کامل
class PersonsPage extends StatelessWidget {
final int businessId;
final AuthStore authStore;
const PersonsPage({
super.key,
required this.businessId,
required this.authStore,
});
@override
Widget build(BuildContext context) {
// بررسی دسترسی خواندن
if (!authStore.canReadSection('people')) {
return AccessDeniedPage(
message: 'شما دسترسی لازم برای مشاهده لیست اشخاص را ندارید',
);
}
return Scaffold(
appBar: AppBar(
title: Text('لیست اشخاص'),
actions: [
// دکمه اضافه کردن فقط در صورت داشتن دسترسی
PermissionButton(
section: 'people',
action: 'add',
authStore: authStore,
child: IconButton(
onPressed: () => _addPerson(),
icon: const Icon(Icons.add),
tooltip: 'اضافه کردن شخص',
),
),
],
),
body: PersonsList(),
);
}
}
نکات مهم
- امنیت: همیشه دسترسیها را در سمت سرور نیز بررسی کنید
- عملکرد: دسترسیها در AuthStore کش میشوند
- بهروزرسانی: دسترسیها هنگام تغییر کسب و کار بهروزرسانی میشوند
- مالک کسب و کار: مالک کسب و کار تمام دسترسیها را دارد