Mercurial > libervia-backend
comparison src/plugins/plugin_misc_invitations.py @ 2211:df115e4a36c7
plugin invitations: invitation id and invitee jid are now added to return dict in invitationCreate, bridge signature has changed too
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 29 Mar 2017 19:35:55 +0200 |
parents | f8d61592f1fc |
children | eaf2467d19ce |
comparison
equal
deleted
inserted
replaced
2210:f8d61592f1fc | 2211:df115e4a36c7 |
---|---|
42 } | 42 } |
43 | 43 |
44 | 44 |
45 SUFFIX_MAX = 5 | 45 SUFFIX_MAX = 5 |
46 INVITEE_PROFILE_TPL = u"guest@@{uuid}" | 46 INVITEE_PROFILE_TPL = u"guest@@{uuid}" |
47 KEY_ID = u'id' | |
48 KEY_JID = u'jid' | |
47 KEY_CREATED = u'created' | 49 KEY_CREATED = u'created' |
48 KEY_LAST_CONNECTION = u'last_connection' | 50 KEY_LAST_CONNECTION = u'last_connection' |
49 EXTRA_RESERVED = {KEY_CREATED, u'jid_', u'jid', KEY_LAST_CONNECTION} | 51 EXTRA_RESERVED = {KEY_ID, KEY_JID, KEY_CREATED, u'jid_', u'jid', KEY_LAST_CONNECTION} |
50 DEFAULT_SUBJECT = D_(u"You have been invited by {host_name} to {app_name}") | 52 DEFAULT_SUBJECT = D_(u"You have been invited by {host_name} to {app_name}") |
51 DEFAULT_BODY = D_(u"""Hello {name}! | 53 DEFAULT_BODY = D_(u"""Hello {name}! |
52 | 54 |
53 You have received an invitation from {host_name} to participate to "{app_name}". | 55 You have received an invitation from {host_name} to participate to "{app_name}". |
54 To join, you just have to click on the following URL: | 56 To join, you just have to click on the following URL: |
65 | 67 |
66 def __init__(self, host): | 68 def __init__(self, host): |
67 log.info(_(u"plugin Invitations initialization")) | 69 log.info(_(u"plugin Invitations initialization")) |
68 self.host = host | 70 self.host = host |
69 self.invitations = persistent.LazyPersistentBinaryDict(u'invitations') | 71 self.invitations = persistent.LazyPersistentBinaryDict(u'invitations') |
70 host.bridge.addMethod("invitationCreate", ".plugin", in_sign='sssssssssa{ss}s', out_sign='(sa{ss})', | 72 host.bridge.addMethod("invitationCreate", ".plugin", in_sign='sssssssssa{ss}s', out_sign='a{ss}', |
71 method=self._createInvitation, | 73 method=self._createInvitation, |
72 async=True) | 74 async=True) |
73 def _createInvitation(self, jid_=u'', password=u'', name=u'', host_name=u'', email=u'', language=u'', url_template=u'', message_subject=u'', message_body=u'', extra=None, profile=u''): | 75 def _createInvitation(self, jid_=u'', password=u'', name=u'', host_name=u'', email=u'', language=u'', url_template=u'', message_subject=u'', message_body=u'', extra=None, profile=u''): |
74 # XXX: we don't use **kwargs here to keep arguments name for introspection with D-Bus bridge | 76 # XXX: we don't use **kwargs here to keep arguments name for introspection with D-Bus bridge |
75 | 77 |
82 kwargs = {"extra": extra} | 84 kwargs = {"extra": extra} |
83 for key in ("jid_", "password", "name", "host_name", "email", "language", "url_template", "message_subject", "message_body", "profile"): | 85 for key in ("jid_", "password", "name", "host_name", "email", "language", "url_template", "message_subject", "message_body", "profile"): |
84 value = locals()[key] | 86 value = locals()[key] |
85 if value: | 87 if value: |
86 kwargs[key] = unicode(value) | 88 kwargs[key] = unicode(value) |
87 return self.createInvitation(**kwargs) | 89 d = self.createInvitation(**kwargs) |
90 def serialize(data): | |
91 data[KEY_JID] = data[KEY_JID].full() | |
92 d.addCallback(serialize) | |
93 return d | |
88 | 94 |
89 @defer.inlineCallbacks | 95 @defer.inlineCallbacks |
90 def createInvitation(self, **kwargs): | 96 def createInvitation(self, **kwargs): |
91 ur"""create an invitation | 97 ur"""create an invitation |
92 | 98 |
127 extra(dict, None): extra data to associate with the invitee | 133 extra(dict, None): extra data to associate with the invitee |
128 some keys are reserved: | 134 some keys are reserved: |
129 - created (creation date) | 135 - created (creation date) |
130 if email argument is used, "email" key can't be used | 136 if email argument is used, "email" key can't be used |
131 profile(unicode, None): profile of the host (person who is inviting) | 137 profile(unicode, None): profile of the host (person who is inviting) |
132 @return (unicode, dict[unicode, unicode]): tuple with: | 138 @return (dict[unicode, unicode]): dictionary with: |
133 - UUID associated with the invitee | 139 - UUID associated with the invitee (key: id) |
134 - filled extra dictionary, as saved in the databae | 140 - filled extra dictionary, as saved in the databae |
135 """ | 141 """ |
136 ## initial checks | 142 ## initial checks |
137 extra = kwargs.pop('extra', {}) | 143 extra = kwargs.pop('extra', {}) |
138 if set(kwargs).intersection(extra): | 144 if set(kwargs).intersection(extra): |
248 self.invitations[id_] = extra | 254 self.invitations[id_] = extra |
249 | 255 |
250 if kwargs: | 256 if kwargs: |
251 log.warning(_(u"Not all arguments have been consumed: {}").format(kwargs)) | 257 log.warning(_(u"Not all arguments have been consumed: {}").format(kwargs)) |
252 | 258 |
253 defer.returnValue((id_, extra)) | 259 extra[KEY_ID] = id_ |
260 extra[KEY_JID] = jid | |
261 defer.returnValue(extra) |