[Major] Implemented removing and adding of roles

This commit is contained in:
Robert von Burg 2018-03-20 12:07:58 +01:00
parent eb38fe438a
commit 3a26153a86
4 changed files with 192 additions and 32 deletions

View File

@ -33,7 +33,6 @@
display: block;
margin: 0;
padding: 0;
height: 100%;
}
paper-material {
@ -44,10 +43,14 @@
list-style: none;
}
.content {
border-top: 1px black solid;
}
</style>
<paper-material class="g-m-4" elevation="1">
<h3 class="g-pl-4 g-pt-1 g-pb-1" on-tap="_toggleOpened">
<paper-material class="g-mt-0 g-mb-0 g-ml-4 g-mr-4" elevation="1">
<h3 class="g-pl-2 g-pt-1 g-pb-0" on-tap="_toggleOpened">
<template is="dom-if" if="[[!opened]]">
<paper-icon-button icon="arrow-drop-down"></paper-icon-button>
</template>
@ -55,15 +58,20 @@
<paper-icon-button icon="arrow-drop-up"></paper-icon-button>
</template>
[[privilege.name]]
<paper-icon-button on-tap="_removePrivilege" class="g-pull-right" icon="delete"></paper-icon-button>
</h3>
<template is="dom-if" if="[[opened]]">
<div class="g-pt-1 g-pl-4 g-pr-4">
<div class="content g-pt-0 g-pb-2 g-pl-4 g-pr-4">
<p class="g-mt-0">Policy: [[privilege.policy]]</p>
<paper-input class="g-mt-2"
label="Policy"
on-input="_inputChanged"
value="{{privilege.policy}}"></paper-input>
<paper-checkbox checked="{{privilege.allAllowed}}">All allowed</paper-checkbox>
<paper-checkbox class="g-mt-3" on-tap="_inputChanged" checked="{{privilege.allAllowed}}">All allowed
</paper-checkbox>
<template is="dom-if" if="[[!privilege.allAllowed]]">
<br />
@ -76,7 +84,7 @@
<ul>
<template is="dom-repeat" items="[[privilege.allowList]]">
<li>
<paper-icon-button icon="delete"
<paper-icon-button icon="remove-circle-outline"
title="Remove"
on-tap="_removeAllowValue"></paper-icon-button>
[[item]]
@ -93,7 +101,7 @@
<ul>
<template is="dom-repeat" items="[[privilege.denyList]]">
<li>
<paper-icon-button icon="delete"
<paper-icon-button icon="remove-circle-outline"
title="Remove"
on-tap="_removeDenyValue"></paper-icon-button>
[[item]]
@ -114,7 +122,7 @@
<paper-dialog id="dlg" modal>
<h2>[[dlgTitle]]</h2>
<paper-input value="{{listValue}}"></paper-input>
<paper-input label="value" value="{{listValue}}"></paper-input>
<div class="buttons">
<paper-button dialog-confirm autofocus>Close</paper-button>
@ -122,7 +130,6 @@
</div>
</paper-dialog>
<iron-ajax id="ajax"
content-type="application/json"
handle-as="json"
@ -168,8 +175,6 @@
}
},
observers: [],
ready: function () {
//
},
@ -186,6 +191,10 @@
this.opened = !this.opened;
},
_inputChanged: function (e) {
this.fire('strolch-changed', {});
},
_addAllowValue: function (e) {
this.dlgTitle = "Add Allow Value";
this.listToAddTo = 'allowList';
@ -199,9 +208,14 @@
},
_saveAllowDenyValue: function (e) {
if (this.isEmptyString(this.listValue)) {
return;
}
var path = 'privilege.' + this.listToAddTo;
this.push(path, this.listValue);
this.notifyPath(path);
this.fire('strolch-changed', {});
this.listToAddTo = '';
this.listValue = '';
@ -223,7 +237,7 @@
_removeValue: function (value, list, path) {
console.log('Removing vlaue ' + value + ' for path ' + path);
console.log('Removing value ' + value + ' for path ' + path);
for (var i = 0; i < list.length; i++) {
if (list[i] === value) {
@ -238,8 +252,14 @@
}
]);
this.notifyPath(path);
this.fire('strolch-changed', {});
}
}
},
_removePrivilege: function (e) {
e.stopPropagation();
this.fire('strolch-remove-privilege', {privilege: this.privilege})
}
});

View File

@ -33,17 +33,20 @@
display: block;
margin: 0;
padding: 0;
height: 100%;
}
paper-material {
background-color: white;
}
.content {
border-top: 1px black solid;
}
</style>
<paper-material elevation="1">
<h3 class="g-m-3 g-p-2" on-tap="_toggleOpened">
<h3 class="g-m-3 g-pt-2 g-pl-2 g-pr-2" on-tap="_toggleOpened">
<template is="dom-if" if="[[!opened]]">
<paper-icon-button icon="arrow-drop-down"></paper-icon-button>
</template>
@ -51,23 +54,42 @@
<paper-icon-button icon="arrow-drop-up"></paper-icon-button>
</template>
[[role.name]]
<paper-icon-button on-tap="_removeRole" class="g-pull-right" icon="delete"></paper-icon-button>
</h3>
<template is="dom-if" if="[[opened]]">
<template is="dom-repeat" items="[[role.privileges]]" as="privilege">
<strolch-wc-role-privilege base-path="[[basePath]]"
role="[[role]]"
privilege="[[privilege]]"></strolch-wc-role-privilege>
</template>
<div class="content">
<template is="dom-repeat" items="[[role.privileges]]" as="privilege">
<strolch-wc-role-privilege base-path="[[basePath]]"
role="[[role]]"
privilege="[[privilege]]"
on-strolch-changed="onChanged"
on-strolch-remove-privilege="onRemovePrivilege"></strolch-wc-role-privilege>
</template>
<paper-button on-tap="reload" autofocus>Cancel</paper-button>
<paper-button on-tap="_addOrUpdateRole">Save</paper-button>
<div class="g-pt-2 g-pb-2">
<paper-button on-tap="reload" autofocus disabled="[[!changed]]">Cancel</paper-button>
<paper-button on-tap="_addOrUpdateRole" disabled="[[!changed]]">Save</paper-button>
<paper-button on-tap="_openAddPrivilegeDlg">Add Privilege</paper-button>
</div>
</div>
</template>
</paper-material>
<paper-dialog id="dlg" modal>
<h2>[[dlgTitle]]</h2>
<paper-input value="{{privilegeName}}"></paper-input>
<div class="buttons">
<paper-button dialog-confirm autofocus>Close</paper-button>
<paper-button on-tap="_addPrivilege">Add</paper-button>
</div>
</paper-dialog>
<iron-ajax id="ajax"
content-type="application/json"
handle-as="json"
@ -92,24 +114,39 @@
value: false
},
role: {
type: Object
type: Object,
observer: 'roleChanged'
},
isNew: {
type: Boolean
privilegeName: {
type: String
},
changed: {
type: Boolean,
value: false
}
},
listeners: {},
ready: function () {
//
},
roleChanged: function (newValue, oldValue) {
if (newValue != null && newValue.isNew) {
this.changed = true;
}
if ((newValue != null && oldValue == null)
|| (newValue != null && newValue.name != oldValue.name)) {
this.opened = false;
}
},
reload: function () {
this.dlgTitle = 'Role query failed';
this._handleAjaxResponse = function (data) {
this.role = data.detail.response;
this.changed = false;
};
this.$.ajax.url = this.basePath + 'rest/strolch/privilege/roles/' + this.role.name;
@ -125,14 +162,37 @@
this.opened = !this.opened;
},
_openAddPrivilegeDlg: function (e) {
this.dlgTitle = "Add Privilege";
this.$.dlg.open();
},
_addPrivilege: function (e) {
if (this.isEmptyString(this.privilegeName)) {
return;
}
this.push('role.privileges', {
name: this.privilegeName,
policy: "DefaultPrivilege",
allAllowed: false,
allowList: [],
denyList: []
});
this.changed = true;
this.privilegeName = '';
this.$.dlg.close();
},
_addOrUpdateRole: function (e) {
this.dlgTitle = 'Save role failed';
this._handleAjaxResponse = function (data) {
this.changed = false;
this.fire('strolch-role-reload-needed');
};
if (this.isNew) {
if (this.role.isNew) {
this.$.ajax.url = this.basePath + 'rest/strolch/privilege/roles';
this.$.ajax.method = 'POST';
} else {
@ -141,6 +201,33 @@
}
this.$.ajax.body = this.role;
this.$.ajax.generateRequest();
},
_removeRole: function (e) {
e.stopPropagation();
this.fire('strolch-remove-role', {role: this.role})
},
onChanged: function (e) {
this.changed = true;
},
onRemovePrivilege: function (e) {
var privilege = e.detail.privilege;
var index = this.role.privileges.indexOf(privilege);
if (index >= 0) {
this.role.privileges.splice(index, 1);
this.notifySplices('role.privileges', [
{
index: index,
removed: [privilege],
addedCount: 0,
obect: this.role.privileges,
type: 'splice'
}
]);
this.changed = true;
}
}
});

View File

@ -54,15 +54,16 @@
</style>
<!--div class="g-row g-pt-4">
<div class="g-row g-pt-4">
<div class="g-12 g-right">
<paper-button on-tap="_addRole" raised>Add</paper-button>
<paper-button on-tap="_openAddRoleDlg" raised>Add</paper-button>
</div>
</div-->
</div>
<template is="dom-repeat" items="[[roles]]" as="role">
<strolch-wc-role base-path="[[basePath]]"
role="[[role]]"
on-strolch-remove-role="onRemoveRole"
on-strolch-role-reload-needed="onReload"></strolch-wc-role>
</template>
@ -75,6 +76,17 @@
</div>
</paper-dialog>
<paper-dialog id="addRoleDlg" modal>
<h2>[[dlgTitle]]</h2>
<paper-input label="role name" value="{{roleName}}"></paper-input>
<div class="buttons">
<paper-button dialog-confirm autofocus>Close</paper-button>
<paper-button on-tap="_addRole">Add</paper-button>
</div>
</paper-dialog>
<iron-ajax id="ajax"
content-type="application/json"
handle-as="json"
@ -96,6 +108,9 @@
properties: {
roles: {
type: Array
},
roleName: {
type: String
}
},
@ -132,6 +147,44 @@
this.$.ajax.generateRequest();
},
_openAddRoleDlg: function (e) {
this.dlgTitle = 'Add Role';
this.$.addRoleDlg.open();
},
_addRole: function (e) {
if (this.isEmptyString(this.roleName)) {
return;
}
this.push('roles', {
isNew: true,
name: this.roleName,
privileges: []
});
this.roleName = '';
this.$.addRoleDlg.close();
},
onRemoveRole: function (e) {
var role = e.detail.role;
if (!confirm('Do you really want to delete role ' + role.name)) {
return;
}
this.dlgTitle = 'Remove role failed';
this._handleAjaxResponse = function (data) {
this.reload();
};
this.$.ajax.url = this.basePath + 'rest/strolch/privilege/roles/' + role.name;
this.$.ajax.method = 'DELETE';
this.$.ajax.body = {};
this.$.ajax.generateRequest();
},
_handleAjaxResponse: function (evt) {
console.log('NOT YET DEFINED!');
}

View File

@ -327,7 +327,7 @@
return;
}
this.dlgTitle = 'User query failed';
this.dlgTitle = 'Remove user failed';
this._handleAjaxResponse = function (data) {
this.reload();
};