def get_tip_export(session, tid, user_id, rtip_id, language): rtip, itip = db_access_rtip(session, tid, user_id, rtip_id) user, context = session.query(models.User, models.Context) \ .filter(models.User.id == rtip.receiver_id, models.Context.id == models.InternalTip.context_id, models.InternalTip.id == rtip.internaltip_id, models.User.tid == tid).one() rtip_dict = serialize_rtip(session, rtip, itip, language) export_dict = { 'type': 'export_template', 'node': db_admin_serialize_node(session, tid, language), 'notification': db_get_notification(session, tid, language), 'tip': rtip_dict, 'crypto_tip_prv_key': rtip.crypto_tip_prv_key, 'user': user_serialize_user(session, user, language), 'context': admin_serialize_context(session, context, language), 'comments': rtip_dict['comments'], 'messages': rtip_dict['messages'], 'files': [], 'submission_statuses': db_retrieve_all_submission_statuses(session, tid, language) } for rfile in session.query(models.ReceiverFile).filter( models.ReceiverFile.receivertip_id == rtip_id): rfile.last_access = datetime_now() rfile.downloads += 1 file_dict = models.serializers.serialize_rfile(session, tid, rfile) file_dict['name'] = 'files/' + file_dict['name'] file_dict['path'] = os.path.join(Settings.attachments_path, file_dict['filename']) file_dict['forged'] = False export_dict['files'].append(file_dict) for wf in session.query(models.WhistleblowerFile).filter( models.WhistleblowerFile.receivertip_id == models.ReceiverTip.id, models.ReceiverTip.internaltip_id == rtip.internaltip_id, models.InternalTip.id == rtip.internaltip_id): file_dict = models.serializers.serialize_wbfile(session, tid, wf) file_dict['name'] = 'files_from_recipients/' + file_dict['name'] file_dict['path'] = os.path.join(Settings.attachments_path, file_dict['filename']) file_dict[ 'forged'] = True # To be removed as soon it will be encrypted export_dict['files'].append(file_dict) return export_dict
def get_public_resources(session, tid, language): return { 'node': db_serialize_node(session, tid, language), 'contexts': db_get_public_context_list(session, tid, language), 'questionnaires': db_get_questionnaire_list(session, tid, language), 'receivers': db_get_public_receiver_list(session, tid, language), 'submission_statuses': db_retrieve_all_submission_statuses(session, tid, language) }
def get_public_resources(session, tid, language): return { 'node': db_serialize_node(session, tid, language), 'contexts': db_get_public_context_list(session, tid, language), 'questionnaires': db_get_questionnaire_list(session, tid, language), 'receivers': db_get_public_receiver_list(session, tid, language), 'submission_statuses': db_retrieve_all_submission_statuses(session, tid, language) }
def process_mail_creation(self, session, tid, data): user_id = data['user']['id'] language = data['user']['language'] # Do not spool emails if the receiver has opted out of ntfns for this tip. if not data['tip']['enable_notifications']: log.debug("Discarding emails for %s due to receiver's preference.", user_id) return # https://github.com/globaleaks/GlobaLeaks/issues/798 # TODO: the current solution is global and configurable only by the admin sent_emails = self.state.get_mail_counter(user_id) if sent_emails >= self.state.tenant_cache[tid].notification.notification_threshold_per_hour: log.debug("Discarding emails for receiver %s due to threshold already exceeded for the current hour", user_id) return self.state.increment_mail_counter(user_id) if sent_emails >= self.state.tenant_cache[tid].notification.notification_threshold_per_hour: log.info("Reached threshold of %d emails with limit of %d for receiver %s", sent_emails, self.state.tenant_cache[tid].notification.notification_threshold_per_hour, user_id, tid=tid) # simply changing the type of the notification causes # to send the notification_limit_reached data['type'] = 'receiver_notification_limit_reached' data['node'] = self.serialize_config(session, 'node', tid, language) data['submission_statuses'] = db_retrieve_all_submission_statuses(session, tid, language) if data['node']['mode'] != 'whistleblowing.it': data['notification'] = self.serialize_config(session, 'notification', tid, language) else: data['notification'] = self.serialize_config(session, 'notification', 1, language) subject, body = Templating().get_mail_subject_and_body(data) # If the receiver has encryption enabled encrypt the mail body if data['user']['pgp_key_public']: pgpctx = PGPContext(self.state.settings.tmp_path) fingerprint = pgpctx.load_key(data['user']['pgp_key_public'])['fingerprint'] body = pgpctx.encrypt_message(fingerprint, body) session.add(models.Mail({ 'address': data['user']['mail_address'], 'subject': subject, 'body': body, 'tid': tid, }))