diff --git a/platform/commonUI/edit/src/actions/EditAndComposeAction.js b/platform/commonUI/edit/src/actions/EditAndComposeAction.js index 974ab2f001..de43ca0fdc 100644 --- a/platform/commonUI/edit/src/actions/EditAndComposeAction.js +++ b/platform/commonUI/edit/src/actions/EditAndComposeAction.js @@ -37,7 +37,8 @@ define( } EditAndComposeAction.prototype.perform = function () { - var self = this; + var self = this, + editAction = this.domainObject.getCapability('action').getActions("edit")[0]; // Persist changes to the domain object function doPersist() { @@ -54,8 +55,8 @@ define( .then(doPersist); } - if (this.domainObject.getCapability('type').getKey() !== 'folder') { - this.domainObject.getCapability('action').perform('edit'); + if (editAction) { + editAction.perform(); } return this.selectedObject && doLink(); diff --git a/platform/commonUI/edit/src/policies/EditActionPolicy.js b/platform/commonUI/edit/src/policies/EditActionPolicy.js index f266d580eb..86e103b387 100644 --- a/platform/commonUI/edit/src/policies/EditActionPolicy.js +++ b/platform/commonUI/edit/src/policies/EditActionPolicy.js @@ -81,17 +81,14 @@ define( var key = action.getMetadata().key, category = (context || {}).category; - // Only worry about actions in the view-control category - if (category === 'view-control') { - // Restrict 'edit' to cases where there are editable - // views (similarly, restrict 'properties' to when - // the converse is true), and where the domain object is not - // already being edited. - if (key === 'edit') { - return this.countEditableViews(context) > 0 && !isEditing(context); - } else if (key === 'properties') { - return this.countEditableViews(context) < 1 && !isEditing(context); - } + // Restrict 'edit' to cases where there are editable + // views (similarly, restrict 'properties' to when + // the converse is true), and where the domain object is not + // already being edited. + if (key === 'edit') { + return this.countEditableViews(context) > 0 && !isEditing(context); + } else if (key === 'properties' && category === 'view-control') { + return this.countEditableViews(context) < 1 && !isEditing(context); } // Like all policies, allow by default. diff --git a/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js b/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js index a02c259fd1..2e83b2f9c7 100644 --- a/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js +++ b/platform/commonUI/edit/test/actions/EditAndComposeActionSpec.js @@ -32,6 +32,7 @@ define( mockComposition, mockPersistence, mockActionCapability, + mockEditAction, mockType, actionContext, model, @@ -69,7 +70,8 @@ define( mockComposition = jasmine.createSpyObj("composition", [ "invoke", "add" ]); mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]); mockType = jasmine.createSpyObj("type", [ "hasFeature", "getKey" ]); - mockActionCapability = jasmine.createSpyObj("actionCapability", [ "perform"]); + mockActionCapability = jasmine.createSpyObj("actionCapability", [ "getActions"]); + mockEditAction = jasmine.createSpyObj("editAction", ["perform"]); mockDomainObject.getId.andReturn("test"); mockDomainObject.getCapability.andReturn(mockContext); @@ -78,6 +80,7 @@ define( mockType.getKey.andReturn("layout"); mockComposition.invoke.andReturn(mockPromise(true)); mockComposition.add.andReturn(mockPromise(true)); + mockActionCapability.getActions.andReturn([]); capabilities = { composition: mockComposition, @@ -109,9 +112,19 @@ define( expect(mockPersistence.persist).toHaveBeenCalled(); }); - it("enables edit mode", function () { + it("enables edit mode for objects that have an edit action", function () { + mockActionCapability.getActions.andReturn([mockEditAction]); action.perform(); - expect(mockActionCapability.perform).toHaveBeenCalledWith("edit"); + expect(mockEditAction.perform).toHaveBeenCalled(); + }); + + it("Does not enable edit mode for objects that do not have an" + + " edit action", function () { + mockActionCapability.getActions.andReturn([]); + action.perform(); + expect(mockEditAction.perform).not.toHaveBeenCalled(); + expect(mockComposition.add) + .toHaveBeenCalledWith(mockDomainObject); }); });