From abf0b1a7ae0b57cf08ca196adc641f66868e20e5 Mon Sep 17 00:00:00 2001 From: Murtuza Zabuawala Date: Wed, 7 Mar 2018 16:35:33 +0000 Subject: [PATCH] Allow admins to disable the use of Gravatar if they choose. Fixes #3037 --- web/config.py | 5 ++ web/pgadmin/browser/__init__.py | 24 +++---- web/pgadmin/browser/static/css/browser.css | 4 ++ .../browser/templates/browser/index.html | 15 +++- .../browser/macros/gravatar_icon.macro | 8 +++ .../browser/macros/static_user_icon.macro | 3 + .../tests/test_gravatar_image_display.py | 68 +++++++++++++++++++ web/pgadmin/browser/tests/test_login.py | 16 +++-- 8 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 web/pgadmin/browser/templates/browser/macros/gravatar_icon.macro create mode 100644 web/pgadmin/browser/templates/browser/macros/static_user_icon.macro create mode 100644 web/pgadmin/browser/tests/test_gravatar_image_display.py diff --git a/web/config.py b/web/config.py index a72833488..d4ddd9db1 100644 --- a/web/config.py +++ b/web/config.py @@ -356,6 +356,11 @@ SQLALCHEMY_TRACK_MODIFICATIONS = False ########################################################################## ON_DEMAND_RECORD_COUNT = 1000 +########################################################################## +# Allow users to display Gravatar image for their username in Server mode +########################################################################## +SHOW_GRAVATAR_IMAGE = True + ########################################################################## # Local config settings ########################################################################## diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index 158967742..dd2542fbd 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -730,18 +730,18 @@ class BrowserPluginModule(PgAdminModule): @login_required def index(): """Render and process the main browser window.""" - # Get the Gravatar - Gravatar( - current_app, - size=100, - rating='g', - default='retro', - force_default=False, - use_ssl=True, - base_url=None - ) + # Register Gravatar module with the app only if required + if config.SHOW_GRAVATAR_IMAGE: + Gravatar( + current_app, + size=100, + rating='g', + default='retro', + force_default=False, + use_ssl=True, + base_url=None + ) - msg = None # Get the current version info from the website, and flash a message if # the user is out of date, and the check is enabled. if config.UPGRADE_CHECK_ENABLED: @@ -761,7 +761,7 @@ def index(): if response.getcode() == 200: data = json.loads(response.read().decode('utf-8')) current_app.logger.debug('Response data: %s' % data) - except Exception as e: + except Exception: current_app.logger.exception('Exception when checking for update') if data is not None: diff --git a/web/pgadmin/browser/static/css/browser.css b/web/pgadmin/browser/static/css/browser.css index 2fffd6497..3ba330d30 100644 --- a/web/pgadmin/browser/static/css/browser.css +++ b/web/pgadmin/browser/static/css/browser.css @@ -62,3 +62,7 @@ samp, .sql-editor-grid-container { font-family: 'Open Sans' !important; } + +.pg-login-icon { + font-size: 16px; +} diff --git a/web/pgadmin/browser/templates/browser/index.html b/web/pgadmin/browser/templates/browser/index.html index 58ff43f8d..76c3e4c7c 100644 --- a/web/pgadmin/browser/templates/browser/index.html +++ b/web/pgadmin/browser/templates/browser/index.html @@ -1,5 +1,13 @@ {% extends "base.html" %} + +{% if config.SERVER_MODE and config.SHOW_GRAVATAR_IMAGE -%} +{% import 'browser/macros/gravatar_icon.macro' as IMG with context %} +{% elif config.SERVER_MODE %} +{% import 'browser/macros/static_user_icon.macro' as IMG with context %} +{% endif %} + {% block title %}{{ config.APP_NAME }}{% endblock %} + {% block init_script %} try { require( @@ -66,9 +74,11 @@ require.onResourceLoad = function (context, map, depMaps) { }, 400) } }; + +{% if config.SERVER_MODE %} window.onload = function(e){ setTimeout(function() { - var gravatarImg = 'Gravatar image for {{ username }} {{ username }} '; + var gravatarImg = {{ IMG.PREPARE_HTML()|safe }} //$('#navbar-menu .navbar-right > li > a').html(gravatarImg); var navbarRight = document.getElementById("navbar-menu").getElementsByClassName("navbar-right")[0]; if (navbarRight) { @@ -77,8 +87,9 @@ window.onload = function(e){ } }, 1000); }; - +{% endif %} {% endblock %} + {% block body %}