NetworkView: API routing fix, logout button, audit trail, port/notes editor tracking

- Fix frontend API base path (VITE_API_BASE env var, GraphPage hardcoded /api)
- Add logout button to NetworkView sidebar (clears portal SSO)
- Add AuditTrail component: inline change history on all entity pages
- DB migration: add updated_at, last_edited_by to ports table
- DB migration: add notes_last_edited_by, notes_updated_at to all entity tables
- Backend: track actor on port create/update; notes editor on entity PUT
- Frontend: extend types, MarkdownEditor shows last editor, port modal/list show last editor
- Fix port CREATE TABLE definition to include new columns upfront
- Add try/catch in handleSavePort to surface API errors in modal
This commit is contained in:
ske087
2026-05-10 23:10:02 +03:00
parent 8d9df56b0b
commit 0aefadbfd8
27 changed files with 470 additions and 355 deletions
+3 -3
View File
@@ -34,12 +34,12 @@ def login():
@auth_bp.route('/logout')
@login_required
def logout():
"""User logout"""
"""Log out of DigiServer and redirect to portal logout to clear the SSO cookie."""
username = current_user.username
logout_user()
log_action('info', f'User {username} logged out')
flash('You have been logged out.', 'info')
return redirect(url_for('auth.login'))
portal_logout = current_app.config.get('PORTAL_LOGOUT_URL', 'http://localhost:8080/logout')
return redirect(portal_logout)
@auth_bp.route('/register', methods=['GET', 'POST'])
+1
View File
@@ -54,6 +54,7 @@ class Config:
# URL of the portal login page — users are redirected here if they try to
# access DigiServer directly without a portal session.
PORTAL_LOGIN_URL = os.getenv('PORTAL_LOGIN_URL', 'http://localhost:8080/login')
PORTAL_LOGOUT_URL = os.getenv('PORTAL_LOGOUT_URL', 'http://localhost:8080/logout')
# Set to True to disable DigiServer's own user registration and management UI.
# When True, all user accounts are managed exclusively through the portal.
@@ -5,7 +5,15 @@
{% block content %}
<div class="page-header">
<h1>👥 User Management</h1>
<button class="btn btn-primary" onclick="showCreateUserModal()">+ Create New User</button>
</div>
<div class="portal-notice">
<span class="portal-notice-icon">🔒</span>
<div>
<strong>User accounts are managed by the Enterprise Digital Platform portal.</strong><br>
To create users or change roles, visit <a href="/settings" target="_blank">Portal Settings → Users</a>.
This page shows only the users who currently have access to DigiServer.
</div>
</div>
<!-- Users Table -->
@@ -19,7 +27,6 @@
<th>Role</th>
<th>Created At</th>
<th>Last Login</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@@ -39,26 +46,11 @@
</td>
<td>{{ user.created_at | localtime if user.created_at else 'N/A' }}</td>
<td>{{ user.last_login | localtime if user.last_login else 'Never' }}</td>
<td class="actions">
{% if user.id != current_user.id %}
<button class="btn btn-sm btn-warning" onclick="showEditUserModal({{ user.id }}, '{{ user.username }}', '{{ user.role }}')">
Edit Role
</button>
<button class="btn btn-sm btn-secondary" onclick="showResetPasswordModal({{ user.id }}, '{{ user.username }}')">
Reset Password
</button>
<button class="btn btn-sm btn-danger" onclick="confirmDeleteUser({{ user.id }}, '{{ user.username }}')">
Delete
</button>
{% else %}
<span class="text-muted">Current User</span>
{% endif %}
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="5" class="text-center">No users found</td>
<td colspan="4" class="text-center">No users found</td>
</tr>
{% endif %}
</tbody>
@@ -94,93 +86,7 @@
</div>
</div>
<!-- Create User Modal -->
<div id="createUserModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Create New User</h2>
<span class="close" onclick="closeModal('createUserModal')">&times;</span>
</div>
<form method="POST" action="{{ url_for('admin.create_user') }}">
<div class="form-group">
<label for="username">Username *</label>
<input type="text" id="username" name="username" required minlength="3"
placeholder="Enter username" class="form-control">
<small>Minimum 3 characters</small>
</div>
<div class="form-group">
<label for="password">Password *</label>
<input type="password" id="password" name="password" required minlength="6"
placeholder="Enter password" class="form-control">
<small>Minimum 6 characters</small>
</div>
<div class="form-group">
<label for="role">Role *</label>
<select id="role" name="role" required class="form-control">
<option value="user">Normal User</option>
<option value="admin">Admin User</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="closeModal('createUserModal')">Cancel</button>
<button type="submit" class="btn btn-primary">Create User</button>
</div>
</form>
</div>
</div>
<!-- Edit Role Modal -->
<div id="editRoleModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Edit User Role</h2>
<span class="close" onclick="closeModal('editRoleModal')">&times;</span>
</div>
<form method="POST" id="editRoleForm">
<div class="form-group">
<label>Username</label>
<input type="text" id="edit_username" readonly class="form-control">
</div>
<div class="form-group">
<label for="edit_role">New Role *</label>
<select id="edit_role" name="role" required class="form-control">
<option value="user">Normal User</option>
<option value="admin">Admin User</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="closeModal('editRoleModal')">Cancel</button>
<button type="submit" class="btn btn-primary">Update Role</button>
</div>
</form>
</div>
</div>
<!-- Reset Password Modal -->
<div id="resetPasswordModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Reset User Password</h2>
<span class="close" onclick="closeModal('resetPasswordModal')">&times;</span>
</div>
<form method="POST" id="resetPasswordForm">
<div class="form-group">
<label>Username</label>
<input type="text" id="reset_username" readonly class="form-control">
</div>
<div class="form-group">
<label for="new_password">New Password *</label>
<input type="password" id="new_password" name="password" required minlength="6"
placeholder="Enter new password" class="form-control">
<small>Minimum 6 characters</small>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="closeModal('resetPasswordModal')">Cancel</button>
<button type="submit" class="btn btn-primary">Reset Password</button>
</div>
</form>
</div>
</div>
<style>
.page-header {
@@ -190,22 +96,37 @@
margin-bottom: 20px;
}
.page-header .btn-primary {
background: #667eea;
color: white;
border: none;
.portal-notice {
display: flex;
align-items: flex-start;
gap: 12px;
background: #eff6ff;
border: 1px solid #93c5fd;
border-radius: 8px;
padding: 14px 18px;
margin-bottom: 20px;
font-size: 14px;
color: #1e40af;
}
.page-header .btn-primary:hover {
background: #5568d3;
.portal-notice a {
color: #1d4ed8;
font-weight: 600;
}
body.dark-mode .page-header .btn-primary {
background: #7c3aed;
.portal-notice-icon {
font-size: 20px;
flex-shrink: 0;
}
body.dark-mode .page-header .btn-primary:hover {
background: #6d28d9;
body.dark-mode .portal-notice {
background: #1e293b;
border-color: #3b82f6;
color: #93c5fd;
}
body.dark-mode .portal-notice a {
color: #60a5fa;
}
.table-responsive {
@@ -273,35 +194,6 @@ body.dark-mode .user-table tbody tr:hover {
margin-left: 8px;
}
.actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.btn-sm {
padding: 6px 12px;
font-size: 14px;
}
.btn-warning {
background: #ffc107;
color: #000;
}
.btn-warning:hover {
background: #e0a800;
}
.btn-danger {
background: #dc3545;
color: white;
}
.btn-danger:hover {
background: #c82333;
}
.role-descriptions {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
@@ -344,132 +236,6 @@ body.dark-mode .role-item li {
color: #a0aec0;
}
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
}
.modal-content {
background-color: #fff;
margin: 5% auto;
padding: 0;
border-radius: 8px;
width: 90%;
max-width: 500px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
body.dark-mode .modal-content {
background-color: #2d3748;
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
border-bottom: 1px solid #e0e0e0;
}
body.dark-mode .modal-header {
border-bottom: 1px solid #4a5568;
}
.modal-header h2 {
margin: 0;
font-size: 20px;
}
body.dark-mode .modal-header h2 {
color: #e2e8f0;
}
.close {
font-size: 28px;
font-weight: bold;
color: #aaa;
cursor: pointer;
}
.close:hover {
color: #000;
}
.modal form {
padding: 20px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #495057;
}
body.dark-mode .form-group label {
color: #e2e8f0;
}
.form-control {
width: 100%;
padding: 10px;
border: 1px solid #ced4da;
border-radius: 4px;
font-size: 14px;
background: white;
color: #2d3748;
}
.form-control:focus {
outline: none;
border-color: #667eea;
}
body.dark-mode .form-control {
background: #1a202c;
border-color: #4a5568;
color: #e2e8f0;
}
body.dark-mode .form-control:focus {
border-color: #7c3aed;
}
.form-group small {
display: block;
margin-top: 5px;
color: #6c757d;
font-size: 12px;
}
body.dark-mode .form-group small {
color: #a0aec0;
}
.modal-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
padding-top: 20px;
border-top: 1px solid #e0e0e0;
margin-top: 20px;
}
body.dark-mode .modal-footer {
border-top: 1px solid #4a5568;
}
.text-muted {
color: #6c757d;
}
@@ -479,46 +245,5 @@ body.dark-mode .modal-footer {
}
</style>
<script>
function showCreateUserModal() {
document.getElementById('createUserModal').style.display = 'block';
}
function showEditUserModal(userId, username, currentRole) {
document.getElementById('edit_username').value = username;
document.getElementById('edit_role').value = currentRole;
document.getElementById('editRoleForm').action = `/admin/user/${userId}/role`;
document.getElementById('editRoleModal').style.display = 'block';
}
function showResetPasswordModal(userId, username) {
document.getElementById('reset_username').value = username;
document.getElementById('resetPasswordForm').action = `/admin/user/${userId}/password`;
document.getElementById('resetPasswordModal').style.display = 'block';
}
function closeModal(modalId) {
document.getElementById(modalId).style.display = 'none';
}
function confirmDeleteUser(userId, username) {
if (confirm(`Are you sure you want to delete user "${username}"? This action cannot be undone.`)) {
const form = document.createElement('form');
form.method = 'POST';
form.action = `/admin/user/${userId}/delete`;
document.body.appendChild(form);
form.submit();
}
}
// Close modal when clicking outside
window.onclick = function(event) {
const modals = document.getElementsByClassName('modal');
for (let modal of modals) {
if (event.target === modal) {
modal.style.display = 'none';
}
}
}
</script>
{% endblock %}