[Create] Utilize passed-in filter

...when determining which objects should be cloned.
This commit is contained in:
Victor Woeltjen
2016-02-10 13:38:53 -08:00
parent f602aa9247
commit 72df464f0f
2 changed files with 25 additions and 9 deletions

View File

@@ -81,10 +81,23 @@ define(
* domainObject when the duplication is successful.
*/
CopyService.prototype.perform = function (domainObject, parent, filter) {
var $q = this.$q,
copyTask = new CopyTask(domainObject, parent, this.policyService, this.$q);
var policyService = this.policyService;
function completeFilter(domainObject) {
return (!filter || filter(domainObject)) &&
policyService.allow(
"creation",
domainObject.getCapability("type")
);
}
if (this.validate(domainObject, parent)) {
return copyTask.perform();
return new CopyTask(
domainObject,
parent,
completeFilter,
this.$q
).perform();
} else {
throw new Error(
"Tried to copy objects without validating first."