CMS_NODE_API.available_parents_for_node

- Fixed comment.
     - added check to know if there are potencial cycles
     - added postcondition to ensure the list of potencial parent will not produce a cycle.

CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER.update_node
     - Updated code to handle unassing parent from a node when the user
     - submit a -1 value.

NODE_FORM_RESPONSE.edit_form_validation
      - Added validation for node_parent, check if the input is valid and then
      - if exist a valid node in the list of available parents for the current node.

Signed-off-by: jvelilla <javier.hector@gmail.com>
This commit is contained in:
jvelilla
2015-09-08 18:16:18 -03:00
committed by Jocelyn Fiat
parent 5f4eb2cf10
commit eb70af6f19
5 changed files with 98 additions and 34 deletions

View File

@@ -329,9 +329,58 @@ feature -- Access: Node
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
-- Given the node `a_node', return the list of possible parent nodes
-- List of possible parents nodes for node `a_node'.
-- Ensure the list of possible parent nodes does not allow a potential cycle.
do
Result := node_storage.available_parents_for_node(a_node)
create {ARRAYED_LIST[CMS_NODE]}Result.make (0)
across node_storage.available_parents_for_node(a_node) as ic loop
if not has_cycle (a_node, ic.item) then
Result.force (ic.item)
end
end
ensure
not_cycle: Result.for_all (agent not_cycle (a_node, ?))
end
feature {NONE} -- Implementation
not_cycle (a_node: CMS_NODE; a_parent: CMS_NODE): BOOLEAN
do
Result := not has_cycle (a_node, a_parent)
end
has_cycle (a_node: CMS_NODE; a_parent: CMS_NODE): BOOLEAN
-- Check if adding the node `a_parent' as parent of node `a_node' form a cycle.
local
l_flag: BOOLEAN
l_item: detachable CMS_PAGE
do
Result := False
if
attached {CMS_PAGE} a_node as l_page and then
attached {CMS_PAGE} full_node (a_parent) as l_page_parent
then
l_page.set_parent (l_page_parent)
from
l_item := l_page_parent
until
l_flag or else Result
loop
if attached l_item and then attached {CMS_PAGE} node (l_item.id) as l_parent then
if l_parent.id = l_page.id then
Result := True
else
l_item := l_parent.parent
end
else
l_flag := True
end
end
-- Set parent to void.
l_page.set_parent (Void)
end
end
feature -- Permission Scope: Node