Skip to content

Fixes for test task - #244

Open
JuliaDvirnik wants to merge 1 commit into
Base360-AI:mainfrom
JuliaDvirnik:main
Open

JuliaDvirnik wants to merge 1 commit into
Base360-AI:mainfrom
JuliaDvirnik:main

Conversation

@JuliaDvirnik

Copy link
Copy Markdown

Fixed bugs:

  1. Setup fixes:
  • Added greenland to requirements.txt (it was missed)
  • Fixed DB connection pool (use correct connection address, removed QueuePool, got pool sized from settings)
  • Use 1 shared pull instead of 1 per request (every revenue created a new pool and never closed it, now reuse shared db_pool)
  1. Fixes for client privacy:
  • added tenant in cache key
  • added new endpoint dashboard/properties to fix the list of properties (before every account saw all 5 properties)
  • removed fake-data fallback (now we have 503 error if db failed)
  • removed 'default tenant' (unknown user get no tenant and can't log in with 403 except admins)
  • property ownership check (another client property return 404, the check is before cache is read)
  • DB level isolation with low-level security (added policies, app_user role, tenant_session())
  • removed X-Simulated-Tenant header (tenant comes only from the login tocken)
  • closed unauthenticated endpoints (added require_admin check)
  1. Accuracy:
  • revenue by month and year in property timezone (month and year boundaries calculated in property's timezone)
  • switched from float to decimal
  • used real currency from DB reservations

TODO (What i have found but don't fix):

  • no month/year selector on the page. The API supports it but dashboard don't show
  • the 12% badge is hardcoded placeholder

- added greenland to requirements
- fixed DB connection pool
- use 1 shared pull instead of 1 per request
2. Fixes for client privacy:
- added tenant in cache key
- added new endpoint dashboard/properties to fix the list of properties
- removed fake-data fallback
- removed 'default tenant'
- property ownership check
- DB level isolation with low-level security
- removed X-Simulated-Tenant header
- closed unauthenticated endpoints
3. Accuracy:
- revenue by month and year in property timezone
- switched from float to decimal
- used real currency
Comment on lines 159 to 169
user: AuthenticatedUser = Depends(authenticate_request)
):
"""Get departments for a specific user"""
if user_id != user.id and not user.is_admin:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Not allowed to view another user's departments"
)
try:
departments = await get_user_departments(user_id)
# Return just the department IDs for simplicity

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Administrators without a statically mapped tenant receive tokens with null tenant_id, causing immediate 403 errors on tenant-dependent dashboard endpoints.
Severity: HIGH

Suggested Fix

Update TenantResolver.resolve_tenant_id or authenticate_request to derive tenant_id from database associations such as user_tenants or token metadata, or permit admin bypass / tenant selection in dashboard endpoints.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: backend/app/api/v1/auth_info.py#L159-L169

Potential issue: `TenantResolver.resolve_tenant_id` does not resolve tenant IDs for
database-backed users and only returns tenants for hardcoded emails. While `login.py`
permits administrators to log in when `tenant_id` is null, their issued token lacks a
`tenant_id`. Consequently, subsequent requests to dashboard endpoints like
`/dashboard/properties` and `/dashboard/summary` fail with a 403 Forbidden error because
`get_user_tenant_id` requires a non-null `tenant_id` and does not check administrator
privileges.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant