Ejemplo n.º 1
0
def before_edit_check_permissions(document, original):
    # Allow admin users to do whatever they want.
    # TODO: possibly move this into the check_permissions function.
    if user_has_role(u'admin'):
        return

    check_permissions('projects', original, request.method)
Ejemplo n.º 2
0
def before_edit_check_permissions(document, original):
    # Allow admin users to do whatever they want.
    # TODO: possibly move this into the check_permissions function.
    if user_has_role(u'admin'):
        return

    check_permissions('projects', original, request.method)
Ejemplo n.º 3
0
def before_delete_project(document):
    """Checks permissions before we allow deletion"""

    # Allow admin users to do whatever they want.
    # TODO: possibly move this into the check_permissions function.
    if user_has_role(u'admin'):
        return

    check_permissions('projects', document, request.method)
Ejemplo n.º 4
0
def before_delete_project(document):
    """Checks permissions before we allow deletion"""

    # Allow admin users to do whatever they want.
    # TODO: possibly move this into the check_permissions function.
    if user_has_role(u'admin'):
        return

    check_permissions('projects', document, request.method)
Ejemplo n.º 5
0
def project_quotas(project_id):
    """Returns information about the project's limits."""

    # Check that the user has GET permissions on the project itself.
    project = mongo.find_one_or_404('projects', project_id)
    check_permissions('projects', project, 'GET')

    file_size_used = project_total_file_size(project_id)

    info = {
        'file_size_quota': None,  # TODO: implement this later.
        'file_size_used': file_size_used,
    }

    return jsonify(info)
Ejemplo n.º 6
0
def project_quotas(project_id):
    """Returns information about the project's limits."""

    # Check that the user has GET permissions on the project itself.
    project = mongo.find_one_or_404('projects', project_id)
    check_permissions('projects', project, 'GET')

    file_size_used = project_total_file_size(project_id)

    info = {
        'file_size_quota': None,  # TODO: implement this later.
        'file_size_used': file_size_used,
    }

    return jsonify(info)
Ejemplo n.º 7
0
def project_node_type_has_method(response):
    """Check for a specific request arg, and check generate the allowed_methods
    list for the required node_type.
    """

    node_type_name = request.args.get('node_type', '')

    # Proceed only node_type has been requested
    if not node_type_name:
        return

    # Look up the node type in the project document
    if not any(node_type.get('name') == node_type_name
               for node_type in response['node_types']):
        return abort(404)

    # Check permissions and append the allowed_methods to the node_type
    check_permissions('projects', response, 'GET', append_allowed_methods=True,
                      check_node_type=node_type_name)
Ejemplo n.º 8
0
def before_inserting_nodes(items):
    """Before inserting a node in the collection we check if the user is allowed
    and we append the project id to it.
    """
    nodes_collection = current_app.data.driver.db['nodes']

    def find_parent_project(node):
        """Recursive function that finds the ultimate parent of a node."""
        if node and 'parent' in node:
            parent = nodes_collection.find_one({'_id': node['parent']})
            return find_parent_project(parent)
        if node:
            return node
        else:
            return None

    for item in items:
        check_permissions('nodes', item, 'POST')
        if 'parent' in item and 'project' not in item:
            parent = nodes_collection.find_one({'_id': item['parent']})
            project = find_parent_project(parent)
            if project:
                item['project'] = project['_id']
Ejemplo n.º 9
0
def project_node_type_has_method(response):
    """Check for a specific request arg, and check generate the allowed_methods
    list for the required node_type.
    """

    node_type_name = request.args.get('node_type', '')

    # Proceed only node_type has been requested
    if not node_type_name:
        return

    # Look up the node type in the project document
    if not any(
            node_type.get('name') == node_type_name
            for node_type in response['node_types']):
        return abort(404)

    # Check permissions and append the allowed_methods to the node_type
    check_permissions('projects',
                      response,
                      'GET',
                      append_allowed_methods=True,
                      check_node_type=node_type_name)
Ejemplo n.º 10
0
Archivo: nodes.py Proyecto: JT-a/pillar
def before_inserting_nodes(items):
    """Before inserting a node in the collection we check if the user is allowed
    and we append the project id to it.
    """
    nodes_collection = current_app.data.driver.db['nodes']

    def find_parent_project(node):
        """Recursive function that finds the ultimate parent of a node."""
        if node and 'parent' in node:
            parent = nodes_collection.find_one({'_id': node['parent']})
            return find_parent_project(parent)
        if node:
            return node
        else:
            return None

    for item in items:
        check_permissions('nodes', item, 'POST')
        if 'parent' in item and 'project' not in item:
            parent = nodes_collection.find_one({'_id': item['parent']})
            project = find_parent_project(parent)
            if project:
                item['project'] = project['_id']
Ejemplo n.º 11
0
def before_replacing_node(item, original):
    check_permissions('nodes', original, 'PUT')
    update_file_name(item)
Ejemplo n.º 12
0
def before_returning_node_resource_permissions(response):
    for item in response['_items']:
        check_permissions('nodes', item, 'GET', append_allowed_methods=True)
Ejemplo n.º 13
0
def before_returning_node_permissions(response):
    # Run validation process, since GET on nodes entry point is public
    check_permissions('nodes', response, 'GET', append_allowed_methods=True)
Ejemplo n.º 14
0
Archivo: nodes.py Proyecto: JT-a/pillar
def before_replacing_node(item, original):
    check_permissions('nodes', original, 'PUT')
    update_file_name(item)
Ejemplo n.º 15
0
Archivo: nodes.py Proyecto: JT-a/pillar
def before_returning_node_resource_permissions(response):
    for item in response['_items']:
        check_permissions('nodes', item, 'GET', append_allowed_methods=True)
Ejemplo n.º 16
0
Archivo: nodes.py Proyecto: JT-a/pillar
def before_returning_node_permissions(response):
    # Run validation process, since GET on nodes entry point is public
    check_permissions('nodes', response, 'GET', append_allowed_methods=True)