def get_revision():
    """
    Retrieve a DocumentCaseRevision to be viewd.

    Returns
    -------
    DocumentCaseRevision[]
        DocumentCaseRevision that matched the given Id.

    ApiException
        Exception if the revision ID given was not fount.
    
    """
    revDocId = request.form.get('revDocId')
    valid_revdoc_id = objectId_is_valid(revDocId)
    if not valid_revdoc_id:
        return ApiException(
            error_type="Validation Error",
            message='The revision document ID given is not valid.',
            status=400)
    revision = dao.get_document_rev(revDocId)
    if revision is None:
        return ApiException(
            error_type="Database Error",
            message='The revision document ID given was not found.',
            status=404)

    body = {
        'new': revision.field_changed.new.to_json(),
        'old': revision.field_changed.old.to_json()
    }
    return ApiResult(body={'revision': body})
Esempio n. 2
0
def tags_remove():
    """
    Remove a tag from all documents and the system tags colleciton.
    
    Returns
    -------
    ObjectID
        ObjectID of the tag removed.
    """
    tagID = request.form.get('tagID')
    password = request.form.get('password')
    if not objectId_is_valid(tagID):
        return ApiException(error_type="Validation Error",
                            message='The tag ID given is not valid.',
                            status=400)
    if not daoAdmin.check_password(
            daoAdmin.get_admin(get_jwt_identity()).password, password):
        return ApiException(
            error_type="Authentication Error",
            message='The password given was does not match our records.',
            status=403)
    tag = dao.remove_tag(tagID)
    if tag is None:
        return ApiException(error_type="Database Error",
                            message='The tag ID given was not found.',
                            status=404)
    return ApiResult(body={'tag': tagID})
Esempio n. 3
0
def documents_view(docID):
    """
    Returns a document to view. 
    
    Parameters
    ----------
    docID : ObjectId
        12-byte MongoDB compliant Object id of the document to be publish.
    
    Returns
    -------
    Document
        Document that is going to be viewed.
    
    ApiException
        If the document id is not valid or if a document with the given id was not found.

    """
    valid_doc_id = objectId_is_valid(docID)
    if not valid_doc_id:
        return ApiException(error_type="Validation Error",
                            message='The documents ID given is not valid.',
                            status=400)
    document = dao.get_document(docID)
    if not document:
        return ApiException(error_type="Database Error",
                            message='The documents ID given was not found.',
                            status=404)
    collab = document.creatoriD
    actors = []
    authors = []
    sections = []
    for author in document.author:
        authors.append(json.loads(author.to_json()))
    for actor in document.actor:
        actors.append(json.loads(actor.to_json()))
    for section in document.section:
        sections.append(json.loads(section.to_json()))
    body = {
        '_id': str(document.id),
        'title': document.title,
        'description': document.description,
        'creatorFullName': collab.first_name + " " + collab.last_name,
        'creatorEmail': collab.email,
        'creationDate': document.creationDate,
        'lastModificationDate': document.lastModificationDate,
        'incidentDate': document.incidentDate,
        'tagsDoc': document.tagsDoc,
        'infrasDocList': document.infrasDocList,
        'damageDocList': document.damageDocList,
        'author': authors,
        'actor': actors,
        'section': sections
    }
    body = json.dumps(body)
    return ApiResult(body={'document': json.loads(body)})
def access_requests_deny():
    """
    Deny the access request of a user.
    
    Parameters
    ----------
    collabID : ObjectId
        12-byte MongoDB compliant Object id of the access request to be denied.
    
    Returns
    -------
    ObjectID
        ObjectID of the access request that was denied.

    ApiException
        If the access request id is not valid or if an access request with the given id was not found.
    """
    collab_id = request.form.get('collabID')
    password = request.form.get('password')
    valid_collab_id = objectId_is_valid(collab_id)
    if not valid_collab_id:
        return ApiException(
            error_type="Validation Error",
            message='The access request ID given is not valid.',
            status=400)
    if not daoAdmin.check_password(
            daoAdmin.get_admin(get_jwt_identity()).password, password):
        return ApiException(
            error_type="Authentication Error",
            message='The password given does not match our records.',
            status=403)
    access_request = dao.deny_access_request(collab_id)
    if access_request is None:
        return ApiException(
            error_type="Database Error",
            message='The access request ID given was not found.',
            status=404)

    # TODO: Use DAOs to retrieve the necessary information.
    return ApiResult(body={'access_request': collab_id})
def collaborators_ban():
    """
    Ban a collaborator. 
    
    Parameters
    ----------
    collabID : ObjectId
        12-byte MongoDB compliant Object id of the collaborator to be banned.
    
    Returns
    -------
    ObjectID
        ObjectID of the collaborator that was banned.
    
    ApiException
        If the collaborators id is not valid or if a collaborator with the given id was not found.

    """
    collab_id = request.form.get('collabID')
    password = request.form.get('password')
    valid_collab_id = objectId_is_valid(collab_id)
    if not valid_collab_id:
        return ApiException(error_type="Validation Error",
                            message='The collaborators ID given is not valid.',
                            status=400)
    if not daoAdmin.check_password(
            daoAdmin.get_admin(get_jwt_identity()).password, password):
        return ApiException(
            error_type="Authentication Error",
            message='The password given does not match our records.',
            status=403)
    collaborator = dao.ban_collaborator(collab_id)
    if collaborator is None:
        return ApiException(
            error_type="Database Error",
            message='The collaborators ID given was not found.',
            status=404)

    return ApiResult(body={'collaborator': collab_id})
Esempio n. 6
0
def documents_publish():
    """
    Publish a document. 
    
    Parameters
    ----------
    docID : ObjectId
        12-byte MongoDB compliant Object id of the document to be publish.
    
    Returns
    -------
    ObjectID
        ObjectID of the document that was published.
    
    ApiException
        If the document id is not valid or if a document with the given id was not found.

    """
    doc_id = request.form.get('docID')
    password = request.form.get('password')
    valid_doc_id = objectId_is_valid(doc_id)
    if not valid_doc_id:
        return ApiException(error_type="Validation Error",
                            message='The documents ID given is not valid.',
                            status=400)
    if not daoAdmin.check_password(
            daoAdmin.get_admin(get_jwt_identity()).password, password):
        return ApiException(
            error_type="Authentication Error",
            message='The password given was does not match our records.',
            status=403)
    document = dao.publish_document(doc_id)
    if not document:
        return ApiException(error_type="Database Error",
                            message='The documents ID given was not found.',
                            status=404)
    return ApiResult(body={'docID': doc_id})