comparison libervia.tac @ 318:c12c9a1acf2f

server_side: added support for paramsRegisterApp to define frontend's specific parameters like "Enable unibox"
author souliane <souliane@mailoo.org>
date Fri, 03 Jan 2014 14:19:01 +0100
parents bbadd490e63c
children 0b7934e75e76
comparison
equal deleted inserted replaced
317:bbadd490e63c 318:c12c9a1acf2f
40 import tempfile, shutil, uuid 40 import tempfile, shutil, uuid
41 from server_side.blog import MicroBlog 41 from server_side.blog import MicroBlog
42 from zope.interface import Interface, Attribute, implements 42 from zope.interface import Interface, Attribute, implements
43 from xml.dom import minidom 43 from xml.dom import minidom
44 from constants import Const 44 from constants import Const
45 from sat.core.i18n import _, D_
45 46
46 47
47 class ISATSession(Interface): 48 class ISATSession(Interface):
48 profile = Attribute("Sat profile") 49 profile = Attribute("Sat profile")
49 jid = Attribute("JID associated with the profile") 50 jid = Attribute("JID associated with the profile")
439 return self.sat_host.bridge.getCard(jid, profile) 440 return self.sat_host.bridge.getCard(jid, profile)
440 441
441 def jsonrpc_getParamsUI(self): 442 def jsonrpc_getParamsUI(self):
442 """Return the parameters XML for profile""" 443 """Return the parameters XML for profile"""
443 profile = ISATSession(self.session).profile 444 profile = ISATSession(self.session).profile
444 d = self.asyncBridgeCall("getParams", Const.SECURITY_LIMIT, profile) 445 d = self.asyncBridgeCall("getParams", Const.SECURITY_LIMIT, Const.APP_NAME, profile)
445 446
446 def setAuthorizedParams(d): 447 def setAuthorizedParams(d):
447 if self.authorized_params is None: 448 if self.authorized_params is None:
448 self.authorized_params = {} 449 self.authorized_params = {}
449 for cat in minidom.parseString(d.encode('utf-8')).getElementsByTagName("category"): 450 for cat in minidom.parseString(d.encode('utf-8')).getElementsByTagName("category"):
528 def render(self, request): 529 def render(self, request):
529 """ 530 """
530 Render method with some hacks: 531 Render method with some hacks:
531 - if login is requested, try to login with form data 532 - if login is requested, try to login with form data
532 - except login, every method is jsonrpc 533 - except login, every method is jsonrpc
533 - user doesn't need to be authentified for isRegistered, but must be for all other methods 534 - user doesn't need to be authentified for isRegistered or registerParams, but must be for all other methods
534 """ 535 """
535 if request.postpath==['login']: 536 if request.postpath==['login']:
536 return self.login(request) 537 return self.login(request)
537 _session = request.getSession() 538 _session = request.getSession()
538 parsed = jsonrpclib.loads(request.content.read()) 539 parsed = jsonrpclib.loads(request.content.read())
539 if parsed.get("method")!="isRegistered": 540 method = parsed.get("method")
541 if method != "isRegistered" and method != "registerParams":
540 #if we don't call login or isRegistered, we need to be identified 542 #if we don't call login or isRegistered, we need to be identified
541 profile = ISATSession(_session).profile 543 profile = ISATSession(_session).profile
542 if not profile: 544 if not profile:
543 #user is not identified, we return a jsonrpc fault 545 #user is not identified, we return a jsonrpc fault
544 fault = jsonrpclib.Fault(Const.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia 546 fault = jsonrpclib.Fault(Const.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia
715 def jsonrpc_isRegistered(self): 717 def jsonrpc_isRegistered(self):
716 """Tell if the user is already registered""" 718 """Tell if the user is already registered"""
717 _session = self.request.getSession() 719 _session = self.request.getSession()
718 profile = ISATSession(_session).profile 720 profile = ISATSession(_session).profile
719 return bool(profile) 721 return bool(profile)
722
723 def jsonrpc_registerParams(self):
724 """Register the frontend specific parameters"""
725 params = """
726 <params>
727 <individual>
728 <category name="%(category_name)s" label="%(category_label)s">
729 <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" security="0"/>
730 </category>
731 </individual>
732 </params>
733 """ % {
734 'category_name': Const.ENABLE_UNIBOX_KEY,
735 'category_label': _(Const.ENABLE_UNIBOX_KEY),
736 'param_name': Const.ENABLE_UNIBOX_PARAM,
737 'param_label': _(Const.ENABLE_UNIBOX_PARAM)
738 }
739
740 self.sat_host.bridge.paramsRegisterApp(params, Const.SECURITY_LIMIT, Const.APP_NAME)
720 741
721 742
722 class SignalHandler(jsonrpc.JSONRPC): 743 class SignalHandler(jsonrpc.JSONRPC):
723 744
724 def __init__(self, sat_host): 745 def __init__(self, sat_host):
976 reactor.run() 997 reactor.run()
977 998
978 def stop(self): 999 def stop(self):
979 reactor.stop() 1000 reactor.stop()
980 1001
981
982 registerAdapter(SATSession, server.Session, ISATSession) 1002 registerAdapter(SATSession, server.Session, ISATSession)
983 application = service.Application(Const.APP_NAME) 1003 application = service.Application(Const.APP_NAME)
984 service = Libervia() 1004 service = Libervia()
985 service.setServiceParent(application) 1005 service.setServiceParent(application)