Add support for protected permission in webadmin and show label instead of permission name

This commit is contained in:
Josué Tille 2020-04-24 00:01:35 +02:00
parent d426831b3f
commit 8817890a05
No known key found for this signature in database
GPG key ID: 716A6C99B04194EF
2 changed files with 20 additions and 22 deletions

View file

@ -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);
});

View file

@ -18,15 +18,17 @@
<span class="fa-fw fa-{{icon}}"></span>
{{text}}
<button data-type="{{type}}s" data-action="remove" data-item="{{value}}" data-group="{{group}}">
<span class="fa-close" style="margin-left:5px"></span>
<span class="sr-only">{{t 'delete'}}</span>
{{#unless protected}}
<span class="fa-close" style="margin-left:5px"></span>
<span class="sr-only">{{t 'delete'}}</span>
{{/unless}}
</button>
</span>
{{/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}}
<div class="btn-group">
@ -73,7 +75,7 @@
<div style="font-style:italic">{{t 'group_explain_visitors_needed_for_external_client'}}</div>
{{/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}}
</div>
</div>
@ -83,7 +85,7 @@
<h3>{{t 'permissions'}}</h3>
</div>
<div class="col-sm-10">
{{> 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}}
</div>
</div>
</div>
@ -111,7 +113,7 @@
<h3><span class="fa-fw fa-user"></span> {{@key}}</h3>
</div>
<div class="col-sm-10">
{{> 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}}
</div>
</div>
<hr />