IT Assets: remove manual user creation from settings
Users are sourced exclusively from the portal (via SSO auto-create or the Sync from Portal button). The Add User form and create_admin route are removed to prevent out-of-sync local-only accounts. A footer hint now links admins to the portal settings page.
This commit is contained in:
@@ -15,35 +15,6 @@ def index():
|
|||||||
return render_template('settings/index.html', admins=admins, config=current_app.config)
|
return render_template('settings/index.html', admins=admins, config=current_app.config)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/admin/new', methods=['POST'])
|
|
||||||
@login_required
|
|
||||||
@admin_required
|
|
||||||
def create_admin():
|
|
||||||
username = request.form.get('username', '').strip()
|
|
||||||
email = request.form.get('email', '').strip()
|
|
||||||
full_name = request.form.get('full_name', '').strip()
|
|
||||||
password = request.form.get('password', '')
|
|
||||||
role = request.form.get('role', 'readonly')
|
|
||||||
|
|
||||||
if role not in ('admin', 'editor', 'readonly'):
|
|
||||||
role = 'readonly'
|
|
||||||
|
|
||||||
if not username or not email or not password:
|
|
||||||
flash('Username, email and password are required.', 'danger')
|
|
||||||
return redirect(url_for('settings.index'))
|
|
||||||
|
|
||||||
if AdminUser.query.filter_by(username=username).first():
|
|
||||||
flash(f'Username "{username}" is already taken.', 'danger')
|
|
||||||
return redirect(url_for('settings.index'))
|
|
||||||
|
|
||||||
admin = AdminUser(username=username, email=email, full_name=full_name, role=role)
|
|
||||||
admin.set_password(password)
|
|
||||||
db.session.add(admin)
|
|
||||||
db.session.commit()
|
|
||||||
flash(f'User "{username}" created with role "{role}".', 'success')
|
|
||||||
return redirect(url_for('settings.index'))
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/admin/<int:admin_id>/toggle', methods=['POST'])
|
@bp.route('/admin/<int:admin_id>/toggle', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
|
|||||||
@@ -87,41 +87,14 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add user form (admin only) -->
|
<!-- Add user form removed — users are managed via the portal and synced automatically -->
|
||||||
{% if current_user.is_admin %}
|
{% if current_user.is_admin %}
|
||||||
<div class="card-footer bg-white">
|
<div class="card-footer bg-white">
|
||||||
<h6 class="fw-semibold mb-3 mt-1"><i class="bi bi-person-plus me-1"></i>Add User</h6>
|
<small class="text-muted">
|
||||||
<form method="POST" action="{{ url_for('settings.create_admin') }}">
|
<i class="bi bi-info-circle me-1"></i>
|
||||||
<div class="row g-2">
|
Users are managed in the <a href="/" class="text-decoration-none">Portal</a>.
|
||||||
<div class="col-md-3">
|
Use <strong>Sync from Portal</strong> above to pull the latest access list.
|
||||||
<input type="text" name="username" class="form-control form-control-sm" placeholder="Username" required>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-3">
|
|
||||||
<input type="text" name="full_name" class="form-control form-control-sm" placeholder="Full Name">
|
|
||||||
</div>
|
|
||||||
<div class="col-md-3">
|
|
||||||
<input type="email" name="email" class="form-control form-control-sm" placeholder="Email" required>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<input type="password" name="password" class="form-control form-control-sm" placeholder="Password" required minlength="8">
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<select name="role" class="form-select form-select-sm">
|
|
||||||
<option value="readonly">readonly</option>
|
|
||||||
<option value="editor">editor</option>
|
|
||||||
<option value="admin">admin</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="col-auto">
|
|
||||||
<button type="submit" class="btn btn-sm btn-primary">Add</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<small class="text-muted mt-1 d-block">
|
|
||||||
<strong>readonly</strong> – view only |
|
|
||||||
<strong>editor</strong> – create & edit data |
|
|
||||||
<strong>admin</strong> – full access including user management
|
|
||||||
</small>
|
</small>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user