From ad895fcb3a19573c6e16c99ef808e5b4a163ae55 Mon Sep 17 00:00:00 2001 From: "IGNY8 VPS (Salman)" Date: Sat, 13 Dec 2025 12:24:54 +0000 Subject: [PATCH] Fixed: Missing monthly word count limit check in views.py:754-787 --- backend/igny8_core/modules/writer/views.py | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/igny8_core/modules/writer/views.py b/backend/igny8_core/modules/writer/views.py index e0b41163..169ffd49 100644 --- a/backend/igny8_core/modules/writer/views.py +++ b/backend/igny8_core/modules/writer/views.py @@ -752,8 +752,33 @@ class ContentViewSet(SiteSectorModelViewSet): ] def perform_create(self, serializer): - """Override to automatically set account""" + """Override to check monthly word limit and set account""" + user = getattr(self.request, 'user', None) account = getattr(self.request, 'account', None) + + if not account and user and user.is_authenticated: + account = getattr(user, 'account', None) + + # Get word count from validated data + word_count = serializer.validated_data.get('word_count', 0) + + # If word_count not provided, calculate from content_html using standardized utility + if not word_count and 'content_html' in serializer.validated_data: + from igny8_core.utils.word_counter import calculate_word_count + html_content = serializer.validated_data.get('content_html', '') + word_count = calculate_word_count(html_content) + serializer.validated_data['word_count'] = word_count + + # Check monthly word count limit (enforces ALL entry points: manual, import, AI, automation) + if account and word_count > 0: + from igny8_core.business.billing.services.limit_service import LimitService, MonthlyLimitExceededError + from rest_framework.exceptions import ValidationError + + try: + LimitService.check_monthly_limit(account, 'content_words', amount=word_count) + except MonthlyLimitExceededError as e: + raise ValidationError(str(e)) + if account: serializer.save(account=account) else: