zulip-api 0.0.8

Client library for interacting with the Zulip API
Documentation
use serde_repr::{Deserialize_repr, Serialize_repr};

use crate::{impl_default, impl_display};

/// A deprecated representation of a superset of the users who have permission to create private channels in the organization, available for backwards-compatibility.
///
/// Clients should use `can_create_private_channel_group` instead.
///
/// It is an enum with the following possible values, corresponding to roles/system groups:
///
/// - 1: Members only
/// - 2: Admins only
/// - 3: [Full members](https://zulip.com/api/roles-and-permissions#determining-if-a-user-is-a-full-member) only
/// - 4: Admins and moderators only
///
/// **Changes**: Deprecated in Zulip 9.0 (feature level 266) and replaced by `realm_can_create_private_channel_group`,
/// which supports finer resolution of configurations, resulting in this property being inaccurate following that transition.
///
/// **Changes**: Before Zulip 5.0 (feature level 102), permission to create channels was controlled by the `realm_create_stream_policy` setting.
///
/// [permission-level](https://zulip.com/api/roles-and-permissions#permission-levels)
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize_repr, Serialize_repr)]
pub enum RealmCreatePrivateStreamPolicy {
    /// Members only
    MembersOnly = 1,
    /// Admins only
    AdminsOnly = 2,
    /// Full members
    FullMembersOnly = 3,
    /// Admins and moderators only
    Admins = 4,
}

impl RealmCreatePrivateStreamPolicy {
    /// Represents the string value of the members only policy.
    pub const MEMBERS_ONLY: &str = "members_only";
    /// Represents the string value of the admins only policy.
    pub const ADMINS_ONLY: &str = "admins_only";
    /// Represents the string value of the full members policy.
    pub const FULL_MEMBERS_ONLY: &str = "full_members_only";
    /// Represents the string value of the admins or moderators policy.
    pub const ADMINS: &str = "admins";

    /// Creates a new [Self].
    pub const fn new() -> Self {
        Self::MembersOnly
    }

    /// Gets the string representation of the [Self].
    pub const fn as_str(&self) -> &'static str {
        match self {
            Self::MembersOnly => Self::MEMBERS_ONLY,
            Self::AdminsOnly => Self::ADMINS_ONLY,
            Self::FullMembersOnly => Self::FULL_MEMBERS_ONLY,
            Self::Admins => Self::ADMINS,
        }
    }
}

impl_default!(RealmCreatePrivateStreamPolicy);
impl_display!(RealmCreatePrivateStreamPolicy: str);