Commit 887a5009 authored by Łukasz Nowak's avatar Łukasz Nowak

Drop getComputerInformation

It is just alias to getFullComputerInformation.
Also simplify code and drop obsoleted parameter.
parent d57629d6
...@@ -35,8 +35,7 @@ def Item_activateFillComputerInformationCache(state_change): ...@@ -35,8 +35,7 @@ def Item_activateFillComputerInformationCache(state_change):
try: try:
newSecurityManager(None, newSecurityManager(None,
portal.acl_users.getUserById(computer_reference)) portal.acl_users.getUserById(computer_reference))
for full in (True, False): portal.portal_slap._activateFillComputerInformationCache(
portal.portal_slap._activateFillComputerInformationCache( computer_reference, computer_reference)
computer_reference, computer_reference, full)
finally: finally:
setSecurityManager(sm) setSecurityManager(sm)
846 847
\ No newline at end of file \ No newline at end of file
...@@ -161,14 +161,14 @@ class SlapTool(BaseTool): ...@@ -161,14 +161,14 @@ class SlapTool(BaseTool):
.getRamCacheRoot().get('computer_information_cache_factory')\ .getRamCacheRoot().get('computer_information_cache_factory')\
.getCachePluginList()[0] .getCachePluginList()[0]
def _getCacheComputerInformation(self, computer_id, user, full): def _getCacheComputerInformation(self, computer_id, user):
self.REQUEST.response.setHeader('Content-Type', 'text/xml') self.REQUEST.response.setHeader('Content-Type', 'text/xml')
slap_computer = Computer(computer_id) slap_computer = Computer(computer_id)
parent_uid = self._getComputerUidByReference(computer_id) parent_uid = self._getComputerUidByReference(computer_id)
slap_computer._computer_partition_list = [] slap_computer._computer_partition_list = []
slap_computer._software_release_list = \ slap_computer._software_release_list = \
self._getSoftwareReleaseValueListForComputer(computer_id, full=full) self._getSoftwareReleaseValueListForComputer(computer_id)
for computer_partition in self.getPortalObject().portal_catalog.unrestrictedSearchResults( for computer_partition in self.getPortalObject().portal_catalog.unrestrictedSearchResults(
parent_uid=parent_uid, parent_uid=parent_uid,
validation_state="validated", validation_state="validated",
...@@ -177,13 +177,13 @@ class SlapTool(BaseTool): ...@@ -177,13 +177,13 @@ class SlapTool(BaseTool):
self._getSlapPartitionByPackingList(_assertACI(computer_partition.getObject()))) self._getSlapPartitionByPackingList(_assertACI(computer_partition.getObject())))
return xml_marshaller.xml_marshaller.dumps(slap_computer) return xml_marshaller.xml_marshaller.dumps(slap_computer)
def _fillComputerInformationCache(self, computer_id, user, full): def _fillComputerInformationCache(self, computer_id, user):
key = '%s_%s_%s' % (full, computer_id, user) key = '%s_%s' % (computer_id, user)
try: try:
self._getCachePlugin().set(key, DEFAULT_CACHE_SCOPE, self._getCachePlugin().set(key, DEFAULT_CACHE_SCOPE,
dict ( dict (
time=time.time(), time=time.time(),
data=self._getCacheComputerInformation(computer_id, user, full), data=self._getCacheComputerInformation(computer_id, user),
), ),
cache_duration=self.getPortalObject().portal_caches\ cache_duration=self.getPortalObject().portal_caches\
.getRamCacheRoot().get('computer_information_cache_factory'\ .getRamCacheRoot().get('computer_information_cache_factory'\
...@@ -215,13 +215,13 @@ class SlapTool(BaseTool): ...@@ -215,13 +215,13 @@ class SlapTool(BaseTool):
entry = entry.getValue() entry = entry.getValue()
return entry return entry
def _activateFillComputerInformationCache(self, computer_id, user, full): def _activateFillComputerInformationCache(self, computer_id, user):
tag = 'computer_information_cache_fill_%s_%s_%s' % (computer_id, user, full) tag = 'computer_information_cache_fill_%s_%s' % (computer_id, user)
if self.getPortalObject().portal_activities.countMessageWithTag(tag) == 0: if self.getPortalObject().portal_activities.countMessageWithTag(tag) == 0:
self.activate(activity='SQLQueue', tag=tag)._fillComputerInformationCache( self.activate(activity='SQLQueue', tag=tag)._fillComputerInformationCache(
computer_id, user, full) computer_id, user)
def _getComputerInformation(self, computer_id, user, full): def _getComputerInformation(self, computer_id, user):
user_document = _assertACI(self.getPortalObject().portal_catalog.unrestrictedGetResultValue( user_document = _assertACI(self.getPortalObject().portal_catalog.unrestrictedGetResultValue(
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()
...@@ -234,21 +234,21 @@ class SlapTool(BaseTool): ...@@ -234,21 +234,21 @@ class SlapTool(BaseTool):
if not self._isTestRun(): if not self._isTestRun():
cache_plugin = self._getCachePlugin() cache_plugin = self._getCachePlugin()
try: try:
key = '%s_%s_%s' % (full, computer_id, user) key = '%s_%s' % (computer_id, user)
entry = cache_plugin.get(key, DEFAULT_CACHE_SCOPE) entry = cache_plugin.get(key, DEFAULT_CACHE_SCOPE)
except KeyError: except KeyError:
entry = None entry = None
if entry is not None and type(entry.getValue()) == type({}): if entry is not None and type(entry.getValue()) == type({}):
result = entry.getValue()['data'] result = entry.getValue()['data']
self._activateFillComputerInformationCache(computer_id, user, full) self._activateFillComputerInformationCache(computer_id, user)
return result return result
else: else:
self._activateFillComputerInformationCache(computer_id, user, full) self._activateFillComputerInformationCache(computer_id, user)
self.REQUEST.response.setStatus(503) self.REQUEST.response.setStatus(503)
return self.REQUEST.response return self.REQUEST.response
else: else:
return self._getCacheComputerInformation(computer_id, user, full) return self._getCacheComputerInformation(computer_id, user)
# return self._getCacheComputerInformation(computer_id, user, full) # return self._getCacheComputerInformation(computer_id, user)
else: else:
slap_computer._software_release_list = [] slap_computer._software_release_list = []
if user_type == 'Software Instance': if user_type == 'Software Instance':
...@@ -268,31 +268,6 @@ class SlapTool(BaseTool): ...@@ -268,31 +268,6 @@ class SlapTool(BaseTool):
self._getSlapPartitionByPackingList(_assertACI(computer_partition.getObject()))) self._getSlapPartitionByPackingList(_assertACI(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()
self._logAccess(user, user, '#access %s' % computer_id)
result = self._getComputerInformation(computer_id, user, False)
if self.REQUEST.response.getStatus() == 200:
# Keep in cache server for 7 days
self.REQUEST.response.setHeader('Cache-Control',
'public, max-age=1, stale-if-error=604800')
self.REQUEST.response.setHeader('Vary',
'REMOTE_USER')
self.REQUEST.response.setHeader('Last-Modified', rfc1123_date(DateTime()))
self.REQUEST.response.setBody(result)
return self.REQUEST.response
else:
return result
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getFullComputerInformation') 'getFullComputerInformation')
def getFullComputerInformation(self, computer_id): def getFullComputerInformation(self, computer_id):
...@@ -304,7 +279,7 @@ class SlapTool(BaseTool): ...@@ -304,7 +279,7 @@ class SlapTool(BaseTool):
""" """
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)
result = self._getComputerInformation(computer_id, user, True) result = self._getComputerInformation(computer_id, user)
if self.REQUEST.response.getStatus() == 200: if self.REQUEST.response.getStatus() == 200:
# Keep in cache server for 7 days # Keep in cache server for 7 days
...@@ -341,6 +316,10 @@ class SlapTool(BaseTool): ...@@ -341,6 +316,10 @@ class SlapTool(BaseTool):
self.REQUEST.response.setBody(result) self.REQUEST.response.setBody(result)
return self.REQUEST.response return self.REQUEST.response
security.declareProtected(Permissions.AccessContentsInformation,
'getComputerInformation')
getComputerInformation = getFullComputerInformation
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getComputerPartitionStatus') 'getComputerPartitionStatus')
def getComputerPartitionStatus(self, computer_id, computer_partition_id): def getComputerPartitionStatus(self, computer_id, computer_partition_id):
...@@ -1420,8 +1399,7 @@ class SlapTool(BaseTool): ...@@ -1420,8 +1399,7 @@ class SlapTool(BaseTool):
} }
@UnrestrictedMethod @UnrestrictedMethod
def _getSoftwareReleaseValueListForComputer(self, computer_reference, def _getSoftwareReleaseValueListForComputer(self, computer_reference):
full=False):
"""Returns list of Software Releases documentsfor computer""" """Returns list of Software Releases documentsfor computer"""
computer_document = self._getComputerDocument(computer_reference) computer_document = self._getComputerDocument(computer_reference)
portal = self.getPortalObject() portal = self.getPortalObject()
......
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