Remove server settings from navigation and add tenant display name support
- Remove server settings link from main navigation bar - Add separate display name field for tenant creation - Support uppercase characters in tenant display names while keeping IDs lowercase - Improve tenant creation UX with clearer field descriptions
This commit is contained in:
@@ -9,7 +9,21 @@ import os
|
|||||||
@tenant_access_required
|
@tenant_access_required
|
||||||
def index(tenant_id):
|
def index(tenant_id):
|
||||||
"""Tenant home page - product listing"""
|
"""Tenant home page - product listing"""
|
||||||
tenant = TenantModel.get_or_create(tenant_id)
|
# Get the tenant name from query parameter if provided (for new tenant creation)
|
||||||
|
tenant_name = request.args.get('tenant_name')
|
||||||
|
|
||||||
|
# Check if tenant exists first
|
||||||
|
existing_tenant = TenantModel.get_by_id(tenant_id)
|
||||||
|
|
||||||
|
if existing_tenant:
|
||||||
|
tenant = existing_tenant
|
||||||
|
elif tenant_name:
|
||||||
|
# Create new tenant with display name
|
||||||
|
tenant = TenantModel.create(tenant_id, tenant_name)
|
||||||
|
else:
|
||||||
|
# Create with default name (tenant_id)
|
||||||
|
tenant = TenantModel.create(tenant_id)
|
||||||
|
|
||||||
if tenant is None:
|
if tenant is None:
|
||||||
return jsonify({"error": f"'{tenant_id}' is a reserved name and cannot be used as a tenant ID"}), 404
|
return jsonify({"error": f"'{tenant_id}' is a reserved name and cannot be used as a tenant ID"}), 404
|
||||||
|
|
||||||
|
|||||||
@@ -65,11 +65,6 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/">Home</a>
|
<a class="nav-link" href="/">Home</a>
|
||||||
</li>
|
</li>
|
||||||
{% if session.user and session.user.role == 'admin' %}
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/settings">Server Settings</a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="navbar-nav ms-auto">
|
<ul class="navbar-nav ms-auto">
|
||||||
{% if config.AUTH_MODE == 'none' %}
|
{% if config.AUTH_MODE == 'none' %}
|
||||||
|
|||||||
@@ -155,10 +155,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form id="newTenantForm">
|
<form id="newTenantForm">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="tenantName" class="form-label">Tenant Display Name</label>
|
||||||
|
<input type="text" class="form-control" id="tenantName" placeholder="e.g., Demo Company" required>
|
||||||
|
<small class="form-text text-muted">This is how the tenant name will be displayed</small>
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="tenantId" class="form-label">Tenant ID</label>
|
<label for="tenantId" class="form-label">Tenant ID</label>
|
||||||
<input type="text" class="form-control" id="tenantId" placeholder="e.g., demo-company" required pattern="[a-zA-Z0-9_-]+">
|
<input type="text" class="form-control" id="tenantId" placeholder="e.g., demo-company" required pattern="[a-zA-Z0-9_-]+">
|
||||||
<small class="form-text text-muted">Only letters, numbers, hyphens, and underscores allowed</small>
|
<small class="form-text text-muted">Only letters, numbers, hyphens, and underscores allowed. Will be converted to lowercase.</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
@@ -246,17 +251,22 @@
|
|||||||
document.getElementById('newTenantForm').addEventListener('submit', function(e) {
|
document.getElementById('newTenantForm').addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const tenantId = document.getElementById('tenantId').value;
|
const tenantId = document.getElementById('tenantId').value;
|
||||||
|
const tenantName = document.getElementById('tenantName').value;
|
||||||
const createDefaults = document.getElementById('createDefaultFields').checked;
|
const createDefaults = document.getElementById('createDefaultFields').checked;
|
||||||
|
|
||||||
if (tenantId) {
|
if (tenantId && tenantName) {
|
||||||
const normalizedId = tenantId.toLowerCase();
|
const normalizedId = tenantId.toLowerCase();
|
||||||
if (reservedIds.includes(normalizedId)) {
|
if (reservedIds.includes(normalizedId)) {
|
||||||
alert(`"${tenantId}" is a reserved name and cannot be used as a tenant ID.`);
|
alert(`"${tenantId}" is a reserved name and cannot be used as a tenant ID.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect with query parameter for default fields
|
// Redirect with query parameters for default fields and tenant name
|
||||||
const url = '/' + normalizedId + '/' + (createDefaults ? '?create_defaults=1' : '');
|
const params = new URLSearchParams();
|
||||||
|
if (createDefaults) params.append('create_defaults', '1');
|
||||||
|
params.append('tenant_name', tenantName);
|
||||||
|
|
||||||
|
const url = '/' + normalizedId + '/?' + params.toString();
|
||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user