Ejemplo n.º 1
0
 def update_file_info(self, file_id):
     file_object = get_file_by_id(self._db_session, file_id)
     self._check_file_lock(file_object)
     params = json.load(request.body)
     for key, value in params.items():
         if not hasattr(FileModel, key):
             abort(400, 'File has no attribute {0}.'.format(key))
         if key == 'parent':
             # Move
             parent_id = value['id']
             parent_folder = get_folder_by_id(self._db_session, parent_id)
             file_object.parent_id = parent_folder.id
             self._db_session.add(
                 EventModel(event_type='ITEM_MOVE', source_id=file_object.file_id, source_type='file'),
             )
         else:
             setattr(file_object, key, value)
             if key == 'name':
                 self._db_session.add(
                     EventModel(event_type='ITEM_RENAME', source_id=file_object.file_id, source_type='file'),
                 )
             elif key == 'sync_state':
                 event_type = 'ITEM_SYNC' if value == 'synced' else 'ITEM_UNSYNC'
                 self._db_session.add(
                     EventModel(event_type=event_type, source_id=file_object.file_id, source_type='file'),
                 )
     self._db_session.commit()
     return json.dumps(file_object)
Ejemplo n.º 2
0
 def update_file_info(self, file_id):
     file_object = get_file_by_id(self._db_session, file_id)
     self._check_file_lock(file_object)
     params = json.load(request.body)
     for key, value in params.items():
         if not hasattr(FileModel, key):
             abort(400, 'File has no attribute {0}.'.format(key))
         if key == 'parent':
             # Move
             parent_id = value['id']
             parent_folder = get_folder_by_id(self._db_session, parent_id)
             file_object.parent_id = parent_folder.id
             self._db_session.add(
                 EventModel(event_type='ITEM_MOVE',
                            source_id=file_object.file_id,
                            source_type='file'), )
         else:
             setattr(file_object, key, value)
             if key == 'name':
                 self._db_session.add(
                     EventModel(event_type='ITEM_RENAME',
                                source_id=file_object.file_id,
                                source_type='file'), )
             elif key == 'sync_state':
                 event_type = 'ITEM_SYNC' if value == 'synced' else 'ITEM_UNSYNC'
                 self._db_session.add(
                     EventModel(event_type=event_type,
                                source_id=file_object.file_id,
                                source_type='file'), )
     self._db_session.commit()
     return json.dumps(file_object)
Ejemplo n.º 3
0
 def download_file(self, file_id):
     """
     https://developers.box.com/docs/#files-download-a-file
     """
     file_object = get_file_by_id(self._db_session, file_id)
     self._check_file_lock(file_object, is_download=True)
     return file_object.content
Ejemplo n.º 4
0
 def delete_file(self, file_id):
     file_object = get_file_by_id(self._db_session, file_id)
     self._check_file_lock(file_object)
     self._db_session.delete(file_object)
     self._db_session.add(EventModel(event_type='ITEM_TRASH', source_id=file_object.file_id, source_type='file'))
     self._db_session.commit()
     response.status = 204
Ejemplo n.º 5
0
 def download_file(self, file_id):
     """
     https://developers.box.com/docs/#files-download-a-file
     """
     file_object = get_file_by_id(self._db_session, file_id)
     self._check_file_lock(file_object, is_download=True)
     return file_object.content
Ejemplo n.º 6
0
 def copy_file(self, file_id):
     file_object = get_file_by_id(self._db_session, file_id)
     self._check_file_lock(file_object)
     parent_folder = self._get_parent()
     self._db_session.expunge(file_object)
     make_transient(file_object)
     file_object.id = None
     file_object.file_id = None
     file_object.parent_id = parent_folder.id
     self._db_session.add(file_object)
     self._db_session.commit()
     self._db_session.add(EventModel(event_type='ITEM_COPY', source_id=file_object.file_id, source_type='file'))
     self._db_session.commit()
     return json.dumps(file_object)
Ejemplo n.º 7
0
 def update_file(self, file_id):
     """
     https://developers.box.com/docs/#files-upload-a-new-version-of-a-file
     """
     file_object = get_file_by_id(self._db_session, file_id)
     self._check_file_lock(file_object)
     content = request.files.file.file.read()
     file_hash = sha1()
     file_hash.update(content)
     file_object.content = content
     file_object.sha1 = file_hash.hexdigest()
     file_object.size = len(content)
     self._db_session.add(EventModel(event_type='ITEM_UPLOAD', source_id=file_object.file_id, source_type='file'))
     self._db_session.commit()
     return json.dumps(file_object)
Ejemplo n.º 8
0
 def get_file_info(self, file_id):
     """
     https://developers.box.com/docs/#files-get
     """
     file_object = get_file_by_id(self._db_session, file_id)
     return json.dumps(file_object)
Ejemplo n.º 9
0
 def get_file_info(self, file_id):
     """
     https://developers.box.com/docs/#files-get
     """
     file_object = get_file_by_id(self._db_session, file_id)
     return json.dumps(file_object)