def register_wbfile_on_db(session, tid, rtip_id, uploaded_file): rtip, itip = session.query(models.ReceiverTip, models.InternalTip) \ .filter(models.ReceiverTip.id == rtip_id, models.ReceiverTip.internaltip_id == models.InternalTip.id, models.InternalTip.tid == tid).one() itip.update_date = rtip.last_access = datetime_now() if itip.crypto_tip_pub_key: for k in ['name', 'description', 'type', 'size']: uploaded_file[k] = base64.b64encode( GCE.asymmetric_encrypt(itip.crypto_tip_pub_key, text_type(uploaded_file[k]))) new_file = models.WhistleblowerFile() new_file.name = uploaded_file['name'] new_file.description = uploaded_file['description'] new_file.content_type = uploaded_file['type'] new_file.size = uploaded_file['size'] new_file.receivertip_id = rtip_id new_file.filename = uploaded_file['filename'] session.add(new_file) return serializers.serialize_wbfile(session, tid, new_file)
def register_wbfile_on_db(store, uploaded_file, receivertip_id): receivertip = store.find(ReceiverTip, ReceiverTip.id == receivertip_id).one() if not receivertip: log.err("Cannot associate a file to a not existent receivertip!") raise errors.TipIdNotFound receivertip.update_date = datetime_now() new_file = WhistleblowerFile() new_file.name = uploaded_file['name'] new_file.description = uploaded_file['description'] new_file.content_type = uploaded_file['type'] new_file.size = uploaded_file['size'] new_file.receivertip_id = receivertip.id new_file.file_path = uploaded_file['path'] store.add(new_file) log.debug("=> Recorded new WhistleblowerFile %s" % uploaded_file['name']) return serializers.serialize_wbfile(new_file)
def db_get_wbfile_list(session, itip_id): wbfiles = session.query(models.WhistleblowerFile) \ .filter(models.WhistleblowerFile.receivertip_id == models.ReceiverTip.id, models.ReceiverTip.internaltip_id == itip_id) return [ serializers.serialize_wbfile(session, wbfile) for wbfile in wbfiles ]
def download_wbfile(self, session, tid, user_id, file_id): wbfile = session.query(models.WhistleblowerFile) \ .filter(models.WhistleblowerFile.id == file_id).one_or_none() if wbfile is None or not self.user_can_access(session, tid, wbfile): raise errors.ModelNotFound(models.WhistleblowerFile) self.access_wbfile(session, wbfile) return serializers.serialize_wbfile(session, tid, wbfile)
def download_wbfile(self, store, user_id, file_id): wbfile = store.find(WhistleblowerFile, WhistleblowerFile.id == file_id).one() if wbfile is None or not self.user_can_access(wbfile): raise errors.FileIdNotFound self.access_wbfile(wbfile) return serializers.serialize_wbfile(wbfile)
def download_wbfile(self, session, tid, file_id): wbfile, wbtip = db_get(session, (models.WhistleblowerFile, models.WhistleblowerTip), (models.WhistleblowerFile.id == file_id, models.WhistleblowerFile.receivertip_id == models.ReceiverTip.id, models.ReceiverTip.internaltip_id == models.WhistleblowerTip.id)) if not self.user_can_access(session, tid, wbfile): raise errors.ResourceNotFound() self.access_wbfile(session, wbfile) return serializers.serialize_wbfile(session, wbfile), base64.b64decode(wbtip.crypto_tip_prv_key)
def download_wbfile(self, session, tid, user_id, file_id): x = session.query(models.WhistleblowerFile, models.WhistleblowerTip) \ .filter(models.WhistleblowerFile.id == file_id, models.WhistleblowerFile.receivertip_id == models.ReceiverTip.id, models.ReceiverTip.internaltip_id == models.WhistleblowerTip.id).one_or_none() if x is None or not self.user_can_access(session, tid, x[0]): raise errors.ModelNotFound(models.WhistleblowerFile) wbfile, wbtip = x[0], x[1] self.access_wbfile(session, wbfile) return serializers.serialize_wbfile(session, tid, wbfile), wbtip.crypto_tip_prv_key
def download_wbfile(self, session, tid, file_id): wbfile, wbtip, = db_get( session, (models.WhistleblowerFile, models.WhistleblowerTip), (models.WhistleblowerFile.id == file_id, models.WhistleblowerFile.receivertip_id == models.ReceiverTip.id, models.ReceiverTip.internaltip_id == models.WhistleblowerTip.id)) rtip = session.query(models.ReceiverTip) \ .filter(models.ReceiverTip.receiver_id == self.current_user.user_id, models.ReceiverTip.internaltip_id == wbtip.id).one_or_none() if not rtip: raise errors.ResourceNotFound() self.access_wbfile(session, wbfile) return serializers.serialize_wbfile(session, wbfile), base64.b64decode( rtip.crypto_tip_prv_key)
def register_wbfile_on_db(store, rtip_id, uploaded_file): rtip, itip = store.find((models.ReceiverTip, models.InternalTip), models.ReceiverTip.id == rtip_id, models.InternalTip.id == models.ReceiverTip.internaltip_id).one() itip.update_date = rtip.last_access = datetime_now() new_file = models.WhistleblowerFile() new_file.name = uploaded_file['name'] new_file.description = uploaded_file['description'] new_file.content_type = uploaded_file['type'] new_file.size = uploaded_file['size'] new_file.receivertip_id = rtip_id new_file.file_path = uploaded_file['path'] store.add(new_file) return serializers.serialize_wbfile(store, new_file)
def register_wbfile_on_db(session, tid, rtip_id, uploaded_file): rtip, itip = session.query(models.ReceiverTip, models.InternalTip) \ .filter(models.ReceiverTip.id == rtip_id, models.ReceiverTip.internaltip_id == models.InternalTip.id, models.InternalTip.tid == tid).one() itip.update_date = rtip.last_access = datetime_now() new_file = models.WhistleblowerFile() new_file.name = uploaded_file['name'] new_file.description = uploaded_file['description'] new_file.content_type = uploaded_file['type'] new_file.size = uploaded_file['size'] new_file.receivertip_id = rtip_id new_file.filename = uploaded_file['filename'] session.add(new_file) return serializers.serialize_wbfile(session, tid, new_file)
def register_wbfile_on_db(session, tid, rtip_id, uploaded_file): """ Register a file on the database :param session: An ORM session :param tid: A tenant id :param rtip_id: A id of the rtip on which attaching the file :param uploaded_file: A file to be attached :return: A descriptor of the file """ rtip, itip = session.query(models.ReceiverTip, models.InternalTip) \ .filter(models.ReceiverTip.id == rtip_id, models.ReceiverTip.internaltip_id == models.InternalTip.id, models.InternalTip.status != 'closed', models.InternalTip.tid == tid).one() itip.update_date = rtip.last_access = datetime_now() if itip.crypto_tip_pub_key: for k in ['name', 'description', 'type', 'size']: if k == 'size': uploaded_file[k] = str(uploaded_file[k]) uploaded_file[k] = base64.b64encode( GCE.asymmetric_encrypt(itip.crypto_tip_pub_key, uploaded_file[k])) new_file = models.WhistleblowerFile() new_file.name = uploaded_file['name'] new_file.description = uploaded_file['description'] new_file.content_type = uploaded_file['type'] new_file.size = uploaded_file['size'] new_file.receivertip_id = rtip_id new_file.filename = uploaded_file['filename'] session.add(new_file) return serializers.serialize_wbfile(session, new_file)