set permissions to membership actions

This commit is contained in:
2025-05-29 14:42:23 +03:00
parent e30eb10d7d
commit be27f5ee97
3 changed files with 65 additions and 12 deletions

View File

@@ -0,0 +1,14 @@
from django.utils.timezone import now
from datetime import timedelta
from sitemanagement.models import RoutePromotionLog
MAX_ACTIONS_PER_MONTH = 5
def check_monthly_limit(user, route, action_type):
month_ago = now() - timedelta(days=30)
return RoutePromotionLog.objects.filter(
user=user,
route=route,
action_type=action_type,
created_at__gte=month_ago
).count() < MAX_ACTIONS_PER_MONTH