mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 21:38:48 +00:00
* Add generic implementation for barcode actions - Commonize code against tables - Cleaner UI - Better code - Will make future react refactor easier * Add permissions.js - Separate .js file for dynamically checking permissions * Update stock table to use client-side actions * API endpoint for bulk category adjustment * Bug fix for purchase_order.js - Prevent some really strange API calls * Refactor actions for part table - Now done dynamically * Refactor actions for the attachment tables * Refactor actions for build output table * Increment API version * Cleanup janky button * Refactor supplier part table * Refactor manufacturer part table * Remove linkButtonsToSelection - no longer needed - Cleanup, yay! * Cleanup purchase order line table * Refactor BOM table buttons * JS linting * Further cleanup * Template cleanup - remove extra div elements * js linting * js fix
60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
/*
|
|
* globals
|
|
inventreeGet,
|
|
|
|
/* exported
|
|
checkPermission,
|
|
*/
|
|
|
|
// Keep track of the current user permissions
|
|
var user_roles = null;
|
|
|
|
|
|
/*
|
|
* Check if the user has the specified role and permission
|
|
*/
|
|
function checkPermission(role, permission='view') {
|
|
|
|
// Allow permission to be specified in dotted notation, e.g. 'part.add'
|
|
if (role.indexOf('.') > 0) {
|
|
let parts = role.split('.');
|
|
role = parts[0];
|
|
permission = parts[1];
|
|
}
|
|
|
|
// Request user roles if we do not have them
|
|
if (user_roles == null) {
|
|
inventreeGet('{% url "api-user-roles" %}', {}, {
|
|
async: false,
|
|
success: function(response) {
|
|
user_roles = response.roles || {};
|
|
}
|
|
});
|
|
}
|
|
|
|
if (user_roles == null) {
|
|
console.error("Failed to fetch user roles");
|
|
return false;
|
|
}
|
|
|
|
if (!(role in user_roles)) {
|
|
return false;
|
|
}
|
|
|
|
let roles = user_roles[role];
|
|
|
|
if (!roles) {
|
|
return false;
|
|
}
|
|
|
|
let found = false;
|
|
|
|
user_roles[role].forEach(function(p) {
|
|
if (String(p).valueOf() == String(permission).valueOf()) {
|
|
found = true;
|
|
}
|
|
});
|
|
|
|
return found;
|
|
}
|