mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-13 22:32:15 +00:00
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
from datetime import datetime
|
|
from hr.app_defines import *
|
|
from hr.models import Blacklist
|
|
from django.db import models
|
|
from eve_api.models import EVEPlayerCharacter
|
|
|
|
def installed(value):
|
|
from django.conf import settings
|
|
apps = settings.INSTALLED_APPS
|
|
if "." in value:
|
|
for app in apps:
|
|
if app == value:
|
|
return True
|
|
else:
|
|
for app in apps:
|
|
fields = app.split(".")
|
|
if fields[-1] == value:
|
|
return True
|
|
return False
|
|
|
|
|
|
def blacklist_values(user):
|
|
"""
|
|
Returns a list of blacklist values that apply to the application
|
|
"""
|
|
|
|
blacklist = []
|
|
bl_items = Blacklist.objects.filter(models.Q(expiry_date__gt=datetime.now()) | models.Q(expiry_date=None))
|
|
|
|
# Check Reddit blacklists
|
|
if installed('reddit'):
|
|
reddit_uids = user.redditaccount_set.all().values_list('username', flat=True)
|
|
objs = bl_items.filter(type=BLACKLIST_TYPE_REDDIT, value__in=reddit_uids)
|
|
blacklist.extend(objs)
|
|
|
|
# Check email blacklists
|
|
blacklist.extend(bl_items.filter(type=BLACKLIST_TYPE_EMAIL, value=user.email.lower()))
|
|
|
|
# Check Auth blacklists
|
|
blacklist.extend(bl_items.filter(type=BLACKLIST_TYPE_AUTH, value=user.username.lower()))
|
|
|
|
# Check EVE Related blacklists
|
|
evechars = EVEPlayerCharacter.objects.filter(eveaccount__user=user).select_related('corporation__alliance')
|
|
|
|
# Check Character blacklists
|
|
characters = evechars.values_list('name', flat=True)
|
|
objs = bl_items.filter(type=BLACKLIST_TYPE_CHARACTER, value__in=characters)
|
|
blacklist.extend(objs)
|
|
|
|
# Check Corporation blacklists
|
|
corporations = evechars.values_list('corporation__name', flat=True)
|
|
objs = bl_items.filter(type=BLACKLIST_TYPE_CORPORATION, value__in=corporations)
|
|
blacklist.extend(objs)
|
|
|
|
# Check Alliance blacklists
|
|
alliances = evechars.values_list('corporation__alliance__name', flat=True)
|
|
objs = bl_items.filter(type=BLACKLIST_TYPE_ALLIANCE, value__in=alliances)
|
|
blacklist.extend(objs)
|
|
|
|
# Check API Key blacklists
|
|
keys = user.eveaccount_set.all().values_list('api_user_id', flat=True)
|
|
objs = bl_items.filter(type=BLACKLIST_TYPE_APIUSERID, value__in=keys)
|
|
blacklist.extend(objs)
|
|
|
|
return blacklist
|