From 8817890a055d8df364cd979a79788acf9f016d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 24 Apr 2020 00:01:35 +0200 Subject: [PATCH 1/5] Add support for protected permission in webadmin and show label instead of permission name --- src/js/yunohost/controllers/users.js | 28 ++++++++++++---------------- src/views/user/group_list.ms | 14 ++++++++------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/js/yunohost/controllers/users.js b/src/js/yunohost/controllers/users.js index 7a26ce37..0d3bc029 100644 --- a/src/js/yunohost/controllers/users.js +++ b/src/js/yunohost/controllers/users.js @@ -119,7 +119,7 @@ app.get('#/groups', function (c) { c.api('GET', '/users/groups?full&include_primary_groups', {}, function(data_groups) { c.api('GET', '/users', {}, function(data_users) { - c.api('GET', '/users/permissions?short', {}, function(data_permissions) { + c.api('GET', '/users/permissions?full', {}, function(data_permissions) { //var perms = data_permissions.permissions; var specific_perms = {}; var all_perms = data_permissions.permissions; @@ -128,10 +128,11 @@ // Enrich groups data with primary group indicator and inversed items list for (var group in data_groups.groups) { data_groups.groups[group].primary = users.indexOf(group) !== -1; - data_groups.groups[group].permissionsInv = all_perms.filter(function(item) { + data_groups.groups[group].permissionsInv = Object.keys(all_perms).filter(function(item) { return data_groups.groups[group].permissions.indexOf(item) === -1; }).filter(function(item) { - return group != "visitors" || (item != "mail.main" && item != "xmpp.main"); // Remove 'email' and 'xmpp' in visitors's permission choice list + // Remove 'email', 'xmpp' and protected permission in visitors's permission choice list + return group != "visitors" || (item != "mail.main" && item != "xmpp.main" && ! all_perms[item].protected == true); }); data_groups.groups[group].membersInv = users.filter(function(item) { return data_groups.groups[group].members.indexOf(item) === -1; @@ -147,23 +148,18 @@ data = { 'groups':data_groups.groups, 'displayPermission': function (text) { - // Display a permission correctly for a human - text = text.replace('.main', ''); - if (text.indexOf('.') > -1) - text = text.replace('.', ' (') + ')'; - - if (text == "mail") - text = "E-mail"; - else if (text == "xmpp") - text = "XMPP"; - else - text = toTitleCase(text); - - return text; + return all_perms[text].label; }, 'displayUser': function (text) { return text; }, + 'is_protected': function (item, type, group) { + if (type == 'permission' && group == 'visitors') { + return all_perms[item].protected; + } else { + return false + } + }, }; updateView(data); }); diff --git a/src/views/user/group_list.ms b/src/views/user/group_list.ms index 932f8f33..8f1d30bc 100644 --- a/src/views/user/group_list.ms +++ b/src/views/user/group_list.ms @@ -18,15 +18,17 @@ {{text}} {{/inline}} {{#*inline "labelsLine"}} {{#each items}} - {{> label text=(call ../display .) value=. icon=../icon type=../type item=. group=../group}} + {{> label text=(call ../display .) value=. icon=../icon type=../type item=. group=../group protected=(call ../is_protected . ../type ../group)}} {{/each}} {{#if inv}}
@@ -73,7 +75,7 @@
{{t 'group_explain_visitors_needed_for_external_client'}}
{{/if}} {{else}} - {{> labelsLine display=../displayUser icon="user" type="member" items=members inv=membersInv group=@key}} + {{> labelsLine display=../displayUser icon="user" type="member" items=members inv=membersInv group=@key is_protected=../is_protected}} {{/if}}
@@ -83,7 +85,7 @@

{{t 'permissions'}}

- {{> labelsLine display=../displayPermission icon="key-modern" type="permission" items=permissions inv=permissionsInv group=@key}} + {{> labelsLine display=../displayPermission icon="key-modern" type="permission" items=permissions inv=permissionsInv group=@key is_protected=../is_protected}}
@@ -111,7 +113,7 @@

{{@key}}

- {{> labelsLine display=../displayPermission icon="key-modern" type="permission" items=permissions inv=permissionsInv group=@key}} + {{> labelsLine display=../displayPermission icon="key-modern" type="permission" items=permissions inv=permissionsInv group=@key is_protected=../is_protected}}

From 439564be83c93bf216578bade25842265de39595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 24 Apr 2020 17:32:14 +0200 Subject: [PATCH 2/5] Implementation of permission label management --- src/js/yunohost/controllers/apps.js | 55 ++++++++++++++++++-- src/js/yunohost/controllers/users.js | 12 ----- src/locales/en.json | 6 ++- src/views/app/app_changelabel.ms | 76 +++++++++++++++++----------- src/views/app/app_info.ms | 4 +- src/views/backup/backup_create.ms | 2 +- 6 files changed, 103 insertions(+), 52 deletions(-) diff --git a/src/js/yunohost/controllers/apps.js b/src/js/yunohost/controllers/apps.js index a0ccf5b0..9503231c 100644 --- a/src/js/yunohost/controllers/apps.js +++ b/src/js/yunohost/controllers/apps.js @@ -665,12 +665,49 @@ ); }); + // A small utility to convert a string to title case + // e.g. "hAvE a NicE dAy" --> "Have A Nice Day" + // Savagely stolen from https://stackoverflow.com/a/196991 + function toFriendrlyName(str) { + return str.split('.')[1].replace( + /\w\S*/g, + function(txt) { + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + } + ); + } + // Get app change label page app.get('#/apps/:app/changelabel', function (c) { - c.api('GET', '/apps/'+c.params['app']+'?full', {}, function(app_data) { + c.api('GET', '/users/permissions?full', {}, function(data_permissions) { + var permissions_dict = data_permissions.permissions; + var permissions = [ + permissions_dict[c.params['app'] + '.main'] + ]; + permissions[0].name = c.params['app'] + '.main'; + permissions[0].title = y18n.t('main_permission'); + permissions[0].tile_available = permissions[0].url != null && ! permissions[0].url.startsWith('re:'); + + var i = 1; + for (var permission in permissions_dict) { + if (permission.startsWith(c.params['app'])) { + if (! permission.endsWith('.main')) { + permissions[i] = permissions_dict[permission]; + permissions[i].name = permission; + permissions[i].title = toFriendrlyName(permission); + permissions[i].tile_available = permissions_dict[permission].url != null && ! permissions_dict[permission].url.startsWith('re:'); + } + i++; + } + } + data = { - id: c.params['app'], - label: app_data.settings.label, + 'id': c.params['app'], + 'label': permissions[0].label, + 'permissions': permissions, + 'show_tile': function(permission_name) { + return permissions_dict[permission_name].show_tile; + } }; c.view('app/app_changelabel', data); }); @@ -678,8 +715,16 @@ // Change app label app.post('#/apps/:app/changelabel', function (c) { - params = {'new_label': c.params['label']}; - c.api('PUT', '/apps/' + c.params['app'] + '/label', params, function(data) { + c.api('GET', '/users/permissions?short', {}, function(data_permissions) { + for (perm of data_permissions.permissions) { + if ('show_tile_' + perm in c.params) { + show_tile = "True"; + } else { + show_tile = "False"; + } + new_label = c.params["label_" + perm] + c.api('PUT', '/users/permissions/' + perm, {show_tile: show_tile, label: new_label}, function(data) {}); + } c.redirect_to('#/apps/'+ c.params['app']); }); }); diff --git a/src/js/yunohost/controllers/users.js b/src/js/yunohost/controllers/users.js index 0d3bc029..8fc20d99 100644 --- a/src/js/yunohost/controllers/users.js +++ b/src/js/yunohost/controllers/users.js @@ -5,18 +5,6 @@ var PASSWORD_MIN_LENGTH = 4; - // A small utility to convert a string to title case - // e.g. "hAvE a NicE dAy" --> "Have A Nice Day" - // Savagely stolen from https://stackoverflow.com/a/196991 - function toTitleCase(str) { - return str.replace( - /\w\S*/g, - function(txt) { - return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); - } - ); - } - /** * Groups and permissions * diff --git a/src/locales/en.json b/src/locales/en.json index 80811662..fefd56c6 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -7,10 +7,10 @@ "all": "All", "all_apps": "All apps", "api_not_responding": "The YunoHost API is not responding. Maybe 'yunohost-api' is down or got restarted?", - "app_change_label": "Change Label", + "app_manage_label": "Manage label and tiles", "app_change_url": "Change URL", "app_info_access_desc": "Groups / users currently allowed to access this app:", - "app_info_changelabel_desc": "Change app label in the portal.", + "app_info_managelabel_desc": "Manage permissions labels in the portal.", "app_info_default_desc": "Redirect domain root to this application (%s).", "app_info_changeurl_desc": "Change the access URL of this application (domain and/or path).", "app_info_change_url_disabled_tooltip": "This feature hasn't been implemented in this app yet", @@ -176,6 +176,7 @@ "logout": "Logout", "mailbox_quota_description": "For example, 700M is a CD, 4700M is a DVD.", "mailbox_quota_placeholder": "Leave empty or set to 0 to disable.", + "main_permission": "Main permission of the app", "maintained": "maintained", "maintained_details": "This app was maintained by its maintainer in the last few months.", "manage_apps": "Manage apps", @@ -253,6 +254,7 @@ "service_start_on_boot": "Start on boot", "services": "Services", "set_default": "Set default", + "show_tile_enabled": "Show the tile in the portail", "size": "Size", "since": "since", "skip": "Skip", diff --git a/src/views/app/app_changelabel.ms b/src/views/app/app_changelabel.ms index 0dc6aafc..ab4e692c 100644 --- a/src/views/app/app_changelabel.ms +++ b/src/views/app/app_changelabel.ms @@ -1,30 +1,46 @@ - - -
- -
-
-
-

{{t 'app_change_label'}}

-
-
-
- -
- -
-
-
- -
- -
-
-
-
+ + +
+ + +
+ +
+
+

{{t 'app_manage_label'}}

+
+
+ {{#each permissions}} +
+
+

{{title}}

+
+
+ {{#if tile_available}} +

Permission url: https://{{url}}

+ {{/if}} + +
+ {{#if tile_available}} +
+

{{t 'show_tile_enabled'}}

+ + +
+ {{/if}} +
+
+ {{/each}} +
+ +
+
+
+ +
diff --git a/src/views/app/app_info.ms b/src/views/app/app_info.ms index b8da64da..f443d7eb 100644 --- a/src/views/app/app_info.ms +++ b/src/views/app/app_info.ms @@ -41,9 +41,9 @@
-

{{t 'app_info_changelabel_desc' settings.label}}

+

{{t 'app_info_managelabel_desc' settings.label}}

- {{t 'app_change_label'}} + {{t 'app_manage_label'}}

diff --git a/src/views/backup/backup_create.ms b/src/views/backup/backup_create.ms index e354e9e1..854bf152 100644 --- a/src/views/backup/backup_create.ms +++ b/src/views/backup/backup_create.ms @@ -45,7 +45,7 @@
{{#each apps}}
- +

{{label}} {{id}}

From 257b2e7890ceb6977dd6825d67ffc40d6131c3dc Mon Sep 17 00:00:00 2001 From: Kay0u Date: Mon, 14 Sep 2020 12:36:41 +0200 Subject: [PATCH 3/5] Fix label --- src/js/yunohost/controllers/apps.js | 11 +++++++---- src/views/app/app_info.ms | 2 +- src/views/app/app_list.ms | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/js/yunohost/controllers/apps.js b/src/js/yunohost/controllers/apps.js index d60d318e..fc8ae896 100644 --- a/src/js/yunohost/controllers/apps.js +++ b/src/js/yunohost/controllers/apps.js @@ -12,6 +12,11 @@ app.get('#/apps', function (c) { c.api('GET', '/apps?full', {}, function(data) { var apps = data['apps']; + for (var a in apps) + { + var app = apps[a] + app['label'] = app['permissions'][app['id'] + ".main"]['label'] + } c.arraySortById(apps); c.view('app/app_list', {apps: apps}); }); @@ -262,10 +267,9 @@ // Get app information app.get('#/apps/:app', function (c) { c.api('GET', '/apps/'+c.params['app']+'?full', {}, function(data) { - c.api('GET', '/users/permissions', {}, function(data_permissions) { + data.label = data.permissions[c.params['app']+".main"]['label'] - // Permissions - data.permissions = data_permissions.permissions[c.params['app']+".main"]["allowed"]; + data.permissions = data.permissions[c.params['app']+".main"]["allowed"]; // Multilingual description data.description = (typeof data.manifest.description[y18n.locale] !== 'undefined') ? @@ -304,7 +308,6 @@ }); }); }); - }); }); // diff --git a/src/views/app/app_info.ms b/src/views/app/app_info.ms index f443d7eb..8f498645 100644 --- a/src/views/app/app_info.ms +++ b/src/views/app/app_info.ms @@ -16,7 +16,7 @@
{{t 'id'}}
{{settings.id}}
{{t 'label'}}
-
{{settings.label}}
+
{{label}}
{{t 'description'}}
{{description}}
{{t 'version'}}
diff --git a/src/views/app/app_list.ms b/src/views/app/app_list.ms index bf658106..a502aa42 100644 --- a/src/views/app/app_list.ms +++ b/src/views/app/app_list.ms @@ -16,7 +16,7 @@

- {{settings.label}} {{name}} + {{label}} {{name}}

{{description}}

From d40731aa76b0075c055c96ea677cfc45a87e8dd0 Mon Sep 17 00:00:00 2001 From: Josue-T Date: Tue, 15 Sep 2020 20:46:56 +0200 Subject: [PATCH 4/5] Change only the current app label Co-authored-by: Kayou --- src/js/yunohost/controllers/apps.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/js/yunohost/controllers/apps.js b/src/js/yunohost/controllers/apps.js index fc8ae896..62e52626 100644 --- a/src/js/yunohost/controllers/apps.js +++ b/src/js/yunohost/controllers/apps.js @@ -732,6 +732,8 @@ app.post('#/apps/:app/changelabel', function (c) { c.api('GET', '/users/permissions?short', {}, function(data_permissions) { for (perm of data_permissions.permissions) { + if (perm.split('.')[0] == c.params['app']) + { if ('show_tile_' + perm in c.params) { show_tile = "True"; } else { @@ -739,6 +741,7 @@ } new_label = c.params["label_" + perm] c.api('PUT', '/users/permissions/' + perm, {show_tile: show_tile, label: new_label}, function(data) {}); + } } c.redirect_to('#/apps/'+ c.params['app']); }); From abb44a7924c2e49486134f1e3ca6c2e6f65a2648 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 28 Oct 2020 17:33:00 +0100 Subject: [PATCH 5/5] Cleanup / simplify app permission view and controller --- src/js/yunohost/controllers/apps.js | 49 ++++++++++++++--------------- src/locales/en.json | 8 +++-- src/views/app/app_changelabel.ms | 46 +++++++++++---------------- src/views/app/app_info.ms | 2 +- 4 files changed, 47 insertions(+), 58 deletions(-) diff --git a/src/js/yunohost/controllers/apps.js b/src/js/yunohost/controllers/apps.js index 62e52626..dd12881a 100644 --- a/src/js/yunohost/controllers/apps.js +++ b/src/js/yunohost/controllers/apps.js @@ -683,8 +683,8 @@ // A small utility to convert a string to title case // e.g. "hAvE a NicE dAy" --> "Have A Nice Day" // Savagely stolen from https://stackoverflow.com/a/196991 - function toFriendrlyName(str) { - return str.split('.')[1].replace( + function toFriendlyName(str) { + return str.split('.')[1].replace(/_/g, " ").replace( /\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); @@ -694,26 +694,25 @@ // Get app change label page app.get('#/apps/:app/changelabel', function (c) { - c.api('GET', '/users/permissions?full', {}, function(data_permissions) { - var permissions_dict = data_permissions.permissions; + c.api('GET', '/apps/'+c.params['app']+'?full', {}, function(app_data) { + var permissions_dict = app_data.permissions; var permissions = [ permissions_dict[c.params['app'] + '.main'] ]; permissions[0].name = c.params['app'] + '.main'; - permissions[0].title = y18n.t('main_permission'); + permissions[0].title = y18n.t('permission_main'); permissions[0].tile_available = permissions[0].url != null && ! permissions[0].url.startsWith('re:'); var i = 1; for (var permission in permissions_dict) { - if (permission.startsWith(c.params['app'])) { - if (! permission.endsWith('.main')) { - permissions[i] = permissions_dict[permission]; - permissions[i].name = permission; - permissions[i].title = toFriendrlyName(permission); - permissions[i].tile_available = permissions_dict[permission].url != null && ! permissions_dict[permission].url.startsWith('re:'); - } - i++; + if (! permission.endsWith('.main')) { + permissions[i] = permissions_dict[permission]; + permissions[i].name = permission; + permissions[i].label = permissions[i].sublabel; + permissions[i].title = toFriendlyName(permission); + permissions[i].tile_available = permissions_dict[permission].url != null && ! permissions_dict[permission].url.startsWith('re:'); } + i++; } data = { @@ -730,21 +729,19 @@ // Change app label app.post('#/apps/:app/changelabel', function (c) { - c.api('GET', '/users/permissions?short', {}, function(data_permissions) { - for (perm of data_permissions.permissions) { - if (perm.split('.')[0] == c.params['app']) - { - if ('show_tile_' + perm in c.params) { - show_tile = "True"; - } else { - show_tile = "False"; - } - new_label = c.params["label_" + perm] - c.api('PUT', '/users/permissions/' + perm, {show_tile: show_tile, label: new_label}, function(data) {}); + + $.each($(".permission-row", c.target), function() { + var perm = $(this).data('permission'); + if ('show_tile_' + perm in c.params) { + show_tile = "True"; + } else { + show_tile = "False"; } - } - c.redirect_to('#/apps/'+ c.params['app']); + new_label = c.params["label_" + perm] + c.api('PUT', '/users/permissions/' + perm, {show_tile: show_tile, label: new_label}, function(data) {}); }); + + c.redirect_to('#/apps/'+ c.params['app']); }); // Get app change URL page diff --git a/src/locales/en.json b/src/locales/en.json index 8528f221..e7d04006 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -6,8 +6,8 @@ "administration_password": "Administration password", "all": "All", "all_apps": "All apps", + "apply": "Apply", "api_not_responding": "The YunoHost API is not responding. Maybe 'yunohost-api' is down or got restarted?", - "app_manage_label": "Manage label and tiles", "app_change_url": "Change URL", "app_info_access_desc": "Groups / users currently allowed to access this app:", "app_info_managelabel_desc": "Manage permissions labels in the portal.", @@ -17,6 +17,7 @@ "app_info_uninstall_desc": "Remove this application.", "app_install_cancel": "Installation cancelled.", "app_install_custom_no_manifest": "No manifest.json file", + "app_manage_label_and_tiles": "Manage label and tiles", "app_make_default": "Make default", "app_no_actions": "This application doesn't have any actions", "app_state_inprogress": "not yet working", @@ -177,7 +178,6 @@ "logout": "Logout", "mailbox_quota_description": "For example, 700M is a CD, 4700M is a DVD.", "mailbox_quota_placeholder": "Leave empty or set to 0 to disable.", - "main_permission": "Main permission of the app", "maintained": "maintained", "maintained_details": "This app was maintained by its maintainer in the last few months.", "manage_apps": "Manage apps", @@ -231,6 +231,9 @@ "logs_more": "Display more lines", "path_url": "Path", "pending_migrations": "There are some pending migrations waiting to be ran. Please go to the Tools > Migrations view to run them.", + "permission_corresponding_url": "Corresponding URL", + "permission_main": "Main permission", + "permission_show_tile_enabled": "Show the tile in the user portal", "port": "Port", "ports": "Ports", "postinstall": "Post-installation", @@ -257,7 +260,6 @@ "service_start_on_boot": "Start on boot", "services": "Services", "set_default": "Set default", - "show_tile_enabled": "Show the tile in the portail", "size": "Size", "since": "since", "skip": "Skip", diff --git a/src/views/app/app_changelabel.ms b/src/views/app/app_changelabel.ms index ab4e692c..61fec73b 100644 --- a/src/views/app/app_changelabel.ms +++ b/src/views/app/app_changelabel.ms @@ -3,44 +3,34 @@ {{label}} - {{t 'app_change_label'}} + {{t 'app_manage_label_and_tiles'}}
-
- -
-
-

{{t 'app_manage_label'}}

-
-
+
+
+

{{t 'app_manage_label_and_tiles'}}

+
+
{{#each permissions}} -
-
-

{{title}}

-
-
- {{#if tile_available}} -

Permission url: https://{{url}}

- {{/if}} - -
+
+

{{title}}

{{#if tile_available}} -
-

{{t 'show_tile_enabled'}}

- - -
+

{{t 'permission_corresponding_url'}}: https://{{url}}

+ {{/if}} + + {{#if tile_available}} + + {{/if}}

{{/each}} -
- +
+ +
+
-
-
- diff --git a/src/views/app/app_info.ms b/src/views/app/app_info.ms index 8f498645..3fc867fa 100644 --- a/src/views/app/app_info.ms +++ b/src/views/app/app_info.ms @@ -43,7 +43,7 @@

{{t 'app_info_managelabel_desc' settings.label}}

- {{t 'app_manage_label'}} + {{t 'app_manage_label_and_tiles'}}