fixes #1503 Add role CRUD to the GUI.

As given in the subject this implements role create/update/delete over
the manager.

There's currently no coler highlightning for "special" roles.

Signed-off-by: René Jochum <r.jochum@proxmox.com>
This commit is contained in:
René Jochum 2018-05-08 11:32:26 +02:00 committed by Thomas Lamprecht
parent cdd9b6c0a7
commit 675e71d37a
4 changed files with 166 additions and 4 deletions

View File

@ -21,6 +21,7 @@ JSSRC= \
form/Boolean.js \
form/CompressionSelector.js \
form/PoolSelector.js \
form/PrivilegesSelector.js \
form/GroupSelector.js \
form/UserSelector.js \
form/RoleSelector.js \
@ -185,6 +186,7 @@ JSSRC= \
dc/GroupView.js \
dc/GroupEdit.js \
dc/RoleView.js \
dc/RoleEdit.js \
dc/ACLView.js \
dc/AuthView.js \
dc/AuthEdit.js \

View File

@ -0,0 +1,61 @@
Ext.define('PVE.dc.RoleEdit', {
extend: 'Proxmox.window.Edit',
xtype: 'pveDcRoleEdit',
width: 400,
initComponent : function() {
var me = this;
me.isCreate = !me.roleid;
var url;
var method;
if (me.isCreate) {
url = '/api2/extjs/access/roles';
method = 'POST';
} else {
url = '/api2/extjs/access/roles/' + me.roleid;
method = 'PUT';
}
Ext.applyIf(me, {
subject: gettext('Role'),
url: url,
method: method,
items: [
{
xtype: me.isCreate ? 'proxmoxtextfield' : 'displayfield',
name: 'roleid',
value: me.roleid,
allowBlank: false,
fieldLabel: gettext('Name')
},
{
xtype: 'pvePrivilegesSelector',
name: 'privs',
value: me.privs,
allowBlank: false,
fieldLabel: gettext('Privileges')
}
]
});
me.callParent();
if (!me.isCreate) {
me.load({
success: function(response) {
var data = response.result.data;
var keys = Ext.Object.getKeys(data);
me.setValues({
privs: keys,
roleid: me.roleid
});
}
});
}
}
});

View File

@ -13,9 +13,9 @@ Ext.define('PVE.dc.RoleView', {
var store = new Ext.data.Store({
model: 'pve-roles',
sorters: {
property: 'roleid',
order: 'DESC'
sorters: {
property: 'roleid',
order: 'DESC'
}
});
@ -33,13 +33,45 @@ Ext.define('PVE.dc.RoleView', {
Proxmox.Utils.monStoreErrors(me, store);
var sm = Ext.create('Ext.selection.RowModel', {});
var reload = function() {
store.load();
};
var run_editor = function() {
var rec = sm.getSelection()[0];
if (!rec) {
return;
}
if (rec.data.special === "1") {
return;
}
var win = Ext.create('PVE.dc.RoleEdit',{
roleid: rec.data.roleid,
privs: rec.data.privs,
});
win.on('destroy', reload);
win.show();
};
Ext.apply(me, {
store: store,
selModel: sm,
viewConfig: {
trackOver: false
},
columns: [
{
header: gettext('Built-In'),
width: 65,
sortable: true,
dataIndex: 'special',
renderer: Proxmox.Utils.format_boolean
},
{
header: gettext('Name'),
width: 150,
@ -58,8 +90,40 @@ Ext.define('PVE.dc.RoleView', {
listeners: {
activate: function() {
store.load();
},
itemdblclick: run_editor,
},
tbar: [
{
text: gettext('Create'),
handler: function() {
var win = Ext.create('PVE.dc.RoleEdit', {});
win.on('destroy', reload);
win.show();
}
},
{
xtype: 'proxmoxButton',
text: gettext('Edit'),
disabled: true,
selModel: sm,
handler: run_editor,
enableFn: function(record) {
return record.data.special !== '1';
}
},
{
xtype: 'proxmoxStdRemoveButton',
selModel: sm,
callback: function() {
reload();
},
baseurl: '/access/roles/',
enableFn: function(record) {
return record.data.special !== '1';
}
}
}
]
});
me.callParent();

View File

@ -0,0 +1,35 @@
Ext.define('PVE.form.PrivilegesSelector', {
extend: 'Proxmox.form.KVComboBox',
xtype: 'pvePrivilegesSelector',
multiSelect: true,
initComponent: function() {
var me = this;
// So me.store is available.
me.callParent();
Proxmox.Utils.API2Request({
url: '/access/roles/Administrator',
method: 'GET',
success: function(response, options) {
var data = [];
for (var key in response.result.data) {
data.push([key, key]);
}
me.store.setData(data);
me.store.sort({
property: 'key',
direction: 'ASC'
});
},
failure: function (response, opts) {
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
}
});
}
});