weirdnet-songnotes 0.3.0

SongNotes collaboration: the roles, permissions, links and consent requests for a SongNotes session, built on weirdnet-collab.
Documentation
//! The SongNotes roles and their presets.
use crate::perm::*;
use weirdnet_collab::{Gate, RoleSpec, RoleTable};

/// The host role (the project's owner).
pub const HOST: &str = "host";
/// May change the project.
pub const EDITOR: &str = "editor";
/// Hears, exports and routes, but does not change the project.
pub const ENGINEER: &str = "engineer";
/// Watches and listens; the default for a new invitee.
pub const VIEWER: &str = "viewer";
/// Only listens.
pub const LISTENER: &str = "listener";

/// The name shown for the local mic switch gate.
pub const MIC_SWITCH: &str = "mic switch";

/// The SongNotes role table.
///
/// * Host: everything, but the audio owner's consent and the local mic switch still apply.
/// * Editor: edit, load, save, publish, listen, export, talk, viewer links, and record with consent.
/// * Engineer: listen, export, route (connect with consent and manage), record with consent, talk.
/// * Viewer: presence, listen, talkback listen and chat. The default role.
/// * Listener: recording and stream listening, chat reading and talkback listening.
pub fn roles() -> RoleTable {
    RoleTable::new()
        .role(HOST, host_spec())
        .role(
            EDITOR,
            RoleSpec::with(&[
                SESSION_JOIN,
                SESSION_INVITE,
                PRESENCE_READ,
                PROJECT_EDIT,
                PROJECT_LOAD,
                PROJECT_SAVE,
                RECORDING_LISTEN,
                RECORDING_EXPORT,
                FEED_READ,
                FEED_WRITE,
                STREAM_PUBLISH,
                STREAM_SUBSCRIBE,
                STREAM_RECORD,
                ROUTE_PUBLISH,
                MIC_TALK,
                MIC_LISTEN,
                CHAT_READ,
                CHAT_WRITE,
            ])
            .inviting(&[VIEWER]),
        )
        .role(
            ENGINEER,
            RoleSpec::with(&[
                SESSION_JOIN,
                PRESENCE_READ,
                RECORDING_LISTEN,
                RECORDING_EXPORT,
                FEED_READ,
                STREAM_SUBSCRIBE,
                STREAM_RECORD,
                ROUTE_PUBLISH,
                ROUTE_CONNECT,
                ROUTE_MANAGE,
                MIC_TALK,
                MIC_LISTEN,
                CHAT_READ,
                CHAT_WRITE,
            ]),
        )
        .role(
            VIEWER,
            RoleSpec::with(&[SESSION_JOIN, PRESENCE_READ, RECORDING_LISTEN, FEED_READ, STREAM_SUBSCRIBE, MIC_LISTEN, CHAT_READ, CHAT_WRITE]),
        )
        .role(LISTENER, RoleSpec::with(&[SESSION_JOIN, RECORDING_LISTEN, STREAM_SUBSCRIBE, CHAT_READ, MIC_LISTEN]))
        .with_host(HOST)
        .with_default_role(VIEWER)
        .gate(STREAM_RECORD, Gate::OwnerConsent)
        .gate(MIC_RECORD, Gate::OwnerConsent)
        .gate(ROUTE_CONNECT, Gate::OwnerConsent)
        .gate(MIC_TALK, Gate::Local(MIC_SWITCH.into()))
}

/// The host holds every permission, listed so the catalog shows them, and may invite as any other role.
fn host_spec() -> RoleSpec {
    RoleSpec { all: true, ..RoleSpec::with(ALL) }.inviting(&[EDITOR, ENGINEER, VIEWER, LISTENER])
}