def serialize_obj(self, store, key, obj, language): obj_id = obj.id cache_key = key + '-' + obj_id + '-' + language cache_obj = None if cache_key not in self.cache: if key == 'user': cache_obj = user_serialize_user(store, obj, language) elif key == 'context': cache_obj = admin_serialize_context(store, obj, language) elif key == 'tip': itip = store.find(models.InternalTip, id=obj.internaltip_id).one() cache_obj = serialize_rtip(store, obj, itip, language) elif key == 'message': cache_obj = serialize_message(store, obj) elif key == 'comment': cache_obj = serialize_comment(store, obj) elif key == 'file': cache_obj = models.serializers.serialize_ifile(store, obj) self.cache[cache_key] = cache_obj return self.cache[cache_key]
def create_comment(session, tid, wbtip_id, content): wbtip, itip = db_get( session, (models.WhistleblowerTip, models.InternalTip), (models.WhistleblowerTip.id == wbtip_id, models.InternalTip.id == models.WhistleblowerTip.id, models.InternalTip.enable_two_way_comments.is_(True), models.InternalTip.status != 'closed', models.InternalTip.tid == tid)) itip.update_date = itip.wb_last_access = datetime_now() _content = content if itip.crypto_tip_pub_key: _content = base64.b64encode( GCE.asymmetric_encrypt(itip.crypto_tip_pub_key, content)).decode() comment = models.Comment() comment.internaltip_id = wbtip_id comment.type = 'whistleblower' comment.content = _content session.add(comment) session.flush() ret = serialize_comment(session, comment) ret['content'] = content return ret
def serialize_obj(self, session, key, obj, tid, language): obj_id = obj.id cache_key = gen_cache_key(key, tid, obj_id, language) cache_obj = None if cache_key not in self.cache: if key == 'user': cache_obj = user_serialize_user(session, obj, language) elif key == 'context': cache_obj = admin_serialize_context(session, obj, language) elif key == 'tip': itip = session.query(models.InternalTip).filter( models.InternalTip.id == obj.internaltip_id).one() cache_obj = serialize_rtip(session, obj, itip, language) elif key == 'message': cache_obj = serialize_message(session, obj) elif key == 'comment': cache_obj = serialize_comment(session, obj) elif key == 'file': cache_obj = models.serializers.serialize_ifile(session, obj) self.cache[cache_key] = cache_obj return self.cache[cache_key]
def process_event(self, store, comment): comment_desc = serialize_comment(comment) context_desc = admin.context.admin_serialize_context(store, comment.internaltip.context, self.language) # for every comment, iterate on the associated receiver(s) log.debug("Comments from %s - Receiver(s) %d" % \ (comment.author, comment.internaltip.receivers.count())) for receiver in comment.internaltip.receivers: if comment.type == u'receiver' and comment.author == receiver.user.name: log.debug("Receiver is the Author (%s): skipped" % receiver.user.username) return receivertip = store.find(models.ReceiverTip, (models.ReceiverTip.internaltip_id == comment.internaltip_id, models.ReceiverTip.receiver_id == receiver.id)).one() tip_desc = serialize_rtip(store, receivertip, self.language) do_mail, receiver_desc = self.import_receiver(receiver) self.events.append(Event(type=self.template_type, trigger=self.trigger, node_info={}, receiver_info=receiver_desc, context_info=context_desc, tip_info=tip_desc, subevent_info=comment_desc, do_mail=do_mail))
def process_event(self, store, comment): comment_desc = serialize_comment(comment) context_desc = admin.context.admin_serialize_context( store, comment.internaltip.context, self.language) # for every comment, iterate on the associated receiver(s) log.debug("Comments from %s - Receiver(s) %d" % \ (comment.author, comment.internaltip.receivers.count())) for receiver in comment.internaltip.receivers: if comment.type == u'receiver' and comment.author == receiver.user.name: log.debug("Receiver is the Author (%s): skipped" % receiver.user.username) return receivertip = store.find( models.ReceiverTip, (models.ReceiverTip.internaltip_id == comment.internaltip_id, models.ReceiverTip.receiver_id == receiver.id)).one() tip_desc = serialize_rtip(store, receivertip, self.language) do_mail, receiver_desc = self.import_receiver(receiver) self.events.append( Event(type=self.template_type, trigger=self.trigger, node_info={}, receiver_info=receiver_desc, context_info=context_desc, tip_info=tip_desc, subevent_info=comment_desc, do_mail=do_mail))
def create_comment(session, tid, wbtip_id, user_key, content): wbtip, itip = session.query(models.WhistleblowerTip, models.InternalTip)\ .filter(models.WhistleblowerTip.id == wbtip_id, models.InternalTip.id == models.WhistleblowerTip.id, models.InternalTip.tid == tid).one_or_none() if wbtip is None: raise errors.ModelNotFound(models.WhistleblowerTip) itip.update_date = itip.wb_last_access = datetime_now() comment = models.Comment() comment.internaltip_id = wbtip_id comment.type = u'whistleblower' if itip.crypto_tip_pub_key: comment.content = base64.b64encode(GCE.asymmetric_encrypt(itip.crypto_tip_pub_key, content)).decode() else: comment.content = content session.add(comment) session.flush() ret = serialize_comment(session, comment) ret['content'] = content return ret
def create_comment(store, wbtip_id, request): wbtip = db_access_wbtip(store, wbtip_id) wbtip.internaltip.update_date = datetime_now() comment = Comment() comment.content = request['content'] comment.internaltip_id = wbtip.id comment.type = u'whistleblower' wbtip.internaltip.comments.add(comment) return serialize_comment(comment)
def create_comment(store, wbtip_id, request): internaltip = models.db_get(store, models.InternalTip, id=wbtip_id) internaltip.update_date = internaltip.wb_last_access = datetime_now() comment = models.Comment() comment.content = request['content'] comment.internaltip_id = wbtip_id comment.type = u'whistleblower' store.add(comment) return serialize_comment(store, comment)
def create_comment(session, tid, wbtip_id, request): internaltip = session.query(models.InternalTip).filter(models.InternalTip.id == wbtip_id, models.InternalTip.tid == tid) internaltip.update_date = internaltip.wb_last_access = datetime_now() comment = models.Comment() comment.content = request['content'] comment.internaltip_id = wbtip_id comment.type = u'whistleblower' session.add(comment) session.flush() return serialize_comment(session, comment)
def process_Comment(self, store, comment, data): for rtip in comment.internaltip.receivertips: if comment.type == u'receiver' and comment.author == rtip.receiver.user.name: continue language = rtip.receiver.user.language dataX = copy.deepcopy(data) dataX['comment'] = serialize_comment(comment) dataX['tip'] = serialize_rtip(store, rtip, language) dataX['context'] = admin_serialize_context(store, comment.internaltip.context, language) dataX['receiver'] = admin_serialize_receiver(rtip.receiver, language) self.process_mail_creation(store, dataX)
def serialize_obj(self, store, key, obj, language): obj_id = obj.id cache_key = key + '-' + obj_id + '-' + language if cache_key not in self.cache: if key == 'tip': cache_obj = serialize_rtip(store, obj, language) elif key == 'context': cache_obj = admin_serialize_context(store, obj, language) elif key == 'receiver': cache_obj = admin_serialize_receiver(obj, language) elif key == 'message': cache_obj = serialize_message(obj) elif key == 'comment': cache_obj = serialize_comment(obj) elif key == 'file': cache_obj = serialize_internalfile(obj) self.cache[cache_key] = cache_obj return self.cache[cache_key]
def serialize_content(store, cache, key, obj, language): obj_id = obj.id cache_key = key + obj_id + language if cache_key not in cache: if key == 'tip': cache_obj = serialize_rtip(store, obj, language) elif key == 'context': cache_obj = admin_serialize_context(store, obj, language) elif key == 'receiver': cache_obj = admin_serialize_receiver(obj, language) elif key == 'message': cache_obj = serialize_message(obj) elif key == 'comment': cache_obj = serialize_comment(obj) elif key == 'file': cache_obj = serialize_internalfile(obj) cache[cache_key] = cache_obj return copy.deepcopy(cache[cache_key])
def serialize_obj(self, session, key, obj, tid, language): obj_id = obj.id cache_key = gen_cache_key(key, tid, obj_id, language) cache_obj = None if cache_key not in self.cache: if key == 'user': cache_obj = user_serialize_user(session, obj, language) elif key == 'context': cache_obj = admin_serialize_context(session, obj, language) elif key == 'tip': itip = session.query(models.InternalTip).filter(models.InternalTip.id == obj.internaltip_id).one() cache_obj = serialize_rtip(session, obj, itip, language) elif key == 'message': cache_obj = serialize_message(session, obj) elif key == 'comment': cache_obj = serialize_comment(session, obj) elif key == 'file': cache_obj = models.serializers.serialize_ifile(session, obj) self.cache[cache_key] = cache_obj return self.cache[cache_key]
def get_comment_list(store, wbtip_id): wbtip = db_access_wbtip(store, wbtip_id) return [ serialize_comment(comment) for comment in wbtip.internaltip.comments ]
def get_comment_list(store, wbtip_id): wbtip = db_access_wbtip(store, wbtip_id) return [serialize_comment(comment) for comment in wbtip.internaltip.comments]