Skip to main content

zulip_api/message/
realm_create_public_stream_policy.rs

1use serde_repr::{Deserialize_repr, Serialize_repr};
2
3use crate::{impl_default, impl_display};
4
5/// A deprecated representation of a superset of the users who have permission to create private channels in the organization, available for backwards-compatibility.
6///
7/// Clients should use `can_create_public_channel_group` instead.
8///
9/// It is an enum with the following possible values, corresponding to roles/system groups:
10///
11/// - 1: Members only
12/// - 2: Admins only
13/// - 3: [Full members](https://zulip.com/api/roles-and-permissions#determining-if-a-user-is-a-full-member) only
14/// - 4: Admins and moderators only
15///
16/// **Changes**: Deprecated in Zulip 9.0 (feature level 264) and replaced by `realm_can_create_public_channel_group`,
17/// which supports finer resolution of configurations, resulting in this property being inaccurate following that transition.
18///
19/// **Changes**: Before Zulip 5.0 (feature level 102), permission to create channels was controlled by the `realm_create_stream_policy` setting.
20///
21/// [permission-level](https://zulip.com/api/roles-and-permissions#permission-levels)
22#[repr(u8)]
23#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize_repr, Serialize_repr)]
24pub enum RealmCreatePublicStreamPolicy {
25    /// Members only
26    MembersOnly = 1,
27    /// Admins only
28    AdminsOnly = 2,
29    /// Full members
30    FullMembers = 3,
31    /// Admins and moderators only
32    Admins = 4,
33}
34
35impl RealmCreatePublicStreamPolicy {
36    /// Represents the string value of the members only policy.
37    pub const MEMBERS_ONLY: &str = "members_only";
38    /// Represents the string value of the admins only policy.
39    pub const ADMINS_ONLY: &str = "admins_only";
40    /// Represents the string value of the full members policy.
41    pub const FULL_MEMBERS: &str = "full_members";
42    /// Represents the string value of the admins or moderators policy.
43    pub const ADMINS: &str = "admins";
44
45    /// Creates a new [Self].
46    pub const fn new() -> Self {
47        Self::MembersOnly
48    }
49
50    /// Gets the string representation of the [Self].
51    pub const fn as_str(&self) -> &'static str {
52        match self {
53            Self::MembersOnly => Self::MEMBERS_ONLY,
54            Self::AdminsOnly => Self::ADMINS_ONLY,
55            Self::FullMembers => Self::FULL_MEMBERS,
56            Self::Admins => Self::ADMINS,
57        }
58    }
59}
60
61impl_default!(RealmCreatePublicStreamPolicy);
62impl_display!(RealmCreatePublicStreamPolicy: str);