ui: dc/Auth: add sync button

opens a window with the parameters for the sync and two buttons:
'preview' and 'sync'

both open the taskviewer, but the 'preview' one sets the 'dry-run'
parameter so that it does not get written out to the user.cfg

loads the realm config and prefills the selection with values from
the config, and shows a hint about where to set the defaults
if none are set

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-04-29 14:32:35 +02:00 committed by Thomas Lamprecht
parent 4119b159e9
commit 4b60ee19de
3 changed files with 208 additions and 0 deletions

View File

@ -232,6 +232,7 @@ JSSRC= \
dc/RoleView.js \
dc/RoleEdit.js \
dc/ACLView.js \
dc/SyncWindow.js \
dc/AuthView.js \
dc/AuthEditBase.js \
dc/AuthEditAD.js \

View File

@ -73,6 +73,19 @@ Ext.define('PVE.dc.AuthView', {
me.openEditWindow(rec.data.type, rec.data.realm);
},
open_sync_window: function() {
let me = this;
let rec = me.getSelection()[0];
if (!rec) {
return;
}
Ext.create('PVE.dc.SyncWindow', {
realm: rec.data.realm,
listeners: {
destroy: () => me.reload(),
},
}).show();
},
initComponent: function() {
var me = this;
@ -107,6 +120,14 @@ Ext.define('PVE.dc.AuthView', {
enableFn: (rec) => PVE.Utils.authSchema[rec.data.type].add,
callback: () => me.reload(),
},
'-',
{
xtype: 'proxmoxButton',
text: gettext('Sync'),
disabled: true,
enableFn: (rec) => Boolean(PVE.Utils.authSchema[rec.data.type].syncipanel),
handler: () => me.open_sync_window(),
},
],
listeners: {
activate: () => me.reload(),

View File

@ -0,0 +1,186 @@
Ext.define('PVE.dc.SyncWindow', {
extend: 'Ext.window.Window',
title: gettext('Realm Sync'),
width: 600,
bodyPadding: 10,
modal: true,
resizable: false,
controller: {
xclass: 'Ext.app.ViewController',
control: {
'form': {
validitychange: function(field, valid) {
let me = this;
me.lookup('preview_btn').setDisabled(!valid);
me.lookup('sync_btn').setDisabled(!valid);
},
},
'button': {
click: function(btn) {
this.sync_realm(btn.reference === 'preview_btn');
},
},
},
sync_realm: function(is_preview) {
let me = this;
let view = me.getView();
let ipanel = me.lookup('ipanel');
let params = ipanel.getValues();
params['dry-run'] = is_preview ? 1 : 0;
Proxmox.Utils.API2Request({
url: `/access/domains/${view.realm}/sync`,
waitMsgTarget: view,
method: 'POST',
params,
failure: function(response) {
view.show();
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
},
success: function(response) {
view.hide();
Ext.create('Proxmox.window.TaskViewer', {
upid: response.result.data,
listeners: {
destroy: function() {
if (is_preview) {
view.show();
} else {
view.close();
}
},
},
}).show();
},
});
},
},
items: [
{
xtype: 'form',
reference: 'form',
border: false,
fieldDefaults: {
labelWidth: 100,
anchor: '100%',
},
items: [{
xtype: 'inputpanel',
reference: 'ipanel',
column1: [
{
xtype: 'proxmoxKVComboBox',
name: 'scope',
fieldLabel: gettext('Scope'),
value: '',
deleteEmpty: false,
allowBlank: false,
comboItems: [
['users', gettext('Users')],
['groups', gettext('Groups')],
['both', gettext('Users and Groups')],
],
},
{
xtype: 'proxmoxKVComboBox',
value: '',
deleteEmpty: false,
allowBlank: false,
comboItems: [
['1', Proxmox.Utils.yesText],
['0', Proxmox.Utils.noText],
],
name: 'full',
fieldLabel: gettext('Full'),
},
],
column2: [
{
xtype: 'proxmoxKVComboBox',
value: '1',
deleteEmpty: false,
allowBlank: false,
comboItems: [
['1', Proxmox.Utils.yesText],
['0', Proxmox.Utils.noText],
],
name: 'enable-new',
fieldLabel: gettext('Enable new'),
},
{
xtype: 'proxmoxKVComboBox',
value: '',
deleteEmpty: false,
allowBlank: false,
comboItems: [
['1', Proxmox.Utils.yesText],
['0', Proxmox.Utils.noText],
],
name: 'purge',
fieldLabel: gettext('Purge'),
},
],
columnB: [
{
xtype: 'displayfield',
reference: 'defaulthint',
value: gettext('Default sync options can be set by editing the realm.'),
userCls: 'pmx-hint',
hidden: true
},
],
}],
},
],
buttons: [
{
text: gettext('Preview'),
reference: 'preview_btn',
},
{
text: gettext('Sync'),
reference: 'sync_btn',
},
],
initComponent: function() {
let me = this;
if (!me.realm) {
throw "no realm defined";
}
me.callParent();
Proxmox.Utils.API2Request({
url: `/access/domains/${me.realm}`,
waitMsgTarget: me,
method: 'GET',
failure: function(response) {
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
me.close();
},
success: function(response) {
let default_options = response.result.data['sync-defaults-options'];
if (default_options) {
let options = PVE.Parser.parsePropertyString(default_options);
let ipanel = me.lookup('ipanel');
ipanel.setValues(options);
} else {
me.lookup('defaulthint').setVisible(true);
}
// check validity for button state
me.lookup('form').isValid();
},
});
},
});