mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Allow admins to disable the use of Gravatar if they choose. Fixes #3037
This commit is contained in:
parent
ae5c13188d
commit
abf0b1a7ae
@ -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
|
||||
##########################################################################
|
||||
|
@ -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:
|
||||
|
@ -62,3 +62,7 @@ samp,
|
||||
.sql-editor-grid-container {
|
||||
font-family: 'Open Sans' !important;
|
||||
}
|
||||
|
||||
.pg-login-icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
@ -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 = '<img src="{{ username | gravatar }}" width="18" height="18" alt="Gravatar image for {{ username }}"> {{ username }} <span class="caret"></span>';
|
||||
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 %}
|
||||
<style>
|
||||
#pg-spinner {
|
||||
|
@ -0,0 +1,8 @@
|
||||
{##########################################################################
|
||||
We wrote separate macro because if user choose to disable Gravatar then
|
||||
we will not associate our application with Gravatar module which will make
|
||||
'gravatar' filter unavailable in Jinja templates
|
||||
###########################################################################}
|
||||
{% macro PREPARE_HTML() -%}
|
||||
'<img src = "{{ username | gravatar }}" width = "18" height = "18" alt = "Gravatar image for {{ username }}" > {{ username }} <span class="caret"></span>';
|
||||
{%- endmacro %}
|
@ -0,0 +1,3 @@
|
||||
{% macro PREPARE_HTML() -%}
|
||||
'<i class="fa fa-user-circle pg-login-icon" aria-hidden="true"></i> {{ username }} <span class="caret"></span>';
|
||||
{%- endmacro %}
|
68
web/pgadmin/browser/tests/test_gravatar_image_display.py
Normal file
68
web/pgadmin/browser/tests/test_gravatar_image_display.py
Normal file
@ -0,0 +1,68 @@
|
||||
##########################################################################
|
||||
#
|
||||
# pgAdmin 4 - PostgreSQL Tools
|
||||
#
|
||||
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
|
||||
import config
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression.python_test_utils import test_utils as utils
|
||||
from regression.test_setup import config_data as tconfig
|
||||
|
||||
|
||||
class TestLoginUserImage(BaseTestGenerator):
|
||||
"""
|
||||
This class checks for user image after successful login.
|
||||
- If SHOW_GRAVATAR_IMAGE config option is set to True then we will show
|
||||
Gravatar on the Page.
|
||||
- If SHOW_GRAVATAR_IMAGE config option is set to False then we will show
|
||||
Static image on the Page.
|
||||
"""
|
||||
|
||||
scenarios = [
|
||||
(
|
||||
'Verify gravatar image on the page', dict(
|
||||
email=(
|
||||
tconfig['pgAdmin4_login_credentials']['login_username']
|
||||
),
|
||||
password=(
|
||||
tconfig['pgAdmin4_login_credentials']['login_password']
|
||||
),
|
||||
respdata='Gravatar image for %s' %
|
||||
tconfig['pgAdmin4_login_credentials']
|
||||
['login_username'],
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"Logout first if already logged in"
|
||||
utils.logout_tester_account(cls.tester)
|
||||
|
||||
def runTest(self):
|
||||
# Login and check type of image in response
|
||||
response = self.tester.post(
|
||||
'/login', data=dict(
|
||||
email=self.email,
|
||||
password=self.password
|
||||
),
|
||||
follow_redirects=True
|
||||
)
|
||||
# Should have gravatar image
|
||||
if config.SHOW_GRAVATAR_IMAGE:
|
||||
self.assertIn(self.respdata, response.data.decode('utf8'))
|
||||
# Should not have gravatar image
|
||||
else:
|
||||
self.assertNotIn(self.respdata, response.data.decode('utf8'))
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
"""
|
||||
We need to again login the test client as soon as test scenarios
|
||||
finishes.
|
||||
"""
|
||||
utils.login_tester_account(cls.tester)
|
@ -62,13 +62,15 @@ class LoginTestCase(BaseTestGenerator):
|
||||
# This test case validates the valid/correct credentials and allow user
|
||||
# to login pgAdmin 4
|
||||
('Valid_Credentials', dict(
|
||||
email=(config_data['pgAdmin4_login_credentials']
|
||||
['login_username']),
|
||||
password=(config_data['pgAdmin4_login_credentials']
|
||||
['login_password']),
|
||||
respdata='Gravatar image for %s' %
|
||||
config_data['pgAdmin4_login_credentials']
|
||||
['login_username']))
|
||||
email=(config_data[
|
||||
'pgAdmin4_login_credentials'
|
||||
]['login_username']),
|
||||
password=(config_data[
|
||||
'pgAdmin4_login_credentials'
|
||||
]['login_password']),
|
||||
respdata='%s' % config_data['pgAdmin4_login_credentials']
|
||||
['login_username'])
|
||||
)
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user