Skip to content

Commit d037df1

Browse files
committed
Disable role controls for protected users with consistent styling
1 parent 894caa3 commit d037df1

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/main.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,34 @@ footer {
15101510
transform: none;
15111511
}
15121512

1513+
/* Disabled role controls */
1514+
.role-select.disabled {
1515+
background: #6b7280;
1516+
color: #9ca3af;
1517+
cursor: not-allowed;
1518+
opacity: 0.6;
1519+
border-color: #6b7280;
1520+
}
1521+
1522+
.role-select.disabled:hover {
1523+
background: #6b7280;
1524+
color: #9ca3af;
1525+
border-color: #6b7280;
1526+
}
1527+
1528+
.update-role-btn.disabled {
1529+
background: #6b7280;
1530+
color: #9ca3af;
1531+
cursor: not-allowed;
1532+
opacity: 0.6;
1533+
}
1534+
1535+
.update-role-btn.disabled:hover {
1536+
background: #6b7280;
1537+
color: #9ca3af;
1538+
transform: none;
1539+
}
1540+
15131541
/* Modal Styles */
15141542
.modal {
15151543
display: none;

views/admin.ejs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,23 @@
9999
<div class="user-actions">
100100
<div class="role-controls">
101101
<label for="role-<%= currentUser.userid %>">Change Role:</label>
102-
<select id="role-<%= currentUser.userid %>" class="role-select" data-user-id="<%= currentUser.userid %>">
103-
<option value="admin" <%= currentUser.role === 'admin' ? 'selected' : '' %>>Admin</option>
104-
<option value="contributor" <%= currentUser.role === 'contributor' ? 'selected' : '' %>>Contributor</option>
105-
<option value="viewer" <%= currentUser.role === 'viewer' ? 'selected' : '' %>>Viewer</option>
106-
</select>
107-
<button class="button primary small update-role-btn" data-user-id="<%= currentUser.userid %>">
108-
Update
109-
</button>
102+
<% if (currentUser.isProtected) { %>
103+
<select id="role-<%= currentUser.userid %>" class="role-select disabled" data-user-id="<%= currentUser.userid %>" disabled title="Protected system account - role cannot be changed">
104+
<option value="<%= currentUser.role %>" selected><%= currentUser.role.charAt(0).toUpperCase() + currentUser.role.slice(1) %></option>
105+
</select>
106+
<button class="button primary small update-role-btn disabled" data-user-id="<%= currentUser.userid %>" disabled title="Protected system account - role cannot be changed">
107+
Update
108+
</button>
109+
<% } else { %>
110+
<select id="role-<%= currentUser.userid %>" class="role-select" data-user-id="<%= currentUser.userid %>">
111+
<option value="admin" <%= currentUser.role === 'admin' ? 'selected' : '' %>>Admin</option>
112+
<option value="contributor" <%= currentUser.role === 'contributor' ? 'selected' : '' %>>Contributor</option>
113+
<option value="viewer" <%= currentUser.role === 'viewer' ? 'selected' : '' %>>Viewer</option>
114+
</select>
115+
<button class="button primary small update-role-btn" data-user-id="<%= currentUser.userid %>">
116+
Update
117+
</button>
118+
<% } %>
110119
</div>
111120
112121
<div class="action-buttons">
@@ -240,6 +249,13 @@
240249
async function updateUserRole(event) {
241250
const userId = event.target.dataset.userId;
242251
const roleSelect = document.getElementById(`role-${userId}`);
252+
253+
// Check if the role select is disabled (protected user)
254+
if (roleSelect.disabled) {
255+
alert('Cannot modify protected system account');
256+
return;
257+
}
258+
243259
const newRole = roleSelect.value;
244260
245261
try {

0 commit comments

Comments
 (0)