diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 874ec168..4454229c 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -62,7 +62,7 @@ class _CategoryDisplayState extends RefreshableState { ) ); - if (category != null) { + if ((category != null) && InvenTreeAPI().checkPermission('part_category', 'change')) { actions.add( IconButton( icon: FaIcon(FontAwesomeIcons.edit), diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index a3c82e1f..7991d155 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -62,7 +62,7 @@ class _LocationDisplayState extends RefreshableState { ), ); - if (location != null) { + if ((location != null) && (InvenTreeAPI().checkPermission('stock_location', 'change'))) { actions.add( IconButton( icon: FaIcon(FontAwesomeIcons.edit), @@ -320,22 +320,29 @@ List detailTiles() { tiles.add(locationDescriptionCard()); - // Scan items into location - tiles.add( - ListTile( - title: Text(I18N.of(context).barcodeScanInItems), - leading: FaIcon(FontAwesomeIcons.exchangeAlt), - trailing: FaIcon(FontAwesomeIcons.qrcode), - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) => InvenTreeQRView(StockLocationScanInItemsHandler(location))) - ).then((context) { - refresh(); - }); - }, - ) - ); + // Stock adjustment actions + if (InvenTreeAPI().checkPermission('stock', 'change')) { + // Scan items into location + tiles.add( + ListTile( + title: Text(I18N + .of(context) + .barcodeScanInItems), + leading: FaIcon(FontAwesomeIcons.exchangeAlt), + trailing: FaIcon(FontAwesomeIcons.qrcode), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => + InvenTreeQRView( + StockLocationScanInItemsHandler(location))) + ).then((context) { + refresh(); + }); + }, + ) + ); + } // Move location into another location // TODO: Implement this! diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 2cf540e1..ed661ff5 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -41,18 +41,29 @@ class _PartDisplayState extends RefreshableState { @override List getAppBarActions(BuildContext context) { - return [ - IconButton( - icon: FaIcon(FontAwesomeIcons.globe), - onPressed: _openInvenTreePage, - ), - // TODO: Hide the 'edit' button if the user does not have permission!! - IconButton( - icon: FaIcon(FontAwesomeIcons.edit), - tooltip: I18N.of(context).edit, - onPressed: _editPartDialog, - ) - ]; + + List actions = []; + + if (InvenTreeAPI().checkPermission('part', 'view')) { + actions.add( + IconButton( + icon: FaIcon(FontAwesomeIcons.globe), + onPressed: _openInvenTreePage, + ), + ); + } + + if (InvenTreeAPI().checkPermission('part', 'change')) { + actions.add( + IconButton( + icon: FaIcon(FontAwesomeIcons.edit), + tooltip: I18N.of(context).edit, + onPressed: _editPartDialog, + ) + ); + } + + return actions; } _PartDisplayState(this.part) { @@ -82,8 +93,11 @@ class _PartDisplayState extends RefreshableState { } void _toggleStar() async { - await part.update(context, values: {"starred": "${!part.starred}"}); - refresh(); + + if (InvenTreeAPI().checkPermission('part', 'change')) { + await part.update(context, values: {"starred": "${!part.starred}"}); + refresh(); + } } void _savePart(Map values) async { diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index 40275aab..9b69ad04 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -140,10 +140,9 @@ class _StockItemDisplayState extends RefreshableState { void _stockUpdateMessage(bool result) { - showSnackIcon( - result ? "Stock item updated" : "Stock item updated failed", - success: result - ); + if (result) { + showSnackIcon("Stock item updated", success: true); + } } void _removeStock() async { @@ -514,6 +513,24 @@ class _StockItemDisplayState extends RefreshableState { tiles.add(headerTile()); + // First check that the user has the required permissions to adjust stock + if (!InvenTreeAPI().checkPermission('stock', 'change')) { + tiles.add( + ListTile( + title: Text("Permission Required"), + leading: FaIcon(FontAwesomeIcons.userTimes) + ) + ); + + tiles.add( + ListTile( + subtitle: Text("Your account does not have permission to perform stock adjustments"), + ) + ); + + return tiles; + } + if (!item.isSerialized()) { tiles.add( ListTile(