Cleanup / simplify app permission view and controller

This commit is contained in:
Alexandre Aubin 2020-10-28 17:33:00 +01:00
parent d40731aa76
commit abb44a7924
4 changed files with 47 additions and 58 deletions

View file

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

View file

@ -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 <a href='#/tools/migrations'>Tools > Migrations</a> 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",

View file

@ -3,44 +3,34 @@
<a href="#/apps" class="hidden-xs">{{t 'applications'}}</a>
<a href="#/apps" class="visible-xs">&hellip;</a>
<a href="#/apps/{{id}}">{{label}}</a>
<a href="#/apps/{{id}}/changelabel">{{t 'app_change_label'}}</a>
<a href="#/apps/{{id}}/changelabel">{{t 'app_manage_label_and_tiles'}}</a>
</div>
<div class="separator"></div>
<form action="#/apps/{{id}}/changelabel" method="POST" class="form-horizontal form-app-install">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title"><span class="fa-fw fa-tag"></span> {{t 'app_manage_label'}}</h2>
</div>
<div class="panel-body">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title"><span class="fa-fw fa-tag"></span> {{t 'app_manage_label_and_tiles'}}</h2>
</div>
<div class="panel-body">
{{#each permissions}}
<div class="row">
<div class="col-sm-2">
<h3>{{title}}</h3>
</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 class="permission-row" data-permission="{{name}}">
<h3>{{title}}</h3>
{{#if tile_available}}
<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>
<p>{{t 'permission_corresponding_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">
{{#if tile_available}}
<input type="checkbox" id="show_tile_{{name}}" name="show_tile_{{name}}" value="{{name}}" {{#if show_tile}} checked {{/if}}>
<label for="show_tile_{{name}}" style="font-weight:normal;"> {{t 'permission_show_tile_enabled'}}</label>
{{/if}}
</div>
<hr />
{{/each}}
<div class="text-center">
<input type="submit" role="button" class="btn btn-success slide back" value="{{t 'app_change_label'}}">
<div class="text-center">
<input type="submit" role="button" class="btn btn-success slide back" value="{{t 'apply'}}">
</div>
</div>
</div>
</div>
</div>
</form>

View file

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