From 054a3744d5d65d8b6431a313e22e08ec3cd6250e Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 15 Oct 2019 13:28:43 -0700 Subject: [PATCH] frontpage: Show shortcuts that public even if need a group Closes: #1659. When shortcuts have login_required=False and allow_groups set to a list of groups, the current behavior for logged in users is to match for allowed_groups even when login_required is False. Thus, for searx, when public mode is enabled searx shortcut is not shown for logged in users who are not part of searx group. Fix this by ignoring allowed_groups if login_required is False. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/frontpage.py | 6 ++++-- plinth/tests/test_frontpage.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plinth/frontpage.py b/plinth/frontpage.py index 1feeb53ab..664249d6e 100644 --- a/plinth/frontpage.py +++ b/plinth/frontpage.py @@ -78,7 +78,9 @@ class Shortcut(app.FollowerComponent): 'allowed_groups' specifies a list of user groups to whom this shortcut must be shown. All other user groups will not be shown this shortcut on - the frontpage. + the frontpage. If 'login_required' is False, this property has not + effect and the shortcut is shown to all the users including anonymous + users. """ super().__init__(component_id) @@ -131,7 +133,7 @@ class Shortcut(app.FollowerComponent): shortcuts = {} for shortcut_id, shortcut in cls._all_shortcuts.items(): - if shortcut.allowed_groups and \ + if shortcut.login_required and shortcut.allowed_groups and \ user_groups.isdisjoint(shortcut.allowed_groups): continue diff --git a/plinth/tests/test_frontpage.py b/plinth/tests/test_frontpage.py index 764cc14b3..1566a5b4b 100644 --- a/plinth/tests/test_frontpage.py +++ b/plinth/tests/test_frontpage.py @@ -86,9 +86,9 @@ def fixture_common_shortcuts(clean_global_shortcuts): shortcuts = [ Shortcut('anon-web-app-component-1', 'name1', 'short4', url='url1'), Shortcut('group1-web-app-component-1', 'Name2', 'Short3', url='url2', - allowed_groups=['group1']), + login_required=True, allowed_groups=['group1']), Shortcut('group2-web-app-component-1', 'name3', 'short2', url='url3', - allowed_groups=['group2']), + login_required=True, allowed_groups=['group2']), Shortcut('anon-non-web-app-component-1', 'name4', 'short1', url=None), ] return shortcuts @@ -142,6 +142,16 @@ def test_shortcut_list_with_username(superuser_run, common_shortcuts): return_list = Shortcut.list(username='user2') assert return_list == [cuts[0], cuts[1], cuts[2], cuts[3]] + cut = Shortcut('group2-web-app-component-1', 'name5', 'short2', url='url4', + login_required=False, allowed_groups=['group3']) + superuser_run.return_value = 'group3' + return_list = Shortcut.list(username='user3') + assert return_list == [cuts[0], cuts[3], cut] + + superuser_run.return_value = 'group4' + return_list = Shortcut.list(username='user4') + assert return_list == [cuts[0], cuts[3], cut] + @pytest.mark.usefixtures('nextcloud_shortcut') def test_add_custom_shortcuts():