Fixed: Missing monthly word count limit check in views.py:754-787
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user