Example #1
0
def update_role(role):
    """Synchronize denormalised role configuration."""
    db.session.flush()
    for group in Role.all_groups():
        Subscription.unsubscribe(role=role, channel=channel(group))

    Subscription.subscribe(role, channel(role))
    Subscription.subscribe(role, Notification.GLOBAL)
    for group in role.roles:
        Subscription.subscribe(role, channel(group))
Example #2
0
def update_subscriptions(role_id):
    role = Role.by_id(role_id, deleted=True)
    if role is None:
        return
    Subscription.unsubscribe(role=role, channel=channel(role))
    for group in Role.all_groups():
        Subscription.unsubscribe(role=role, channel=channel(group))

    if role.deleted_at is None and role.type == Role.USER:
        Subscription.subscribe(role, channel(role))
        Subscription.subscribe(role, Notification.GLOBAL)
        for group in role.roles:
            Subscription.subscribe(role, channel(group))
    db.session.commit()
Example #3
0
def update_role(role):
    """Synchronize denormalised role configuration."""
    db.session.flush()
    log.info("Updating: %r", role)
    Subscription.unsubscribe(role=role, channel=channel(role))
    for group in Role.all_groups():
        Subscription.unsubscribe(role=role, channel=channel(group))

    if role.deleted_at is None and role.type == Role.USER:
        Subscription.subscribe(role, channel(role))
        Subscription.subscribe(role, Notification.GLOBAL)
        for group in role.roles:
            Subscription.subscribe(role, channel(group))

    db.session.commit()
def collection(id):
    require(request.authz.logged_in)
    collection = get_db_collection(id)
    channel_name = channel(collection)
    query = Notification.by_channel(channel_name)
    result = DatabaseQueryResult(request, query, schema=NotificationSchema)
    return jsonify(result)
Example #5
0
def collection(id):
    require(request.authz.logged_in)
    collection = get_db_collection(id)
    channel_name = channel(collection)
    query = Notification.by_channel(channel_name)
    result = DatabaseQueryResult(request, query)
    return NotificationSerializer.jsonify_result(result)
Example #6
0
def update_permission(role, collection, read, write, editor_id=None):
    """Update a roles permission to access a given collection."""
    pre = Permission.by_collection_role(collection, role)
    post = Permission.grant(collection, role, read, write)

    params = {'role': role, 'collection': collection}
    if (pre is None or not pre.read) and post.read:
        if role.is_public:
            publish(Events.PUBLISH_COLLECTION,
                    actor_id=editor_id,
                    params=params,
                    channels=[Notification.GLOBAL])
        else:
            publish(Events.GRANT_COLLECTION, actor_id=editor_id, params=params)
    elif pre is not None and pre.read and not post.read:
        publish(Events.REVOKE_COLLECTION, actor_id=editor_id, params=params)
        cchannel = channel(collection)
        Subscription.unsubscribe(role=role, channel=cchannel)

    db.session.commit()
    return post