Add RBAC: admin user management, audit log, runtime settings, delete PC
This commit is contained in:
@@ -81,7 +81,12 @@
|
||||
<td>{{ c.current_ram_percent | round(1) if c.current_ram_percent is not none else '-' }}%</td>
|
||||
<td>{{ c.os_info or '-' }}</td>
|
||||
<td class="last-seen">{% if c.last_seen %}{{ c.last_seen.strftime('%Y-%m-%d %H:%M') }}{% else %}-{% endif %}</td>
|
||||
<td><a href="/computers/{{ c.id }}" class="btn btn-sm btn-outline-primary">Детали</a></td>
|
||||
<td>
|
||||
<a href="/computers/{{ c.id }}" class="btn btn-sm btn-outline-primary">Детали</a>
|
||||
{% if user.role == 'admin' %}
|
||||
<button class="btn btn-sm btn-outline-danger delete-pc" data-id="{{ c.id }}" data-hostname="{{ c.hostname }}">Удалить</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -94,10 +99,23 @@
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
const isAdmin = {{ 'true' if user.role == 'admin' else 'false' }};
|
||||
|
||||
function currentQuery() {
|
||||
return new URLSearchParams(window.location.search).toString();
|
||||
}
|
||||
|
||||
async function deleteComputer(id, hostname) {
|
||||
if (!confirm(`Удалить ПК ${hostname}?`)) return;
|
||||
const res = await fetch(`/api/computers/${id}`, {method: 'DELETE'});
|
||||
if (res.ok) location.reload();
|
||||
else alert('Ошибка удаления');
|
||||
}
|
||||
|
||||
document.querySelectorAll('.delete-pc').forEach(btn => {
|
||||
btn.addEventListener('click', () => deleteComputer(btn.dataset.id, btn.dataset.hostname));
|
||||
});
|
||||
|
||||
async function loadDashboard() {
|
||||
try {
|
||||
const res = await fetch('/api/computers?' + currentQuery());
|
||||
@@ -114,9 +132,15 @@ async function loadDashboard() {
|
||||
<td>${c.current_ram_percent != null ? c.current_ram_percent.toFixed(1) : '-'}%</td>
|
||||
<td>${escapeHtml(c.os_info || '-')}</td>
|
||||
<td class="last-seen">${c.last_seen ? c.last_seen.replace('T', ' ').slice(0, 16) : '-'}</td>
|
||||
<td><a href="/computers/${c.id}" class="btn btn-sm btn-outline-primary">Детали</a></td>
|
||||
<td>
|
||||
<a href="/computers/${c.id}" class="btn btn-sm btn-outline-primary">Детали</a>
|
||||
${isAdmin ? `<button class="btn btn-sm btn-outline-danger delete-pc" data-id="${c.id}" data-hostname="${escapeHtml(c.hostname)}">Удалить</button>` : ''}
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
document.querySelectorAll('.delete-pc').forEach(btn => {
|
||||
btn.addEventListener('click', () => deleteComputer(btn.dataset.id, btn.dataset.hostname));
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Dashboard refresh failed', e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user