Commit 701c53aa authored by Ayush Tiwari's avatar Ayush Tiwari Committed by Ayush Tiwari

bt5_config: Generate sha256 for Business Item object

parent 22d9ef4f
...@@ -332,6 +332,7 @@ class BusinessManager(XMLObject): ...@@ -332,6 +332,7 @@ class BusinessManager(XMLObject):
Override subtract to find difference b/w the values in different cases. Override subtract to find difference b/w the values in different cases.
""" """
# Reverse the sign of Business Item objects for the old Business Manager # Reverse the sign of Business Item objects for the old Business Manager
# Trying comparing/subtracting ZODB with old installed object
for path_item in other._path_item_list: for path_item in other._path_item_list:
path_item._sign = -1 path_item._sign = -1
self._path_item_list.append(path_item) self._path_item_list.append(path_item)
...@@ -562,6 +563,8 @@ class BusinessItem(Implicit, Persistent): ...@@ -562,6 +563,8 @@ class BusinessItem(Implicit, Persistent):
if value: if value:
# Generate hash of from the value # Generate hash of from the value
self._sha = self._generateHash() self._sha = self._generateHash()
else:
self._sha = ''
def _generateHash(self): def _generateHash(self):
""" """
...@@ -575,7 +578,11 @@ class BusinessItem(Implicit, Persistent): ...@@ -575,7 +578,11 @@ class BusinessItem(Implicit, Persistent):
else: else:
# Expects to raise error on case the value for the object # Expects to raise error on case the value for the object
# is not picklable # is not picklable
try:
sha256 = hashlib.sha256(self._value).hexdigest() sha256 = hashlib.sha256(self._value).hexdigest()
except TypeError:
sha256 = hashlib.sha256(self._value.asXML()).hexdigest()
self._sha = sha256
def build(self, context, **kw): def build(self, context, **kw):
""" """
...@@ -584,8 +591,8 @@ class BusinessItem(Implicit, Persistent): ...@@ -584,8 +591,8 @@ class BusinessItem(Implicit, Persistent):
Three different situations to extract value: Three different situations to extract value:
1. For paths which point directly to an object in OFS 1. For paths which point directly to an object in OFS
2. For paths which point to multiple objects inside a folder 2. For paths which point to multiple objects inside a folder
3. For paths which point to property of an object in OFS : In this case, we 3. For paths which point to property of an object in OFS : In this case,
can have URL delimiters like ?, #, = in the path we can have URL delimiters like ?, #, = in the path
""" """
LOG('Business Manager', INFO, 'Building Business Item') LOG('Business Manager', INFO, 'Building Business Item')
p = context.getPortalObject() p = context.getPortalObject()
...@@ -596,13 +603,21 @@ class BusinessItem(Implicit, Persistent): ...@@ -596,13 +603,21 @@ class BusinessItem(Implicit, Persistent):
obj = p.unrestrictedTraverse(relative_url) obj = p.unrestrictedTraverse(relative_url)
property_value = obj.getProperty(property_id) property_value = obj.getProperty(property_id)
self._value = property_value self._value = property_value
# Generate hash for the property value
self._generateHash()
else: else:
try:
for relative_url in self._resolvePath(p, [], path.split('/')): for relative_url in self._resolvePath(p, [], path.split('/')):
obj = p.unrestrictedTraverse(relative_url) obj = p.unrestrictedTraverse(relative_url)
obj = obj._getCopy(context) obj = obj._getCopy(context)
obj = obj.__of__(context) obj = obj.__of__(context)
_recursiveRemoveUid(obj) _recursiveRemoveUid(obj)
self._value = obj self._value = obj
# Generate hash for the erp5 object value
self._generateHash()
except AttributeError:
# In case the object doesn't exist, just pass without raising error
pass
def applyValueToPath(self): def applyValueToPath(self):
""" """
...@@ -694,6 +709,8 @@ class BusinessItem(Implicit, Persistent): ...@@ -694,6 +709,8 @@ class BusinessItem(Implicit, Persistent):
old_obj = container._getOb(object_id, None) old_obj = container._getOb(object_id, None)
# delete the old object before installing a new object # delete the old object before installing a new object
if old_obj: if old_obj:
# XXX: In case there is an old object which has been modified from the
# older installation, then show the conflict status.
container._delObject(object_id) container._delObject(object_id)
# If sign is +1, set the new object on the container # If sign is +1, set the new object on the container
if self._sign == 1: if self._sign == 1:
...@@ -745,7 +762,7 @@ class BusinessItem(Implicit, Persistent): ...@@ -745,7 +762,7 @@ class BusinessItem(Implicit, Persistent):
if not validate(container, container, key, value): if not validate(container, container, key, value):
raise Unauthorized('unauthorized access to element %s' % key) raise Unauthorized('unauthorized access to element %s' % key)
except Unauthorized: except Unauthorized:
LOG('BusinessTemplate', WARNING, LOG('BusinessManager', WARNING,
'access to %s is forbidden' % (path,)) 'access to %s is forbidden' % (path,))
if default is _MARKER: if default is _MARKER:
raise raise
...@@ -943,7 +960,7 @@ class BusinessItem(Implicit, Persistent): ...@@ -943,7 +960,7 @@ class BusinessItem(Implicit, Persistent):
def export(self, context, bma, **kw): def export(self, context, bma, **kw):
""" """
Export the business item object : fill the BusinessManageArchive with Export the business item object : fill the BusinessManagerArchive with
objects exported as XML, hierarchicaly organised. objects exported as XML, hierarchicaly organised.
""" """
if not self._value: if not self._value:
......
...@@ -1678,6 +1678,14 @@ class TemplateTool (BaseTool): ...@@ -1678,6 +1678,14 @@ class TemplateTool (BaseTool):
# Reduce the final Business Manager # Reduce the final Business Manager
combinedBM.reduceBusinessManager() combinedBM.reduceBusinessManager()
# Build BM from the paths of combined Business Manager and then comapare
# then to show the changes in both states
buildBM = self.newContent(portal_type='Business Manager')
final_template_path_list = list(set(combinedBM.getTemplatePathList()))
buildBM._setTemplatePathList(final_template_path_list)
buildBM.build()
# combinedBM.flattenBusinessManager() # combinedBM.flattenBusinessManager()
return combinedBM return combinedBM
...@@ -1720,6 +1728,10 @@ class TemplateTool (BaseTool): ...@@ -1720,6 +1728,10 @@ class TemplateTool (BaseTool):
final_bm_list.append(bm) final_bm_list.append(bm)
combinedBM = self.combineMultipleBusinessManager(final_bm_list) combinedBM = self.combineMultipleBusinessManager(final_bm_list)
# XXX: Build Business Manager from ZODB and compare the changes done by
# the user which might get affetcted.
self.installBusinessManager(combinedBM) self.installBusinessManager(combinedBM)
# Explicilty change the status of Business Manager which are installed # Explicilty change the status of Business Manager which are installed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment