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 do_fileprocess_validation(self, store, context_gus, filepath ): plugin_type = u'fileprocess' profile_iface = PluginProfiles(store) profile_associated = profile_iface.get_profiles_by_contexts([ context_gus ] ) plugin_found = False validate_file = False for p_cfg in profile_associated: # Plugin FileProcess if p_cfg['plugin_type'] != plugin_type: continue plugin_found = True print "processing", filepath, "using the profile", p_cfg['profile_gus'], "configured for", p_cfg['plugin_name'] plugin = PluginManager.instance_plugin(p_cfg['plugin_name']) validate_file = plugin.do_fileprocess(filepath, p_cfg['admin_settings']) if not plugin_found: # FileProcess profile has been not configured, file accepted by default validate_file = True return validate_file
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 get_profiles_by_receiver(self, receiver_associated_contexts): store = self.getStore() profile_iface = PluginProfiles(store) profiles_list = profile_iface.get_profiles_by_contexts(receiver_associated_contexts) self.returnData(profiles_list) self.returnCode(200) return self.prepareRetVals()
def operation(self): """ Goal of this function is to check all the new files and validate thru the configured SystemSettings possible marker in the file are: 'not processed', 'ready', 'blocked', 'stored' defined in File._marker """ plugin_type = u'fileprocess' file_iface = File() profile_iface = PluginProfiles() not_processed_file = yield file_iface.get_file_by_marker(file_iface._marker[0]) print "FileProcess", not_processed_file for single_file in not_processed_file: profile_associated = yield profile_iface.get_profiles_by_contexts([ single_file['context_gus'] ] ) for p_cfg in profile_associated: if p_cfg['plugin_type'] != plugin_type: continue print "processing", single_file['file_name'], "using the profile", p_cfg['profile_gus'], "configured for", p_cfg['plugin_name'] plugin = PluginManager.instance_plugin(p_cfg['plugin_name']) try: tempfpath = os.path.join(config.advanced.submissions_dir, single_file['file_gus']) except AttributeError: # XXX hi level danger Log - no directory present to perform file analysis continue return_code = plugin.do_fileprocess(tempfpath, p_cfg['admin_settings']) # Todo Log/stats in both cases if return_code: yield file_iface.flip_mark(single_file['file_gus'], file_iface._marker[1]) # ready else: yield file_iface.flip_mark(single_file['file_gus'], file_iface._marker[2]) # blocked
def fileprocess(self): plugin_type = u'fileprocess' store = self.getStore() file_iface = File(store) profile_iface = PluginProfiles(store) not_processed_file = file_iface.get_file_by_marker(file_iface._marker[0]) for single_file in not_processed_file: profile_associated = profile_iface.get_profiles_by_contexts([ single_file['context_gus'] ] ) for p_cfg in profile_associated: if p_cfg['plugin_type'] != plugin_type: continue print "processing", single_file['file_name'], "using the profile", p_cfg['profile_gus'], "configured for", p_cfg['plugin_name'] plugin = PluginManager.instance_plugin(p_cfg['plugin_name']) try: tempfpath = os.path.join(config.advanced.submissions_dir, single_file['file_gus']) except AttributeError: # XXX hi level danger Log - no directory present to perform file analysis continue return_code = plugin.do_fileprocess(tempfpath, p_cfg['admin_settings']) # Todo Log/stats in both cases if return_code: file_iface.flip_mark(single_file['file_gus'], file_iface._marker[1]) # ready else: file_iface.flip_mark(single_file['file_gus'], file_iface._marker[2]) # blocked