mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-28 09:06:44 -06:00
Inter-facet expiration
Problem: When some facet perform action which modifies data, some other facet may become expired. Example: User modifies group's description. Now group search facet contains old data and has to be refreshed. Solution: New event was added to facet: on_update. It should be executed when facet performs action which modifies data ie: details facet update or add entry to dnsrecord. Then entity policies were introduced. Entity policies are a objects which are stored in entity.policies. They have similar function as facet_policies - performing communications and other functionality between facets. This way facets don't have to contain such logic and thus they aren't dependant on each other. This patch adds IPA.facet_update_policy, IPA.adder_facet_update_policy, IPA.search_facet_update_policy, IPA.details_facet_update_policy. IPA.facet_update_policy: On facets_created it bind itself to [current entity].[source facet].[event]. Default event is on_update. When the event is executed it sets expiration flag to [dest entity].[dest facet]. IPA.search_facet_update_policy: IPA.facet_update_policy where source facet = search, dest facet = details, dest entity = current entity. Its a default policy for updatein changes from search facet to details facet. Right now it isn't needed but it will be needed when action lists come to play. IPA.details_facet_update_policy: same as IPA.search_facet_update_policy just reversed. Very important. IPA.adder_facet_update_policy: similar functionality, just source of the event is dialog. Default event is added (new event in entity_adder_dialog). Entity policies should be specified in entity's spec object. If none are specified a default ones are used. Default policies are: IPA.search_facet_update_policy and IPA.details_facet_update_policy. https://fedorahosted.org/freeipa/ticket/2075
This commit is contained in:
parent
bbe672a2ae
commit
18a6ab356a
@ -33,6 +33,7 @@ IPA.entity_adder_dialog = function(spec) {
|
||||
that.on_error = spec.on_error ;
|
||||
that.retry = typeof spec.retry !== 'undefined' ? spec.retry : true;
|
||||
that.command = null;
|
||||
that.added = IPA.observer();
|
||||
|
||||
that.show_edit_page = spec.show_edit_page || show_edit_page;
|
||||
|
||||
@ -44,6 +45,7 @@ IPA.entity_adder_dialog = function(spec) {
|
||||
that.hide_message();
|
||||
that.add(
|
||||
function(data, text_status, xhr) {
|
||||
that.added.notify();
|
||||
var facet = IPA.current_entity.get_facet();
|
||||
facet.refresh();
|
||||
that.close();
|
||||
@ -59,6 +61,7 @@ IPA.entity_adder_dialog = function(spec) {
|
||||
that.hide_message();
|
||||
that.add(
|
||||
function(data, text_status, xhr) {
|
||||
that.added.notify();
|
||||
var label = that.entity.metadata.label_singular;
|
||||
var message = IPA.messages.dialogs.add_confirmation;
|
||||
message = message.replace('${entity}', label);
|
||||
@ -79,6 +82,7 @@ IPA.entity_adder_dialog = function(spec) {
|
||||
that.hide_message();
|
||||
that.add(
|
||||
function(data, text_status, xhr) {
|
||||
that.added.notify();
|
||||
that.close();
|
||||
var result = data.result.result;
|
||||
that.show_edit_page(that.entity, result);
|
||||
|
@ -33,6 +33,19 @@ IPA.automember.entity = function(spec) {
|
||||
IPA.metadata.objects.automember.takes_params.push(pkey_attr);
|
||||
IPA.metadata.objects.automember.primary_key = pkey_attr.name;
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
spec.policies = spec.policies || [
|
||||
IPA.facet_update_policy({
|
||||
source_facet: 'usergrouprule',
|
||||
dest_facet: 'searchgroup'
|
||||
}),
|
||||
IPA.facet_update_policy({
|
||||
source_facet: 'hostgrouprule',
|
||||
dest_facet: 'searchhostgroup'
|
||||
})
|
||||
];
|
||||
|
||||
var that = IPA.entity(spec);
|
||||
|
||||
that.init = function() {
|
||||
|
@ -153,6 +153,16 @@ IPA.automount.map_entity = function(spec) {
|
||||
|
||||
IPA.automount.key_entity = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
spec.policies = spec.policies || [
|
||||
IPA.facet_update_policy({
|
||||
source_facet: 'details',
|
||||
dest_entity: 'automountmap',
|
||||
dest_facet: 'keys'
|
||||
})
|
||||
];
|
||||
|
||||
var that = IPA.entity(spec);
|
||||
|
||||
that.init = function() {
|
||||
|
@ -535,6 +535,7 @@ IPA.details_facet = function(spec) {
|
||||
|
||||
that.update_on_success = function(data, text_status, xhr) {
|
||||
that.load(data);
|
||||
that.on_update.notify();
|
||||
};
|
||||
|
||||
that.update_on_error = function(xhr, text_status, error_thrown) {
|
||||
|
@ -262,6 +262,7 @@ IPA.dnszone_details_facet = function(spec) {
|
||||
|
||||
that.update_on_success = function(data, text_status, xhr) {
|
||||
that.refresh();
|
||||
that.on_update.notify();
|
||||
};
|
||||
|
||||
that.update_on_error = function(xhr, text_status, error_thrown) {
|
||||
@ -914,6 +915,17 @@ IPA.dns.get_record_type = function(type_name) {
|
||||
|
||||
IPA.dns.record_entity = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
spec.policies = spec.policies || [
|
||||
IPA.facet_update_policy({
|
||||
source_facet: 'details',
|
||||
dest_entity: 'dnszone',
|
||||
dest_facet: 'records'
|
||||
}),
|
||||
IPA.adder_facet_update_policy()
|
||||
];
|
||||
|
||||
var that = IPA.entity(spec);
|
||||
|
||||
that.init = function() {
|
||||
@ -1599,6 +1611,7 @@ IPA.dns.record_type_table_widget = function(spec) {
|
||||
function(data) {
|
||||
that.reload_facet(data);
|
||||
dialog.close();
|
||||
that.notify_facet_update();
|
||||
},
|
||||
function() {
|
||||
that.refresh_facet();
|
||||
@ -1670,6 +1683,7 @@ IPA.dns.record_type_table_widget = function(spec) {
|
||||
that.refresh_facet();
|
||||
}
|
||||
dialog.close();
|
||||
that.notify_facet_update();
|
||||
},
|
||||
dialog.on_error);
|
||||
}
|
||||
@ -1693,6 +1707,7 @@ IPA.dns.record_type_table_widget = function(spec) {
|
||||
that.refresh_facet();
|
||||
}
|
||||
dialog.reset();
|
||||
that.notify_facet_update();
|
||||
},
|
||||
dialog.on_error);
|
||||
}
|
||||
@ -1784,6 +1799,7 @@ IPA.dns.record_type_table_widget = function(spec) {
|
||||
command.on_success = function(data) {
|
||||
that.reload_facet(data);
|
||||
dialog.close();
|
||||
that.notify_facet_update();
|
||||
};
|
||||
command.on_error = function() {
|
||||
that.refresh_facet();
|
||||
@ -1825,6 +1841,11 @@ IPA.dns.record_type_table_widget = function(spec) {
|
||||
facet.refresh();
|
||||
};
|
||||
|
||||
that.notify_facet_update = function() {
|
||||
var facet = IPA.current_entity.get_facet();
|
||||
facet.on_update.notify();
|
||||
};
|
||||
|
||||
that.update = function(values) {
|
||||
|
||||
that.idnsname = values.idnsname;
|
||||
|
@ -31,6 +31,11 @@ IPA.entity = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
spec.policies = spec.policies || [
|
||||
IPA.search_facet_update_policy(),
|
||||
IPA.details_facet_update_policy()
|
||||
];
|
||||
|
||||
var that = {};
|
||||
|
||||
that.name = spec.name;
|
||||
@ -43,6 +48,11 @@ IPA.entity = function(spec) {
|
||||
that.dialog_specs = spec.dialogs || [];
|
||||
that.dialogs_created = false;
|
||||
|
||||
that.policies = IPA.entity_policies({
|
||||
entity: that,
|
||||
policies: spec.policies
|
||||
});
|
||||
|
||||
that.facets = $.ordered_map();
|
||||
that.facet_groups = $.ordered_map();
|
||||
that.facet_specs = spec.facets || [];
|
||||
@ -116,6 +126,7 @@ IPA.entity = function(spec) {
|
||||
var builder = IPA.facet_builder(that);
|
||||
builder.build_facets();
|
||||
that.facets_created = true;
|
||||
that.policies.facets_created();
|
||||
}
|
||||
|
||||
if (name === undefined) {
|
||||
@ -568,4 +579,144 @@ IPA.dialog_builder = function(entity) {
|
||||
};
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.entity_policy = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
var that = {};
|
||||
|
||||
that.entity = spec.entity;
|
||||
|
||||
that.facets_created = function() {
|
||||
};
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.entity_policies = function(spec) {
|
||||
|
||||
var that = {};
|
||||
|
||||
that.entity = spec.entity;
|
||||
that.policies = [];
|
||||
|
||||
that.add_policy = function(policy) {
|
||||
|
||||
policy.entity = that.entity;
|
||||
that.policies.push(policy);
|
||||
};
|
||||
|
||||
that.add_policies = function(policies) {
|
||||
|
||||
if (!policies) return;
|
||||
|
||||
for (var i=0; i<policies.length; i++) {
|
||||
that.add_policy(policies[i]);
|
||||
}
|
||||
};
|
||||
|
||||
that.facets_created = function() {
|
||||
|
||||
for (var i=0; i<that.policies.length; i++) {
|
||||
that.policies[i].facets_created();
|
||||
}
|
||||
};
|
||||
|
||||
that.add_policies(spec.policies);
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.facet_update_policy = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
var that = IPA.entity_policy();
|
||||
|
||||
that.event = spec.event || 'on_update';
|
||||
that.source_facet_name = spec.source_facet;
|
||||
that.dest_facet_name = spec.dest_facet;
|
||||
that.dest_entity_name = spec.dest_entity;
|
||||
|
||||
that.facets_created = function() {
|
||||
|
||||
that.source_facet = that.entity.get_facet(that.source_facet_name);
|
||||
var dest_entity = that.entity;
|
||||
if (that.dest_entity_name) {
|
||||
dest_entity = IPA.get_entity(that.dest_entity_name);
|
||||
if (!dest_entity) return;
|
||||
}
|
||||
that.dest_facet = dest_entity.get_facet(that.dest_facet_name);
|
||||
|
||||
if (!that.source_facet || !that.dest_facet) return;
|
||||
|
||||
var event = that.source_facet[that.event];
|
||||
if (!event && !event.attach) return;
|
||||
|
||||
event.attach(that.set_expired_flag);
|
||||
};
|
||||
|
||||
that.set_expired_flag = function() {
|
||||
|
||||
that.dest_facet.set_expired_flag();
|
||||
};
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.adder_facet_update_policy = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
var that = IPA.entity_policy();
|
||||
|
||||
that.event = spec.event || 'added';
|
||||
that.dialog_name = spec.dialog_name || 'add';
|
||||
that.dest_facet_name = spec.dest_facet || 'details';
|
||||
that.dest_entity_name = spec.dest_entity;
|
||||
|
||||
that.facets_created = function() {
|
||||
|
||||
that.dialog = that.entity.get_dialog(that.dialog_name);
|
||||
var dest_entity = that.entity;
|
||||
if (that.dest_entity_name) {
|
||||
dest_entity = IPA.get_entity(that.dest_entity_name);
|
||||
if (!dest_entity) return;
|
||||
}
|
||||
that.dest_facet = dest_entity.get_facet(that.dest_facet_name);
|
||||
|
||||
if (!that.dialog || !that.dest_facet) return;
|
||||
|
||||
var event = that.dialog[that.event];
|
||||
if (!event && !event.attach) return;
|
||||
|
||||
event.attach(that.set_expired_flag);
|
||||
};
|
||||
|
||||
that.set_expired_flag = function() {
|
||||
|
||||
that.dest_facet.set_expired_flag();
|
||||
};
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.search_facet_update_policy = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
spec.source_facet = 'search';
|
||||
spec.dest_facet = 'details';
|
||||
|
||||
return IPA.facet_update_policy(spec);
|
||||
};
|
||||
|
||||
IPA.details_facet_update_policy = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
spec.source_facet = 'details';
|
||||
spec.dest_facet = 'search';
|
||||
|
||||
return IPA.facet_update_policy(spec);
|
||||
};
|
@ -48,6 +48,7 @@ IPA.facet = function(spec) {
|
||||
that.expired_flag = true;
|
||||
that.last_updated = null;
|
||||
that.expire_timeout = spec.expire_timeout || 600; //[seconds]
|
||||
that.on_update = IPA.observer();
|
||||
|
||||
that.dialogs = $.ordered_map();
|
||||
|
||||
|
@ -518,6 +518,7 @@ IPA.hbacrule_details_facet = function(spec) {
|
||||
|
||||
that.update_on_success = function(data, text_status, xhr) {
|
||||
that.refresh();
|
||||
that.on_update.notify();
|
||||
};
|
||||
|
||||
that.update_on_error = function(xhr, text_status, error_thrown) {
|
||||
|
@ -282,6 +282,7 @@ IPA.selinux_details_facet = function(spec) {
|
||||
|
||||
that.update_on_success = function(data, text_status, xhr) {
|
||||
that.refresh();
|
||||
that.on_update.notify();
|
||||
};
|
||||
|
||||
that.update_on_error = function(xhr, text_status, error_thrown) {
|
||||
|
@ -633,6 +633,7 @@ IPA.sudorule_details_facet = function(spec) {
|
||||
|
||||
that.update_on_success = function(data, text_status, xhr) {
|
||||
that.refresh();
|
||||
that.on_update.notify();
|
||||
};
|
||||
|
||||
that.update_on_error = function(xhr, text_status, error_thrown) {
|
||||
|
Loading…
Reference in New Issue
Block a user