Remove the guest system entirely: no is_guest/device_id, no guest throttles, phone login is the only way in

accounts.0008 drops the columns and refuses to run while guest rows exist.
Docs describe the current state; tests that only proved guest behaviour are gone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-05 18:20:10 +03:30
parent 8835e01595
commit 663252a260
61 changed files with 357 additions and 1518 deletions

View File

@@ -24,24 +24,6 @@ from .serializers import (
from .services import credit_balance, has_active_subscription, hearts_pass_until
class GuestAwarePurchaseThrottle(ScopedRateThrottle):
"""همون الگوی GuestAwareAIThrottle/GuestAwareDiscountThrottle/etc: چرخشِ
حساب مهمان نباید bucket تازه‌ی purchase بده — این endpoint حساسِ مالیه
(Subscription می‌سازه/آپدیت می‌کنه، create_order رو صدا می‌زنه). برای
مهمان‌ها کلیدِ cache بر اساسِ IP هست، نه pk."""
def get_cache_key(self, request, view):
user = request.user
if user and user.is_authenticated and getattr(user, 'is_guest', False):
ident = f'guest-ip:{self.get_ident(request)}'
elif user and user.is_authenticated:
ident = user.pk
else:
ident = self.get_ident(request)
return self.cache_format % {'scope': self.scope, 'ident': ident}
# پلن‌ها تقریباً هیچ‌وقت عوض نمی‌شوند و روی صفحه‌ی اشتراک هر بار خوانده می‌شوند.
# با هر save/delete روی Plan کش باطل می‌شود (subscription/receivers.py).
PLANS_CACHE_KEY = 'subscription:plans:v3' # v3: بسته‌های سوال
@@ -89,13 +71,9 @@ class PurchaseView(APIView):
permission_classes = [IsAuthenticated]
# این throttle مستقلِ Idempotency-Key است چون اون فقط جلوی تکرارِ *همون*
# کلید رو می‌گیره، نه حجمِ درخواست‌های متفاوت. کاربرهای مهمان با هر
# deviceId یک pk تازه می‌گیرن، پس کلیدِ per-user ساده قابل‌دورزدنه؛
# GuestAwarePurchaseThrottle برای مهمان‌ها بر اساسِ IP کلید می‌سازه
# (مثلِ GuestAwareAIThrottle/DiscountThrottle) و برای
# کاربرهای غیرمهمان رفتارِ per-user را حفظ می‌کنه.
# کلید رو می‌گیره، نه حجمِ درخواست‌های متفاوت.
throttle_scope = 'purchase'
throttle_classes = [GuestAwarePurchaseThrottle]
throttle_classes = [ScopedRateThrottle]
@extend_schema(
request=PurchaseRequestSerializer,