aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/service.c45
-rw-r--r--tests/test-service.cc125
2 files changed, 155 insertions, 15 deletions
diff --git a/src/service.c b/src/service.c
index 034e67c..445f1af 100644
--- a/src/service.c
+++ b/src/service.c
@@ -613,7 +613,7 @@ static GMenuModel *
create_switch_section (IndicatorSessionService * self, int profile)
{
GMenu * menu;
- GMenuItem * item;
+ GMenuItem * item = NULL;
gboolean want_accel;
guint i;
gpointer guser;
@@ -635,32 +635,47 @@ create_switch_section (IndicatorSessionService * self, int profile)
indicator_session_guest_is_active (p->backend_guest))
{
const char * action = "indicator.switch-to-greeter";
- item = g_menu_item_new (ellipsis ? _("Switch Account…")
- : _("Switch Account"), action);
+ if (indicator_session_actions_can_switch (p->backend_actions))
+ item = g_menu_item_new (ellipsis ? _("Switch Account…")
+ : _("Switch Account"), action);
want_accel = FALSE;
}
else
{
- const char * action = "indicator.switch-to-screensaver";
+ const char * lock_switch_action = "indicator.switch-to-screensaver";
+ const char * switch_action = "indicator.switch-to-greeter";
- if (g_hash_table_size (p->users) == 1)
- item = g_menu_item_new (_("Lock"), action);
- else
- item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
- : _("Lock/Switch Account"), action);
+ if (g_hash_table_size (p->users) > 1 &&
+ indicator_session_actions_can_switch (p->backend_actions))
+ {
+ if (indicator_session_actions_can_lock (p->backend_actions))
+ item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
+ : _("Lock/Switch Account"), lock_switch_action);
+ else
+ item = g_menu_item_new (ellipsis ? _("Switch Account…")
+ : _("Switch Account"), switch_action);
+ }
+ else if (indicator_session_actions_can_lock (p->backend_actions))
+ item = g_menu_item_new (_("Lock"), lock_switch_action);
want_accel = TRUE;
}
- if (want_accel)
+ if (item)
{
- gchar * str = g_settings_get_string (p->keybinding_settings, "screensaver");
- g_menu_item_set_attribute (item, "accel", "s", str);
- g_free (str);
+ if (want_accel)
+ {
+ gchar * str = g_settings_get_string (p->keybinding_settings, "screensaver");
+ g_menu_item_set_attribute (item, "accel", "s", str);
+ g_free (str);
+ }
+
+ g_menu_append_item (menu, item);
+ g_object_unref (item);
}
- g_menu_append_item (menu, item);
- g_object_unref (item);
+ if (!indicator_session_actions_can_switch (p->backend_actions))
+ return G_MENU_MODEL (menu);
if (indicator_session_guest_is_allowed (p->backend_guest))
{
diff --git a/tests/test-service.cc b/tests/test-service.cc
index ab84459..9ee7236 100644
--- a/tests/test-service.cc
+++ b/tests/test-service.cc
@@ -503,6 +503,19 @@ TEST_F (ServiceTest, ConfirmationDisabledByBackend)
bool confirm_disabled = g_settings_get_boolean (indicator_settings, confirm_disabled_key);
bool confirm = confirm_supported && !confirm_disabled;
+ // Add users so switch options are shown
+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 100;
+ u->user_name = g_strdup ("thing1");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 101;
+ u->user_name = g_strdup ("thing2");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ wait_for_menu_resync ();
+
// confirm that the ellipsis are correct
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));
@@ -537,6 +550,19 @@ TEST_F (ServiceTest, ConfirmationDisabledByUser)
bool confirm_disabled = g_settings_get_boolean (indicator_settings, confirm_disabled_key);
bool confirm = confirm_supported && !confirm_disabled;
+ // Add users so switch options are shown
+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 100;
+ u->user_name = g_strdup ("thing1");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 101;
+ u->user_name = g_strdup ("thing2");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ wait_for_menu_resync ();
+
// confirm that the ellipsis are correct
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));
ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));
@@ -562,6 +588,105 @@ TEST_F (ServiceTest, ConfirmationDisabledByUser)
g_settings_reset (indicator_settings, confirm_disabled_key);
}
+TEST_F (ServiceTest, LockdownUserSwitching)
+{
+ const char * const can_switch_key = "can-switch-sessions";
+
+ // Add users so switch options are shown
+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 100;
+ u->user_name = g_strdup ("thing1");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 101;
+ u->user_name = g_strdup ("thing2");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ wait_for_menu_resync ();
+
+ // Check can enable screensaver lock
+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
+
+ g_settings_set_boolean (mock_settings, can_switch_key, FALSE);
+ wait_for_menu_resync ();
+
+ // Check can still enable screensaver (though it can't switch)
+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
+
+ // cleanup
+ g_settings_reset (mock_settings, can_switch_key);
+}
+
+TEST_F (ServiceTest, LockdownLockScreen)
+{
+ const char * const can_lock_key = "can-lock";
+
+ // Add users so switch options are shown
+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 100;
+ u->user_name = g_strdup ("thing1");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 101;
+ u->user_name = g_strdup ("thing2");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ wait_for_menu_resync ();
+
+ // Check can enable screensaver lock
+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
+
+ g_settings_set_boolean (mock_settings, can_lock_key, FALSE);
+ wait_for_menu_resync ();
+
+ // Check can't enable screensaver - just go to greeter
+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-screensaver"));
+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-greeter"));
+
+ // cleanup
+ g_settings_reset (mock_settings, can_lock_key);
+}
+
+TEST_F (ServiceTest, LockdownUserSwitchingAndLockScreen)
+{
+ const char * const can_switch_key = "can-switch-sessions";
+ const char * const can_lock_key = "can-lock";
+
+ // Add users so switch options are shown
+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 100;
+ u->user_name = g_strdup ("thing1");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ u = g_new0 (IndicatorSessionUser, 1);
+ u->uid = 101;
+ u->user_name = g_strdup ("thing2");
+ u->real_name = g_strdup (" ");
+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
+ wait_for_menu_resync ();
+
+ // Check can enable screensaver lock
+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
+
+ g_settings_set_boolean (mock_settings, can_switch_key, FALSE);
+ g_settings_set_boolean (mock_settings, can_lock_key, FALSE);
+ wait_for_menu_resync ();
+
+ // Check can't enable screensaver or go to greeter
+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-screensaver"));
+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
+
+ // cleanup
+ g_settings_reset (mock_settings, can_switch_key);
+ g_settings_reset (mock_settings, can_lock_key);
+}
+
/**
* Check that the default menu has items for each of these actions
*/