示例#1
0
 def update_document(session, auth_info, doc_id, attributes):
     document = session.query(Document) \
         .filter(Document.id == doc_id).one()
     # To change not supposed to be done in Controller
     documents = session.query(Document).join(ValidationStatus).filter(
         and_(Document.id == doc_id,
              ValidationStatus.status == Status.InValidation)).all()
     doc_count = len([doc for doc in documents
                      if doc.owner_id() == auth_info['user_id']])
     if Document.is_allowed(auth_info) or doc_count > 0:
         ArchiveController.create_archive(document.serialize())
         document.update(attributes)
         session.add(document)
         return document
     else:
         raise AuthError
示例#2
0
def get_archive(doc_id, auth_info):
    try:
        DocController.get_document_by_id(doc_id, auth_info)
    except NoResultFound:
        raise NotFound("Document does not exist")
    archive = ArchiveController.get_archive(doc_id)
    return ResponseOK(archive)
示例#3
0
 def delete_document_file(session, auth_info, doc_id):
     document = session.query(Document) \
         .filter(Document.id == doc_id).one()
     if document:
         if document.is_owner(auth_info) or \
            Document.is_allowed(auth_info):
             filename = document.file
             if filename:
                 ArchiveController.create_archive(document.serialize())
                 document.update({
                     'file': None
                 })
                 session.add(document)
                 return document
             else:
                 raise NotFound
         else:
             raise AuthError
     else:
         raise NotFound
示例#4
0
 def delete_documents(session, *args):
     an_id = args[0]
     attributes = args[1]
     documents = session.query(Document).filter(
         Document.id == an_id).all()
     doc_count = len([doc for doc in documents
                      if doc.owner_id() == attributes['user_id']])
     if Document.is_allowed(attributes) or doc_count > 0:
         # we also remove the associated image
         # located in 'UPLOAD_FOLDER' directory
         a_doc = session.query(Document).filter(
             Document.id == an_id).one()
         if a_doc:
             ArchiveController.create_archive(a_doc.serialize())
             session.delete(a_doc)
         try:
             os.remove(UPLOAD_FOLDER + '/' + a_doc.file)
             return a_doc
         except Exception as e:
             print(e)
             info_logger.error(e)
     else:
         raise AuthError
示例#5
0
 def test_get_archive(self):
     print("get the archives")
     expected_response = [{
         'positionZ': None,
         'source': 'source1',
         'quaternionW': None,
         'user_id': 1,
         'refDate': None,
         'id': 3,
         'positionX': 12.0,
         'quaternionX': None,
         'rightsHolder': None,
         'version': 3,
         'quaternionY': None,
         'title': 'title',
         'description': 'a new description',
         'doc_id': 1,
         'file': '1.gif',
         'quaternionZ': None,
         'positionY': 15.0,
         'publicationDate': None,
     }, {
         'positionZ': None,
         'source': 'source1',
         'quaternionW': None,
         'user_id': 1,
         'refDate': None,
         'id': 2,
         'positionX': 12.0,
         'quaternionX': None,
         'rightsHolder': None,
         'version': 2,
         'quaternionY': None,
         'title': 'title',
         'description': 'description of a document',
         'doc_id': 1,
         'file': '1.gif',
         'quaternionZ': None,
         'positionY': None,
         'publicationDate': None,
     }, {
         'positionZ': None,
         'source': 'source1',
         'quaternionW': None,
         'user_id': 1,
         'refDate': None,
         'id': 1,
         'positionX': None,
         'quaternionX': None,
         'rightsHolder': None,
         'version': 1,
         'quaternionY': None,
         'title': 'title',
         'description': 'a description',
         'doc_id': 1,
         'file': '1.gif',
         'quaternionZ': None,
         'positionY': None,
         'publicationDate': None
     }]
     assert expected_response == ArchiveController.get_archive(1)