After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 652038 - user-status: Hide "Power off" option if shutdown is disabled
user-status: Hide "Power off" option if shutdown is disabled
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
Depends on:
Blocks:
 
 
Reported: 2011-06-07 11:45 UTC by Florian Müllner
Modified: 2011-06-27 19:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
user-status: Hide "Power off" option if shutdown is disabled (5.05 KB, patch)
2011-06-07 11:45 UTC, Florian Müllner
needs-work Details | Review
user-status: Hide "Power off" option if shutdown is disabled (5.53 KB, patch)
2011-06-27 17:35 UTC, Florian Müllner
reviewed Details | Review
user-status: Hide "Power off" option if shutdown is disabled (5.57 KB, patch)
2011-06-27 19:20 UTC, Florian Müllner
committed Details | Review

Description Florian Müllner 2011-06-07 11:45:29 UTC
Shutdown may be disable due to lockdown settings or Polkit policy. We shouldn't show the "Power off..." action in the menu in this case.
Comment 1 Florian Müllner 2011-06-07 11:45:37 UTC
Created attachment 189385 [details] [review]
user-status: Hide "Power off" option if shutdown is disabled

Due to lockdown settings or Polkit policy, shutdown may not be
available. If this is the case, the "Power off ..." action should
be hidden from the user status menu.
Comment 2 Dan Winship 2011-06-27 13:37:48 UTC
Comment on attachment 189385 [details] [review]
user-status: Hide "Power off" option if shutdown is disabled

>-        if (showSeparator)
>+        if (showSeparator && this._suspendOrPowerOffItem.actor.visible) {
>             this._sessionSeparator.actor.show();

I'd rename the "showSeparator" variable. Especially since you're now dealing with two different separators in this function.

>+    _updateHaveShutdown: function() {
>+        this._session.CanShutdownRemote(Lang.bind(this,
>+            function(canShutdown) {
>+                this._haveShutdown = canShutdown;

gjs-dbus callbacks are "function(array_of_out_values, error)", where one of the two will be null. So you need something like:

    function(result, error) {
        if (result)
            this._haveShutdown = result[0];
or
            [this._haveShutdown] = result;
Comment 3 Florian Müllner 2011-06-27 17:35:17 UTC
Created attachment 190782 [details] [review]
user-status: Hide "Power off" option if shutdown is disabled

(In reply to comment #2)
> I'd rename the "showSeparator" variable. Especially since you're now dealing
> with two different separators in this function.

Done.


> gjs-dbus callbacks are "function(array_of_out_values, error)", where one of the
> two will be null.

Doh.
Comment 4 Dan Winship 2011-06-27 18:46:20 UTC
Comment on attachment 190782 [details] [review]
user-status: Hide "Power off" option if shutdown is disabled

>+        let showSesssionSeparator = sessionItemsVisible &&

too many "s"s there

I tried to test the patch, but could not figure out how to either disable suspend or enable shutdown, so...

ok to commit after fixing the above
Comment 5 Florian Müllner 2011-06-27 19:20:14 UTC
Created attachment 190788 [details] [review]
user-status: Hide "Power off" option if shutdown is disabled

(In reply to comment #4)
> I tried to test the patch, but could not figure out how to either disable
> suspend or enable shutdown, so...

Not sure about suspend (to test I just hardcoded 'false' when updating _haveSuspend ...), shutdown can be disabled with org.gnome.desktop.lockdown disable-log-out.


> ok to commit after fixing the above

Actually no. I hadn't tested the modified patch until now, and it doesn't actually work as expected. The attached one should be fine, here's the interdiff:


diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js
index 58c6bc6..7d49743 100644
--- a/js/ui/statusMenu.js
+++ b/js/ui/statusMenu.js
@@ -130,8 +130,8 @@ StatusMenuButton.prototype = {
                                   this._logoutItem.actor.visible ||
                                   this._lockScreenItem.actor.visible;
 
-        let showSesssionSeparator = sessionItemsVisible &&
-                                    this._suspendOrPowerOffItem.actor.visible;
+        let showSessionSeparator = sessionItemsVisible &&
+                                   this._suspendOrPowerOffItem.actor.visible;
 
         let showSettingsSeparator = sessionItemsVisible ||
                                     this._suspendOrPowerOffItem.actor.visible;
@@ -177,8 +177,8 @@ StatusMenuButton.prototype = {
     _updateHaveShutdown: function() {
         this._session.CanShutdownRemote(Lang.bind(this,
             function(result, error) {
-                if (result) {
-                    this._haveShutdown = result[0];
+                if (!error) {
+                    this._haveShutdown = result;
                     this._updateSuspendOrPowerOff();
                 }
             }));
@@ -194,6 +194,7 @@ StatusMenuButton.prototype = {
             this._suspendOrPowerOffItem.actor.hide();
         else
             this._suspendOrPowerOffItem.actor.show();
+         this._updateSessionSeparator();
 
         // If we can't suspend show Power Off... instead
         // and disable the alt key
Comment 6 Florian Müllner 2011-06-27 19:41:20 UTC
Attachment 190788 [details] pushed as 6b2b347 - user-status: Hide "Power off" option if shutdown is disabled

Pushed after approval on IRC