diff --git a/CyberCP/settings.py b/CyberCP/settings.py index c5ce2e71f..8d59217a6 100644 --- a/CyberCP/settings.py +++ b/CyberCP/settings.py @@ -159,6 +159,7 @@ TEMPLATES = [ 'baseTemplate.context_processors.notification_preferences_context', 'baseTemplate.context_processors.firewall_static_context', 'baseTemplate.context_processors.dns_static_context', + 'baseTemplate.context_processors.plugin_sidebar_context', ], }, }, diff --git a/baseTemplate/context_processors.py b/baseTemplate/context_processors.py index 83215a38a..911f698f0 100644 --- a/baseTemplate/context_processors.py +++ b/baseTemplate/context_processors.py @@ -102,4 +102,84 @@ def dns_static_context(request): version = int(time.time()) return { 'DNS_STATIC_VERSION': version - } \ No newline at end of file + } + + +def plugin_sidebar_context(request): + """ + Sidebar Plugins menu: Installed / Plugin Store (ACL), Limited phpMyAdmin link + for admins, plugin managers, or cpuser grantees; grant-only users see LPMA only. + """ + defaults = { + 'lpma_plugin_installed': False, + 'lpma_has_cpuser_grant': False, + 'show_plugin_management_links': False, + 'show_lpma_sidebar_link': False, + 'show_plugins_menu': False, + 'grant_only_lpma_sidebar': False, + 'plugin_sidebar_extra_links': [], + 'lpma_sidebar_url': '/plugins/limitedPhpmyAdmin/', + } + try: + if 'userID' not in request.session: + return defaults + uid = request.session['userID'] + from plogical.acl import ACLManager + + acl = ACLManager.loadedACL(uid) + admin = bool(acl.get('admin')) + manage_plugins = bool(acl.get('managePlugins')) + show_plugin_management_links = admin or manage_plugins + + lpma_plugin_installed = os.path.isdir('/usr/local/CyberCP/limitedPhpmyAdmin') + + lpma_has_cpuser_grant = False + if lpma_plugin_installed: + try: + from django.apps import apps + + if apps.is_installed('limitedPhpmyAdmin'): + from limitedPhpmyAdmin.models import LimitedPhpmyAdminGrant + + lpma_has_cpuser_grant = LimitedPhpmyAdminGrant.objects.filter( + enabled=True, + subject_type='cpuser', + administrator_id=uid, + ).exists() + except Exception: + lpma_has_cpuser_grant = False + + show_lpma_sidebar_link = lpma_plugin_installed and ( + show_plugin_management_links or lpma_has_cpuser_grant + ) + show_plugins_menu = show_plugin_management_links or ( + lpma_has_cpuser_grant and lpma_plugin_installed + ) + grant_only_lpma_sidebar = ( + lpma_has_cpuser_grant and lpma_plugin_installed and not show_plugin_management_links + ) + + extra = [] + if show_lpma_sidebar_link: + extra.append( + { + 'url': '/plugins/limitedPhpmyAdmin/', + 'label_key': 'limited_phpmyadmin_sidebar', + } + ) + + defaults.update( + { + 'lpma_plugin_installed': lpma_plugin_installed, + 'lpma_has_cpuser_grant': lpma_has_cpuser_grant, + 'show_plugin_management_links': show_plugin_management_links, + 'show_lpma_sidebar_link': show_lpma_sidebar_link, + 'show_plugins_menu': show_plugins_menu, + 'grant_only_lpma_sidebar': grant_only_lpma_sidebar, + 'plugin_sidebar_extra_links': extra, + 'lpma_sidebar_url': '/plugins/limitedPhpmyAdmin/', + } + ) + return defaults + except Exception: + return defaults \ No newline at end of file diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index bcd21031b..a090cfd21 100644 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -2396,8 +2396,8 @@ {% endif %} {% endif %} - {% if admin or managePlugins %} - {% if managePlugins and not admin %} + {% if show_plugins_menu %} + {% if grant_only_lpma_sidebar or managePlugins and not admin %}
{% trans "PLUGINS" %}
{% endif %} @@ -2408,12 +2408,19 @@ {% endif %}