zulip_api/message/user_group.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display, GroupSetting};
4
5/// Represents the user group's attributes.
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)]
29pub struct UserGroup {
30 #[serde(skip_serializing_if = "Option::is_none")]
31 name: Option<String>,
32 #[serde(skip_serializing_if = "Option::is_none")]
33 date_created: Option<u64>,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 creator_id: Option<u64>,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 description: Option<String>,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 members: Option<Vec<u64>>,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 direct_subgroup_ids: Option<Vec<u64>>,
42 #[serde(skip_serializing_if = "Option::is_none")]
43 id: Option<u64>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 is_system_group: Option<bool>,
46 #[serde(skip_serializing_if = "Option::is_none")]
47 can_add_members_group: Option<GroupSetting>,
48 #[serde(skip_serializing_if = "Option::is_none")]
49 can_join_group: Option<GroupSetting>,
50 #[serde(skip_serializing_if = "Option::is_none")]
51 can_leave_group: Option<GroupSetting>,
52 #[serde(skip_serializing_if = "Option::is_none")]
53 can_manage_group: Option<GroupSetting>,
54 #[serde(skip_serializing_if = "Option::is_none")]
55 can_mention_group: Option<GroupSetting>,
56 #[serde(skip_serializing_if = "Option::is_none")]
57 can_remove_members_group: Option<GroupSetting>,
58 #[serde(skip_serializing_if = "Option::is_none")]
59 deactivated: Option<bool>,
60}
61
62impl UserGroup {
63 /// Creates a new [UserGroup].
64 pub const fn new() -> Self {
65 Self {
66 name: None,
67 date_created: None,
68 creator_id: None,
69 description: None,
70 members: None,
71 direct_subgroup_ids: None,
72 id: None,
73 is_system_group: None,
74 can_add_members_group: None,
75 can_join_group: None,
76 can_leave_group: None,
77 can_manage_group: None,
78 can_mention_group: None,
79 can_remove_members_group: None,
80 deactivated: None,
81 }
82 }
83}
84
85field_access! {
86 UserGroup {
87 /// The name of the user group.
88 name: option_cow_deref { str, String },
89 /// The description of the user group.
90 description: option_cow_deref { str, String },
91 /// Array containing the ID of the users who are members of this user group.
92 ///
93 /// **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.
94 members: option_cow_deref { [u64], Vec<u64> },
95 /// Array containing the ID of the direct_subgroups of this user group.
96 ///
97 /// **Changes**: New in Zulip 6.0 (feature level 131).
98 /// Introduced in feature level 127 as `subgroups`, but clients can ignore older events as this feature level predates subgroups being fully implemented.
99 direct_subgroup_ids: option_cow_deref { [u64], Vec<u64> },
100 }
101}
102
103field_access! {
104 UserGroup {
105 /// The UNIX timestamp for when the user group was created, in UTC seconds.
106 ///
107 /// A `null` value means the user group has no recorded date, which is often because the user group is very old,
108 /// or because it was created via a data import tool or [management command](https://zulip.readthedocs.io/en/latest/production/management-commands.html).
109 ///
110 /// **Changes**: New in Zulip 10.0 (feature level 292).
111 date_created: option { u64 },
112 /// The ID of the user who created this user group.
113 ///
114 /// A `null` value means the user group has no recorded creator, which is often because the user group is very old,
115 /// or because it was created via a data import tool or [management command](https://zulip.readthedocs.io/en/latest/production/management-commands.html).
116 ///
117 /// **Changes**: New in Zulip 10.0 (feature level 292).
118 creator_id: option { u64 },
119 /// The ID of the user group.
120 id: option { u64 },
121 /// Whether the user group is a system group which cannot be directly modified by users.
122 ///
123 /// **Changes**: New in Zulip 5.0 (feature level 93).
124 is_system_group: option { bool },
125 /// Whether the user group is deactivated.
126 ///
127 /// Deactivated groups cannot be used as a subgroup of another group or used for any other purpose.
128 ///
129 /// **Changes**: New in Zulip 10.0 (feature level 290).
130 deactivated: option { bool },
131 }
132}
133
134field_access! {
135 UserGroup {
136 /// A [GroupSetting] defining the set of users who have permission to add members to this user group.
137 can_add_members_group: option_ref { GroupSetting },
138 /// A [GroupSetting] defining the set of users who have permission to join this user group.
139 can_join_group: option_ref { GroupSetting },
140 /// A [GroupSetting] defining the set of users who have permission to leave this user group.
141 can_leave_group: option_ref { GroupSetting },
142 /// A [GroupSetting] defining the set of users who have permission to [manage this user group](https://zuliip.com/help/manage-user-groups).
143 can_manage_group: option_ref { GroupSetting },
144 /// A [GroupSetting] defining the set of users who have permission to [mention this user group](https://zulip.com/help/mention-a-user-or-group).
145 can_mention_group: option_ref { GroupSetting },
146 /// A [GroupSetting] defining the set of users who have permission to remove members from this user group.
147 can_remove_members_group: option_ref { GroupSetting },
148 }
149}
150
151impl_default!(UserGroup);
152impl_display!(UserGroup);