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
|
ON_DEMAND_RECORD_COUNT = 1000
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
# Allow users to display Gravatar image for their username in Server mode
|
||||||
|
##########################################################################
|
||||||
|
SHOW_GRAVATAR_IMAGE = True
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Local config settings
|
# Local config settings
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -730,7 +730,8 @@ class BrowserPluginModule(PgAdminModule):
|
|||||||
@login_required
|
@login_required
|
||||||
def index():
|
def index():
|
||||||
"""Render and process the main browser window."""
|
"""Render and process the main browser window."""
|
||||||
# Get the Gravatar
|
# Register Gravatar module with the app only if required
|
||||||
|
if config.SHOW_GRAVATAR_IMAGE:
|
||||||
Gravatar(
|
Gravatar(
|
||||||
current_app,
|
current_app,
|
||||||
size=100,
|
size=100,
|
||||||
@ -741,7 +742,6 @@ def index():
|
|||||||
base_url=None
|
base_url=None
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = None
|
|
||||||
# Get the current version info from the website, and flash a message if
|
# Get the current version info from the website, and flash a message if
|
||||||
# the user is out of date, and the check is enabled.
|
# the user is out of date, and the check is enabled.
|
||||||
if config.UPGRADE_CHECK_ENABLED:
|
if config.UPGRADE_CHECK_ENABLED:
|
||||||
@ -761,7 +761,7 @@ def index():
|
|||||||
if response.getcode() == 200:
|
if response.getcode() == 200:
|
||||||
data = json.loads(response.read().decode('utf-8'))
|
data = json.loads(response.read().decode('utf-8'))
|
||||||
current_app.logger.debug('Response data: %s' % data)
|
current_app.logger.debug('Response data: %s' % data)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
current_app.logger.exception('Exception when checking for update')
|
current_app.logger.exception('Exception when checking for update')
|
||||||
|
|
||||||
if data is not None:
|
if data is not None:
|
||||||
|
@ -62,3 +62,7 @@ samp,
|
|||||||
.sql-editor-grid-container {
|
.sql-editor-grid-container {
|
||||||
font-family: 'Open Sans' !important;
|
font-family: 'Open Sans' !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pg-login-icon {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
{% extends "base.html" %}
|
{% 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 title %}{{ config.APP_NAME }}{% endblock %}
|
||||||
|
|
||||||
{% block init_script %}
|
{% block init_script %}
|
||||||
try {
|
try {
|
||||||
require(
|
require(
|
||||||
@ -66,9 +74,11 @@ require.onResourceLoad = function (context, map, depMaps) {
|
|||||||
}, 400)
|
}, 400)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{% if config.SERVER_MODE %}
|
||||||
window.onload = function(e){
|
window.onload = function(e){
|
||||||
setTimeout(function() {
|
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);
|
//$('#navbar-menu .navbar-right > li > a').html(gravatarImg);
|
||||||
var navbarRight = document.getElementById("navbar-menu").getElementsByClassName("navbar-right")[0];
|
var navbarRight = document.getElementById("navbar-menu").getElementsByClassName("navbar-right")[0];
|
||||||
if (navbarRight) {
|
if (navbarRight) {
|
||||||
@ -77,8 +87,9 @@ window.onload = function(e){
|
|||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<style>
|
<style>
|
||||||
#pg-spinner {
|
#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
|
# This test case validates the valid/correct credentials and allow user
|
||||||
# to login pgAdmin 4
|
# to login pgAdmin 4
|
||||||
('Valid_Credentials', dict(
|
('Valid_Credentials', dict(
|
||||||
email=(config_data['pgAdmin4_login_credentials']
|
email=(config_data[
|
||||||
['login_username']),
|
'pgAdmin4_login_credentials'
|
||||||
password=(config_data['pgAdmin4_login_credentials']
|
]['login_username']),
|
||||||
['login_password']),
|
password=(config_data[
|
||||||
respdata='Gravatar image for %s' %
|
'pgAdmin4_login_credentials'
|
||||||
config_data['pgAdmin4_login_credentials']
|
]['login_password']),
|
||||||
['login_username']))
|
respdata='%s' % config_data['pgAdmin4_login_credentials']
|
||||||
|
['login_username'])
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user