Implementation of permission label management

This commit is contained in:
Josué Tille 2020-04-24 17:32:14 +02:00
parent 8817890a05
commit 439564be83
No known key found for this signature in database
GPG key ID: 716A6C99B04194EF
6 changed files with 103 additions and 52 deletions

View file

@ -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 // Get app change label page
app.get('#/apps/:app/changelabel', function (c) { 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 = { data = {
id: c.params['app'], 'id': c.params['app'],
label: app_data.settings.label, 'label': permissions[0].label,
'permissions': permissions,
'show_tile': function(permission_name) {
return permissions_dict[permission_name].show_tile;
}
}; };
c.view('app/app_changelabel', data); c.view('app/app_changelabel', data);
}); });
@ -678,8 +715,16 @@
// Change app label // Change app label
app.post('#/apps/:app/changelabel', function (c) { app.post('#/apps/:app/changelabel', function (c) {
params = {'new_label': c.params['label']}; c.api('GET', '/users/permissions?short', {}, function(data_permissions) {
c.api('PUT', '/apps/' + c.params['app'] + '/label', params, function(data) { 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']); c.redirect_to('#/apps/'+ c.params['app']);
}); });
}); });

View file

@ -5,18 +5,6 @@
var PASSWORD_MIN_LENGTH = 4; 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 * Groups and permissions
* *

View file

@ -7,10 +7,10 @@
"all": "All", "all": "All",
"all_apps": "All apps", "all_apps": "All apps",
"api_not_responding": "The YunoHost API is not responding. Maybe 'yunohost-api' is down or got restarted?", "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_change_url": "Change URL",
"app_info_access_desc": "Groups / users currently allowed to access this app:", "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_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_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_change_url_disabled_tooltip": "This feature hasn't been implemented in this app yet",
@ -176,6 +176,7 @@
"logout": "Logout", "logout": "Logout",
"mailbox_quota_description": "For example, 700M is a CD, 4700M is a DVD.", "mailbox_quota_description": "For example, 700M is a CD, 4700M is a DVD.",
"mailbox_quota_placeholder": "Leave empty or set to 0 to disable.", "mailbox_quota_placeholder": "Leave empty or set to 0 to disable.",
"main_permission": "Main permission of the app",
"maintained": "maintained", "maintained": "maintained",
"maintained_details": "This app was maintained by its maintainer in the last few months.", "maintained_details": "This app was maintained by its maintainer in the last few months.",
"manage_apps": "Manage apps", "manage_apps": "Manage apps",
@ -253,6 +254,7 @@
"service_start_on_boot": "Start on boot", "service_start_on_boot": "Start on boot",
"services": "Services", "services": "Services",
"set_default": "Set default", "set_default": "Set default",
"show_tile_enabled": "Show the tile in the portail",
"size": "Size", "size": "Size",
"since": "since", "since": "since",
"skip": "Skip", "skip": "Skip",

View file

@ -8,23 +8,39 @@
<div class="separator"></div> <div class="separator"></div>
<form action="#/apps/{{id}}/changelabel" method="POST" class="form-horizontal form-app-install"> <form action="#/apps/{{id}}/changelabel" method="POST" class="form-horizontal form-app-install">
<div class="panel panel-default">
<div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h2 class="panel-title"><span class="fa-fw fa-tag"></span> {{t 'app_change_label'}}</h2> <h2 class="panel-title"><span class="fa-fw fa-tag"></span> {{t 'app_manage_label'}}</h2>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="form-group"> {{#each permissions}}
<label for="label" class="col-sm-12">{{t 'label'}}</label> <div class="row">
<div class="col-sm-12"> <div class="col-sm-2">
<input class="col-sm-12" type="text" id="label" name="label" class="form-control" value="{{label}}" required="required"> <h3>{{title}}</h3>
</div> </div>
<div class="col-sm-8">
{{#if tile_available}}
<p>Permission url: <a href=https://{{url}}>https://{{url}}</a></p>
{{/if}}
<input type="text" id="label" name="label_{{name}}" class="form-control" value="{{label}}" required="required">
</div> </div>
<hr> {{#if tile_available}}
<input type="hidden" name="app" value="{{id}}"> <div class="col-sm-2">
<p>{{t 'show_tile_enabled'}}</p>
<input type="checkbox" id="show_tile_{{name}}" name="show_tile_{{name}}" value="{{name}}" {{#if show_tile}} checked {{/if}} class="nice-checkbox">
<label for="show_tile_{{name}}" class="pull-right"><span class="sr-only">{{t 'check'}}</span></label>
</div>
{{/if}}
</div>
<hr />
{{/each}}
<div class="text-center"> <div class="text-center">
<input type="submit" role="button" class="btn btn-success slide back" value="{{t 'app_change_label'}}"> <input type="submit" role="button" class="btn btn-success slide back" value="{{t 'app_change_label'}}">
</div> </div>
</div> </div>
</div> </div>
</form> </form>

View file

@ -41,9 +41,9 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="container"> <div class="container">
<p>{{t 'app_info_changelabel_desc' settings.label}}</p> <p>{{t 'app_info_managelabel_desc' settings.label}}</p>
<a role="button" href="#/apps/{{settings.id}}/changelabel" class="btn btn-info slide"> <a role="button" href="#/apps/{{settings.id}}/changelabel" class="btn btn-info slide">
<span class="fa-tag"></span> {{t 'app_change_label'}} <span class="fa-tag"></span> {{t 'app_manage_label'}}
</a> </a>
</div> </div>
<hr> <hr>

View file

@ -45,7 +45,7 @@
<div class="list-group"> <div class="list-group">
{{#each apps}} {{#each apps}}
<div class="list-group-item"> <div class="list-group-item">
<input type="checkbox" id="{{id}}" name="apps" value="{{id}}" checked class="nice-checkbox"> <input type="checkbox" id="{{id}}" name="apps" value="1" checked class="nice-checkbox">
<label for="{{id}}" class="pull-right"><span class="sr-only">{{t 'check'}}</span></label> <label for="{{id}}" class="pull-right"><span class="sr-only">{{t 'check'}}</span></label>
<h2 class="list-group-item-heading">{{label}} <small>{{id}}</small></h2> <h2 class="list-group-item-heading">{{label}} <small>{{id}}</small></h2>
</div> </div>