Add support for reset saved password. Fixes #3074

This commit is contained in:
Akshay Joshi 2018-07-27 14:36:42 +05:30
parent 00139f7750
commit 0138dee989
8 changed files with 126 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

View File

@ -13,15 +13,17 @@ The pgAdmin menu bar provides drop-down menus for access to options, commands, a
Use the *File* menu to access the following options:
+----------------------+---------------------------------------------------------------------------------------------------------+
| Option | Action |
+======================+=========================================================================================================+
| *Change Password...* | Click to open the :ref:`Change Password... <change_password_dialog>` dialog to change your password. |
+----------------------+---------------------------------------------------------------------------------------------------------+
| *Preferences* | Click to open the :ref:`Preferences <preferences>` dialog to to customize your pgAdmin settings. |
+----------------------+---------------------------------------------------------------------------------------------------------+
| *Reset Layout* | If you have modified the workspace, click to restore the default layout. |
+----------------------+---------------------------------------------------------------------------------------------------------+
+-------------------------+---------------------------------------------------------------------------------------------------------+
| Option | Action |
+=========================+=========================================================================================================+
| *Change Password...* | Click to open the :ref:`Change Password... <change_password_dialog>` dialog to change your password. |
+-------------------------+---------------------------------------------------------------------------------------------------------+
| *Preferences* | Click to open the :ref:`Preferences <preferences>` dialog to to customize your pgAdmin settings. |
+-------------------------+---------------------------------------------------------------------------------------------------------+
| *Reset Layout* | If you have modified the workspace, click to restore the default layout. |
+-------------------------+---------------------------------------------------------------------------------------------------------+
| *Reset server password* | If you have saved the database server password, click to reset the saved password. |
+-------------------------+---------------------------------------------------------------------------------------------------------+
**The Object Menu**

View File

@ -11,6 +11,7 @@ Features
********
| `Feature #2214 <https://redmine.postgresql.org/issues/2214>`_ - Add support for SCRAM password changes (requires psycopg2 >= 2.8).
| `Feature #3074 <https://redmine.postgresql.org/issues/3074>`_ - Add support for reset saved password.
| `Feature #3397 <https://redmine.postgresql.org/issues/3397>`_ - Add support for Trigger and JIT stats in the graphical query plan viewer.
| `Feature #3506 <https://redmine.postgresql.org/issues/3506>`_ - Allow the user to specify a fixed port number in the runtime to aid cookie whitelisting etc.
| `Feature #3510 <https://redmine.postgresql.org/issues/3510>`_ - Add a menu option to the runtime to copy the appserver URL to the clipboard.

View File

@ -0,0 +1,13 @@
.. _reset_passwords:
************************
`Reset Passwords`:index:
************************
Use *Reset server password* functionality to reset the saved password for the database server.
.. image:: images/reset_server_password.png
*Reset server password* shows in the context menu for the selected server as well as under the *File* menu on the top menu bar.
**Note:** It will be enabled/visible when the password for the selected database server is already saved.

View File

@ -92,3 +92,7 @@ Use the fields in the *Advanced* tab to configure a connection:
* Click the *Save* button to save your work.
* Click the *Cancel* button to exit without saving your work.
* Click the *Reset* button to return the values specified on the Server dialog to their original condition.
.. toctree::
reset_passwords

View File

@ -137,7 +137,9 @@ class ServerModule(sg.ServerGroupPluginModule):
db=manager.db,
user=manager.user_info if connected else None,
in_recovery=in_recovery,
wal_pause=wal_paused
wal_pause=wal_paused,
is_password_saved=True if server.password is not None
else False
)
@property
@ -248,7 +250,8 @@ class ServerNode(PGChildNodeView):
'wal_replay': [{
'delete': 'pause_wal_replay', 'put': 'resume_wal_replay'
}],
'check_pgpass': [{'get': 'check_pgpass'}]
'check_pgpass': [{'get': 'check_pgpass'}],
'reset_server_password': [{'put': 'reset_server_password'}]
})
EXP_IP4 = "^\s*((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\." \
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\." \
@ -357,7 +360,9 @@ class ServerNode(PGChildNodeView):
db=manager.db,
user=manager.user_info if connected else None,
in_recovery=in_recovery,
wal_pause=wal_paused
wal_pause=wal_paused,
is_password_saved=True if server.password is not None
else False
)
)
@ -410,7 +415,9 @@ class ServerNode(PGChildNodeView):
db=manager.db,
user=manager.user_info if connected else None,
in_recovery=in_recovery,
wal_pause=wal_paused
wal_pause=wal_paused,
is_password_saved=True if server.password is not None
else False
)
)
@ -1440,5 +1447,40 @@ class ServerNode(PGChildNodeView):
)
)
def reset_server_password(self, gid, sid):
"""
This function is used to remove database server password stored into
the pgAdmin's db file.
:param gid:
:param sid:
:return:
"""
try:
server = Server.query.filter_by(
user_id=current_user.id, id=sid
).first()
if server is None:
return make_json_response(
success=0,
info=gettext("Could not find the required server.")
)
setattr(server, 'password', None)
db.session.commit()
except Exception as e:
current_app.logger.error(
"Unable to reset password.\nError: {0}".format(str(e))
)
return internal_server_error(errormsg=str(e))
return make_json_response(
success=1,
info=gettext("Reset server password successfully."),
data={'is_password_saved': False}
)
ServerNode.register_node_view(blueprint)

View File

@ -107,6 +107,17 @@ define('pgadmin.node.server', [
applies: ['tools', 'context'], callback: 'resume_wal_replay',
category: 'wal_replay_resume', priority: 8, label: gettext('Resume Replay of WAL'),
icon: 'fa fa-play-circle', enable : 'wal_resume_enabled',
},{
name: 'reset_server_password', node: 'server', module: this,
applies: ['file', 'context'], callback: 'reset_server_password',
label: gettext('Reset server password'), icon: 'fa fa-eraser',
enable: function(node) {
if (node && node._type === 'server' &&
node.connected !== true && node.is_password_saved) {
return true;
}
return false;
},
}]);
_.bindAll(this, 'connection_lost');
@ -596,6 +607,46 @@ define('pgadmin.node.server', [
t.unload(i);
});
},
/* Reset stored database server password */
reset_server_password: function(args){
var input = args || {},
obj = this,
t = pgBrowser.tree,
i = input.item || t.selected(),
d = i && i.length == 1 ? t.itemData(i) : undefined;
if (!d)
return false;
Alertify.confirm(
gettext('Reset server password'),
S(
gettext('Are you sure you want to reset the stored password for server %s?')
).sprintf(d.label).value(),
function() {
$.ajax({
url: obj.generate_url(i, 'reset_server_password', d, true),
method:'PUT',
})
.done(function(res) {
if (res.success == 1) {
Alertify.success(res.info);
t.itemData(i).is_password_saved=res.data.is_password_saved;
}
else {
Alertify.error(res.info);
}
})
.fail(function(xhr, status, error) {
Alertify.pgRespErrorNotify(xhr, error);
});
},
function() { return true; }
);
return false;
},
},
model: pgAdmin.Browser.Node.Model.extend({
defaults: {