[gnome-shell/T27795: 8/138] polkitAgent: Use dialog as confirmation when the user has no password



commit 64d2f96213335f3ab0ab743e77a7e0f1b2ccf6ba
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Wed Jul 19 13:42:34 2017 +0200

    polkitAgent: Use dialog as confirmation when the user has no password
    
    When a user has no password and a polkit authentication is started,
    instead of blindly initiating the admin session, the regular
    "Authentication Requested" dialog is shown (but without the password
    entry). This means that the user's admin session is only effectively
    started after the user chooses to proceed with the authentication which
    provides an extra confirmation step that can be vital for critical
    tasks.
    
    Ideally we should use a different wording than "authentication" when the
    user has no password set, and use "confirmation" instead. However polkit
    already sends the requests with such messages (e.g. "Authentication is
    required to configure software repositories"), and it's important to
    show those to the user, so this patch keeps the regular wording.
    
    https://phabricator.endlessm.com/T17269

 js/ui/components/polkitAgent.js | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/components/polkitAgent.js b/js/ui/components/polkitAgent.js
index 7b47246d40..773d3c801c 100644
--- a/js/ui/components/polkitAgent.js
+++ b/js/ui/components/polkitAgent.js
@@ -15,6 +15,11 @@ var DIALOG_ICON_SIZE = 48;
 
 var WORK_SPINNER_ICON_SIZE = 16;
 
+const DialogMode = {
+    AUTH: 0,
+    CONFIRM: 1
+};
+
 var AuthenticationDialog = GObject.registerClass({
     Signals: { 'done': { param_types: [GObject.TYPE_BOOLEAN] } }
 }, class AuthenticationDialog extends ModalDialog.ModalDialog {
@@ -52,10 +57,6 @@ var AuthenticationDialog = GObject.registerClass({
 
         this._user = AccountsService.UserManager.get_default().get_user(userName);
         let userRealName = this._user.get_real_name();
-        this._userLoadedId = this._user.connect('notify::is_loaded',
-                                                this._onUserChanged.bind(this));
-        this._userChangedId = this._user.connect('changed',
-                                                 this._onUserChanged.bind(this));
 
         // Special case 'root'
         let userIsRoot = false;
@@ -91,10 +92,14 @@ var AuthenticationDialog = GObject.registerClass({
                           y_align: St.Align.MIDDLE });
         }
 
-        this._onUserChanged();
-
         this._passwordBox = new St.BoxLayout({ vertical: false, style_class: 'prompt-dialog-password-box' });
         content.messageBox.add(this._passwordBox);
+
+        // onUserChanged needs to be called after we have the _passwordBox set
+        this._userLoadedId = this._user.connect('notify::is_loaded', this._onUserChanged.bind(this));
+        this._userChangedId = this._user.connect('changed', this._onUserChanged.bind(this));
+        this._onUserChanged();
+
         this._passwordLabel = new St.Label(({ style_class: 'prompt-dialog-password-label' }));
         this._passwordBox.add(this._passwordLabel, { y_fill: false, y_align: St.Align.MIDDLE });
         this._passwordEntry = new St.Entry({ style_class: 'prompt-dialog-password-entry',
@@ -154,7 +159,7 @@ var AuthenticationDialog = GObject.registerClass({
             this._workSpinner.stop();
     }
 
-    performAuthentication() {
+    _initiateSession() {
         this._destroySession();
         this._session = new PolkitAgent.Session({ identity: this._identityToAuth,
                                                   cookie: this._cookie });
@@ -165,6 +170,12 @@ var AuthenticationDialog = GObject.registerClass({
         this._session.initiate();
     }
 
+    performAuthentication() {
+        if (this._mode == DialogMode.AUTH)
+            this._initiateSession();
+        this._ensureOpen();
+    }
+
     _ensureOpen() {
         // NOTE: ModalDialog.open() is safe to call if the dialog is
         // already open - it just returns true without side-effects
@@ -215,7 +226,10 @@ var AuthenticationDialog = GObject.registerClass({
     }
 
     _onAuthenticateButtonPressed() {
-        this._onEntryActivate();
+        if (this._mode == DialogMode.CONFIRM)
+            this._initiateSession();
+        else
+            this._onEntryActivate();
     }
 
     _onSessionCompleted(session, gainedAuthorization) {
@@ -306,6 +320,13 @@ var AuthenticationDialog = GObject.registerClass({
             this._userAvatar.update();
             this._userAvatar.actor.show();
         }
+
+        if (this._user.get_password_mode() == AccountsService.UserPasswordMode.NONE) {
+            this._mode = DialogMode.CONFIRM;
+            this._passwordBox.hide();
+        } else {
+            this._mode = DialogMode.AUTH;
+        }
     }
 
     cancel() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]