[Callbacks] add new callback to report LDAP updates to OFBiz
- XmlRpcCallback was simplified to be a simple holder of an action for administrative and persistence purpose. - XmlRpcAction was created to hold a XML-RPC callback action, you can precise the action and the arguments. - IdentitiesStoreIFEF.save() was added to call the callback when an identity is updated.
This commit is contained in:
parent
883a92192f
commit
6b6a29d2bf
|
@ -3,12 +3,39 @@ import xmlrpclib
|
|||
from qommon.storage import StorableObject
|
||||
from qommon.publisher import get_logger
|
||||
|
||||
|
||||
class XmlRpcAction(object):
|
||||
ACTION_CREATE_LDAP_CLASSIFICATION = 'IFEF-createLDAPClassification'
|
||||
ACTION_CREATE_LDAP_UPDATE = 'IFEF-createLDAPUpdate'
|
||||
|
||||
TYPE_ORGANISME = 'ORGANISME'
|
||||
TYPE_PERSONNE = 'PERSONNE'
|
||||
|
||||
def __init__(self, action, *args):
|
||||
self.action = action
|
||||
self.args = args
|
||||
|
||||
@classmethod
|
||||
def create_ldap_classification(email, classification):
|
||||
return XmlRpcAction(ACTION_CREATE_LDAP_CLASSIFICATION, email, classification)
|
||||
|
||||
@classmethod
|
||||
def create_ldap_update(type, id):
|
||||
return XmlRpcAction(ACTION_CREATE_LDAP_UPDATE, type, id)
|
||||
|
||||
def do(self):
|
||||
identity_configuration = configuration.get_configuration('identities')
|
||||
url = identity_configuration.get('xmlrpc_registration_url')
|
||||
server = xmlrpclib.ServerProxy(url)
|
||||
method = getattr(server, self.action)
|
||||
method(*self.args)
|
||||
get_logger().info('Neogia XmlRpc callback action:%r args:%r' % (self.action, self.args))
|
||||
|
||||
class XmlRpcCallback(StorableObject):
|
||||
_names = 'neogia-callback'
|
||||
|
||||
def __init__(self, email, classification):
|
||||
self.email = email
|
||||
self.classification = classification
|
||||
def __init__(self, action):
|
||||
self.action = action
|
||||
self.error = ''
|
||||
StorableObject.__init__(self)
|
||||
|
||||
|
@ -18,12 +45,7 @@ class XmlRpcCallback(StorableObject):
|
|||
|
||||
def do(self):
|
||||
try:
|
||||
identity_configuration = configuration.get_configuration('identities')
|
||||
url = identity_configuration.get('xmlrpc_registration_url')
|
||||
server = xmlrpclib.ServerProxy(url)
|
||||
method = getattr(server, 'IFEF-createLDAPClassification')
|
||||
method(self.email, self.classification)
|
||||
get_logger().info('Neogia registration %r %r' % (self.email, self.classification))
|
||||
self.action.do()
|
||||
except Exception, e:
|
||||
self.error = repr(e)
|
||||
self.store()
|
||||
|
|
|
@ -9,7 +9,7 @@ import authentic.publisher
|
|||
import authentic.admin.configuration as configuration
|
||||
import urllib2
|
||||
import captcha
|
||||
from callback import XmlRpcCallback
|
||||
from callback import XmlRpcCallback, XmlRpcAction
|
||||
|
||||
schema = (('PART_EMP', _('Particulier-employeur')),
|
||||
(_('Salarie du Particulier-employeur'),
|
||||
|
@ -184,9 +184,9 @@ href="conditions">conditions d'utilisation</a>''')),
|
|||
def registration_callback(self, identity):
|
||||
email = identity.email
|
||||
classification = get_request().form['classification']
|
||||
action = XmlRpcAction.create_ldap_classification(email, classification)
|
||||
get_response().add_after_job('''Send registration to Neogia, email = %r,\
|
||||
classification = %r''' % (email, classification), XmlRpcCallback(email, classification))
|
||||
|
||||
classification = %r''' % (email, classification), XmlRpcCallback(action))
|
||||
|
||||
from qommon.publisher import get_publisher_class
|
||||
get_publisher_class().root_directory_class = IfefRootDirectory
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import authentic.identities
|
||||
from authentic.identities import Field
|
||||
from qommon.publisher import utf82sitecharset, sitecharset2utf8
|
||||
from quixote import get_response
|
||||
|
||||
class IdentitiesStoreIFEF(authentic.identities.IdentitiesStoreLdap):
|
||||
label = N_('IFEF Ldap Directory')
|
||||
|
@ -58,4 +59,18 @@ class IdentitiesStoreIFEF(authentic.identities.IdentitiesStoreLdap):
|
|||
self.alpha_request_str = '(&(uid=%%s*)(objectclass=%(oc)s))' % \
|
||||
{ 'oc': self.ldap_object_class }
|
||||
|
||||
def save(self):
|
||||
res = authentic.identities.IdentitiesStoreLdap.save(self)
|
||||
response = get_response()
|
||||
try:
|
||||
if response:
|
||||
action = XmlRpcCallback.create_ldap_update(XmlRpcCallback.TYPE_PERSONNE, self.id)
|
||||
response.add_after_job('''Send use information update to Ofbix, \
|
||||
id: %r''' % self.id, XmlRpcCallback(action))
|
||||
except e:
|
||||
pass
|
||||
return res
|
||||
|
||||
|
||||
|
||||
authentic.identities.stores['ifef'] = IdentitiesStoreIFEF
|
||||
|
|
Reference in New Issue