Commit fcb70136 authored by Nicolas Delaby's avatar Nicolas Delaby

Code optimization, LOG management more clever, typo

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15763 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f6b4bff8
...@@ -217,7 +217,6 @@ class Publication(Subscription): ...@@ -217,7 +217,6 @@ class Publication(Subscription):
""" """
return self.objectValues() return self.objectValues()
def delSubscriber(self, subscription_url): def delSubscriber(self, subscription_url):
""" """
Delete a subscriber for this publication Delete a subscriber for this publication
......
...@@ -52,7 +52,7 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -52,7 +52,7 @@ class PublicationSynchronization(XMLSyncUtils):
Read the client xml message Read the client xml message
Send the first XML message from the server Send the first XML message from the server
""" """
LOG('PubSyncInit', DEBUG, 'Starting... publication: %s' % (publication.getPath())) LOG('PubSyncInit', INFO, 'Starting... publication: %s' % (publication.getPath()))
#the session id is set at the same value of those of the client #the session id is set at the same value of those of the client
subscriber.setSessionId(self.getSessionId(xml_client)) subscriber.setSessionId(self.getSessionId(xml_client))
#same for the message id #same for the message id
...@@ -111,9 +111,9 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -111,9 +111,9 @@ class PublicationSynchronization(XMLSyncUtils):
#at the begining, the code is initialised at UNAUTHORIZED #at the begining, the code is initialised at UNAUTHORIZED
auth_code=self.UNAUTHORIZED auth_code = self.UNAUTHORIZED
if not cred: if not cred:
auth_code=self.AUTH_REQUIRED auth_code = self.AUTH_REQUIRED
LOG("PubSyncInit there's no credential !!!", INFO,'') LOG("PubSyncInit there's no credential !!!", INFO,'')
# Prepare the xml message for the Sync initialization package # Prepare the xml message for the Sync initialization package
xml(self.SyncMLChal(cmd_id, "SyncHdr", xml(self.SyncMLChal(cmd_id, "SyncHdr",
...@@ -122,8 +122,12 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -122,8 +122,12 @@ class PublicationSynchronization(XMLSyncUtils):
publication.getAuthenticationType(), auth_code)) publication.getAuthenticationType(), auth_code))
cmd_id += 1 cmd_id += 1
# chal message # chal message
xml_status, cmd_id = self.SyncMLStatus(xml_client, auth_code, xml_status, cmd_id = self.SyncMLStatus(
cmd_id, next_anchor, subscription=subscriber).values() xml_client,
auth_code,
cmd_id,
next_anchor,
subscription=subscriber).values()
xml(xml_status) xml(xml_status)
else: else:
(authentication_format, authentication_type, data) = \ (authentication_format, authentication_type, data) = \
...@@ -139,14 +143,16 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -139,14 +143,16 @@ class PublicationSynchronization(XMLSyncUtils):
if plugin.authenticateCredentials( if plugin.authenticateCredentials(
{'login':login, 'password':password}) is not None: {'login':login, 'password':password}) is not None:
subscriber.setAuthenticated(True) subscriber.setAuthenticated(True)
auth_code=self.AUTH_ACCEPTED auth_code = self.AUTH_ACCEPTED
LOG("PubSyncInit Authentication Accepted", INFO, '')
#here we must log in with the user authenticated : #here we must log in with the user authenticated :
user = uf.getUserById(login).__of__(uf) user = uf.getUserById(login).__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
subscriber.setUser(login) subscriber.setUser(user)
break break
else: else:
auth_code=self.UNAUTHORIZED LOG("PubSyncInit Authentication Failed !! with login :", INFO, login)
auth_code = self.UNAUTHORIZED
#in all others cases, the auth_code is set to UNAUTHORIZED #in all others cases, the auth_code is set to UNAUTHORIZED
# Prepare the xml message for the Sync initialization package # Prepare the xml message for the Sync initialization package
...@@ -246,7 +252,7 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -246,7 +252,7 @@ class PublicationSynchronization(XMLSyncUtils):
self.setRidWithMap(xml_client, subscriber) self.setRidWithMap(xml_client, subscriber)
if subscriber.isAuthenticated(): if subscriber.isAuthenticated():
uf = self.getPortalObject().acl_users uf = self.getPortalObject().acl_users
user = uf.getUserById(subscriber.getUser()).__of__(uf) user = subscriber.getUser().__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
result = self.PubSyncModif(publication, xml_client) result = self.PubSyncModif(publication, xml_client)
else: else:
......
...@@ -192,12 +192,12 @@ class Conflict(SyncCode, Base): ...@@ -192,12 +192,12 @@ class Conflict(SyncCode, Base):
p_sync = getToolByName(self, 'portal_synchronizations') p_sync = getToolByName(self, 'portal_synchronizations')
p_sync.applySubscriberDocument(self) p_sync.applySubscriberDocument(self)
def applySubscriberValue(self,object=None): def applySubscriberValue(self, object=None):
""" """
get the domain get the domain
""" """
p_sync = getToolByName(self, 'portal_synchronizations') p_sync = getToolByName(self, 'portal_synchronizations')
p_sync.applySubscriberValue(self,object=object) p_sync.applySubscriberValue(self, object=object)
def setSubscriber(self, subscriber): def setSubscriber(self, subscriber):
""" """
...@@ -235,7 +235,7 @@ class Conflict(SyncCode, Base): ...@@ -235,7 +235,7 @@ class Conflict(SyncCode, Base):
""" """
self.copy_path = path self.copy_path = path
class Signature(Folder,SyncCode): class Signature(Folder, SyncCode):
""" """
status -- SENT, CONFLICT... status -- SENT, CONFLICT...
md5_object -- An MD5 value of a given document md5_object -- An MD5 value of a given document
...@@ -1125,6 +1125,8 @@ class Subscription(Folder, SyncCode): ...@@ -1125,6 +1125,8 @@ class Subscription(Folder, SyncCode):
query_list = query_method(**kw) query_list = query_method(**kw)
elif callable(query): # used in the test elif callable(query): # used in the test
query_list = query(destination) query_list = query(destination)
else:
LOG('This Subscriber %s provide no Query with id :' % (self.getTitle()), INFO, query)
return [x for x in query_list return [x for x in query_list
if not getattr(x,'_conflict_resolution',False)] if not getattr(x,'_conflict_resolution',False)]
......
...@@ -178,7 +178,7 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -178,7 +178,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
self.sendResponse(from_url=subscription.subscription_url, self.sendResponse(from_url=subscription.subscription_url,
to_url=subscription.publication_url, sync_id=subscription.getTitle(), to_url=subscription.publication_url, sync_id=subscription.getTitle(),
xml=xml_a,domain=subscription, xml=xml_a, domain=subscription,
content_type=subscription.getSyncContentType()) content_type=subscription.getSyncContentType())
return {'has_response':1, 'xml':xml_a} return {'has_response':1, 'xml':xml_a}
......
...@@ -222,9 +222,6 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -222,9 +222,6 @@ class SynchronizationTool( SubscriptionSynchronization,
XXX should be renamed as addSubscription XXX should be renamed as addSubscription
create a new subscription create a new subscription
""" """
#if not('subscriptions' in self.objectIds()):
# subscriptions = Folder('subscriptions')
# self._setObject(subscriptions.id, subscriptions)
folder = self.getObjectContainer() folder = self.getObjectContainer()
new_id = self.getSubscriptionIdFromTitle(title) new_id = self.getSubscriptionIdFromTitle(title)
sub = Subscription(new_id, title, publication_url, subscription_url, sub = Subscription(new_id, title, publication_url, subscription_url,
...@@ -234,9 +231,6 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -234,9 +231,6 @@ class SynchronizationTool( SubscriptionSynchronization,
login, password, activity_enabled, alert_code, login, password, activity_enabled, alert_code,
synchronize_with_erp5_sites, sync_content_type) synchronize_with_erp5_sites, sync_content_type)
folder._setObject( new_id, sub ) folder._setObject( new_id, sub )
#if len(self.list_subscriptions) == 0:
# self.list_subscriptions = PersistentMapping()
#self.list_subscriptions[id] = sub
if RESPONSE is not None: if RESPONSE is not None:
RESPONSE.redirect('manageSubscriptions') RESPONSE.redirect('manageSubscriptions')
...@@ -372,9 +366,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -372,9 +366,7 @@ class SynchronizationTool( SubscriptionSynchronization,
Return a list of publications Return a list of publications
""" """
folder = self.getObjectContainer() folder = self.getObjectContainer()
object_list = [pub for pub in folder.objectValues() if pub.getDomainType() == self.PUB] return [pub for pub in folder.objectValues() if pub.getDomainType() == self.PUB]
#object_list = filter(lambda x: x.id.find('pub')==0,object_list)
return object_list
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getPublication') 'getPublication')
...@@ -409,9 +401,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -409,9 +401,7 @@ class SynchronizationTool( SubscriptionSynchronization,
Return a list of publications Return a list of publications
""" """
folder = self.getObjectContainer() folder = self.getObjectContainer()
object_list = [sub for sub in folder.objectValues() if sub.getDomainType() == self.SUB] return [sub for sub in folder.objectValues() if sub.getDomainType() == self.SUB]
#object_list = filter(lambda x: x.id.find('sub')==0,object_list)
return object_list
def getSubscription(self, title): def getSubscription(self, title):
""" """
......
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