zulip-api 0.0.8

Client library for interacting with the Zulip API
Documentation
use serde::{Deserialize, Serialize};

use crate::{field_access, impl_default, impl_display, GroupSetting};

/// Represents the user group's attributes.
///
/// Modified from `openapi-generator-cli` output:
///
/// ```shell,no_build,no_run
/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
/// ```
///
/// ```text
/// /*
/// * Zulip REST API
/// *
/// * Powerful open source group chat
/// *
/// * The version of the OpenAPI document: 1.0.0
/// *
/// * Generated by: https://openapi-generator.tech
/// */
/// ```
///
/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
///
/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UserGroup {
    #[serde(skip_serializing_if = "Option::is_none")]
    name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    date_created: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    creator_id: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    members: Option<Vec<u64>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    direct_subgroup_ids: Option<Vec<u64>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    id: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    is_system_group: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    can_add_members_group: Option<GroupSetting>,
    #[serde(skip_serializing_if = "Option::is_none")]
    can_join_group: Option<GroupSetting>,
    #[serde(skip_serializing_if = "Option::is_none")]
    can_leave_group: Option<GroupSetting>,
    #[serde(skip_serializing_if = "Option::is_none")]
    can_manage_group: Option<GroupSetting>,
    #[serde(skip_serializing_if = "Option::is_none")]
    can_mention_group: Option<GroupSetting>,
    #[serde(skip_serializing_if = "Option::is_none")]
    can_remove_members_group: Option<GroupSetting>,
    #[serde(skip_serializing_if = "Option::is_none")]
    deactivated: Option<bool>,
}

impl UserGroup {
    /// Creates a new [UserGroup].
    pub const fn new() -> Self {
        Self {
            name: None,
            date_created: None,
            creator_id: None,
            description: None,
            members: None,
            direct_subgroup_ids: None,
            id: None,
            is_system_group: None,
            can_add_members_group: None,
            can_join_group: None,
            can_leave_group: None,
            can_manage_group: None,
            can_mention_group: None,
            can_remove_members_group: None,
            deactivated: None,
        }
    }
}

field_access! {
    UserGroup {
        /// The name of the user group.
        name: option_cow_deref { str, String },
        /// The description of the user group.
        description: option_cow_deref { str, String },
        /// Array containing the ID of the users who are members of this user group.
        ///
        /// **Changes**: Prior to Zulip 10.0 (feature level 303), this list also included deactivated users who were members of the user group before being deactivated.
        members: option_cow_deref { [u64], Vec<u64> },
        /// Array containing the ID of the direct_subgroups of this user group.
        ///
        /// **Changes**: New in Zulip 6.0 (feature level 131).
        /// Introduced in feature level 127 as `subgroups`, but clients can ignore older events as this feature level predates subgroups being fully implemented.
        direct_subgroup_ids: option_cow_deref { [u64], Vec<u64> },
    }
}

field_access! {
    UserGroup {
        /// The UNIX timestamp for when the user group was created, in UTC seconds.
        ///
        /// A `null` value means the user group has no recorded date, which is often because the user group is very old,
        /// or because it was created via a data import tool or [management command](https://zulip.readthedocs.io/en/latest/production/management-commands.html).
        ///
        /// **Changes**: New in Zulip 10.0 (feature level 292).
        date_created: option { u64 },
        /// The ID of the user who created this user group.
        ///
        /// A `null` value means the user group has no recorded creator, which is often because the user group is very old,
        /// or because it was created via a data import tool or [management command](https://zulip.readthedocs.io/en/latest/production/management-commands.html).
        ///
        /// **Changes**: New in Zulip 10.0 (feature level 292).
        creator_id: option { u64 },
        /// The ID of the user group.
        id: option { u64 },
        /// Whether the user group is a system group which cannot be directly modified by users.
        ///
        /// **Changes**: New in Zulip 5.0 (feature level 93).
        is_system_group: option { bool },
        /// Whether the user group is deactivated.
        ///
        /// Deactivated groups cannot be used as a subgroup of another group or used for any other purpose.
        ///
        /// **Changes**: New in Zulip 10.0 (feature level 290).
        deactivated: option { bool },
    }
}

field_access! {
    UserGroup {
        /// A [GroupSetting] defining the set of users who have permission to add members to this user group.
        can_add_members_group: option_ref { GroupSetting },
        /// A [GroupSetting] defining the set of users who have permission to join this user group.
        can_join_group: option_ref { GroupSetting },
        /// A [GroupSetting] defining the set of users who have permission to leave this user group.
        can_leave_group: option_ref { GroupSetting },
        /// A [GroupSetting] defining the set of users who have permission to [manage this user group](https://zuliip.com/help/manage-user-groups).
        can_manage_group: option_ref { GroupSetting },
        /// A [GroupSetting] defining the set of users who have permission to [mention this user group](https://zulip.com/help/mention-a-user-or-group).
        can_mention_group: option_ref { GroupSetting },
        /// A [GroupSetting] defining the set of users who have permission to remove members from this user group.
        can_remove_members_group: option_ref { GroupSetting },
    }
}

impl_default!(UserGroup);
impl_display!(UserGroup);