def get(self, tip_token, *uriargs): """ Parameters: None Response: actorsTipDesc Errors: InvalidTipAuthToken tip_token can be: a tip_gus for a receiver, or a WhistleBlower receipt, understand the format, help in addressing which kind of Tip need to be handled. """ try: if is_receiver_token(tip_token): requested_t = ReceiverTip() tip_description = yield requested_t.get_single(tip_token) else: requested_t = WhistleblowerTip() tip_description = yield requested_t.get_single(tip_token) # TODO output filtering: actorsTipDesc self.set_status(200) self.write(json.dumps(tip_description)) except TipGusNotFound, e: self.set_status(e.http_status) self.write({'error_message' : e.error_message, 'error_code' : e.error_code})
def get(self, tip_token, *uriargs): """ Parameters: None Response: actorsReceiverList Errors: InvalidTipAuthToken """ try: if is_receiver_token(tip_token): requested_t = ReceiverTip() tip_description = yield requested_t.get_single(tip_token) else: requested_t = WhistleblowerTip() tip_description = yield requested_t.get_single(tip_token) itip_iface = InternalTip() inforet = yield itip_iface.get_receivers_by_itip(tip_description['internaltip_id']) self.write(json.dumps(inforet)) 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 get(self, tip_token, *uriargs): """ Parameters: None (TODO start/end, date) Response: actorsCommentList Errors: InvalidTipAuthToken """ try: if is_receiver_token(tip_token): requested_t = ReceiverTip() tip_description = yield requested_t.get_single(tip_token) else: requested_t = WhistleblowerTip() tip_description = yield requested_t.get_single(tip_token) comment_iface = Comment() comment_list = yield comment_iface.get_comment_by_itip(tip_description['internaltip_id']) self.set_status(200) self.write(json.dumps(comment_list)) except TipGusNotFound, 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, 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, context_gus, *uriargs): """ Request: adminContextDesc Response: None Errors: InvalidInputFormat, ContextGusNotFound """ context_iface = Context() receivertip_iface = ReceiverTip() internaltip_iface = InternalTip() whistlebtip_iface = WhistleblowerTip() comment_iface = Comment() receiver_iface = Receiver() file_iface = File() # This DELETE operation, its permanent, and remove all the reference # a Context has within the system (in example: remove associated Tip, # remove try: context_desc = yield context_iface.get_single(context_gus) tips_related_blocks = yield receivertip_iface.get_tips_by_context(context_gus) print "Tip that need to be deleted, associated with the context",\ context_gus, ":", len(tips_related_blocks) for tip_block in tips_related_blocks: internaltip_id = tip_block.get('internaltip')['internaltip_id'] yield whistlebtip_iface.delete_access_by_itip(internaltip_id) yield receivertip_iface.massive_delete(internaltip_id) yield comment_iface.delete_comment_by_itip(internaltip_id) yield file_iface.delete_file_by_itip(internaltip_id) # and finally, delete the InternalTip yield internaltip_iface.tip_delete(internaltip_id) # (Just consistency check) receivers_associated = yield receiver_iface.get_receivers_by_context(context_gus) print "receiver associated by context POV:", len(receivers_associated),\ "receiver associated by context DB-field:", len(context_desc['receivers']) # Align all the receiver associated to the context, that the context cease to exist yield receiver_iface.align_context_delete(context_desc['receivers'], context_gus) # TODO delete stats associated with context ? # TODO delete profile associated with the context # Finally, delete the context yield context_iface.delete_context(context_gus) self.set_status(200) except ContextGusNotFound, e: self.set_status(e.http_status) self.write({'error_message': e.error_message, 'error_code' : e.error_code})
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 post(self, tip_token, *uriargs): """ Request: actorsCommentDesc Response: actorsCommentDesc Errors: InvalidTipAuthToken, InvalidInputFormat, TipGusNotFound, TipReceiptNotFound """ comment_iface = Comment() try: request = validateMessage(self.request.body, requests.actorsCommentDesc) if is_receiver_token(tip_token): requested_t = ReceiverTip() tip_description = yield requested_t.get_single(tip_token) comment_stored = yield comment_iface.add_comment(tip_description['internaltip_id'], request['content'], u"receiver", tip_description['receiver_gus']) else: requested_t = WhistleblowerTip() tip_description = yield requested_t.get_single(tip_token) comment_stored = yield comment_iface.add_comment(tip_description['internaltip_id'], request['content'], u"whistleblower") self.set_status(200) self.write(json.dumps(comment_stored)) 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, tip_auth_token, *uriargs): """ Parameters: tip_auth_token Response: receiverTipList Errors: InvalidTipAuthToken """ receivertip_iface = ReceiverTip() try: # TODO validate parameter tip format or raise InvalidInputFormat tips = yield receivertip_iface.get_tips_by_tip(tip_auth_token) # this function return a dict with: { 'othertips': [$rtip], 'request' : $rtip } tips['othertips'].append(tips['request']) self.write(tips['othergroup']) 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 delete_receiver(self, receiver_gus): store = self.getStore() receiver_iface = Receiver(store) receiver_desc = receiver_iface.get_single(receiver_gus) receivertip_iface = ReceiverTip(store) # Remove Tip possessed by the receiver related_tips = receivertip_iface.get_tips_by_receiver(receiver_gus) for tip in related_tips: receivertip_iface.personal_delete(tip['tip_gus']) # Remind: the comment are kept, and the name do not use a reference # but is stored in the comment entry. context_iface = Context(store) # Just an alignment check that need to be removed contexts_associated = context_iface.get_contexts_by_receiver(receiver_gus) print "context associated by receiver POV:", len(contexts_associated),\ "context associated by receiver-DB field:", len(receiver_desc['contexts']) context_iface.align_receiver_delete(receiver_desc['contexts'], receiver_gus) receiverconf_iface = ReceiverConfs(store) receivercfg_list = receiverconf_iface.get_confs_by_receiver(receiver_gus) for rcfg in receivercfg_list: receiverconf_iface.delete(rcfg['config_id'], receiver_gus) # Finally delete the receiver receiver_iface.receiver_delete(receiver_gus) self.returnData(receiver_desc) self.returnCode(200) return self.prepareRetVals()
def delete_context(self, context_gus): """ This DELETE operation, its permanent, and remove all the reference a Context has within the system (Tip, File, submission...) """ store = self.getStore() # Get context description, just to verify that context_gus is valid context_iface = Context(store) context_desc = context_iface.get_single(context_gus) # Collect tip by context and iter on the list receivertip_iface = ReceiverTip(store) tips_related_blocks = receivertip_iface.get_tips_by_context(context_gus) internaltip_iface = InternalTip(store) whistlebtip_iface = WhistleblowerTip(store) file_iface = File(store) comment_iface = Comment(store) # For every InternalTip, delete comment, wTip, rTip and Files for tip_block in tips_related_blocks: internaltip_id = tip_block.get('internaltip')['internaltip_id'] whistlebtip_iface.delete_access_by_itip(internaltip_id) receivertip_iface.massive_delete(internaltip_id) comment_iface.delete_comment_by_itip(internaltip_id) file_iface.delete_file_by_itip(internaltip_id) # and finally, delete the InternalTip internaltip_iface.tip_delete(internaltip_id) # (Just a consistency check - need to be removed) receiver_iface = Receiver(store) receivers_associated = receiver_iface.get_receivers_by_context(context_gus) print "receiver associated by context POV:", len(receivers_associated),\ "receiver associated by context DB-field:", len(context_desc['receivers']) # Align all the receiver associated to the context, that the context cease to exist receiver_iface.align_context_delete(context_desc['receivers'], context_gus) # Get the profile list related to context_gus and delete all of them profile_iface = PluginProfiles(store) profile_list = profile_iface.get_profiles_by_contexts([ context_gus ]) for prof in profile_list: profile_iface.delete_profile(prof['profile_gus']) # Get the submission list under the context, and delete all of them submission_iface = Submission(store) submission_list = submission_iface.get_all() for single_sub in submission_list: submission_iface.submission_delete(single_sub['submission_gus'], wb_request=False) # Finally, delete the context context_iface.delete_context(context_gus) self.returnData(context_desc) self.returnCode(200) return self.prepareRetVals()
def put(self, tip_token, *uriargs): """ Request: actorsTipOpsDesc Response: actorsTipDesc Errors: InvalidTipAuthToken, InvalidInputFormat, ForbiddenOperation This interface modify some tip status value. pertinence, personal delete are handled here. Total delete operation is handled in this class, by the DELETE HTTP method. Those operations (may) trigger a 'system comment' inside of the Tip comment list. """ try: request = validateMessage(self.request.body, requests.actorsTipOpsDesc) if not is_receiver_token(tip_token): raise ForbiddenOperation requested_t = ReceiverTip() if request['personal_delete']: yield requested_t.personal_delete(tip_token) if request['is_pertinent']: yield requested_t.pertinence_vote(tip_token, request['is_pertinent']) 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_tip_by_receiver(self, tip_gus): requested_t = ReceiverTip(self.getStore()) tip_description = requested_t.get_single(tip_gus) self.returnData(tip_description) self.returnCode(200) return self.prepareRetVals()
def get(self, what, *uriargs): """ Parameters: None Response: Unknown Errors: None /admin/overview GET should return up to all the tables of GLBackend """ from globaleaks.models.externaltip import ReceiverTip, WhistleblowerTip, Comment from globaleaks.models.options import PluginProfiles, ReceiverConfs from globaleaks.models.internaltip import InternalTip from globaleaks.models.receiver import Receiver expected = [ 'itip', 'wtip', 'rtip', 'receivers', 'comment', 'profiles', 'rcfg', 'all' ] if what == 'receivers' or what == 'all': receiver_iface = Receiver() receiver_list = yield receiver_iface.admin_get_all() self.write({ 'elements' : len(receiver_list), 'receivers' : receiver_list}) if what == 'itip' or what == 'all': itip_iface = InternalTip() itip_list = yield itip_iface.admin_get_all() self.write({ 'elements' : len(itip_list), 'internaltips' : itip_list }) if what == 'rtip' or what == 'all': rtip_iface = ReceiverTip() rtip_list = yield rtip_iface.admin_get_all() self.write({ 'elements' : len(rtip_list), 'receivers_tips' : rtip_list }) if what == 'wtip' or what == 'all': wtip_iface = WhistleblowerTip() wtip_list = yield wtip_iface.admin_get_all() self.write({ 'elements' : len(wtip_list), 'whistleblower_tips' : wtip_list }) if what == 'comment' or what == 'all': comment_iface = Comment() comment_list = yield comment_iface.admin_get_all() self.write({ 'elements' : len(comment_list), 'comments' : comment_list }) if what == 'profiles' or what == 'all': profile_iface = PluginProfiles() profile_list = yield profile_iface.admin_get_all() self.write({ 'elements' : len(profile_list), 'profiles' : profile_list }) if what == 'rcfg' or what == 'all': rconf_iface = ReceiverConfs() rconf_list = yield rconf_iface.admin_get_all() self.write({ 'elements' : len(rconf_list), 'settings' : rconf_list }) if not what in expected: self.set_status(405) else: self.set_status(200) self.finish()
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 get_receiver_list_by_receiver(self, tip_gus): store = self.getStore() requested_t = ReceiverTip(store) tip_description = requested_t.get_single(tip_gus) itip_iface = InternalTip(store) inforet = itip_iface.get_receivers_by_itip(tip_description['internaltip_id']) self.returnData(inforet) self.returnCode(200) return self.prepareRetVals()
def get_tip_list(self, valid_tip): store = self.getStore() receivertip_iface = ReceiverTip(store) tips = receivertip_iface.get_tips_by_tip(valid_tip) # this function return a dict with: { 'othertips': [$rtip], 'request' : $rtip } tips['othertips'].append(tips['request']) self.returnData(tips) self.returnCode(200) return self.prepareRetVals()
def get_comment_list_by_receiver(self, tip_gus): store = self.getStore() requested_t = ReceiverTip(store) tip_description = requested_t.get_single(tip_gus) comment_iface = Comment(store) comment_list = comment_iface.get_comment_by_itip(tip_description['internaltip_id']) self.returnData(comment_list) self.returnCode(200) return self.prepareRetVals()
def new_comment_by_receiver(self, tip_gus, request): store = self.getStore() requested_t = ReceiverTip(store) tip_description = requested_t.get_single(tip_gus) comment_iface = Comment(store) comment_stored = comment_iface.new(tip_description['internaltip_id'], request['content'], u"receiver", tip_description['receiver_gus']) # XXX here can be put the name of the Receiver self.returnData(comment_stored) self.returnCode(201) return self.prepareRetVals()
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 delete(self, receiver_gus, *uriargs): """ Parameter: receiver_gus Request: None Response: None Errors: InvalidInputFormat, ReceiverGusNotFound """ receiver_iface = Receiver() try: # TODO parameter receiver_gus validation - InvalidInputFormat receiver_desc = yield receiver_iface.get_single(receiver_gus) receivertip_iface = ReceiverTip() # Remove Tip possessed by the receiver related_tips = yield receivertip_iface.get_tips_by_receiver(receiver_gus) for tip in related_tips: yield receivertip_iface.personal_delete(tip['tip_gus']) # Remind: the comment are kept, and the name is not referenced but stored # in the comment entry. context_iface = Context() # TODO make an app log contexts_associated = yield context_iface.get_contexts_by_receiver(receiver_gus) print "context associated by receiver POV:", len(contexts_associated),\ "context associated by receiver-DB field:", len(receiver_desc['contexts']) yield context_iface.align_receiver_delete(receiver_desc['contexts'], receiver_gus) receiverconf_iface = ReceiverConfs() # Delete all the receiver configuration associated TODO - App log an number of RCFGs receivercfg_list = yield receiverconf_iface.get_confs_by_receiver(receiver_gus) for rcfg in receivercfg_list: yield receiverconf_iface.delete(rcfg['config_id'], receiver_gus) # Finally delete the receiver yield receiver_iface.receiver_delete(receiver_gus) self.set_status(200) except ReceiverGusNotFound, 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 InternalTip and create the Tips for the receiver needing. Create the ReceiverTip only, because WhistleBlowerTip is created when submission is finalized, along with the receipt exchange. Only the Receiver marked as first tier receiver has a Tip now, the receiver marked as tier 2 (if configured in the context) had their Tip only when the escalation_threshold has reached the requested value. """ log.debug("[D]", self.__class__, 'operation', datetime.today().ctime()) internaltip_iface = InternalTip() receivertip_iface = ReceiverTip() internal_id_list = yield internaltip_iface.get_newly_generated() if len(internal_id_list): log.debug("TipSched: found %d new Tip: %s" % (len(internal_id_list), str(internal_id_list))) for id in internal_id_list: yield receivertip_iface.create_receiver_tips(id, 1) yield internaltip_iface.flip_mark(id, u'first') # loops over the InternalTip and checks the escalation threshold # It may require the creation of second-step Tips escalated_id_list = yield internaltip_iface.get_newly_escalated() if len(escalated_id_list): log.debug("TipSched: %d Tip are escalated: %s" % (len(escalated_id_list), str(escalated_id_list))) # This event would be notified as system Comment comment_iface = Comment() for id in escalated_id_list: # yield comment_iface.add_comment(id, u"Escalation threshold has been reached", u'system') yield receivertip_iface.create_receiver_tips(id, 2) yield internaltip_iface.flip_mark(id, u'second')
def update_tip_by_receiver(self, tip_gus, request): store = self.getStore() receivertip_iface = ReceiverTip(store) if request['personal_delete']: receivertip_iface.personal_delete(tip_gus) elif request['is_pertinent']: # elif is used to avoid the message with both delete+pertinence. # This operation is based in ReceiverTip and is returned # the sum of the vote expressed. This value is updated in InternalTip (itip_id, vote_sum) = receivertip_iface.pertinence_vote(tip_gus, request['is_pertinent']) internaltip_iface = InternalTip(store) internaltip_iface.update_pertinence(itip_id, vote_sum) self.returnCode(200) return self.prepareRetVals()
def put(self, tip_token, *uriargs): """ Request: actorsTipOpsDesc Response: None Errors: InvalidTipAuthToken, InvalidInputFormat, ForbiddenOperation This interface modify some tip status value. pertinence, personal delete are handled here. Total delete operation is handled in this class, by the DELETE HTTP method. Those operations (may) trigger a 'system comment' inside of the Tip comment list. This interface return None, because may execute a delete operation. The client know which kind of operation has been requested. If a pertinence vote, would perform a refresh on get() API, if a delete, would bring the user in other places. """ try: request = validateMessage(self.request.body, requests.actorsTipOpsDesc) if not is_receiver_token(tip_token): raise ForbiddenOperation receivertip_iface = ReceiverTip() if request['personal_delete']: yield receivertip_iface.personal_delete(tip_token) elif request['is_pertinent']: # elif is used to avoid the message with both delete+pertinence. # This operation is based in ReceiverTip and is returned # the sum of the vote expressed. This value is updated in InternalTip (itip_id, vote_sum) = yield receivertip_iface.pertinence_vote(tip_token, request['is_pertinent']) internaltip_iface = InternalTip() yield internaltip_iface.update_pertinence(itip_id, vote_sum) 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 delete(self, tip_token, *uriargs): """ Request: None Response: None Errors: ForbiddenOperation 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 requested_t = ReceiverTip() yield requested_t.total_delete(tip_token) 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 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 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')