diff --git a/src/js/yunohost/controllers/apps.js b/src/js/yunohost/controllers/apps.js index b7067a57..c41b0a7b 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 @@ }); }); }); - }); }); // @@ -677,12 +680,48 @@ }); + // 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 toFriendlyName(str) { + return str.split('.')[1].replace(/_/g, " ").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) { + 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('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.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 = { - 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); }); @@ -690,10 +729,19 @@ // 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.redirect_to('#/apps/'+ c.params['app']); + + $.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"; + } + 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/js/yunohost/controllers/users.js b/src/js/yunohost/controllers/users.js index fb2524c2..80ee3054 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 * @@ -119,7 +107,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 +116,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 +136,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/locales/en.json b/src/locales/en.json index a4e64a56..e7d04006 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -6,17 +6,18 @@ "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_change_label": "Change Label", "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", "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", @@ -230,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", diff --git a/src/views/app/app_changelabel.ms b/src/views/app/app_changelabel.ms index 0dc6aafc..61fec73b 100644 --- a/src/views/app/app_changelabel.ms +++ b/src/views/app/app_changelabel.ms @@ -1,30 +1,36 @@ -
- {{t 'home'}} - - - {{label}} - {{t 'app_change_label'}} -
- -
- -
-
-
-

{{t 'app_change_label'}}

-
-
-
- -
- -
-
-
- -
- -
-
-
-
+
+ {{t 'home'}} + + + {{label}} + {{t 'app_manage_label_and_tiles'}} +
+ +
+ +
+
+
+

{{t 'app_manage_label_and_tiles'}}

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

{{title}}

+ {{#if tile_available}} +

{{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 b8da64da..3fc867fa 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'}}
@@ -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_and_tiles'}}

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}}

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}}

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}}