49 lines
1.7 KiB
Python
49 lines
1.7 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)
|