def new(self, receiver_dict): """ @receiver_dict: here is supposed to be already sanitized @return: the receiver_gus or raise an exception Behold! this method convert a soulless dict in Tha Man, The Choosen One that want review the whistles blowed documents. It's a sort of transparency baptism: here you get your GlobaLeaks Unique String, sir! """ store = self.getStore('receiver new') baptized_receiver = Receiver() try: baptized_receiver._import_dict(receiver_dict) except KeyError: store.close() raise InvalidInputFormat("Error near the Storm") baptized_receiver.receiver_gus = idops.random_receiver_gus() baptized_receiver.contexts = [] baptized_receiver.creation_date = gltime.utcDateNow() baptized_receiver.update_date = gltime.utcDateNow() # last_access is not initialized store.add(baptized_receiver) store.commit() store.close() return baptized_receiver.receiver_gus
def initialize(self, submission): """ initialized an internalTip having the context @return: none """ self.last_activity = gltime.utcDateNow() self.creation_date = gltime.utcDateNow() self.context = submission.context self.context_gus = submission.context_gus # those four can be referenced thru self.context. self.context_gus = submission.context.context_gus self.escalation_threshold = submission.context.escalation_threshold self.access_limit = submission.context.tip_max_access self.download_limit = submission.context.file_max_download # remind: files has not yet been referenced to InternalTip self.files = submission.files # need operations in File.internaltip_id File.internaltip self.expiration_date = submission.expiration_time self.fields = submission.fields self.pertinence_counter = 0 self.receivers_map = [] self.mark = u'new'
def new(self, context_dict): """ @param context_dict: a dictionary containing the expected field of a context, is called and define as contextDescriptionDict @return: context_gus, the universally unique identifier of the context """ log.debug("[D] %s %s " % (__file__, __name__), "Context new", context_dict) store = self.getStore('context new') cntx = Context() cntx.context_gus = idops.random_context_gus() cntx.node_id = 1 cntx.creation_date = gltime.utcDateNow() cntx.update_date = gltime.utcDateNow() cntx.last_activity = gltime.utcDateNow() cntx.receivers = [] try: cntx._import_dict(context_dict) except KeyError: store.rollback() store.close() raise InvalidInputFormat("Import failed near the Storm") store.add(cntx) log.msg("Created context %s at the %s" % (cntx.name, cntx.creation_date) ) store.commit() store.close() # return context_dict return cntx.context_gus
def admin_update(self, receiver_gus, receiver_dict): """ This is the method called by the admin for change receiver preferences. may edit more elements than the next method (self_update) the dict need to be already validated """ store = self.getStore('receiver admin_update') # I didn't understand why, but NotOneError is not raised even if the search return None try: requested_r = store.find(Receiver, Receiver.receiver_gus == unicode(receiver_gus)).one() except NotOneError: store.close() raise ReceiverGusNotFound if requested_r is None: store.close() raise ReceiverGusNotFound try: requested_r._import_dict(receiver_dict) except KeyError: store.close() raise InvalidInputFormat("Error near the Storm") requested_r.update_date = gltime.utcDateNow() store.commit() store.close()
def update(self, context_gus, context_dict): """ @param context_gus: the universal unique identifier @param context_dict: the information fields that need to be update, here is supported to be already validated, sanitized and logically verified by handlers @return: None or Exception on error """ log.debug("[D] %s %s " % (__file__, __name__), "Context update of", context_gus) store = self.getStore('context update') try: requested_c = store.find(Context, Context.context_gus == unicode(context_gus)).one() except NotOneError: store.close() raise ContextGusNotFound if requested_c is None: store.close() raise ContextGusNotFound try: requested_c._import_dict(context_dict) except KeyError: store.rollback() store.close() raise InvalidInputFormat("Import failed near the Storm") requested_c.update_date = gltime.utcDateNow() store.commit() log.msg("Updated context %s in %s, created in %s" % (requested_c.name, requested_c.update_date, requested_c.creation_date) ) store.close()
def new(self, submission_dict): """ initialize an internalTip form a recently finalized Submission @return: none """ self.last_activity = gltime.utcDateNow() self.creation_date = gltime.utcDateNow() # _import_dict do not exists because InternalTip has not update() try: self.fields = submission_dict['wb_fields'] self.files = submission_dict['files'] self.context_gus = submission_dict['context_gus'] self.receivers = submission_dict['receivers'] # the receivers arrive from the handler *correctly* checked with # context settings, and eventually modified by handler. except KeyError, e: raise InvalidInputFormat("InternalTip initialization failed (missing %s)" % e)
def update_last_activity(self, internaltip_id): """ update_last_activity is called when an operation happen in some elements related to the internaltip (file upload, new comment, receiver escalation, new pertinence, receivertip deleted by receiver) """ try: requested_t = self.store.find(InternalTip, InternalTip.id == int(internaltip_id)).one() except NotOneError: raise Exception("Not found InternalTip %d" % internaltip_id) if requested_t is None: raise Exception("Not found InternalTip %d" % internaltip_id) requested_t.last_activity = gltime.utcDateNow()
def update_pertinence(self, internaltip_id, overall_vote): """ In the case a receiver remove himself from a tip, its vote cease to be valid. In the case a new tier of receiver join, their vote need to be considered. The logic of this function has been changed, because the only safe way to have an updated vote, is getting the value from the handlers (returned by ReceiverTip analysis) @param internaltip_id: valid itip_id related to the Tip analized @return: None """ requested_t = self.store.find(InternalTip, InternalTip.id == int(internaltip_id)).one() requested_t.pertinence_counter = overall_vote requested_t.last_activity = gltime.utcDateNow()
def new(self, received_dict): store = self.getStore() self.files = [] self.receivers = [] self.mark = self._marker[0] # 'incomplete' self.creation_time = gltime.utcDateNow() # TODO with gltimes completed, just gltime.utcTimeNow(associated_c.submission_expire) self.expiration_time = gltime.utcFutureDate(seconds=1, minutes=1, hours=1) try: self._import_dict(received_dict) except KeyError, e: raise InvalidInputFormat("Submission initialization failed (missing %s)" % e)
def new(self, context_gus): store = self.getStore('new submission') try: associated_c = store.find(Context, Context.context_gus == context_gus).one() except NotOneError: store.close() raise ContextGusNotFound if associated_c is None: store.close() raise ContextGusNotFound submission = Submission() submission.submission_gus = idops.random_submission_gus(False) submission.context_gus = context_gus submission.context = associated_c # XXX this was important and actually IS bugged -- review that /me vecna # submission.receivers = associated_c.get_receivers('public') submission.receivers = associated_c.receivers # XXX this was important and actually IS bugged -- review that /me vecna submission.files = {} # TODO submission.context.update_stats() submission.creation_time = gltime.utcDateNow() submission.expiration_time = gltime.utcFutureDate(seconds=1, minutes=1, hours=1) store.add(submission) store.commit() submissionDesc = submission._description_dict() log.debug("[D] submission created", submission._description_dict()) store.close() return submissionDesc
def flip_mark(self, subject_id, newmark): """ @param newmark: u'first' or u'second', at the start is u'new' @subject_id: InternalTip.id to be changed, this mark represent the progress of the iTip @return: None """ if newmark not in self._marker: raise NotImplemented try: requested_t = self.store.find(InternalTip, InternalTip.id == int(subject_id)).one() except NotOneError: raise Exception("Not found InternalTip %d" % subject_id) if requested_t is None: raise Exception("Not found InternalTip %d" % subject_id) # XXX log message log.debug("flip mark in InternalTip %d, from [%s] to [%s]" % (requested_t.id, requested_t.mark, newmark)) requested_t.last_activity = gltime.utcDateNow() requested_t.mark = newmark
def update_languages(self, context_gus): log.debug("[D] %s %s " % (__file__, __name__), "update_languages ", context_gus) language_list = [] # for each receiver check every languages supported, if not # present in the context declared language, append on it for rcvr in self.get_receivers('internal', context_gus): for language in rcvr.get('know_languages'): if not language in language_list: language_list.append(language) store = self.getStore('context update_languages') requested_c = store.find(Context, Context.context_gus == unicode(context_gus)).one() log.debug("[L] before language update, context", context_gus, "was", requested_c.languages_supported, "and after got", language_list) requested_c.languages_supported = language_list requested_c.update_date = gltime.utcDateNow() store.commit() store.close()