Skip to main content

zulip_api/message/
group_setting.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents a group setting value.
6///
7/// Modified from `openapi-generator-cli` output:
8///
9/// ```shell,no_build,no_run
10/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
11/// ```
12///
13/// ```text
14/// /*
15/// * Zulip REST API
16/// *
17/// * Powerful open source group chat
18/// *
19/// * The version of the OpenAPI document: 1.0.0
20/// *
21/// * Generated by: https://openapi-generator.tech
22/// */
23/// ```
24///
25/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
26///
27/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
28#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GroupSetting {
31    /// The ID of the [user group](/help/user-groups) with this permission.
32    GroupId(u64),
33    GroupIds(GroupSettingIds),
34}
35
36impl GroupSetting {
37    /// Creates a new [GroupSetting].
38    pub const fn new() -> Self {
39        Self::GroupId(0)
40    }
41}
42
43impl_default!(GroupSetting);
44impl_display!(GroupSetting);
45
46/// GroupSettingValueOneOf : An object with these fields:
47///
48/// Modified from `openapi-generator-cli` output:
49///
50/// ```shell,no_build,no_run
51/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
52/// ```
53///
54/// ```text
55/// /*
56/// * Zulip REST API
57/// *
58/// * Powerful open source group chat
59/// *
60/// * The version of the OpenAPI document: 1.0.0
61/// *
62/// * Generated by: https://openapi-generator.tech
63/// */
64/// ```
65///
66/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
67///
68/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
69#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
70pub struct GroupSettingIds {
71    #[serde(skip_serializing_if = "Option::is_none")]
72    direct_members: Option<Vec<u64>>,
73    #[serde(skip_serializing_if = "Option::is_none")]
74    direct_subgroups: Option<Vec<u64>>,
75}
76
77impl GroupSettingIds {
78    /// Creates a new [GroupSettingIds].
79    pub const fn new() -> Self {
80        Self {
81            direct_members: None,
82            direct_subgroups: None,
83        }
84    }
85}
86
87field_access! {
88    GroupSettingIds {
89        /// The list of IDs of individual users in the collection of users with this permission.
90        ///
91        /// **Changes**: Prior to Zulip 10.0 (feature level 303), this list would include deactivated users who had the permission before being deactivated.
92        direct_members: option_cow_deref { [u64], Vec<u64> },
93        /// The list of IDs of the groups in the collection of users with this permission.
94        direct_subgroups: option_cow_deref { [u64], Vec<u64> },
95    }
96}
97
98impl_default!(GroupSettingIds);
99impl_display!(GroupSettingIds);
100
101#[cfg(test)]
102mod tests {
103    use super::*;
104
105    #[test]
106    fn test_group_setting_ids() {
107        let direct_members = [1u64];
108        let direct_subgroups = [2u64];
109
110        let ids = GroupSettingIds::new()
111            .with_direct_members(direct_members.as_ref())
112            .with_direct_subgroups(direct_subgroups.as_ref());
113        let ids_json = ids.to_string();
114
115        assert_eq!(serde_json::to_string(&ids).unwrap(), ids_json);
116        assert_eq!(
117            serde_json::from_str::<GroupSettingIds>(&ids_json).unwrap(),
118            ids
119        );
120
121        assert_eq!(ids.direct_members(), Some(direct_members.as_ref()));
122        assert_eq!(ids.direct_subgroups(), Some(direct_subgroups.as_ref()));
123    }
124}