Merge lp:~robert-ancell/indicator-session/lockdown-settings into lp:indicator-session/14.10

Proposed by Robert Ancell
Status: Merged
Approved by: Charles Kerr
Approved revision: 449
Merged at revision: 451
Proposed branch: lp:~robert-ancell/indicator-session/lockdown-settings
Merge into: lp:indicator-session/14.10
Diff against target: 224 lines (+155/-15)
2 files modified
src/service.c (+30/-15)
tests/test-service.cc (+125/-0)
To merge this branch: bzr merge lp:~robert-ancell/indicator-session/lockdown-settings
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+226396@code.launchpad.net

Commit message

Hide relevant items from session indicator when org.gnome.desktop.lockdown disable-lock-screen or disable-user-switching are set to match 12.04 LTS behaviour

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

LGTM.

It's crazy how many special cases there are for how to show / whether to show a single menuitem... :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/service.c'
2--- src/service.c 2014-04-02 15:02:59 +0000
3+++ src/service.c 2014-07-11 01:21:24 +0000
4@@ -537,7 +537,7 @@
5 create_switch_section (IndicatorSessionService * self, int profile)
6 {
7 GMenu * menu;
8- GMenuItem * item;
9+ GMenuItem * item = NULL;
10 gboolean want_accel;
11 guint i;
12 gpointer guser;
13@@ -559,32 +559,47 @@
14 indicator_session_guest_is_active (p->backend_guest))
15 {
16 const char * action = "indicator.switch-to-greeter";
17- item = g_menu_item_new (ellipsis ? _("Switch Account…")
18- : _("Switch Account"), action);
19+ if (indicator_session_actions_can_switch (p->backend_actions))
20+ item = g_menu_item_new (ellipsis ? _("Switch Account…")
21+ : _("Switch Account"), action);
22 want_accel = FALSE;
23 }
24 else
25 {
26- const char * action = "indicator.switch-to-screensaver";
27+ const char * lock_switch_action = "indicator.switch-to-screensaver";
28+ const char * switch_action = "indicator.switch-to-greeter";
29
30- if (g_hash_table_size (p->users) == 1)
31- item = g_menu_item_new (_("Lock"), action);
32- else
33- item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
34- : _("Lock/Switch Account"), action);
35+ if (g_hash_table_size (p->users) > 1 &&
36+ indicator_session_actions_can_switch (p->backend_actions))
37+ {
38+ if (indicator_session_actions_can_lock (p->backend_actions))
39+ item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
40+ : _("Lock/Switch Account"), lock_switch_action);
41+ else
42+ item = g_menu_item_new (ellipsis ? _("Switch Account…")
43+ : _("Switch Account"), switch_action);
44+ }
45+ else if (indicator_session_actions_can_lock (p->backend_actions))
46+ item = g_menu_item_new (_("Lock"), lock_switch_action);
47
48 want_accel = TRUE;
49 }
50
51- if (want_accel)
52+ if (item)
53 {
54- gchar * str = g_settings_get_string (p->keybinding_settings, "screensaver");
55- g_menu_item_set_attribute (item, "accel", "s", str);
56- g_free (str);
57+ if (want_accel)
58+ {
59+ gchar * str = g_settings_get_string (p->keybinding_settings, "screensaver");
60+ g_menu_item_set_attribute (item, "accel", "s", str);
61+ g_free (str);
62+ }
63+
64+ g_menu_append_item (menu, item);
65+ g_object_unref (item);
66 }
67
68- g_menu_append_item (menu, item);
69- g_object_unref (item);
70+ if (!indicator_session_actions_can_switch (p->backend_actions))
71+ return G_MENU_MODEL (menu);
72
73 if (indicator_session_guest_is_allowed (p->backend_guest))
74 {
75
76=== modified file 'tests/test-service.cc'
77--- tests/test-service.cc 2014-03-24 10:19:00 +0000
78+++ tests/test-service.cc 2014-07-11 01:21:24 +0000
79@@ -503,6 +503,19 @@
80 bool confirm_disabled = g_settings_get_boolean (indicator_settings, confirm_disabled_key);
81 bool confirm = confirm_supported && !confirm_disabled;
82
83+ // Add users so switch options are shown
84+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
85+ u->uid = 100;
86+ u->user_name = g_strdup ("thing1");
87+ u->real_name = g_strdup (" ");
88+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
89+ u = g_new0 (IndicatorSessionUser, 1);
90+ u->uid = 101;
91+ u->user_name = g_strdup ("thing2");
92+ u->real_name = g_strdup (" ");
93+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
94+ wait_for_menu_resync ();
95+
96 // confirm that the ellipsis are correct
97 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));
98 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));
99@@ -537,6 +550,19 @@
100 bool confirm_disabled = g_settings_get_boolean (indicator_settings, confirm_disabled_key);
101 bool confirm = confirm_supported && !confirm_disabled;
102
103+ // Add users so switch options are shown
104+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
105+ u->uid = 100;
106+ u->user_name = g_strdup ("thing1");
107+ u->real_name = g_strdup (" ");
108+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
109+ u = g_new0 (IndicatorSessionUser, 1);
110+ u->uid = 101;
111+ u->user_name = g_strdup ("thing2");
112+ u->real_name = g_strdup (" ");
113+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
114+ wait_for_menu_resync ();
115+
116 // confirm that the ellipsis are correct
117 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));
118 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));
119@@ -562,6 +588,105 @@
120 g_settings_reset (indicator_settings, confirm_disabled_key);
121 }
122
123+TEST_F (ServiceTest, LockdownUserSwitching)
124+{
125+ const char * const can_switch_key = "can-switch-sessions";
126+
127+ // Add users so switch options are shown
128+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
129+ u->uid = 100;
130+ u->user_name = g_strdup ("thing1");
131+ u->real_name = g_strdup (" ");
132+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
133+ u = g_new0 (IndicatorSessionUser, 1);
134+ u->uid = 101;
135+ u->user_name = g_strdup ("thing2");
136+ u->real_name = g_strdup (" ");
137+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
138+ wait_for_menu_resync ();
139+
140+ // Check can enable screensaver lock
141+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
142+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
143+
144+ g_settings_set_boolean (mock_settings, can_switch_key, FALSE);
145+ wait_for_menu_resync ();
146+
147+ // Check can still enable screensaver (though it can't switch)
148+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
149+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
150+
151+ // cleanup
152+ g_settings_reset (mock_settings, can_switch_key);
153+}
154+
155+TEST_F (ServiceTest, LockdownLockScreen)
156+{
157+ const char * const can_lock_key = "can-lock";
158+
159+ // Add users so switch options are shown
160+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
161+ u->uid = 100;
162+ u->user_name = g_strdup ("thing1");
163+ u->real_name = g_strdup (" ");
164+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
165+ u = g_new0 (IndicatorSessionUser, 1);
166+ u->uid = 101;
167+ u->user_name = g_strdup ("thing2");
168+ u->real_name = g_strdup (" ");
169+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
170+ wait_for_menu_resync ();
171+
172+ // Check can enable screensaver lock
173+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
174+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
175+
176+ g_settings_set_boolean (mock_settings, can_lock_key, FALSE);
177+ wait_for_menu_resync ();
178+
179+ // Check can't enable screensaver - just go to greeter
180+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-screensaver"));
181+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-greeter"));
182+
183+ // cleanup
184+ g_settings_reset (mock_settings, can_lock_key);
185+}
186+
187+TEST_F (ServiceTest, LockdownUserSwitchingAndLockScreen)
188+{
189+ const char * const can_switch_key = "can-switch-sessions";
190+ const char * const can_lock_key = "can-lock";
191+
192+ // Add users so switch options are shown
193+ IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
194+ u->uid = 100;
195+ u->user_name = g_strdup ("thing1");
196+ u->real_name = g_strdup (" ");
197+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
198+ u = g_new0 (IndicatorSessionUser, 1);
199+ u->uid = 101;
200+ u->user_name = g_strdup ("thing2");
201+ u->real_name = g_strdup (" ");
202+ indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
203+ wait_for_menu_resync ();
204+
205+ // Check can enable screensaver lock
206+ ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
207+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
208+
209+ g_settings_set_boolean (mock_settings, can_switch_key, FALSE);
210+ g_settings_set_boolean (mock_settings, can_lock_key, FALSE);
211+ wait_for_menu_resync ();
212+
213+ // Check can't enable screensaver or go to greeter
214+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-screensaver"));
215+ ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
216+
217+ // cleanup
218+ g_settings_reset (mock_settings, can_switch_key);
219+ g_settings_reset (mock_settings, can_lock_key);
220+}
221+
222 /**
223 * Check that the default menu has items for each of these actions
224 */

Subscribers

People subscribed via source and target branches