Support installing of new plugins to existing environment
* hasChanges method of Settings model is fixed to support environment plugins which are installed after the environment creation or environment deployment Closes-Bug: #1572481 Closes-Bug: #1572906 Change-Id: If2f69a02537c84270f3699240b1e8c7c4cc7a578
This commit is contained in:
parent
9f93d53f77
commit
ecb908c267
|
@ -100,12 +100,23 @@ var cacheMixin = {
|
|||
models.cacheMixin = cacheMixin;
|
||||
|
||||
var restrictionMixin = models.restrictionMixin = {
|
||||
checkRestrictions(models, action, setting) {
|
||||
var restrictions = _.map(setting ? setting.restrictions : this.get('restrictions'),
|
||||
utils.expandRestriction);
|
||||
if (action) {
|
||||
restrictions = _.where(restrictions, {action: action});
|
||||
checkRestrictions(models, actions, setting) {
|
||||
var restrictions = _.map(
|
||||
setting ? setting.restrictions : this.get('restrictions'),
|
||||
utils.expandRestriction
|
||||
);
|
||||
|
||||
if (!actions) {
|
||||
actions = [];
|
||||
} else if (_.isString(actions)) {
|
||||
actions = [actions];
|
||||
}
|
||||
if (actions.length) {
|
||||
restrictions = _.filter(restrictions,
|
||||
(restriction) => _.contains(actions, restriction.action)
|
||||
);
|
||||
}
|
||||
|
||||
var satisfiedRestrictions = _.filter(restrictions,
|
||||
(restriction) => new Expression(restriction.condition, models, restriction).evaluate()
|
||||
);
|
||||
|
@ -748,25 +759,36 @@ models.Settings = Backbone.DeepModel
|
|||
getValueAttribute(settingName) {
|
||||
return settingName === 'metadata' ? 'enabled' : 'value';
|
||||
},
|
||||
hasChanges(initialAttributes, models) {
|
||||
hasChanges(datatoCheck, models) {
|
||||
return _.any(this.attributes, (section, sectionName) => {
|
||||
// plugins installed to already deployed environment
|
||||
// are not presented in the environment deployed configuration
|
||||
var sectionToCheck = datatoCheck[sectionName];
|
||||
if (!sectionToCheck) return true;
|
||||
|
||||
var metadata = section.metadata;
|
||||
var result = false;
|
||||
if (metadata) {
|
||||
if (this.checkRestrictions(models, null, metadata).result) return result;
|
||||
if (!_.isUndefined(metadata.enabled)) {
|
||||
result = metadata.enabled !== initialAttributes[sectionName].metadata.enabled;
|
||||
}
|
||||
if (!result && this.isPlugin(section)) {
|
||||
result = metadata.chosen_id !== initialAttributes[sectionName].metadata.chosen_id;
|
||||
}
|
||||
if (!sectionToCheck.metadata) return false;
|
||||
// restrictions with action = 'none' should not block checking of the setting section
|
||||
if (this.checkRestrictions(models, ['disable', 'hide'], metadata).result) return false;
|
||||
// check the section enableness
|
||||
if (
|
||||
!_.isUndefined(metadata.enabled) && metadata.enabled !== sectionToCheck.metadata.enabled
|
||||
) return true;
|
||||
// check a chosen plugin version
|
||||
if (
|
||||
this.isPlugin(section) && metadata.chosen_id !== sectionToCheck.metadata.chosen_id
|
||||
) return true;
|
||||
}
|
||||
return result || (metadata || {}).enabled !== false &&
|
||||
_.any(section, (setting, settingName) => {
|
||||
if (this.checkRestrictions(models, null, setting).result) return false;
|
||||
return !_.isEqual(setting.value,
|
||||
(initialAttributes[sectionName][settingName] || {}).value);
|
||||
});
|
||||
|
||||
// do not check inactive setting sections
|
||||
if ((metadata || {}).enabled === false) return false;
|
||||
|
||||
return _.any(_.omit(section, 'metadata'), (setting, settingName) => {
|
||||
// restrictions with action = 'none' should not block checking of the setting
|
||||
if (this.checkRestrictions(models, ['disable', 'hide'], setting).result) return false;
|
||||
return !_.isEqual(setting.value, (sectionToCheck[settingName] || {}).value);
|
||||
});
|
||||
});
|
||||
},
|
||||
sanitizeGroup(group) {
|
||||
|
|
Loading…
Reference in New Issue