This commit is contained in:
2025-12-23 07:50:08 +00:00
parent 4c3ea0059d
commit 7826c6ed24
12 changed files with 2008 additions and 98 deletions

View File

@@ -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 {