feat: Conditionally display Create Bucket option based on user permissions
This commit is contained in:
parent
229531c5bf
commit
bd6f175ca7
@ -16,6 +16,7 @@ import 'package:marco/model/directory/create_bucket_bottom_sheet.dart';
|
||||
import 'package:marco/view/directory/contact_detail_screen.dart';
|
||||
import 'package:marco/view/directory/manage_bucket_screen.dart';
|
||||
import 'package:marco/controller/permission_controller.dart';
|
||||
import 'package:marco/helpers/utils/permission_constants.dart';
|
||||
|
||||
class DirectoryView extends StatefulWidget {
|
||||
@override
|
||||
@ -288,35 +289,44 @@ class _DirectoryViewState extends State<DirectoryView> {
|
||||
),
|
||||
);
|
||||
|
||||
// Create Bucket option
|
||||
menuItems.add(
|
||||
PopupMenuItem<int>(
|
||||
value: 2,
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.add_box_outlined,
|
||||
size: 20, color: Colors.black87),
|
||||
SizedBox(width: 10),
|
||||
Expanded(child: Text("Create Bucket")),
|
||||
Icon(Icons.chevron_right,
|
||||
size: 20, color: Colors.red),
|
||||
],
|
||||
// ✅ Conditionally show Create Bucket option
|
||||
if (permissionController
|
||||
.hasPermission(Permissions.directoryAdmin) ||
|
||||
permissionController
|
||||
.hasPermission(Permissions.directoryManager) ||
|
||||
permissionController
|
||||
.hasPermission(Permissions.directoryUser)) {
|
||||
menuItems.add(
|
||||
PopupMenuItem<int>(
|
||||
value: 2,
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.add_box_outlined,
|
||||
size: 20, color: Colors.black87),
|
||||
SizedBox(width: 10),
|
||||
Expanded(child: Text("Create Bucket")),
|
||||
Icon(Icons.chevron_right,
|
||||
size: 20, color: Colors.red),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
Future.delayed(Duration.zero, () async {
|
||||
final created =
|
||||
await showModalBottomSheet<bool>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (_) =>
|
||||
const CreateBucketBottomSheet(),
|
||||
);
|
||||
if (created == true) {
|
||||
await controller.fetchBuckets();
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
onTap: () {
|
||||
Future.delayed(Duration.zero, () async {
|
||||
final created = await showModalBottomSheet<bool>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (_) => const CreateBucketBottomSheet(),
|
||||
);
|
||||
if (created == true) {
|
||||
await controller.fetchBuckets();
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
// Manage Buckets option
|
||||
menuItems.add(
|
||||
@ -355,7 +365,7 @@ class _DirectoryViewState extends State<DirectoryView> {
|
||||
),
|
||||
);
|
||||
|
||||
// Show Inactive switch
|
||||
// Show Inactive toggle
|
||||
menuItems.add(
|
||||
PopupMenuItem<int>(
|
||||
value: 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user