]>
Commit | Line | Data |
---|---|---|
4b60ee19 DC |
1 | Ext.define('PVE.dc.SyncWindow', { |
2 | extend: 'Ext.window.Window', | |
3 | ||
4 | title: gettext('Realm Sync'), | |
5 | ||
6 | width: 600, | |
7 | bodyPadding: 10, | |
8 | modal: true, | |
9 | resizable: false, | |
10 | ||
11 | controller: { | |
12 | xclass: 'Ext.app.ViewController', | |
13 | ||
14 | control: { | |
15 | 'form': { | |
16 | validitychange: function(field, valid) { | |
17 | let me = this; | |
18 | me.lookup('preview_btn').setDisabled(!valid); | |
19 | me.lookup('sync_btn').setDisabled(!valid); | |
20 | }, | |
21 | }, | |
22 | 'button': { | |
23 | click: function(btn) { | |
47ea76b2 | 24 | if (btn.reference === 'help_btn') return; |
4b60ee19 DC |
25 | this.sync_realm(btn.reference === 'preview_btn'); |
26 | }, | |
27 | }, | |
28 | }, | |
29 | ||
30 | sync_realm: function(is_preview) { | |
31 | let me = this; | |
32 | let view = me.getView(); | |
33 | let ipanel = me.lookup('ipanel'); | |
34 | let params = ipanel.getValues(); | |
3e43739f DC |
35 | |
36 | let vanished_opts = []; | |
37 | ['acl', 'entry', 'properties'].forEach((prop) => { | |
38 | if (params[`remove-vanished-${prop}`]) { | |
39 | vanished_opts.push(prop); | |
40 | } | |
41 | delete params[`remove-vanished-${prop}`]; | |
42 | }); | |
43 | if (vanished_opts.length > 0) { | |
44 | params['remove-vanished'] = vanished_opts.join(';'); | |
45 | } | |
46 | ||
4b60ee19 DC |
47 | params['dry-run'] = is_preview ? 1 : 0; |
48 | Proxmox.Utils.API2Request({ | |
49 | url: `/access/domains/${view.realm}/sync`, | |
50 | waitMsgTarget: view, | |
51 | method: 'POST', | |
52 | params, | |
53 | failure: function(response) { | |
54 | view.show(); | |
55 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
56 | }, | |
57 | success: function(response) { | |
58 | view.hide(); | |
59 | Ext.create('Proxmox.window.TaskViewer', { | |
60 | upid: response.result.data, | |
61 | listeners: { | |
62 | destroy: function() { | |
63 | if (is_preview) { | |
64 | view.show(); | |
65 | } else { | |
66 | view.close(); | |
67 | } | |
68 | }, | |
69 | }, | |
70 | }).show(); | |
71 | }, | |
72 | }); | |
73 | }, | |
74 | }, | |
75 | ||
76 | items: [ | |
77 | { | |
78 | xtype: 'form', | |
79 | reference: 'form', | |
80 | border: false, | |
81 | fieldDefaults: { | |
82 | labelWidth: 100, | |
83 | anchor: '100%', | |
84 | }, | |
85 | items: [{ | |
86 | xtype: 'inputpanel', | |
87 | reference: 'ipanel', | |
88 | column1: [ | |
89 | { | |
90 | xtype: 'proxmoxKVComboBox', | |
91 | name: 'scope', | |
92 | fieldLabel: gettext('Scope'), | |
93 | value: '', | |
e5ede40a | 94 | emptyText: gettext('No default available'), |
4b60ee19 DC |
95 | deleteEmpty: false, |
96 | allowBlank: false, | |
97 | comboItems: [ | |
98 | ['users', gettext('Users')], | |
99 | ['groups', gettext('Groups')], | |
100 | ['both', gettext('Users and Groups')], | |
101 | ], | |
102 | }, | |
4b60ee19 DC |
103 | ], |
104 | ||
105 | column2: [ | |
106 | { | |
107 | xtype: 'proxmoxKVComboBox', | |
108 | value: '1', | |
109 | deleteEmpty: false, | |
110 | allowBlank: false, | |
111 | comboItems: [ | |
112 | ['1', Proxmox.Utils.yesText], | |
113 | ['0', Proxmox.Utils.noText], | |
114 | ], | |
115 | name: 'enable-new', | |
116 | fieldLabel: gettext('Enable new'), | |
117 | }, | |
4b60ee19 DC |
118 | ], |
119 | ||
120 | columnB: [ | |
3e43739f | 121 | { |
a9faeb43 DC |
122 | xtype: 'fieldset', |
123 | title: gettext('Remove Vanished Options'), | |
124 | items: [ | |
125 | { | |
126 | xtype: 'proxmoxcheckbox', | |
127 | fieldLabel: gettext('ACL'), | |
128 | name: 'remove-vanished-acl', | |
129 | boxLabel: gettext('Remove ACLs of vanished users and groups.'), | |
130 | }, | |
131 | { | |
132 | xtype: 'proxmoxcheckbox', | |
133 | fieldLabel: gettext('Entry'), | |
134 | name: 'remove-vanished-entry', | |
135 | boxLabel: gettext('Remove vanished user and group entries.'), | |
136 | }, | |
137 | { | |
138 | xtype: 'proxmoxcheckbox', | |
139 | fieldLabel: gettext('Properties'), | |
140 | name: 'remove-vanished-properties', | |
141 | boxLabel: gettext('Remove properties from vanished users.'), | |
142 | }, | |
143 | ], | |
3e43739f | 144 | }, |
4b60ee19 DC |
145 | { |
146 | xtype: 'displayfield', | |
147 | reference: 'defaulthint', | |
148 | value: gettext('Default sync options can be set by editing the realm.'), | |
149 | userCls: 'pmx-hint', | |
f6710aac | 150 | hidden: true, |
4b60ee19 DC |
151 | }, |
152 | ], | |
153 | }], | |
154 | }, | |
155 | ], | |
156 | ||
157 | buttons: [ | |
47ea76b2 DC |
158 | { |
159 | xtype: 'proxmoxHelpButton', | |
160 | reference: 'help_btn', | |
161 | onlineHelp: 'pveum_ldap_sync', | |
162 | hidden: false, | |
163 | }, | |
164 | '->', | |
4b60ee19 DC |
165 | { |
166 | text: gettext('Preview'), | |
167 | reference: 'preview_btn', | |
168 | }, | |
169 | { | |
170 | text: gettext('Sync'), | |
171 | reference: 'sync_btn', | |
172 | }, | |
173 | ], | |
174 | ||
175 | initComponent: function() { | |
176 | let me = this; | |
177 | ||
178 | if (!me.realm) { | |
179 | throw "no realm defined"; | |
180 | } | |
181 | ||
182 | me.callParent(); | |
183 | ||
184 | Proxmox.Utils.API2Request({ | |
185 | url: `/access/domains/${me.realm}`, | |
186 | waitMsgTarget: me, | |
187 | method: 'GET', | |
188 | failure: function(response) { | |
189 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
190 | me.close(); | |
191 | }, | |
192 | success: function(response) { | |
193 | let default_options = response.result.data['sync-defaults-options']; | |
194 | if (default_options) { | |
195 | let options = PVE.Parser.parsePropertyString(default_options); | |
3e43739f DC |
196 | if (options['remove-vanished']) { |
197 | let opts = options['remove-vanished'].split(';'); | |
198 | for (const opt of opts) { | |
199 | options[`remove-vanished-${opt}`] = 1; | |
200 | } | |
201 | } | |
4b60ee19 DC |
202 | let ipanel = me.lookup('ipanel'); |
203 | ipanel.setValues(options); | |
204 | } else { | |
205 | me.lookup('defaulthint').setVisible(true); | |
206 | } | |
207 | ||
208 | // check validity for button state | |
209 | me.lookup('form').isValid(); | |
210 | }, | |
211 | }); | |
212 | }, | |
213 | }); |