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(self, what, *uriargs): """ Parameters: None Response: Unknown Errors: None /dump/overview GET should return up to all the tables of GLBackend """ expected = [ 'itip', 'wtip', 'rtip', 'receivers', 'comment', 'profiles', 'rcfg', 'file', 'submission', 'contexts', 'plugins', 'all', 'count' ] outputDict = {} if what == 'receivers' or what == 'all' or what == 'count': receiver_iface = Receiver() receiver_list = yield receiver_iface.get_all() if what != 'count': outputDict.update({ 'receivers_elements' : len(receiver_list), 'receivers' : receiver_list}) else: outputDict.update({ 'receivers_elements' : len(receiver_list)}) if what == 'itip' or what == 'all' or what == 'count': itip_iface = InternalTip() itip_list = yield itip_iface.get_all() if what != 'count': outputDict.update({ 'internaltips_elements' : len(itip_list), 'internaltips' : itip_list }) else: outputDict.update({ 'internaltips_elements' : len(itip_list)}) if what == 'rtip' or what == 'all' or what == 'count': rtip_iface = ReceiverTip() rtip_list = yield rtip_iface.get_all() if what != 'count': outputDict.update({ 'rtip_elements' : len(rtip_list), 'receivers_tips' : rtip_list }) else: outputDict.update({ 'rtip_elements' : len(rtip_list)}) if what == 'wtip' or what == 'all' or what == 'count': wtip_iface = WhistleblowerTip() wtip_list = yield wtip_iface.get_all() if what != 'count': outputDict.update({ 'wtip_elements' : len(wtip_list), 'whistleblower_tips' : wtip_list }) else: outputDict.update({ 'wtip_elements' : len(wtip_list)}) if what == 'comment' or what == 'all' or what == 'count': comment_iface = Comment() comment_list = yield comment_iface.get_all() if what != 'count': outputDict.update({ 'comment_elements' : len(comment_list), 'comments' : comment_list }) else: outputDict.update({ 'comment_elements' : len(comment_list)}) if what == 'profiles' or what == 'all' or what == 'count': profile_iface = PluginProfiles() profile_list = yield profile_iface.get_all() if what != 'count': outputDict.update({ 'profiles_elements' : len(profile_list), 'profiles' : profile_list }) else: outputDict.update({ 'profiles_elements' : len(profile_list)}) if what == 'plugins' or what == 'all' or what == 'count': plugin_list = yield PluginManager.get_all() if what != 'count': outputDict.update({ 'plugins_elements' : len(plugin_list), 'plugins' : plugin_list }) else: outputDict.update({ 'plugins_elements' : len(plugin_list) }) if what == 'rcfg' or what == 'all' or what == 'count': rconf_iface = ReceiverConfs() rconf_list = yield rconf_iface.get_all() if what != 'count': outputDict.update({ 'rcfg_elements' : len(rconf_list), 'settings' : rconf_list }) else: outputDict.update({ 'rcfg_elements' : len(rconf_list)}) if what == 'submission' or what == 'all' or what == 'count': submission_iface = Submission() submission_list = yield submission_iface.get_all() if what != 'count': outputDict.update({ 'submission_elements' : len(submission_list), 'submissions' : submission_list }) else: outputDict.update({ 'submission_elements' : len(submission_list)}) if what == 'file' or what == 'all' or what == 'count': file_iface = File() file_list = yield file_iface.get_all() if what != 'count': outputDict.update({ 'file_elements' : len(file_list), 'files' : file_list }) else: outputDict.update({ 'file_elements' : len(file_list)}) if what == 'contexts' or what == 'all' or what == 'count': context_iface = Context() context_list = yield context_iface.get_all() if what != 'count': outputDict.update({ 'contexts_elements' : len(context_list), 'contexts' : context_list }) else: outputDict.update({ 'contexts_elements' : len(context_list)}) if not what in expected: self.set_status(405) else: self.set_status(200) self.write(outputDict) self.finish()