[Containment] Enforce containment rules in locator

Enforce containment rules in locator; WTD-962.
This commit is contained in:
Victor Woeltjen 2015-04-07 22:21:37 -07:00
parent 7cabead3bc
commit 0550e09344
5 changed files with 31 additions and 8 deletions

View File

@ -117,7 +117,7 @@
"provides": "actionService",
"type": "provider",
"implementation": "creation/CreateActionProvider.js",
"depends": [ "typeService", "dialogService", "creationService" ]
"depends": [ "typeService", "dialogService", "creationService", "policyService" ]
}
],
"licenses": [

View File

@ -27,7 +27,7 @@ define(
* which handles the actual instantiation and persistence
* of the newly-created domain object
*/
function CreateAction(type, parent, context, dialogService, creationService) {
function CreateAction(type, parent, context, dialogService, creationService, policyService) {
/*
Overview of steps in object creation:
@ -47,7 +47,7 @@ define(
function perform() {
// The wizard will handle creating the form model based
// on the type...
var wizard = new CreateWizard(type, parent);
var wizard = new CreateWizard(type, parent, policyService);
// Create and persist the new object, based on user
// input.

View File

@ -22,7 +22,7 @@ define(
* introduced in this bundle), responsible for handling actual
* object creation.
*/
function CreateActionProvider(typeService, dialogService, creationService) {
function CreateActionProvider(typeService, dialogService, creationService, policyService) {
return {
/**
* Get all Create actions which are applicable in the provided
@ -53,7 +53,8 @@ define(
destination,
context,
dialogService,
creationService
creationService,
policyService
);
});
}

View File

@ -19,10 +19,19 @@ define(
* @constructor
* @memberof module:core/action/create-wizard
*/
function CreateWizard(type, parent) {
function CreateWizard(type, parent, policyService) {
var model = type.getInitialModel(),
properties = type.getProperties();
function validateLocation(locatingObject) {
var locatingType = locatingObject.getCapability('type');
return policyService.allow(
"composition",
locatingType,
type
);
}
return {
/**
* Get the form model for this wizard; this is a description
@ -54,6 +63,7 @@ define(
sections.push({ name: 'Location', rows: [{
name: "Save In",
control: "locator",
validate: validateLocation,
key: "createParent"
}]});

View File

@ -17,13 +17,25 @@ define(
// the full tree
// * treeModel: The model for the embedded tree representation,
// used for bi-directional object selection.
function setLocatingObject(domainObject) {
function setLocatingObject(domainObject, priorObject) {
var context = domainObject &&
domainObject.getCapability("context");
$scope.rootObject = context && context.getRoot();
$scope.rootObject = (context && context.getRoot()) || $scope.rootObject;
$scope.treeModel.selectedObject = domainObject;
$scope.ngModel[$scope.field] = domainObject;
// Restrict which locations can be selected
if (domainObject &&
$scope.structure &&
$scope.structure.validate) {
if (!$scope.structure.validate(domainObject)) {
setLocatingObject(
$scope.structure.validate(priorObject) ?
priorObject : undefined
);
}
}
}
// Initial state for the tree's model