50%
This commit is contained in:
@@ -143,8 +143,45 @@
|
||||
window.location.href = '/login?return=' + encodeURIComponent(window.location.pathname);
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide create/update/delete buttons for viewer role
|
||||
hideButtonsForViewer();
|
||||
})();
|
||||
|
||||
// Get current user role
|
||||
function getCurrentUserRole() {
|
||||
try {
|
||||
const userStr = localStorage.getItem('atlas_user');
|
||||
if (userStr) {
|
||||
const user = JSON.parse(userStr);
|
||||
return (user.role || '').toLowerCase();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error parsing user data:', e);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// Check if current user is viewer
|
||||
function isViewer() {
|
||||
return getCurrentUserRole() === 'viewer';
|
||||
}
|
||||
|
||||
// Hide create/update/delete buttons for viewer role
|
||||
function hideButtonsForViewer() {
|
||||
if (isViewer()) {
|
||||
// Hide create buttons
|
||||
document.querySelectorAll('button').forEach(btn => {
|
||||
const text = btn.textContent || '';
|
||||
const onclick = btn.getAttribute('onclick') || '';
|
||||
if (text.includes('Create') || text.includes('Add LUN') || text.includes('Delete') ||
|
||||
onclick.includes('showCreate') || onclick.includes('addLUN') || onclick.includes('deleteISCSITarget')) {
|
||||
btn.style.display = 'none';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getAuthHeaders() {
|
||||
const token = localStorage.getItem('atlas_token');
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user