Beispiel #1
0
def check_home_project_node_permissions(node):
    """Grants POST access to the node when the user has POST access on its parent."""

    parent_node = get_home_project_parent_node(
        node, {
            'permissions': 1,
            'project': 1,
            'node_type': 1
        }, 'check_home_project_node_permissions')
    if parent_node is None or 'permissions' not in parent_node:
        return

    parent_id = parent_node['_id']

    has_access = authorization.has_permissions('nodes', parent_node, 'POST')
    if not has_access:
        log.debug(
            'check_home_project_node_permissions: No POST access to parent node %s, '
            'ignoring.', parent_id)
        return

    # Grant access!
    log.debug(
        'check_home_project_node_permissions: POST access at parent node %s, '
        'so granting POST access to new child node.', parent_id)

    # Make sure the permissions of the parent node are copied to this node.
    node['permissions'] = copy.deepcopy(parent_node['permissions'])
Beispiel #2
0
def before_returning_project_resource_permissions(response):
    # Return only those projects the user has access to.
    allow = []
    for project in response['_items']:
        if authorization.has_permissions('projects', project,
                                         'GET', append_allowed_methods=True):
            allow.append(project)
        else:
            log.debug('User %s requested project %s, but has no access to it; filtered out.',
                      authentication.current_user_id(), project['_id'])

    response['_items'] = allow