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

Proposed by Robert Ancell
Status: Needs review
Proposed branch: lp:~robert-ancell/indicator-session/lockdown-settings-14.04
Merge into: lp:indicator-session/14.04
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-14.04
Reviewer Review Type Date Requested Status
Indicator Applet Developers Pending
Review via email: mp+227834@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.

Unmerged revisions

447. By Robert Ancell

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/service.c'
--- src/service.c 2014-04-02 15:02:59 +0000
+++ src/service.c 2014-07-22 21:41:51 +0000
@@ -537,7 +537,7 @@
537create_switch_section (IndicatorSessionService * self, int profile)537create_switch_section (IndicatorSessionService * self, int profile)
538{538{
539 GMenu * menu;539 GMenu * menu;
540 GMenuItem * item;540 GMenuItem * item = NULL;
541 gboolean want_accel;541 gboolean want_accel;
542 guint i;542 guint i;
543 gpointer guser;543 gpointer guser;
@@ -559,32 +559,47 @@
559 indicator_session_guest_is_active (p->backend_guest))559 indicator_session_guest_is_active (p->backend_guest))
560 {560 {
561 const char * action = "indicator.switch-to-greeter";561 const char * action = "indicator.switch-to-greeter";
562 item = g_menu_item_new (ellipsis ? _("Switch Account…")562 if (indicator_session_actions_can_switch (p->backend_actions))
563 : _("Switch Account"), action);563 item = g_menu_item_new (ellipsis ? _("Switch Account…")
564 : _("Switch Account"), action);
564 want_accel = FALSE;565 want_accel = FALSE;
565 }566 }
566 else567 else
567 {568 {
568 const char * action = "indicator.switch-to-screensaver";569 const char * lock_switch_action = "indicator.switch-to-screensaver";
570 const char * switch_action = "indicator.switch-to-greeter";
569571
570 if (g_hash_table_size (p->users) == 1)572 if (g_hash_table_size (p->users) > 1 &&
571 item = g_menu_item_new (_("Lock"), action);573 indicator_session_actions_can_switch (p->backend_actions))
572 else574 {
573 item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")575 if (indicator_session_actions_can_lock (p->backend_actions))
574 : _("Lock/Switch Account"), action);576 item = g_menu_item_new (ellipsis ? _("Lock/Switch Account…")
577 : _("Lock/Switch Account"), lock_switch_action);
578 else
579 item = g_menu_item_new (ellipsis ? _("Switch Account…")
580 : _("Switch Account"), switch_action);
581 }
582 else if (indicator_session_actions_can_lock (p->backend_actions))
583 item = g_menu_item_new (_("Lock"), lock_switch_action);
575584
576 want_accel = TRUE;585 want_accel = TRUE;
577 }586 }
578587
579 if (want_accel)588 if (item)
580 {589 {
581 gchar * str = g_settings_get_string (p->keybinding_settings, "screensaver");590 if (want_accel)
582 g_menu_item_set_attribute (item, "accel", "s", str);591 {
583 g_free (str);592 gchar * str = g_settings_get_string (p->keybinding_settings, "screensaver");
593 g_menu_item_set_attribute (item, "accel", "s", str);
594 g_free (str);
595 }
596
597 g_menu_append_item (menu, item);
598 g_object_unref (item);
584 }599 }
585600
586 g_menu_append_item (menu, item);601 if (!indicator_session_actions_can_switch (p->backend_actions))
587 g_object_unref (item);602 return G_MENU_MODEL (menu);
588603
589 if (indicator_session_guest_is_allowed (p->backend_guest))604 if (indicator_session_guest_is_allowed (p->backend_guest))
590 {605 {
591606
=== modified file 'tests/test-service.cc'
--- tests/test-service.cc 2014-03-24 10:19:00 +0000
+++ tests/test-service.cc 2014-07-22 21:41:51 +0000
@@ -503,6 +503,19 @@
503 bool confirm_disabled = g_settings_get_boolean (indicator_settings, confirm_disabled_key);503 bool confirm_disabled = g_settings_get_boolean (indicator_settings, confirm_disabled_key);
504 bool confirm = confirm_supported && !confirm_disabled;504 bool confirm = confirm_supported && !confirm_disabled;
505505
506 // Add users so switch options are shown
507 IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
508 u->uid = 100;
509 u->user_name = g_strdup ("thing1");
510 u->real_name = g_strdup (" ");
511 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
512 u = g_new0 (IndicatorSessionUser, 1);
513 u->uid = 101;
514 u->user_name = g_strdup ("thing2");
515 u->real_name = g_strdup (" ");
516 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
517 wait_for_menu_resync ();
518
506 // confirm that the ellipsis are correct519 // confirm that the ellipsis are correct
507 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));520 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));
508 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));521 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));
@@ -537,6 +550,19 @@
537 bool confirm_disabled = g_settings_get_boolean (indicator_settings, confirm_disabled_key);550 bool confirm_disabled = g_settings_get_boolean (indicator_settings, confirm_disabled_key);
538 bool confirm = confirm_supported && !confirm_disabled;551 bool confirm = confirm_supported && !confirm_disabled;
539552
553 // Add users so switch options are shown
554 IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
555 u->uid = 100;
556 u->user_name = g_strdup ("thing1");
557 u->real_name = g_strdup (" ");
558 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
559 u = g_new0 (IndicatorSessionUser, 1);
560 u->uid = 101;
561 u->user_name = g_strdup ("thing2");
562 u->real_name = g_strdup (" ");
563 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
564 wait_for_menu_resync ();
565
540 // confirm that the ellipsis are correct566 // confirm that the ellipsis are correct
541 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));567 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.switch-to-screensaver"));
542 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));568 ASSERT_EQ (confirm, action_menuitem_label_is_ellipsized ("indicator.logout"));
@@ -562,6 +588,105 @@
562 g_settings_reset (indicator_settings, confirm_disabled_key);588 g_settings_reset (indicator_settings, confirm_disabled_key);
563}589}
564590
591TEST_F (ServiceTest, LockdownUserSwitching)
592{
593 const char * const can_switch_key = "can-switch-sessions";
594
595 // Add users so switch options are shown
596 IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
597 u->uid = 100;
598 u->user_name = g_strdup ("thing1");
599 u->real_name = g_strdup (" ");
600 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
601 u = g_new0 (IndicatorSessionUser, 1);
602 u->uid = 101;
603 u->user_name = g_strdup ("thing2");
604 u->real_name = g_strdup (" ");
605 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
606 wait_for_menu_resync ();
607
608 // Check can enable screensaver lock
609 ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
610 ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
611
612 g_settings_set_boolean (mock_settings, can_switch_key, FALSE);
613 wait_for_menu_resync ();
614
615 // Check can still enable screensaver (though it can't switch)
616 ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
617 ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
618
619 // cleanup
620 g_settings_reset (mock_settings, can_switch_key);
621}
622
623TEST_F (ServiceTest, LockdownLockScreen)
624{
625 const char * const can_lock_key = "can-lock";
626
627 // Add users so switch options are shown
628 IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
629 u->uid = 100;
630 u->user_name = g_strdup ("thing1");
631 u->real_name = g_strdup (" ");
632 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
633 u = g_new0 (IndicatorSessionUser, 1);
634 u->uid = 101;
635 u->user_name = g_strdup ("thing2");
636 u->real_name = g_strdup (" ");
637 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
638 wait_for_menu_resync ();
639
640 // Check can enable screensaver lock
641 ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
642 ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
643
644 g_settings_set_boolean (mock_settings, can_lock_key, FALSE);
645 wait_for_menu_resync ();
646
647 // Check can't enable screensaver - just go to greeter
648 ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-screensaver"));
649 ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-greeter"));
650
651 // cleanup
652 g_settings_reset (mock_settings, can_lock_key);
653}
654
655TEST_F (ServiceTest, LockdownUserSwitchingAndLockScreen)
656{
657 const char * const can_switch_key = "can-switch-sessions";
658 const char * const can_lock_key = "can-lock";
659
660 // Add users so switch options are shown
661 IndicatorSessionUser * u = g_new0 (IndicatorSessionUser, 1);
662 u->uid = 100;
663 u->user_name = g_strdup ("thing1");
664 u->real_name = g_strdup (" ");
665 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
666 u = g_new0 (IndicatorSessionUser, 1);
667 u->uid = 101;
668 u->user_name = g_strdup ("thing2");
669 u->real_name = g_strdup (" ");
670 indicator_session_users_mock_add_user (INDICATOR_SESSION_USERS_MOCK(mock_users), u);
671 wait_for_menu_resync ();
672
673 // Check can enable screensaver lock
674 ASSERT_TRUE (action_menuitem_exists ("indicator.switch-to-screensaver"));
675 ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
676
677 g_settings_set_boolean (mock_settings, can_switch_key, FALSE);
678 g_settings_set_boolean (mock_settings, can_lock_key, FALSE);
679 wait_for_menu_resync ();
680
681 // Check can't enable screensaver or go to greeter
682 ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-screensaver"));
683 ASSERT_FALSE (action_menuitem_exists ("indicator.switch-to-greeter"));
684
685 // cleanup
686 g_settings_reset (mock_settings, can_switch_key);
687 g_settings_reset (mock_settings, can_lock_key);
688}
689
565/**690/**
566 * Check that the default menu has items for each of these actions691 * Check that the default menu has items for each of these actions
567 */692 */

Subscribers

People subscribed via source and target branches