Audit fixes 2026-10-03: seed keeps admin edits, plan cache, refresh limit, payment and tutor guards

- seed_content no longer undoes admin work: a SeedRecord ledger (content/seed_sync.py)
  stops deleted/renamed/re-worded content from being recreated and keeps admin-edited
  lesson text; new rows in the seed files still arrive (migration content.0010)
- plan list cache is invalidated on Plan save (receiver used a stale 'v1' key)
- token refresh per-IP cap 30/hour -> 600/hour (TOKEN_REFRESH_IP_RATE)
- a failed gateway result only changes a pending order (forged NOK no longer
  overwrites refunded/canceled)
- tutor gets the correct answer only after the student has answered
- support reply notification moved to a TicketMessage post_save signal
- global daily cap on paid AI questions (AI_GLOBAL_DAILY_MAX, default 3000)
- Bazaar verify uses only the order's SKU; bazaar orders require a SKU
- /api/health warns on the committed signing key; deploy.sh saves local commits;
  400 for bad ?unit= / ?period=; account delete keeps the referrer's Conversion
- earlier today: no stub answers outside DEBUG, ?grade= removed, logged fallbacks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-03 16:05:27 +03:30
parent 7e027c167c
commit ab5e53730a
31 changed files with 623 additions and 49 deletions

View File

@@ -4,8 +4,10 @@ from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from .models import Plan
PLANS_CACHE_KEY = 'subscription:plans:v1' # هم‌تراز با subscription/views.py
# کلید فقط یک‌جا تعریف می‌شود (views). تا ۲۰۲۶-۱۰-۰۳ این‌جا یک نسخه‌ی جدا ('v1') بود که
# با v3 شدنِ کلیدِ views جا ماند: ذخیره‌ی پلن در ادمین کش را پاک نمی‌کرد و اپ تا یک ساعت
# قیمتِ قدیم را نشان می‌داد در حالی که سفارش با قیمتِ تازه ساخته می‌شد (بازتولید شد).
from .views import PLANS_CACHE_KEY
@receiver(post_save, sender=Plan, dispatch_uid='subscription_invalidate_plans_cache_on_save')

View File

@@ -592,3 +592,26 @@ class YearlyPlanSeedTests(TestCase):
seed.create_yearly_plan(global_apps, None)
self.assertEqual(list(Plan.objects.values_list('title', flat=True)), ['پلنِ ادمین'])
class PlanCacheInvalidationTests(TestCase):
"""
ذخیره‌ی پلن در ادمین باید فهرستِ پلن‌ها را تازه کند. تا ۲۰۲۶-۱۰-۰۳ گیرنده‌ی سیگنال کلیدِ
قدیمیِ 'v1' را پاک می‌کرد و فهرست تا یک ساعت قیمتِ قبلی را نشان می‌داد، در حالی که سفارش با
قیمتِ تازه ساخته می‌شد.
"""
def test_admin_price_change_shows_up_immediately(self):
from django.core.cache import cache
cache.clear()
plan = Plan.objects.create(title='بسته‌ی آزمایشی', price=45000, kind='pack', question_credits=7)
client = APIClient()
def price():
plans = client.get('/api/subscription/plans').json()['plans']
return next(p['price'] for p in plans if p['id'] == str(plan.id))
self.assertEqual(price(), 45000)
plan.price = 99000
plan.save()
self.assertEqual(price(), 99000)