loko/streetup/assets/apps.py

57 lines
2 KiB
Python

from django.apps import AppConfig
class AssetsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'assets'
def ready(self):
"""Import signals when app is ready"""
import assets.signals
# Register private file guards
from common.private_files.registry import register
# Guard for green surfaces comment photos
def guard_green_surfaces_comment_photo(obj, user):
"""
Allow access to comment photos for users with 'nature' thematic access.
"""
from assets.models.nature import GreenSurfacesCommentPhoto
from common.models import UserThematics
if not isinstance(obj, GreenSurfacesCommentPhoto):
return False
if not user.is_authenticated:
return False
# Check if user has access to 'nature' thematic
user_thematics = UserThematics.objects.filter(
user_config__user=user,
thematic__code='nature'
).exists()
return user_thematics
register('assets', 'GreenSurfacesCommentPhoto', 'photo', guard_green_surfaces_comment_photo)
# Guard for traffic light controller log files
def guard_tl_controller_log(obj, user):
from common.models import UserThematics
if not user.is_authenticated:
return False
return UserThematics.objects.filter(
user_config__user=user,
thematic__code='trafficlights'
).exists()
register('assets', 'TrafficLightControllerLogFile', 'file', guard_tl_controller_log)
# Guard for inspection documents (InspectionDocument)
def guard_inspection_document(obj, user):
if not user.is_authenticated:
return False
return True
register('assets', 'InspectionDocument', 'file', guard_inspection_document)