Skip to content

Commit 320b447

Browse files
committed
fix: Remove hardcoded values, use TIER_LIMITS as single source of truth
- routes/users.py: Use TIER_LIMITS[UserTier.FREE] instead of hardcoded values - routes/users.py: Return tier and limit in check-repo-add for API key users - user_limits.py: Remove unused 'field' import from dataclasses
1 parent 80a44a2 commit 320b447

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

backend/routes/users.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dependencies import user_limits
55
from middleware.auth import require_auth, AuthContext
66
from services.observability import logger
7+
from services.user_limits import TIER_LIMITS, UserTier
78

89
router = APIRouter(prefix="/users", tags=["Users"])
910

@@ -24,21 +25,22 @@ def get_user_usage(auth: AuthContext = Depends(require_auth)):
2425
if not user_id:
2526
logger.warning("Usage check without user_id", identifier=auth.identifier)
2627
# Return free tier defaults for API key users
28+
free_limits = TIER_LIMITS[UserTier.FREE]
2729
return {
2830
"tier": "free",
2931
"repositories": {
3032
"current": 0,
31-
"limit": 3,
32-
"display": "0/3"
33+
"limit": free_limits.max_repos,
34+
"display": f"0/{free_limits.max_repos}"
3335
},
3436
"limits": {
35-
"max_files_per_repo": 500,
36-
"max_functions_per_repo": 2000,
37-
"playground_searches_per_day": 50,
37+
"max_files_per_repo": free_limits.max_files_per_repo,
38+
"max_functions_per_repo": free_limits.max_functions_per_repo,
39+
"playground_searches_per_day": free_limits.playground_searches_per_day,
3840
},
3941
"features": {
40-
"priority_indexing": False,
41-
"mcp_access": True,
42+
"priority_indexing": free_limits.priority_indexing,
43+
"mcp_access": free_limits.mcp_access,
4244
}
4345
}
4446

@@ -59,7 +61,14 @@ def check_can_add_repo(auth: AuthContext = Depends(require_auth)):
5961
user_id = auth.user_id
6062

6163
if not user_id:
62-
return {"allowed": True, "message": "OK"}
64+
# API key users - return allowed with free tier info
65+
free_limits = TIER_LIMITS[UserTier.FREE]
66+
return {
67+
"allowed": True,
68+
"message": "OK",
69+
"tier": "free",
70+
"limit": free_limits.max_repos
71+
}
6372

6473
result = user_limits.check_repo_count(user_id)
6574
return result.to_dict()

backend/services/user_limits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- #94: Repo size limits
1313
- #95: Repo count limits
1414
"""
15-
from dataclasses import dataclass, field
15+
from dataclasses import dataclass
1616
from typing import Optional, Dict, Any
1717
from enum import Enum
1818

0 commit comments

Comments
 (0)