polkitAgent: Cancel session after disconnecting signal handlers

When cancelling the PolkitAgent session before disconnecting the signal
handlers, we receive a "completed" signal where `gained_authorization`
is set to FALSE, which means we show an error message inside
`_onSessionCompleted()`.

This in turn means we show an error message every time we cancel a
session. In practice this wasn't really relevant so far since we only
destroyed the session when an actual error occurred before. Now that the
dialog supports empty passwords, we also call `_destroySession()` when
the user changes and no longer has a password set, and in this case we
want to cancel the current session without showing an error message.

So to fix this, disconnect the signal handlers before cancelling the
session, which makes sure we don't receive the last "completed" signal
in case we cancelled the session ourselves. This change also allows
removing `this._wasDismissed`.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/829
This commit is contained in:
Jonas Dreßler 2019-06-23 13:11:58 +02:00 committed by Florian Müllner
parent 89bf360bad
commit 45ebb94b33

View File

@ -31,7 +31,6 @@ var AuthenticationDialog = GObject.registerClass({
this.actionId = actionId; this.actionId = actionId;
this.message = body; this.message = body;
this.userNames = userNames; this.userNames = userNames;
this._wasDismissed = false;
this._sessionUpdatedId = Main.sessionMode.connect('updated', () => { this._sessionUpdatedId = Main.sessionMode.connect('updated', () => {
this.visible = !Main.sessionMode.isLocked; this.visible = !Main.sessionMode.isLocked;
@ -249,7 +248,7 @@ var AuthenticationDialog = GObject.registerClass({
* error providing authentication-method specific information), * error providing authentication-method specific information),
* show "Sorry, that didn't work. Please try again." * show "Sorry, that didn't work. Please try again."
*/ */
if (!this._errorMessageLabel.visible && !this._wasDismissed) { if (!this._errorMessageLabel.visible) {
/* Translators: "that didn't work" refers to the fact that the /* Translators: "that didn't work" refers to the fact that the
* requested authentication was not gained; this can happen * requested authentication was not gained; this can happen
* because of an authentication error (like invalid password), * because of an authentication error (like invalid password),
@ -312,14 +311,15 @@ var AuthenticationDialog = GObject.registerClass({
_destroySession(delay = 0) { _destroySession(delay = 0) {
if (this._session) { if (this._session) {
if (!this._completed)
this._session.cancel();
this._completed = false;
this._session.disconnect(this._sessionCompletedId); this._session.disconnect(this._sessionCompletedId);
this._session.disconnect(this._sessionRequestId); this._session.disconnect(this._sessionRequestId);
this._session.disconnect(this._sessionShowErrorId); this._session.disconnect(this._sessionShowErrorId);
this._session.disconnect(this._sessionShowInfoId); this._session.disconnect(this._sessionShowInfoId);
if (!this._completed)
this._session.cancel();
this._completed = false;
this._session = null; this._session = null;
} }
@ -381,7 +381,6 @@ var AuthenticationDialog = GObject.registerClass({
} }
cancel() { cancel() {
this._wasDismissed = true;
this.close(global.get_current_time()); this.close(global.get_current_time());
this._emitDone(true); this._emitDone(true);
} }