mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-16 20:25:26 +00:00
Make notes widget "generic" (#327)
* Make notes widget "generic" - No longer tied to the "part" model - Will allow us to use it elsewhere * Update release notes * Add helper methods for checking model permissions * Refactoring of permissions checks * Add notes to the "purchase order" widget * Fix typos * remove bom tab from part view * linting fixes
This commit is contained in:
@ -10,6 +10,7 @@ import "package:inventree/api.dart";
|
||||
import "package:inventree/api_form.dart";
|
||||
import "package:inventree/fa_icon_mapping.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/helpers.dart";
|
||||
import "package:inventree/inventree/sentry.dart";
|
||||
import "package:inventree/widget/dialogs.dart";
|
||||
|
||||
@ -78,7 +79,63 @@ class InvenTreeModel {
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/* Return a list of roles which may be required for this model
|
||||
* If multiple roles are required, *any* role which passes the check is sufficient
|
||||
*/
|
||||
List<String> get rolesRequired {
|
||||
// Default implementation should not be called
|
||||
debug("rolesRequired() not implemented for model ${URL} - returning empty list");
|
||||
return [];
|
||||
}
|
||||
|
||||
// Test if the user can "edit" this model
|
||||
bool get canEdit {
|
||||
for (String role in rolesRequired) {
|
||||
if (InvenTreeAPI().checkPermission(role, "change")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
return false;
|
||||
}
|
||||
|
||||
// Test if the user can "create" this model
|
||||
bool get canCreate {
|
||||
for (String role in rolesRequired) {
|
||||
if (InvenTreeAPI().checkPermission(role, "add")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
return false;
|
||||
}
|
||||
|
||||
// Test if the user can "delete" this model
|
||||
bool get canDelete {
|
||||
for (String role in rolesRequired) {
|
||||
if (InvenTreeAPI().checkPermission(role, "delete")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
return false;
|
||||
}
|
||||
|
||||
// Test if the user can "view" this model
|
||||
bool get canView {
|
||||
for (String role in rolesRequired) {
|
||||
if (InvenTreeAPI().checkPermission(role, "view")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fields for editing / creating this model
|
||||
|
Reference in New Issue
Block a user