ssdsds
This commit is contained in:
@@ -205,6 +205,13 @@ class KeywordViewSet(SiteSectorModelViewSet):
|
||||
if not account:
|
||||
account = getattr(site, 'account', None)
|
||||
|
||||
# Check hard limit for keywords (enforces ALL entry points: manual, import, AI, automation)
|
||||
from igny8_core.business.billing.services.limit_service import LimitService, HardLimitExceededError
|
||||
try:
|
||||
LimitService.check_hard_limit(account, 'keywords', additional_count=1)
|
||||
except HardLimitExceededError as e:
|
||||
raise ValidationError(str(e))
|
||||
|
||||
# Save with all required fields explicitly
|
||||
serializer.save(account=account, site=site, sector=sector)
|
||||
|
||||
@@ -337,6 +344,17 @@ class KeywordViewSet(SiteSectorModelViewSet):
|
||||
request=request
|
||||
)
|
||||
|
||||
# Check hard limit BEFORE bulk operation (check max potential additions)
|
||||
from igny8_core.business.billing.services.limit_service import LimitService, HardLimitExceededError
|
||||
try:
|
||||
LimitService.check_hard_limit(account, 'keywords', additional_count=len(seed_keyword_ids))
|
||||
except HardLimitExceededError as e:
|
||||
return error_response(
|
||||
error=str(e),
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
request=request
|
||||
)
|
||||
|
||||
created_count = 0
|
||||
skipped_count = 0
|
||||
errors = []
|
||||
@@ -555,10 +573,28 @@ class KeywordViewSet(SiteSectorModelViewSet):
|
||||
if not account:
|
||||
account = getattr(site, 'account', None)
|
||||
|
||||
# Parse CSV
|
||||
# Parse CSV and count rows first for limit check
|
||||
try:
|
||||
decoded_file = file.read().decode('utf-8')
|
||||
csv_reader = csv.DictReader(decoded_file.splitlines())
|
||||
lines = decoded_file.splitlines()
|
||||
csv_reader = csv.DictReader(lines)
|
||||
|
||||
# Count non-empty keyword rows
|
||||
row_count = sum(1 for row in csv_reader if row.get('keyword', '').strip())
|
||||
|
||||
# Check hard limit BEFORE importing
|
||||
from igny8_core.business.billing.services.limit_service import LimitService, HardLimitExceededError
|
||||
try:
|
||||
LimitService.check_hard_limit(account, 'keywords', additional_count=row_count)
|
||||
except HardLimitExceededError as e:
|
||||
return error_response(
|
||||
error=str(e),
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
request=request
|
||||
)
|
||||
|
||||
# Reset reader for actual import
|
||||
csv_reader = csv.DictReader(lines)
|
||||
|
||||
imported_count = 0
|
||||
skipped_count = 0
|
||||
@@ -861,6 +897,13 @@ class ClusterViewSet(SiteSectorModelViewSet):
|
||||
if not account:
|
||||
account = getattr(site, 'account', None)
|
||||
|
||||
# Check hard limit for clusters (enforces ALL entry points: manual, import, AI, automation)
|
||||
from igny8_core.business.billing.services.limit_service import LimitService, HardLimitExceededError
|
||||
try:
|
||||
LimitService.check_hard_limit(account, 'clusters', additional_count=1)
|
||||
except HardLimitExceededError as e:
|
||||
raise ValidationError(str(e))
|
||||
|
||||
# Save with all required fields explicitly
|
||||
serializer.save(account=account, site=site, sector=sector)
|
||||
|
||||
@@ -1049,6 +1092,13 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
|
||||
if not account:
|
||||
account = getattr(site, 'account', None)
|
||||
|
||||
# Check monthly limit for content_ideas (enforces ALL entry points: manual, import, AI, automation)
|
||||
from igny8_core.business.billing.services.limit_service import LimitService, MonthlyLimitExceededError
|
||||
try:
|
||||
LimitService.check_monthly_limit(account, 'content_ideas', additional_count=1)
|
||||
except MonthlyLimitExceededError as e:
|
||||
raise ValidationError(str(e))
|
||||
|
||||
serializer.save(account=account, site=site, sector=sector)
|
||||
|
||||
@action(detail=False, methods=['POST'], url_path='bulk_delete', url_name='bulk_delete')
|
||||
|
||||
Reference in New Issue
Block a user