Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/admin/blueprints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,27 @@ def google_callback():
"tenant_id": tenant_access["domain_tenant"].tenant_id,
"name": tenant_access["domain_tenant"].name,
"subdomain": tenant_access["domain_tenant"].subdomain,
"is_admin": True, # Domain users get admin access
}
)

for tenant in tenant_access["email_tenants"]:
# Check existing user record for role, default to admin
with get_db_session() as db_session:
from sqlalchemy import select

from src.core.database.models import User

stmt = select(User).filter_by(email=email, tenant_id=tenant.tenant_id)
existing_user = db_session.scalars(stmt).first()
is_admin = existing_user.role == "admin" if existing_user else True

session["available_tenants"].append(
{
"tenant_id": tenant.tenant_id,
"name": tenant.name,
"subdomain": tenant.subdomain,
"is_admin": is_admin,
}
)

Expand Down
31 changes: 19 additions & 12 deletions templates/choose_tenant.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,47 @@ <h2>Select Account</h2>

{% if tenants %}
<p style="margin-bottom: 2rem;">
Your email address has access to the following accounts. Select one to continue, or create a new account:
Select an account to continue:
</p>

<form method="POST" action="{{ url_for('auth.select_tenant') }}">
<div style="margin-bottom: 2rem;">
{% for tenant in tenants %}
<label style="display: block; padding: 1rem; margin-bottom: 0.5rem; border: 1px solid #ddd; border-radius: 4px; cursor: pointer;">
<label style="display: block; padding: 1rem; margin-bottom: 0.5rem; border: 2px solid #ddd; border-radius: 4px; cursor: pointer; transition: all 0.2s;">
<input type="radio" name="tenant_id" value="{{ tenant.tenant_id }}" style="margin-right: 0.5rem;">
<strong>{{ tenant.name }}</strong> <span style="color: #666;">({{ tenant.tenant_id }})</span>
</label>
{% endfor %}
</div>

<button type="submit" class="btn">Continue to Selected Account</button>
<a href="{{ url_for('auth.logout') }}" class="btn btn-secondary" style="margin-left: 0.5rem;">Cancel</a>
<button type="submit" class="btn btn-primary btn-lg w-100" style="margin-bottom: 1rem;">Continue to Selected Account</button>
</form>

<hr style="margin: 2rem 0; border: none; border-top: 1px solid #ddd;">
<div style="text-align: center; padding-top: 1rem; border-top: 1px solid #ddd;">
<p style="margin-bottom: 0.75rem; color: #666; font-size: 0.9rem;">Don't see your account?</p>
<a href="{{ url_for('public.signup_onboarding') }}" class="btn btn-outline-secondary">
Create New Account
</a>
</div>
{% else %}
<p style="margin-bottom: 2rem; color: #666;">
You don't have access to any accounts yet. Create a new account to get started:
You don't have access to any accounts yet.
</p>
{% endif %}

<div style="text-align: center;">
<a href="{{ url_for('public.signup_onboarding') }}" class="btn" style="background: #28a745; border-color: #28a745;">
Create New Account
</a>
</div>
<a href="{{ url_for('public.signup_onboarding') }}" class="btn btn-primary btn-lg w-100">
Create New Account
</a>
{% endif %}
</div>

<style>
label:hover {
background: #f8f9fa;
border-color: #007bff !important;
}
label:has(input:checked) {
background: #e7f3ff;
border-color: #007bff !important;
}
</style>
{% endblock %}