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
...@@ -103,17 +103,17 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -103,17 +103,17 @@ class PublicationSynchronization(XMLSyncUtils):
xml('<SyncML>\n') xml('<SyncML>\n')
# syncml header # syncml header
xml(self.SyncMLHeader(subscriber.getSessionId(), xml(self.SyncMLHeader(subscriber.getSessionId(),
subscriber.getMessageId(), subscriber.getMessageId(),
subscriber.getSubscriptionUrl(), subscriber.getSubscriptionUrl(),
publication.getPublicationUrl())) publication.getPublicationUrl()))
# syncml body # syncml body
xml(' <SyncBody>\n') xml(' <SyncBody>\n')
#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)]
......
...@@ -152,7 +152,7 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -152,7 +152,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
subscription.getPublicationUrl(), subscription.getPublicationUrl(),
subscription.getSubscriptionUrl(), subscription.getSubscriptionUrl(),
source_name=subscription.getLogin(), source_name=subscription.getLogin(),
dataCred=data, dataCred=data,
authentication_format=subscription.getAuthenticationFormat(), authentication_format=subscription.getAuthenticationFormat(),
authentication_type=subscription.getAuthenticationType())) authentication_type=subscription.getAuthenticationType()))
...@@ -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,21 +222,15 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -222,21 +222,15 @@ 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,
destination_path, source_uri, target_uri, query, destination_path, source_uri, target_uri, query,
xml_mapping, conduit, gpg_key, xml_mapping, conduit, gpg_key,
synchronization_id_generator, media_type, synchronization_id_generator, media_type,
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')
...@@ -246,7 +240,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -246,7 +240,7 @@ class SynchronizationTool( SubscriptionSynchronization,
destination_path, source_uri, query, xml_mapping, destination_path, source_uri, query, xml_mapping,
conduit, gpg_key, synchronization_id_generator, conduit, gpg_key, synchronization_id_generator,
media_type=None, media_type=None,
authentication_format='b64', authentication_format='b64',
authentication_type='syncml:auth-basic', authentication_type='syncml:auth-basic',
RESPONSE=None, activity_enabled=False, RESPONSE=None, activity_enabled=False,
sync_content_type='application/vnd.syncml+xml', sync_content_type='application/vnd.syncml+xml',
...@@ -279,8 +273,8 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -279,8 +273,8 @@ class SynchronizationTool( SubscriptionSynchronization,
def manage_editSubscription(self, title, publication_url, subscription_url, def manage_editSubscription(self, title, publication_url, subscription_url,
destination_path, source_uri, target_uri, query, xml_mapping, conduit, destination_path, source_uri, target_uri, query, xml_mapping, conduit,
gpg_key, synchronization_id_generator, media_type=None, gpg_key, synchronization_id_generator, media_type=None,
login='', password='', RESPONSE=None, activity_enabled=False, login='', password='', RESPONSE=None, activity_enabled=False,
alert_code=SyncCode.TWO_WAY, synchronize_with_erp5_sites=False, alert_code=SyncCode.TWO_WAY, synchronize_with_erp5_sites=False,
sync_content_type='application/vnd.syncml+xml'): sync_content_type='application/vnd.syncml+xml'):
""" """
modify a subscription modify a subscription
...@@ -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