2024-09-18 15:51:44 +05:30
|
|
|
"""
|
|
|
|
|
accessibility/methods.py
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from django.core.cache import cache
|
2024-09-19 10:28:11 +05:30
|
|
|
|
2024-09-18 15:51:44 +05:30
|
|
|
from accessibility.filters import AccessibilityFilter
|
2024-09-19 10:28:11 +05:30
|
|
|
from accessibility.models import DefaultAccessibility
|
|
|
|
|
from horilla.horilla_middlewares import _thread_locals
|
2024-09-18 15:51:44 +05:30
|
|
|
|
|
|
|
|
|
2024-09-19 10:28:11 +05:30
|
|
|
def check_is_accessible(feature, cache_key, employee):
|
2024-09-18 15:51:44 +05:30
|
|
|
"""
|
|
|
|
|
Method to check the employee is accessible for the feature or not
|
|
|
|
|
"""
|
|
|
|
|
if not employee:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
accessibility = DefaultAccessibility.objects.filter(feature=feature).first()
|
|
|
|
|
|
2024-09-25 12:47:00 +05:30
|
|
|
if accessibility and accessibility.exclude_all:
|
|
|
|
|
return False
|
2024-09-18 15:51:44 +05:30
|
|
|
if not feature or not accessibility:
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
data: dict = cache.get(cache_key, default={})
|
|
|
|
|
if data and data.get(feature) is not None:
|
|
|
|
|
return data.get(feature)
|
|
|
|
|
|
|
|
|
|
filter = accessibility.filter
|
|
|
|
|
employees = AccessibilityFilter(data=filter).qs
|
2024-09-19 10:28:11 +05:30
|
|
|
accessible = employee in employees
|
|
|
|
|
return accessible
|