From cf522190c6def207e64982d56fe4dd51f56f40d5 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 21 Mar 2026 07:06:53 +0100 Subject: [PATCH] fix: correct indentation in auth.py _check_impl function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Behebt IndentationError in Zeile 204 der _check_impl() Funktion. Die Funktion wurde beim Connection-Pool-Fix erstellt, hatte aber inkonsistente Einrückungen (8 statt 4 Spaces nach der ersten Zeile). Co-Authored-By: Claude Opus 4.6 --- backend/auth.py | 194 ++++++++++++++++++++++++------------------------ 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/backend/auth.py b/backend/auth.py index 936628b..918b5eb 100644 --- a/backend/auth.py +++ b/backend/auth.py @@ -200,115 +200,115 @@ def _check_impl(profile_id: str, feature_id: str, conn) -> dict: """Internal implementation of check_feature_access.""" cur = get_cursor(conn) - # Get feature info - cur.execute(""" - SELECT limit_type, reset_period, default_limit - FROM features - WHERE id = %s AND active = true - """, (feature_id,)) - feature = cur.fetchone() + # Get feature info + cur.execute(""" + SELECT limit_type, reset_period, default_limit + FROM features + WHERE id = %s AND active = true + """, (feature_id,)) + feature = cur.fetchone() - if not feature: - return { - 'allowed': False, - 'limit': None, - 'used': 0, - 'remaining': None, - 'reason': 'feature_not_found' - } + if not feature: + return { + 'allowed': False, + 'limit': None, + 'used': 0, + 'remaining': None, + 'reason': 'feature_not_found' + } - # Priority 1: Check user-specific restriction + # Priority 1: Check user-specific restriction + cur.execute(""" + SELECT limit_value + FROM user_feature_restrictions + WHERE profile_id = %s AND feature_id = %s + """, (profile_id, feature_id)) + restriction = cur.fetchone() + + if restriction is not None: + limit = restriction['limit_value'] + else: + # Priority 2: Check tier limit + tier_id = get_effective_tier(profile_id, conn) cur.execute(""" SELECT limit_value - FROM user_feature_restrictions - WHERE profile_id = %s AND feature_id = %s - """, (profile_id, feature_id)) - restriction = cur.fetchone() + FROM tier_limits + WHERE tier_id = %s AND feature_id = %s + """, (tier_id, feature_id)) + tier_limit = cur.fetchone() - if restriction is not None: - limit = restriction['limit_value'] + if tier_limit is not None: + limit = tier_limit['limit_value'] else: - # Priority 2: Check tier limit - tier_id = get_effective_tier(profile_id, conn) - cur.execute(""" - SELECT limit_value - FROM tier_limits - WHERE tier_id = %s AND feature_id = %s - """, (tier_id, feature_id)) - tier_limit = cur.fetchone() - - if tier_limit is not None: - limit = tier_limit['limit_value'] - else: - # Priority 3: Feature default - limit = feature['default_limit'] - - # For boolean features (limit 0 = disabled, 1 = enabled) - if feature['limit_type'] == 'boolean': - allowed = limit == 1 - return { - 'allowed': allowed, - 'limit': limit, - 'used': 0, - 'remaining': None, - 'reason': 'enabled' if allowed else 'feature_disabled' - } - - # For count-based features - # Check current usage - cur.execute(""" - SELECT usage_count, reset_at - FROM user_feature_usage - WHERE profile_id = %s AND feature_id = %s - """, (profile_id, feature_id)) - usage = cur.fetchone() - - used = usage['usage_count'] if usage else 0 - - # Check if reset is needed - if usage and usage['reset_at'] and datetime.now() > usage['reset_at']: - # Reset usage - used = 0 - next_reset = _calculate_next_reset(feature['reset_period']) - cur.execute(""" - UPDATE user_feature_usage - SET usage_count = 0, reset_at = %s, updated = CURRENT_TIMESTAMP - WHERE profile_id = %s AND feature_id = %s - """, (next_reset, profile_id, feature_id)) - conn.commit() - - # NULL limit = unlimited - if limit is None: - return { - 'allowed': True, - 'limit': None, - 'used': used, - 'remaining': None, - 'reason': 'unlimited' - } - - # 0 limit = disabled - if limit == 0: - return { - 'allowed': False, - 'limit': 0, - 'used': used, - 'remaining': 0, - 'reason': 'feature_disabled' - } - - # Check if within limit - allowed = used < limit - remaining = limit - used if limit else None + # Priority 3: Feature default + limit = feature['default_limit'] + # For boolean features (limit 0 = disabled, 1 = enabled) + if feature['limit_type'] == 'boolean': + allowed = limit == 1 return { 'allowed': allowed, 'limit': limit, - 'used': used, - 'remaining': remaining, - 'reason': 'within_limit' if allowed else 'limit_exceeded' + 'used': 0, + 'remaining': None, + 'reason': 'enabled' if allowed else 'feature_disabled' } + # For count-based features + # Check current usage + cur.execute(""" + SELECT usage_count, reset_at + FROM user_feature_usage + WHERE profile_id = %s AND feature_id = %s + """, (profile_id, feature_id)) + usage = cur.fetchone() + + used = usage['usage_count'] if usage else 0 + + # Check if reset is needed + if usage and usage['reset_at'] and datetime.now() > usage['reset_at']: + # Reset usage + used = 0 + next_reset = _calculate_next_reset(feature['reset_period']) + cur.execute(""" + UPDATE user_feature_usage + SET usage_count = 0, reset_at = %s, updated = CURRENT_TIMESTAMP + WHERE profile_id = %s AND feature_id = %s + """, (next_reset, profile_id, feature_id)) + conn.commit() + + # NULL limit = unlimited + if limit is None: + return { + 'allowed': True, + 'limit': None, + 'used': used, + 'remaining': None, + 'reason': 'unlimited' + } + + # 0 limit = disabled + if limit == 0: + return { + 'allowed': False, + 'limit': 0, + 'used': used, + 'remaining': 0, + 'reason': 'feature_disabled' + } + + # Check if within limit + allowed = used < limit + remaining = limit - used if limit else None + + return { + 'allowed': allowed, + 'limit': limit, + 'used': used, + 'remaining': remaining, + 'reason': 'within_limit' if allowed else 'limit_exceeded' + } + def increment_feature_usage(profile_id: str, feature_id: str) -> None: """