chore(base): remove methods no longer used in context processor

ref: #788 #757
This commit is contained in:
2025-06-05 16:59:56 +09:30
parent 82bfacbab3
commit dd9a906073

View File

@ -74,151 +74,10 @@ def user_settings(context) -> int:
return None
def user_default_organization(context) -> int:
""" Provides the users default organization.
Returns:
int: Users Default Organization
"""
if context.user.is_authenticated:
settings = UserSettings.objects.filter(user=context.user)
if settings[0].default_organization:
return settings[0].default_organization.id
return None
def nav_items(context) -> list(dict()):
""" Fetch All Project URLs
Collect the project URLs for use in creating the site navigation.
The returned list contains a dictionary with the following items:
name: {str} Group Name
urls: {list} List of URLs for the group
is_active: {bool} if any of the links in this group are active
Each group url list item contains a dicionary with the following items:
name: {str} The display name for the link
url: {str} link URL
is_active: {bool} if this link is the active URL
Returns:
list: Items user has view access to
"""
dnav = []
re_pattern = re.compile('[a-z/0-9]+')
for nav_group in urlpatterns:
group_active = False
ignored_apps = [
'admin',
'djdt', # Debug application
'api',
'social',
]
nav_items = []
if (
isinstance(nav_group, URLPattern)
):
group_name = str(nav_group.name)
elif (
isinstance(nav_group, URLResolver)
):
if nav_group.app_name is not None and str(nav_group.app_name).lower() not in ignored_apps:
group_name = str(nav_group.app_name)
for pattern in nav_group.url_patterns:
is_active = False
url = '/' + str(nav_group.pattern) + str(pattern.pattern)
if str(context.path).startswith(url):
is_active = True
if str(context.path).startswith('/' + str(nav_group.pattern)):
group_active = True
if (
pattern.pattern.name is not None
and
not str(pattern.pattern.name).startswith('_')
):
name = str(pattern.name)
if hasattr(pattern.callback.view_class, 'permission_required'):
permissions_required = pattern.callback.view_class.permission_required
user_has_perm = False
if type(permissions_required) is list:
user_has_perm = context.user.has_perms(permissions_required)
else:
user_has_perm = context.user.has_perm(permissions_required)
if hasattr(pattern.callback.view_class, 'model'):
if pattern.callback.view_class.model is Organization and context.user.is_authenticated:
organizations = Organization.objects.filter(manager = context.user)
if len(organizations) > 0:
user_has_perm = True
if str(nav_group.app_name).lower() == 'settings':
user_has_perm = True
if context.user.is_superuser:
user_has_perm = True
if user_has_perm:
nav_items = nav_items + [ {
'name': name,
'url': url,
'is_active': is_active
} ]
if len(nav_items) > 0:
dnav = dnav + [{
'name': group_name,
'urls': nav_items,
'is_active': group_active
}]
return dnav
def common(context):
return {
'build_details': build_details(context),
'nav_items': nav_items(context),
'social_backends': social_backends(context),
'user_settings': user_settings(context),
'user_default_organization': user_default_organization(context)
}