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):
"""
return self.objectValues()
def delSubscriber(self, subscription_url):
"""
Delete a subscriber for this publication
......
......@@ -52,7 +52,7 @@ class PublicationSynchronization(XMLSyncUtils):
Read the client xml message
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
subscriber.setSessionId(self.getSessionId(xml_client))
#same for the message id
......@@ -103,17 +103,17 @@ class PublicationSynchronization(XMLSyncUtils):
xml('<SyncML>\n')
# syncml header
xml(self.SyncMLHeader(subscriber.getSessionId(),
subscriber.getMessageId(),
subscriber.getSubscriptionUrl(),
subscriber.getMessageId(),
subscriber.getSubscriptionUrl(),
publication.getPublicationUrl()))
# syncml body
xml(' <SyncBody>\n')
#at the begining, the code is initialised at UNAUTHORIZED
auth_code=self.UNAUTHORIZED
auth_code = self.UNAUTHORIZED
if not cred:
auth_code=self.AUTH_REQUIRED
auth_code = self.AUTH_REQUIRED
LOG("PubSyncInit there's no credential !!!", INFO,'')
# Prepare the xml message for the Sync initialization package
xml(self.SyncMLChal(cmd_id, "SyncHdr",
......@@ -122,8 +122,12 @@ class PublicationSynchronization(XMLSyncUtils):
publication.getAuthenticationType(), auth_code))
cmd_id += 1
# chal message
xml_status, cmd_id = self.SyncMLStatus(xml_client, auth_code,
cmd_id, next_anchor, subscription=subscriber).values()
xml_status, cmd_id = self.SyncMLStatus(
xml_client,
auth_code,
cmd_id,
next_anchor,
subscription=subscriber).values()
xml(xml_status)
else:
(authentication_format, authentication_type, data) = \
......@@ -139,14 +143,16 @@ class PublicationSynchronization(XMLSyncUtils):
if plugin.authenticateCredentials(
{'login':login, 'password':password}) is not None:
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 :
user = uf.getUserById(login).__of__(uf)
newSecurityManager(None, user)
subscriber.setUser(login)
subscriber.setUser(user)
break
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
# Prepare the xml message for the Sync initialization package
......@@ -246,7 +252,7 @@ class PublicationSynchronization(XMLSyncUtils):
self.setRidWithMap(xml_client, subscriber)
if subscriber.isAuthenticated():
uf = self.getPortalObject().acl_users
user = uf.getUserById(subscriber.getUser()).__of__(uf)
user = subscriber.getUser().__of__(uf)
newSecurityManager(None, user)
result = self.PubSyncModif(publication, xml_client)
else:
......
......@@ -192,12 +192,12 @@ class Conflict(SyncCode, Base):
p_sync = getToolByName(self, 'portal_synchronizations')
p_sync.applySubscriberDocument(self)
def applySubscriberValue(self,object=None):
def applySubscriberValue(self, object=None):
"""
get the domain
"""
p_sync = getToolByName(self, 'portal_synchronizations')
p_sync.applySubscriberValue(self,object=object)
p_sync.applySubscriberValue(self, object=object)
def setSubscriber(self, subscriber):
"""
......@@ -235,7 +235,7 @@ class Conflict(SyncCode, Base):
"""
self.copy_path = path
class Signature(Folder,SyncCode):
class Signature(Folder, SyncCode):
"""
status -- SENT, CONFLICT...
md5_object -- An MD5 value of a given document
......@@ -1125,6 +1125,8 @@ class Subscription(Folder, SyncCode):
query_list = query_method(**kw)
elif callable(query): # used in the test
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
if not getattr(x,'_conflict_resolution',False)]
......
......@@ -152,7 +152,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
subscription.getPublicationUrl(),
subscription.getSubscriptionUrl(),
source_name=subscription.getLogin(),
dataCred=data,
dataCred=data,
authentication_format=subscription.getAuthenticationFormat(),
authentication_type=subscription.getAuthenticationType()))
......@@ -178,7 +178,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
self.sendResponse(from_url=subscription.subscription_url,
to_url=subscription.publication_url, sync_id=subscription.getTitle(),
xml=xml_a,domain=subscription,
xml=xml_a, domain=subscription,
content_type=subscription.getSyncContentType())
return {'has_response':1, 'xml':xml_a}
......
......@@ -222,21 +222,15 @@ class SynchronizationTool( SubscriptionSynchronization,
XXX should be renamed as addSubscription
create a new subscription
"""
#if not('subscriptions' in self.objectIds()):
# subscriptions = Folder('subscriptions')
# self._setObject(subscriptions.id, subscriptions)
folder = self.getObjectContainer()
new_id = self.getSubscriptionIdFromTitle(title)
sub = Subscription(new_id, title, publication_url, subscription_url,
destination_path, source_uri, target_uri, query,
xml_mapping, conduit, gpg_key,
synchronization_id_generator, media_type,
login, password, activity_enabled, alert_code,
login, password, activity_enabled, alert_code,
synchronize_with_erp5_sites, sync_content_type)
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:
RESPONSE.redirect('manageSubscriptions')
......@@ -246,7 +240,7 @@ class SynchronizationTool( SubscriptionSynchronization,
destination_path, source_uri, query, xml_mapping,
conduit, gpg_key, synchronization_id_generator,
media_type=None,
authentication_format='b64',
authentication_format='b64',
authentication_type='syncml:auth-basic',
RESPONSE=None, activity_enabled=False,
sync_content_type='application/vnd.syncml+xml',
......@@ -279,8 +273,8 @@ class SynchronizationTool( SubscriptionSynchronization,
def manage_editSubscription(self, title, publication_url, subscription_url,
destination_path, source_uri, target_uri, query, xml_mapping, conduit,
gpg_key, synchronization_id_generator, media_type=None,
login='', password='', RESPONSE=None, activity_enabled=False,
alert_code=SyncCode.TWO_WAY, synchronize_with_erp5_sites=False,
login='', password='', RESPONSE=None, activity_enabled=False,
alert_code=SyncCode.TWO_WAY, synchronize_with_erp5_sites=False,
sync_content_type='application/vnd.syncml+xml'):
"""
modify a subscription
......@@ -372,9 +366,7 @@ class SynchronizationTool( SubscriptionSynchronization,
Return a list of publications
"""
folder = self.getObjectContainer()
object_list = [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
return [pub for pub in folder.objectValues() if pub.getDomainType() == self.PUB]
security.declareProtected(Permissions.AccessContentsInformation,
'getPublication')
......@@ -409,9 +401,7 @@ class SynchronizationTool( SubscriptionSynchronization,
Return a list of publications
"""
folder = self.getObjectContainer()
object_list = [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
return [sub for sub in folder.objectValues() if sub.getDomainType() == self.SUB]
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