set permissions to membership actions
This commit is contained in:
14
backend/api/utils/permissionChecker.py
Normal file
14
backend/api/utils/permissionChecker.py
Normal 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
|
||||
Reference in New Issue
Block a user