def delete(self, receiver_token_auth, conf_id, *uriargs): """ Parameters: receiver_token_auth, receiver_configuration_id Request: receiverProfileDesc Response: None Errors: InvalidInputFormat, ProfileGusNotFound """ receivertip_iface = ReceiverTip() try: # TODO validate parameters or raise InvalidInputFormat receivers_map = yield receivertip_iface.get_receivers_by_tip(receiver_token_auth) user = receivers_map['actor'] receivercfg_iface = ReceiverConfs() yield receivercfg_iface.delete(conf_id, user['receiver_gus']) self.set_status(200) # OK except TipGusNotFound, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def put(self, receiver_token_auth, *uriargs): """ Parameters: receiver_token_auth Request: receiverReceiverDesc Response: receiverReceiverDesc Errors: ReceiverGusNotFound, InvalidInputFormat, InvalidTipAuthToken, TipGusNotFound """ receivertip_iface = ReceiverTip() try: request = validateMessage(self.request.body, requests.receiverReceiverDesc) receivers_map = yield receivertip_iface.get_receivers_by_tip(receiver_token_auth) # receivers_map is a dict with these keys: 'others' : [$], 'actor': $, 'mapped' [ ] self_receiver_gus = receivers_map['actor']['receiver_gus'] receiver_iface = Receiver() receiver_desc = yield receiver_iface.self_update(self_receiver_gus, request) # context_iface = Context() # yield context_iface.update_languages() -- TODO review in update languages and tags self.write(receiver_desc) self.set_status(200) except InvalidInputFormat, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def get(self, receiver_token_auth, *uriargs): """ Parameters: receiver_token_auth Response: receiverProfileList Errors: None """ try: # TODO receiver_token_auth sanity and security check receivertip_iface = ReceiverTip() receivers_map = yield receivertip_iface.get_receivers_by_tip(receiver_token_auth) # receivers_map is a dict with these keys: 'others' : [$], 'actor': $, 'mapped' [ ] receiver_associated_contexts = receivers_map['actor']['contexts'] profile_iface = PluginProfiles() profiles_list = yield profile_iface.get_profiles_by_contexts(receiver_associated_contexts) # TODO output filtering to receiver recipient # self.write(json.dumps(profiles_list)) self.write({'a' : profiles_list}) self.set_status(200) except TipGusNotFound, e: # InvalidTipAuthToken self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def get(self, receiver_token_auth, rconf_id, *uriargs): """ Parameters: receiver_token_auth, receiver_configuration_id Response: receiverConfDesc Errors: InvalidInputFormat, ProfileGusNotFound, TipGusNotFound, InvalidTipAuthToken """ receivertip_iface = ReceiverTip() try: # TODO receiver_token_auth and rconf_id validation receivers_map = yield receivertip_iface.get_receivers_by_tip(receiver_token_auth) user = receivers_map['actor'] receivercfg_iface = ReceiverConfs() conf_requested = yield receivercfg_iface.get_single(rconf_id) self.write(conf_requested) # TODO output filtering, creating a receiverConfDesc self.set_status(200) except TipGusNotFound, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def delete(self, tip_token, *uriargs): """ Request: None Response: None Errors: ForbiddenOperation, TipGusNotFound When an uber-receiver decide to "total delete" a Tip, is handled by this call. """ try: if not is_receiver_token(tip_token): raise ForbiddenOperation receivertip_iface = ReceiverTip() receivers_map = yield receivertip_iface.get_receivers_by_tip(tip_token) if not receivers_map['actor']['can_delete_submission']: raise ForbiddenOperation # sibilings_tips has the keys: 'sibilings': [$] 'requested': $ sibilings_tips = yield receivertip_iface.get_sibiligs_by_tip(tip_token) # delete all the related tip for sibiltip in sibilings_tips['sibilings']: yield receivertip_iface.personal_delete(sibiltip['tip_gus']) # and the tip of the called yield receivertip_iface.personal_delete(sibilings_tips['requested']['tip_gus']) # extract the internaltip_id, we need for the next operations itip_id = sibilings_tips['requested']['internaltip_id'] file_iface = File() # remove all the files: XXX think if delivery method need to be inquired files_list = yield file_iface.get_files_by_itip(itip_id) print "TODO remove file_list", files_list comment_iface = Comment() # remove all the comments based on a specific itip_id comments_list = yield comment_iface.delete_comment_by_itip(itip_id) internaltip_iface = InternalTip() # finally, delete the internaltip internaltip_iface.tip_delete(sibilings_tips['requested']['internaltip_id']) self.set_status(200) except ForbiddenOperation, e: self.set_status(e.http_status) self.write({'error_message' : e.error_message, 'error_code' : e.error_code})
def put(self, receiver_token_auth, conf_id, *uriargs): """ Parameters: Parameters: receiver_token_auth, receiver_configuration_id Request: receiverConfDesc Response: receiverConfDesc Errors: InvalidInputFormat, ProfileGusNotFound, ContextGusNotFound, ReceiverGusNotFound, update the resource ReceiverConf by a specific receiver, and if is requested as active, deactivate the others related to the same context. """ receivertip_iface = ReceiverTip() try: request = validateMessage(self.request.body, requests.receiverReceiverDesc) receivers_map = yield receivertip_iface.get_receivers_by_tip(receiver_token_auth) user = receivers_map['actor'] # ++ sanity checks that can't be make by validateMessage or by model: profile_iface = PluginProfiles() profile_desc = yield profile_iface.get_single(request['profile_gus']) if profile_desc['plugin_type'] == u'notification' and user['can_configure_notification']: pass elif profile_desc['plugin_type'] == u'delivery' and user['can_configure_delivery']: pass else: raise ForbiddenOperation # -- end of the sanity checks receivercfg_iface = ReceiverConfs() config_update = yield receivercfg_iface.update(conf_id, user['receiver_gus'], request) if config_update['active']: # keeping active only the last configuration requested yield receivercfg_iface.deactivate_all_but(config_update['config_id'], config_update['context_gus'], user['receiver_gus'], config_update['plugin_type']) self.write(config_update) self.set_status(200) # OK except InvalidTipAuthToken, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def post(self, receiver_token_auth, *uriargs): """ Parameters: receiver_token_auth Request: receiverConfDesc Response: receiverConfDesc Errors: TipGusNotFound, InvalidTipAuthToken, ForbiddenOperation, ContextGusNotFound, ReceiverGusNotFound Create a new configuration for a plugin """ receivertip_iface = ReceiverTip() try: request = validateMessage(self.request.body, requests.receiverReceiverDesc) receivers_map = yield receivertip_iface.get_receivers_by_tip(receiver_token_auth) user = receivers_map['actor'] # ++ sanity checks that can't be make by validateMessage or by model: profile_iface = PluginProfiles() profile_desc = yield profile_iface.get_single(request['profile_gus']) if profile_desc['plugin_type'] == u'notification' and user['can_configure_notification']: pass elif profile_desc['plugin_type'] == u'delivery' and user['can_configure_delivery']: pass else: raise ForbiddenOperation # -- end of the sanity checks receivercfg_iface = ReceiverConfs() config_desc = yield receivercfg_iface.new(user['receiver_gus'], request) if config_desc['active']: # keeping active only the last configuration requested yield receivercfg_iface.deactivate_all_but(config_desc['config_id'], config_desc['context_gus'], user['receiver_gus'], config_desc['plugin_type']) self.write(config_desc) self.set_status(201) # Created except InvalidTipAuthToken, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def tip_notification(self): plugin_type = u'notification' store = self.getStore() receivertip_iface = ReceiverTip(store) receivercfg_iface = ReceiverConfs(store) profile_iface = PluginProfiles(store) not_notified_tips = receivertip_iface.get_tips_by_notification_mark(u'not notified') for single_tip in not_notified_tips: # from a single tip, we need to extract the receiver, and then, having # context + receiver, find out which configuration setting has active receivers_map = receivertip_iface.get_receivers_by_tip(single_tip['tip_gus']) receiver_info = receivers_map['actor'] receiver_conf = receivercfg_iface.get_active_conf(receiver_info['receiver_gus'], single_tip['context_gus'], plugin_type) if receiver_conf is None: print "Receiver", receiver_info['receiver_gus'],\ "has not an active notification settings in context", single_tip['context_gus'], "for", plugin_type # TODO separate key in answer continue # Ok, we had a valid an appropriate receiver configuration for the notification task related_profile = profile_iface.get_single(receiver_conf['profile_gus']) settings_dict = { 'admin_settings' : related_profile['admin_settings'], 'receiver_settings' : receiver_conf['receiver_settings']} plugin = PluginManager.instance_plugin(related_profile['plugin_name']) updated_tip = receivertip_iface.update_notification_date(single_tip['tip_gus']) return_code = plugin.do_notify(settings_dict, u'tip', updated_tip) if return_code: receivertip_iface.flip_mark(single_tip['tip_gus'], u'notified') else: receivertip_iface.flip_mark(single_tip['tip_gus'], u'unable to notify')
def delete_tip(self, tip_gus): store = self.getStore() receivertip_iface = ReceiverTip(store) receivers_map = receivertip_iface.get_receivers_by_tip(tip_gus) if not receivers_map['actor']['can_delete_submission']: raise ForbiddenOperation # sibilings_tips has the keys: 'sibilings': [$] 'requested': $ sibilings_tips = receivertip_iface.get_sibiligs_by_tip(tip_gus) # delete all the related tip for sibiltip in sibilings_tips['sibilings']: receivertip_iface.personal_delete(sibiltip['tip_gus']) # and the tip of the called receivertip_iface.personal_delete(sibilings_tips['requested']['tip_gus']) # extract the internaltip_id, we need for the next operations itip_id = sibilings_tips['requested']['internaltip_id'] # remove all the files: XXX think if delivery method need to be inquired file_iface = File(store) files_list = file_iface.get_files_by_itip(itip_id) # remove all the comments based on a specific itip_id comment_iface = Comment(store) comments_list = comment_iface.delete_comment_by_itip(itip_id) internaltip_iface = InternalTip(store) # finally, delete the internaltip internaltip_iface.tip_delete(sibilings_tips['requested']['internaltip_id']) # XXX Notify Tip removal to the receivers ? # XXX ask to the deleter a comment about the action, notifiy this comment ? self.returnCode(200) return self.prepareRetVals()
def get(self, receiver_token_auth, *uriargs): """ Parameters: receiver_token_auth Response: receiverReceiverDesc Errors: TipGusNotFound, InvalidInputFormat, InvalidTipAuthToken """ try: # TODO receiver_token_auth sanity and security check receivertip_iface = ReceiverTip() receivers_map = yield receivertip_iface.get_receivers_by_tip(receiver_token_auth) # receivers_map is a dict with these keys: 'others' : [$], 'actor': $, 'mapped' [ ] # TODO output filtering to receiver recipient self.write(receivers_map['actor']) self.set_status(200) except TipGusNotFound, e: # InvalidTipAuthToken self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def get(self, receiver_token_auth, *uriargs): """ Parameters: receiver_token_auth Response: receiverConfList Errors: TipGusNotFound, InvalidTipAuthToken """ receivertip_iface = ReceiverTip() try: receivers_map = yield receivertip_iface.get_receivers_by_tip(receiver_token_auth) user = receivers_map['actor'] receivercfg_iface = ReceiverConfs() confs_created = yield receivercfg_iface.get_confs_by_receiver(user['receiver_gus']) self.write(json.dumps(confs_created)) self.set_status(200) except TipGusNotFound, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
def operation(self): """ Goal of this function is to check all the: Tips Comment Folder System Event marked as 'not notified' and perform notification. Notification plugin chose if perform a communication or not, Then became marked as: 'notification ignored', or 'notified' Every notification plugin NEED have a checks to verify if notification has been correctly performed. If not (eg: wrong login/password, network errors) would be marked as: 'unable to be notified', and a retry logic is in TODO """ plugin_type = u'notification' log.debug("[D]", self.__class__, 'operation', datetime.today().ctime()) receivertip_iface = ReceiverTip() receivercfg_iface = ReceiverConfs() profile_iface = PluginProfiles() # TODO digest check missing it's required refactor the scheduler using a dedicated Storm table not_notified_tips = yield receivertip_iface.get_tips_by_notification_mark(u'not notified') for single_tip in not_notified_tips: # from a single tip, we need to extract the receiver, and then, having # context + receiver, find out which configuration setting has active receivers_map = yield receivertip_iface.get_receivers_by_tip(single_tip['tip_gus']) receiver_info = receivers_map['actor'] receiver_conf = yield receivercfg_iface.get_active_conf(receiver_info['receiver_gus'], single_tip['context_gus'], plugin_type) if receiver_conf is None: print "Receiver", receiver_info['receiver_gus'], \ "has not an active notification settings in context", single_tip['context_gus'], "for", plugin_type # TODO applicative log, database tracking of queue continue # Ok, we had a valid an appropriate receiver configuration for the notification task related_profile = yield profile_iface.get_single(receiver_conf['profile_gus']) settings_dict = { 'admin_settings' : related_profile['admin_settings'], 'receiver_settings' : receiver_conf['receiver_settings']} plugin = PluginManager.instance_plugin(related_profile['plugin_name']) updated_tip = yield receivertip_iface.update_notification_date(single_tip['tip_gus']) return_code = plugin.do_notify(settings_dict, u'tip', updated_tip) if return_code: yield receivertip_iface.flip_mark(single_tip['tip_gus'], u'notified') else: yield receivertip_iface.flip_mark(single_tip['tip_gus'], u'unable to notify') # Comment Notification here it's just an incomplete version, that never would supports # digest or retry, until Task manager queue is implemented comment_iface = Comment() internaltip_iface = InternalTip() not_notified_comments = yield comment_iface.get_comment_by_mark(marker=u'not notified') for comment in not_notified_comments: receivers_list = yield internaltip_iface.get_receivers_by_itip(comment['internaltip_id']) # needed to obtain context! itip_info = yield internaltip_iface.get_single(comment['internaltip_id']) for receiver_info in receivers_list: receiver_conf = yield receivercfg_iface.get_active_conf(receiver_info['receiver_gus'], itip_info['context_gus'], plugin_type) if receiver_conf is None: # TODO applicative log, database tracking of queue continue # Ok, we had a valid an appropriate receiver configuration for the notification task related_profile = yield profile_iface.get_single(receiver_conf['profile_gus']) settings_dict = { 'admin_settings' : related_profile['admin_settings'], 'receiver_settings' : receiver_conf['receiver_settings']} plugin = PluginManager.instance_plugin(related_profile['plugin_name']) return_code = plugin.do_notify(settings_dict, u'comment', comment) if return_code: print "Notification of comment successful for user", receiver_conf['receiver_gus'] else: print "Notification of comment failed for user", receiver_conf['receiver_gus'] # remind: comment are not guarantee until Task manager is not developed yield comment_iface.flip_mark(comment['comment_id'], u'notified')