4
* Petr Vobornik <pvoborni@redhat.com>
6
* Copyright (C) 2012 Red Hat
7
* see file 'COPYING' for use and warranty information
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
/* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js */
27
IPA.automember.entity = function(spec) {
29
//HACK: Automember takes_params is missing a cn attribute. This hack
30
//copies cn from mod command. Also it is set as pkey.
31
var pkey_attr = IPA.metadata.commands.automember_mod.takes_args[0];
32
pkey_attr.primary_key = true;
33
IPA.metadata.objects.automember.takes_params.push(pkey_attr);
34
IPA.metadata.objects.automember.primary_key = pkey_attr.name;
38
spec.policies = spec.policies || [
39
IPA.facet_update_policy({
40
source_facet: 'usergrouprule',
41
dest_facet: 'searchgroup'
43
IPA.facet_update_policy({
44
source_facet: 'hostgrouprule',
45
dest_facet: 'searchhostgroup'
49
var that = IPA.entity(spec);
51
that.init = function() {
55
that.builder.search_facet({
56
factory: IPA.automember.rule_search_facet,
59
label: IPA.messages.objects.automember.usergrouprules,
60
details_facet: 'usergrouprule',
68
factory: IPA.automember.rule_search_facet,
69
name: 'searchhostgroup',
70
group_type: 'hostgroup',
71
label: IPA.messages.objects.automember.hostgrouprules,
72
details_facet: 'hostgrouprule',
80
factory: IPA.automember.rule_details_facet,
81
name: 'usergrouprule',
83
label: IPA.messages.objects.automember.usergrouprule,
84
disable_facet_tabs: true,
86
redirect_info: { tab: 'amgroup' }
89
factory: IPA.automember.rule_details_facet,
90
name: 'hostgrouprule',
91
group_type: 'hostgroup',
92
label: IPA.messages.objects.automember.hostgrouprule,
93
disable_facet_tabs: true,
95
redirect_info: { tab: 'amhostgroup' }
98
factory: IPA.automember.rule_adder_dialog,
99
title: IPA.messages.objects.automember.add_rule,
102
type: 'entity_select',
104
other_entity: 'group',
111
factory: IPA.automember.rule_deleter_dialog
119
IPA.automember.rule_search_facet = function(spec) {
123
var that = IPA.search_facet(spec);
125
that.group_type = spec.group_type;
127
var init = function() {
129
that.default_group_widget = IPA.automember.default_group_widget({
131
group_type: that.group_type
135
that.refresh = function() {
137
that.search_facet_refresh();
138
that.default_group_widget.refresh();
142
that.get_records_command_name = function() {
143
return that.managed_entity.name + that.group_type+'_get_records';
146
that.get_search_command_name = function() {
147
var name = that.managed_entity.name + that.group_type + '_find';
148
if (that.pagination && !that.search_all_entries) {
154
that.create_get_records_command = function(pkeys, on_success, on_error) {
156
var batch = that.table_facet_create_get_records_command(pkeys, on_success, on_error);
158
for (var i=0; i<batch.commands.length; i++) {
159
var command = batch.commands[i];
160
command.set_option('type', that.group_type);
166
that.create_refresh_command = function() {
168
var command = that.search_facet_create_refresh_command();
170
command.set_option('type', that.group_type);
175
that.create_content = function(container) {
177
var header = $('<div/>', {
178
'class': 'automember-header'
179
}).appendTo(container);
181
var content = $('<div/>', {
182
'class': 'automember-content'
183
}).appendTo(container);
185
that.default_group_widget.create(header);
186
that.table.create(content);
195
IPA.automember.rule_details_facet = function(spec) {
207
widget: 'general.description'
210
type: 'automember_condition',
211
name: 'automemberinclusiveregex',
212
widget: 'inclusive.automemberinclusiveregex'
215
type: 'automember_condition',
216
name: 'automemberexclusiveregex',
217
widget: 'exclusive.automemberexclusiveregex'
223
type: 'details_table_section',
225
label: IPA.messages.details.general,
237
factory: IPA.collapsible_section,
239
label: IPA.messages.objects.automember.inclusive,
242
type: 'automember_condition',
243
name: 'automemberinclusiveregex',
244
group_type: spec.group_type,
245
add_command: 'add_condition',
246
remove_command: 'remove_condition',
248
title: IPA.messages.objects.automember.add_condition,
253
options: IPA.automember.get_condition_attributes(spec.group_type),
254
label: IPA.messages.objects.automember.attribute
257
name: 'automemberinclusiveregex',
258
label: IPA.messages.objects.automember.expression
266
factory: IPA.collapsible_section,
268
label: IPA.messages.objects.automember.exclusive,
271
type: 'automember_condition',
272
name: 'automemberexclusiveregex',
273
group_type: spec.group_type,
274
add_command: 'add_condition',
275
remove_command: 'remove_condition',
277
title: IPA.messages.objects.automember.add_condition,
282
options: IPA.automember.get_condition_attributes(spec.group_type),
283
label: IPA.messages.objects.automember.attribute
286
name: 'automemberexclusiveregex',
287
label: IPA.messages.objects.automember.expression
296
var that = IPA.details_facet(spec);
298
that.group_type = spec.group_type;
300
that.get_refresh_command_name = function() {
301
return that.entity.name+that.group_type+'_show';
304
that.create_refresh_command = function() {
306
var command = that.details_facet_create_refresh_command();
307
command.set_option('type', that.group_type);
312
that.create_update_command = function() {
314
var command = that.details_facet_create_update_command();
315
command.set_option('type', that.group_type);
323
IPA.automember.rule_adder_dialog = function(spec) {
327
var that = IPA.entity_adder_dialog(spec);
329
that.show_edit_page = function (entity,result) {
330
var pkey_name = entity.metadata.primary_key;
331
var pkey = result[pkey_name];
332
if (pkey instanceof Array) {
335
var facet = IPA.current_entity.get_facet();
336
var facetname = facet.group_type === 'group' ? 'usergrouprule' :
339
IPA.nav.show_entity_page(that.entity, facetname, pkey);
342
that.reset = function() {
344
var field = that.fields.get_field('cn');
345
var facet = IPA.current_entity.get_facet();
347
field.widget.other_entity = IPA.get_entity(facet.group_type);
352
that.create_add_command = function(record) {
354
var facet = IPA.current_entity.get_facet();
355
var command = that.entity_adder_dialog_create_add_command(record);
356
command.name = that.entity.name+facet.group_type+'_show';
357
command.set_option('type', facet.group_type);
366
IPA.automember.rule_deleter_dialog = function(spec) {
370
var that = IPA.search_deleter_dialog(spec);
372
that.create_command = function() {
374
var facet = IPA.current_entity.get_facet();
376
var batch = that.search_deleter_dialog_create_command();
378
for (var i=0; i<batch.commands.length; i++) {
379
var command = batch.commands[i];
380
command.set_option('type', facet.group_type);
389
IPA.automember.get_condition_attributes = function(type) {
392
if (type === 'group') {
393
options = IPA.metadata.objects.user.aciattrs;
394
} else if (type === 'hostgroup') {
395
options = IPA.metadata.objects.host.aciattrs;
398
var list_options = IPA.create_options(options);
402
IPA.automember.parse_condition_regex = function(regex) {
404
var delimeter_index = regex.indexOf('=');
407
attribute: regex.substring(0, delimeter_index),
408
expression: regex.substring(delimeter_index+1)
414
IPA.automember.condition_field = function(spec) {
417
var that = IPA.field(spec);
419
that.attr_name = spec.attribute || that.name;
421
that.load = function(record) {
423
var regexes = record[that.attr_name];
427
for (var i=0, j=0; i<regexes.length; i++) {
428
var condition = IPA.automember.parse_condition_regex(regexes[i]);
429
that.values.push(condition);
433
that.load_writable(record);
440
IPA.field_factories['automember_condition'] = IPA.automember.condition_field;
442
IPA.automember.condition_widget = function(spec) {
446
spec.columns = $.merge(spec.columns || [], [
449
label: IPA.messages.objects.automember.attribute
453
label: IPA.messages.objects.automember.expression
457
spec.value_attribute = 'condition';
459
var that = IPA.attribute_table_widget(spec);
461
that.group_type = spec.group_type;
463
that.get_additional_options = function() {
467
value: that.group_type
472
that.on_add = function(data) {
474
if (data.result.completed === 0) {
475
that.refresh_facet();
477
that.reload_facet(data);
481
that.on_remove = function(data) {
483
var results = data.result.results;
485
var i = results.length - 1;
487
if (results[i].completed === 1){
488
that.reload_facet({ result: results[i] });
494
that.refresh_facet();
497
that.create_remove_command = function(values, on_success, on_error) {
499
var batch = IPA.batch_command({
500
name: 'automember_remove_condition',
501
on_success: on_success,
505
var pkeys = that.get_pkeys();
507
for (var i=0; i<values.length; i++) {
508
var condition = IPA.automember.parse_condition_regex(values[i]);
510
var command = that.attribute_table_create_remove_command([]);
511
command.set_option('key', condition.attribute);
512
command.set_option(that.attribute_name, condition.expression);
514
batch.add_command(command);
523
IPA.widget_factories['automember_condition'] = IPA.automember.condition_widget;
525
IPA.automember.default_group_widget = function(spec) {
529
var that = IPA.widget(spec);
530
that.group_type = spec.group_type;
533
var init = function() {
535
that.group_select = IPA.entity_select_widget({
536
name: 'automemberdefaultgroup',
537
other_entity: that.group_type,
542
that.group_select.value_changed.attach(that.group_changed);
545
that.get_group = function() {
547
var group = that.group_select.save();
548
group = group.length === 0 ? '' : group[0];
552
that.set_group = function(group) {
554
if (group === that.group) return;
557
that.group_select.update([group]);
560
that.group_changed = function() {
562
var group = that.get_group();
564
if (group === that.group) return;
567
that.remove_default_group();
569
that.set_default_group(group);
573
that.load = function(data) {
575
var group = data.result.result.automemberdefaultgroup;
577
if (group) group = group[0];
579
if (!group || group.indexOf('cn=') === -1) {
583
var i1 = group.indexOf('=');
584
var i2 = group.indexOf(',');
585
if (i1 > -1 && i2 > -1) {
586
group = group.substring(i1 + 1,i2);
593
that.update = function(group) {
597
that.set_group(group);
600
that.create_command = function(method) {
602
method = 'default_group_' + method;
603
var command_name = that.entity.name + that.group_type + '_' + method;
605
var command = IPA.command({
607
entity: that.entity.name,
610
type: that.group_type
617
that.refresh = function() {
619
var command = that.create_command('show');
620
command.on_success = that.load;
625
that.remove_default_group = function() {
627
var command = that.create_command('remove');
629
command.on_success = function() {
632
command.on_error = that.refresh;
637
that.set_default_group = function(group) {
639
var command = that.create_command('set');
640
command.on_success = that.load;
641
command.on_error = that.refresh;
642
command.set_option('automemberdefaultgroup', group);
648
that.create = function(container) {
650
var title = that.get_title();
652
var default_group = $('<div />', {
653
'class': 'default_group'
654
}).appendTo(container);
656
that.header = $('<h2/>', {
660
}).appendTo(default_group);
662
that.group_select.create(default_group);
665
that.get_title = function() {
666
if (that.group_type === 'group') {
667
return IPA.messages.objects.automember.default_user_group;
669
return IPA.messages.objects.automember.default_host_group;
679
IPA.register('automember', IPA.automember.entity);
b'\\ No newline at end of file'