Skip to main content

slack_web_api/api/
admin_roles.rs

1// このファイルは codegen/generate.py が生成する。手で編集しない
2
3#![allow(unused_imports)]
4
5use crate::objects::*;
6use crate::{
7    CursorPaginated, NextCursor, ResponseMetadata, SlackApiMethod, SlackClient, SlackError,
8};
9use serde::{Deserialize, Serialize};
10
11/// Arguments for the Slack Web API method [`admin.roles.addAssignments`](https://docs.slack.dev/reference/methods/admin.roles.addAssignments): Adds members to the specified role with the specified scopes
12///
13/// Send it with [`SlackClient::admin_roles_add_assignments`].
14#[doc(alias = "admin.roles.addAssignments")]
15#[derive(Debug, Clone, PartialEq, Serialize)]
16#[non_exhaustive]
17pub struct AdminRolesAddAssignmentsRequest {
18    /// ID of the role to which users will be assigned
19    pub role_id: String,
20    /// List of the entity IDs for which roles will be assigned. These can be Org IDs, Team IDs or Channel IDs
21    #[serde(serialize_with = "crate::form::as_json")]
22    pub entity_ids: Vec<String>,
23    /// List of IDs from the users to be added to the given role
24    #[serde(serialize_with = "crate::form::as_json")]
25    pub user_ids: Vec<String>,
26}
27
28impl AdminRolesAddAssignmentsRequest {
29    pub fn new(role_id: impl Into<String>, entity_ids: Vec<String>, user_ids: Vec<String>) -> Self {
30        Self {
31            role_id: role_id.into(),
32            entity_ids,
33            user_ids,
34        }
35    }
36}
37
38impl SlackApiMethod for AdminRolesAddAssignmentsRequest {
39    const METHOD: &'static str = "admin.roles.addAssignments";
40    type Response = AdminRolesAddAssignmentsResponse;
41}
42
43/// Successful response of the Slack Web API method [`admin.roles.addAssignments`](https://docs.slack.dev/reference/methods/admin.roles.addAssignments).
44#[doc(alias = "admin.roles.addAssignments")]
45#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
46pub struct AdminRolesAddAssignmentsResponse {
47    /// Fields returned by Slack. This method has no documented response example.
48    #[serde(flatten)]
49    pub extra: serde_json::Map<String, serde_json::Value>,
50    #[serde(
51        default,
52        deserialize_with = "crate::de::opt_object",
53        skip_serializing_if = "Option::is_none"
54    )]
55    pub response_metadata: Option<ResponseMetadata>,
56    #[serde(
57        default,
58        deserialize_with = "crate::de::opt_string",
59        skip_serializing_if = "Option::is_none"
60    )]
61    pub warning: Option<String>,
62}
63
64/// Arguments for the Slack Web API method [`admin.roles.listAssignments`](https://docs.slack.dev/reference/methods/admin.roles.listAssignments): Lists assignments for all roles across entities. Options to scope results by any combination of roles or entities
65///
66/// Send it with [`SlackClient::admin_roles_list_assignments`].
67#[doc(alias = "admin.roles.listAssignments")]
68#[derive(Debug, Clone, PartialEq, Serialize, Default)]
69#[non_exhaustive]
70pub struct AdminRolesListAssignmentsRequest {
71    /// Set `cursor` to `next_cursor` returned by the previous call to list items in the next page
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub cursor: Option<String>,
74    /// The maximum number of items to return. Must be between 1 - 200 both inclusive.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub limit: Option<i64>,
77    /// collection of role ids to scope results by
78    #[serde(
79        skip_serializing_if = "Option::is_none",
80        serialize_with = "crate::form::as_json"
81    )]
82    pub role_ids: Option<Vec<String>>,
83    /// The entities for which the roles apply
84    #[serde(
85        skip_serializing_if = "Option::is_none",
86        serialize_with = "crate::form::as_json"
87    )]
88    pub entity_ids: Option<Vec<String>>,
89    /// Sort direction. Default is descending on date\_create, can be either ASC or DESC
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub sort_dir: Option<String>,
92}
93
94impl AdminRolesListAssignmentsRequest {
95    pub fn new() -> Self {
96        Self {
97            cursor: None,
98            limit: None,
99            role_ids: None,
100            entity_ids: None,
101            sort_dir: None,
102        }
103    }
104
105    pub fn cursor(mut self, cursor: impl Into<String>) -> Self {
106        self.cursor = Some(cursor.into());
107        self
108    }
109
110    pub fn limit(mut self, limit: i64) -> Self {
111        self.limit = Some(limit);
112        self
113    }
114
115    pub fn role_ids(mut self, role_ids: Vec<String>) -> Self {
116        self.role_ids = Some(role_ids);
117        self
118    }
119
120    pub fn entity_ids(mut self, entity_ids: Vec<String>) -> Self {
121        self.entity_ids = Some(entity_ids);
122        self
123    }
124
125    pub fn sort_dir(mut self, sort_dir: impl Into<String>) -> Self {
126        self.sort_dir = Some(sort_dir.into());
127        self
128    }
129}
130
131impl SlackApiMethod for AdminRolesListAssignmentsRequest {
132    const METHOD: &'static str = "admin.roles.listAssignments";
133    type Response = AdminRolesListAssignmentsResponse;
134}
135
136impl CursorPaginated for AdminRolesListAssignmentsRequest {
137    fn set_cursor(&mut self, cursor: String) {
138        self.cursor = Some(cursor);
139    }
140}
141
142impl NextCursor for AdminRolesListAssignmentsResponse {
143    fn next_cursor(&self) -> Option<&str> {
144        self.response_metadata.as_ref()?.next_cursor.as_deref()
145    }
146}
147
148/// Successful response of the Slack Web API method [`admin.roles.listAssignments`](https://docs.slack.dev/reference/methods/admin.roles.listAssignments).
149#[doc(alias = "admin.roles.listAssignments")]
150#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
151pub struct AdminRolesListAssignmentsResponse {
152    #[serde(
153        default,
154        deserialize_with = "crate::de::vec",
155        skip_serializing_if = "Vec::is_empty"
156    )]
157    pub role_assignments: Vec<AdminRolesListAssignmentsResponseRoleAssignments>,
158    #[serde(
159        default,
160        deserialize_with = "crate::de::opt_object",
161        skip_serializing_if = "Option::is_none"
162    )]
163    pub response_metadata: Option<ResponseMetadata>,
164    #[serde(
165        default,
166        deserialize_with = "crate::de::opt_string",
167        skip_serializing_if = "Option::is_none"
168    )]
169    pub warning: Option<String>,
170}
171
172#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
173pub struct AdminRolesListAssignmentsResponseRoleAssignments {
174    #[serde(
175        default,
176        deserialize_with = "crate::de::opt_string",
177        skip_serializing_if = "Option::is_none"
178    )]
179    pub role_id: Option<String>,
180    #[serde(
181        default,
182        deserialize_with = "crate::de::opt_string",
183        skip_serializing_if = "Option::is_none"
184    )]
185    pub entity_id: Option<String>,
186    #[serde(
187        default,
188        deserialize_with = "crate::de::opt_string",
189        skip_serializing_if = "Option::is_none"
190    )]
191    pub user_id: Option<String>,
192    #[serde(
193        default,
194        deserialize_with = "crate::de::opt_i64",
195        skip_serializing_if = "Option::is_none"
196    )]
197    pub date_create: Option<i64>,
198}
199
200/// Arguments for the Slack Web API method [`admin.roles.removeAssignments`](https://docs.slack.dev/reference/methods/admin.roles.removeAssignments): Removes a set of users from a role for the given scopes and entities
201///
202/// Send it with [`SlackClient::admin_roles_remove_assignments`].
203#[doc(alias = "admin.roles.removeAssignments")]
204#[derive(Debug, Clone, PartialEq, Serialize)]
205#[non_exhaustive]
206pub struct AdminRolesRemoveAssignmentsRequest {
207    /// ID of the role to which users will be assigned
208    pub role_id: String,
209    /// List of the entity IDs for which roles will be revoked. These can be Org IDs, Team IDs or Channel IDs
210    #[serde(serialize_with = "crate::form::as_json")]
211    pub entity_ids: Vec<String>,
212    /// List of IDs of the users whose roles will be revoked
213    #[serde(serialize_with = "crate::form::as_json")]
214    pub user_ids: Vec<String>,
215}
216
217impl AdminRolesRemoveAssignmentsRequest {
218    pub fn new(role_id: impl Into<String>, entity_ids: Vec<String>, user_ids: Vec<String>) -> Self {
219        Self {
220            role_id: role_id.into(),
221            entity_ids,
222            user_ids,
223        }
224    }
225}
226
227impl SlackApiMethod for AdminRolesRemoveAssignmentsRequest {
228    const METHOD: &'static str = "admin.roles.removeAssignments";
229    type Response = AdminRolesRemoveAssignmentsResponse;
230}
231
232/// Successful response of the Slack Web API method [`admin.roles.removeAssignments`](https://docs.slack.dev/reference/methods/admin.roles.removeAssignments).
233#[doc(alias = "admin.roles.removeAssignments")]
234#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
235pub struct AdminRolesRemoveAssignmentsResponse {
236    /// Fields returned by Slack. This method has no documented response example.
237    #[serde(flatten)]
238    pub extra: serde_json::Map<String, serde_json::Value>,
239    #[serde(
240        default,
241        deserialize_with = "crate::de::opt_object",
242        skip_serializing_if = "Option::is_none"
243    )]
244    pub response_metadata: Option<ResponseMetadata>,
245    #[serde(
246        default,
247        deserialize_with = "crate::de::opt_string",
248        skip_serializing_if = "Option::is_none"
249    )]
250    pub warning: Option<String>,
251}
252
253impl SlackClient {
254    /// Calls the Slack Web API method [`admin.roles.addAssignments`](https://docs.slack.dev/reference/methods/admin.roles.addAssignments): Adds members to the specified role with the specified scopes
255    ///
256    /// Required scopes:
257    ///
258    /// - user token: `admin.roles:write`
259    ///
260    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
261    ///
262    /// # Errors
263    ///
264    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
265    #[doc(alias = "admin.roles.addAssignments")]
266    pub async fn admin_roles_add_assignments(
267        &self,
268        request: &AdminRolesAddAssignmentsRequest,
269    ) -> Result<AdminRolesAddAssignmentsResponse, SlackError> {
270        self.call(request).await
271    }
272
273    /// Calls the Slack Web API method [`admin.roles.listAssignments`](https://docs.slack.dev/reference/methods/admin.roles.listAssignments): Lists assignments for all roles across entities. Options to scope results by any combination of roles or entities
274    ///
275    /// Required scopes:
276    ///
277    /// - user token: `admin.roles:read`
278    ///
279    /// Rate limit: Tier 3 (<https://docs.slack.dev/apis/web-api/rate-limits>).
280    ///
281    /// # Errors
282    ///
283    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
284    #[doc(alias = "admin.roles.listAssignments")]
285    pub async fn admin_roles_list_assignments(
286        &self,
287        request: &AdminRolesListAssignmentsRequest,
288    ) -> Result<AdminRolesListAssignmentsResponse, SlackError> {
289        self.call(request).await
290    }
291
292    /// Calls the Slack Web API method [`admin.roles.removeAssignments`](https://docs.slack.dev/reference/methods/admin.roles.removeAssignments): Removes a set of users from a role for the given scopes and entities
293    ///
294    /// Required scopes:
295    ///
296    /// - user token: `admin.roles:write`
297    ///
298    /// Rate limit: Tier 2 (<https://docs.slack.dev/apis/web-api/rate-limits>).
299    ///
300    /// # Errors
301    ///
302    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
303    #[doc(alias = "admin.roles.removeAssignments")]
304    pub async fn admin_roles_remove_assignments(
305        &self,
306        request: &AdminRolesRemoveAssignmentsRequest,
307    ) -> Result<AdminRolesRemoveAssignmentsResponse, SlackError> {
308        self.call(request).await
309    }
310}