Commit 94921f8d authored by Łukasz Nowak's avatar Łukasz Nowak

Factorise code.

parent eeec5cad
...@@ -135,17 +135,7 @@ class SlapTool(BaseTool): ...@@ -135,17 +135,7 @@ class SlapTool(BaseTool):
# Public GET methods # Public GET methods
#################################################### ####################################################
security.declareProtected(Permissions.AccessContentsInformation, def _getComputerInformation(self, computer_id, user, full):
'getComputerInformation')
def getComputerInformation(self, computer_id):
"""Returns marshalled XML of all needed information for computer
Includes Software Releases, which may contain Software Instances.
Reuses slap library for easy marshalling.
"""
def _getComputerInformation(computer_id, user):
user_document = self.getPortalObject().portal_catalog.getResultValue( user_document = self.getPortalObject().portal_catalog.getResultValue(
reference=user, portal_type=['Person', 'Computer', 'Software Instance']) reference=user, portal_type=['Person', 'Computer', 'Software Instance'])
user_type = user_document.getPortalType() user_type = user_document.getPortalType()
...@@ -154,12 +144,11 @@ class SlapTool(BaseTool): ...@@ -154,12 +144,11 @@ class SlapTool(BaseTool):
parent_uid = self._getComputerUidByReference(computer_id) parent_uid = self._getComputerUidByReference(computer_id)
slap_computer._computer_partition_list = [] slap_computer._computer_partition_list = []
if user_type == 'Computer': if user_type in ('Computer', 'Person'):
slap_computer._software_release_list = \ slap_computer._software_release_list = \
self._getSoftwareReleaseValueListForComputer(computer_id) self._getSoftwareReleaseValueListForComputer(computer_id, full=full)
else: else:
slap_computer._software_release_list = [] slap_computer._software_release_list = []
for computer_partition in self.getPortalObject().portal_catalog( for computer_partition in self.getPortalObject().portal_catalog(
parent_uid=parent_uid, parent_uid=parent_uid,
validation_state="validated", validation_state="validated",
...@@ -168,11 +157,21 @@ class SlapTool(BaseTool): ...@@ -168,11 +157,21 @@ class SlapTool(BaseTool):
self._getSlapPartitionByPackingList(computer_partition.getObject())) self._getSlapPartitionByPackingList(computer_partition.getObject()))
return xml_marshaller.xml_marshaller.dumps(slap_computer) return xml_marshaller.xml_marshaller.dumps(slap_computer)
security.declareProtected(Permissions.AccessContentsInformation,
'getComputerInformation')
def getComputerInformation(self, computer_id):
"""Returns marshalled XML of all needed information for computer
Includes Software Releases, which may contain Software Instances.
Reuses slap library for easy marshalling.
"""
user = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserName() user = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserName()
self._logAccess(user, user, '#access %s' % computer_id) self._logAccess(user, user, '#access %s' % computer_id)
return CachingMethod(_getComputerInformation, return CachingMethod(self._getComputerInformation,
id='_getComputerInformation', id='_getComputerInformation',
cache_factory='slap_cache_factory')(computer_id, user) cache_factory='slap_cache_factory')(
computer_id, user, False)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getFullComputerInformation') 'getFullComputerInformation')
...@@ -183,32 +182,12 @@ class SlapTool(BaseTool): ...@@ -183,32 +182,12 @@ class SlapTool(BaseTool):
Reuses slap library for easy marshalling. Reuses slap library for easy marshalling.
""" """
def _getFullComputerInformation(computer_id, user):
user_document = self.getPortalObject().portal_catalog.getResultValue(
reference=user, portal_type=['Person', 'Computer', 'Software Instance'])
user_type = user_document.getPortalType()
self.REQUEST.response.setHeader('Content-Type', 'text/xml')
slap_computer = Computer(computer_id)
parent_uid = self._getComputerUidByReference(computer_id)
slap_computer._computer_partition_list = []
if user_type in ('Computer', 'Person'):
slap_computer._software_release_list = \
self._getSoftwareReleaseValueListForComputer(computer_id, full=True)
else:
slap_computer._software_release_list = []
for computer_partition in self.getPortalObject().portal_catalog(
parent_uid=parent_uid,
validation_state="validated",
portal_type="Computer Partition"):
slap_computer._computer_partition_list.append(
self._getSlapPartitionByPackingList(computer_partition.getObject()))
return xml_marshaller.xml_marshaller.dumps(slap_computer)
user = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserName() user = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserName()
self._logAccess(user, user, '#access %s' % computer_id) self._logAccess(user, user, '#access %s' % computer_id)
return CachingMethod(_getFullComputerInformation, return CachingMethod(self._getComputerInformation,
id='_getFullComputerInformation', id='_getFullComputerInformation',
cache_factory='slap_cache_factory')(computer_id, user) cache_factory='slap_cache_factory')(
computer_id, user, True)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getComputerPartitionCertificate') 'getComputerPartitionCertificate')
......
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