Exemple #1
0
def create_permissions(user, service, *permissions):
    permissions = [
        Permission(service_id=service.id, user_id=user.id, permission=p)
        for p in permissions
    ]

    permission_dao.set_user_service_permission(user, service, permissions)
Exemple #2
0
def set_permissions(user_id, service_id):
    # TODO fix security hole, how do we verify that the user
    # who is making this request has permission to make the request.
    service_user = dao_get_service_user(user_id, service_id)
    user = service_user.user
    service = dao_fetch_service_by_id(service_id=service_id)

    data = request.get_json()
    validate(data, post_set_permissions_schema)

    permission_list = [
        Permission(service_id=service_id,
                   user_id=user_id,
                   permission=p['permission']) for p in data['permissions']
    ]

    permission_dao.set_user_service_permission(user,
                                               service,
                                               permission_list,
                                               _commit=True,
                                               replace=True)

    if 'folder_permissions' in data:
        folders = [
            dao_get_template_folder_by_id_and_service_id(
                folder_id, service_id)
            for folder_id in data['folder_permissions']
        ]

        service_user.folders = folders
        dao_update_service_user(service_user)

    return jsonify({}), 204
Exemple #3
0
def set_permissions(user_id, service_id):
    # TODO fix security hole, how do we verify that the user
    # who is making this request has permission to make the request.
    service_user = dao_get_service_user(user_id, service_id)
    user = service_user.user
    service = dao_fetch_service_by_id(service_id=service_id)

    data = request.get_json()
    validate(data, post_set_permissions_schema)

    permission_list = [
        Permission(service_id=service_id, user_id=user_id, permission=p['permission'])
        for p in data['permissions']
    ]

    service_key = "service_id_{}".format(service_id)
    change_dict = {service_key: service_id, "permissions": permission_list}

    try:
        _update_alert(user, change_dict)
    except Exception as e:
        current_app.logger.error(e)

    permission_dao.set_user_service_permission(user, service, permission_list, _commit=True, replace=True)

    if 'folder_permissions' in data:
        folders = [
            dao_get_template_folder_by_id_and_service_id(folder_id, service_id)
            for folder_id in data['folder_permissions']
        ]

        service_user.folders = folders
        dao_update_service_user(service_user)

    return jsonify({}), 204
Exemple #4
0
def dao_add_user_to_service(service,
                            user,
                            permissions=None,
                            folder_permissions=None):
    permissions = permissions or []
    folder_permissions = folder_permissions or []

    try:
        from app.dao.permissions_dao import permission_dao
        service.users.append(user)
        permission_dao.set_user_service_permission(user,
                                                   service,
                                                   permissions,
                                                   _commit=False)
        db.session.add(service)

        service_user = dao_get_service_user(user.id, service.id)
        valid_template_folders = dao_get_valid_template_folders_by_id(
            folder_permissions)
        service_user.folders = valid_template_folders
        db.session.add(service_user)

    except Exception as e:
        db.session.rollback()
        raise e
    else:
        db.session.commit()
def dao_add_user_to_service(service, user, permissions=[]):
    try:
        from app.dao.permissions_dao import permission_dao
        service.users.append(user)
        permission_dao.set_user_service_permission(user, service, permissions, _commit=False)
        db.session.add(service)
    except Exception as e:
        db.session.rollback()
        raise e
    else:
        db.session.commit()
Exemple #6
0
def set_permissions(user_id, service_id):
    # TODO fix security hole, how do we verify that the user
    # who is making this request has permission to make the request.
    user = get_user_by_id(user_id=user_id)
    service = dao_fetch_service_by_id(service_id=service_id)
    permissions, errors = permission_schema.load(request.get_json(), many=True)

    for p in permissions:
        p.user = user
        p.service = service
    permission_dao.set_user_service_permission(user, service, permissions, _commit=True, replace=True)
    return jsonify({}), 204
def dao_add_user_to_service(service, user, permissions=None):
    permissions = permissions or []
    try:
        from app.dao.permissions_dao import permission_dao
        service.users.append(user)
        permission_dao.set_user_service_permission(user, service, permissions, _commit=False)
        db.session.add(service)
    except Exception as e:
        db.session.rollback()
        raise e
    else:
        db.session.commit()
Exemple #8
0
def set_permissions(user_id, service_id):
    # TODO fix security hole, how do we verify that the user
    # who is making this request has permission to make the request.
    user = get_user_by_id(user_id=user_id)
    service = dao_fetch_service_by_id(service_id=service_id)
    permissions, errors = permission_schema.load(request.get_json(), many=True)

    for p in permissions:
        p.user = user
        p.service = service
    permission_dao.set_user_service_permission(user, service, permissions, _commit=True, replace=True)
    return jsonify({}), 204