Skip to main content

slack_web_api/api/
admin_auth.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.auth.policy.assignEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.assignEntities): Assign entities to a particular authentication policy.
12///
13/// Send it with [`SlackClient::admin_auth_policy_assign_entities`].
14#[doc(alias = "admin.auth.policy.assignEntities")]
15#[derive(Debug, Clone, PartialEq, Serialize)]
16#[non_exhaustive]
17pub struct AdminAuthPolicyAssignEntitiesRequest {
18    /// The name of the authentication policy to assign the entities to. Currently, `email_password` is the only policy that may be used with this method.
19    pub policy_name: String,
20    /// The type of entity to assign to the policy. Currently, `USER` is supported.
21    pub entity_type: String,
22    /// Array of IDs to assign to the policy.
23    #[serde(serialize_with = "crate::form::as_json")]
24    pub entity_ids: Vec<String>,
25}
26
27impl AdminAuthPolicyAssignEntitiesRequest {
28    pub fn new(
29        policy_name: impl Into<String>,
30        entity_type: impl Into<String>,
31        entity_ids: Vec<String>,
32    ) -> Self {
33        Self {
34            policy_name: policy_name.into(),
35            entity_type: entity_type.into(),
36            entity_ids,
37        }
38    }
39}
40
41impl SlackApiMethod for AdminAuthPolicyAssignEntitiesRequest {
42    const METHOD: &'static str = "admin.auth.policy.assignEntities";
43    type Response = AdminAuthPolicyAssignEntitiesResponse;
44}
45
46/// Successful response of the Slack Web API method [`admin.auth.policy.assignEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.assignEntities).
47#[doc(alias = "admin.auth.policy.assignEntities")]
48#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
49pub struct AdminAuthPolicyAssignEntitiesResponse {
50    /// Fields returned by Slack. This method has no documented response example.
51    #[serde(flatten)]
52    pub extra: serde_json::Map<String, serde_json::Value>,
53    #[serde(
54        default,
55        deserialize_with = "crate::de::opt_object",
56        skip_serializing_if = "Option::is_none"
57    )]
58    pub response_metadata: Option<ResponseMetadata>,
59    #[serde(
60        default,
61        deserialize_with = "crate::de::opt_string",
62        skip_serializing_if = "Option::is_none"
63    )]
64    pub warning: Option<String>,
65}
66
67/// Arguments for the Slack Web API method [`admin.auth.policy.getEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.getEntities): Fetch all the entities assigned to a particular authentication policy by name.
68///
69/// Send it with [`SlackClient::admin_auth_policy_get_entities`].
70#[doc(alias = "admin.auth.policy.getEntities")]
71#[derive(Debug, Clone, PartialEq, Serialize)]
72#[non_exhaustive]
73pub struct AdminAuthPolicyGetEntitiesRequest {
74    /// The name of the policy to fetch entities for. Currently, `email_password` is the only policy that may be used with this method.
75    pub policy_name: String,
76    /// The type of entity to assign to the policy. Currently, `USER` is supported.
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub entity_type: Option<String>,
79    /// The maximum number of items to return. Must be between 1 and 1000, both inclusive.
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub limit: Option<i64>,
82    /// Set `cursor` to `next_cursor` returned by the previous call to list items in the next page.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub cursor: Option<String>,
85}
86
87impl AdminAuthPolicyGetEntitiesRequest {
88    pub fn new(policy_name: impl Into<String>) -> Self {
89        Self {
90            policy_name: policy_name.into(),
91            entity_type: None,
92            limit: None,
93            cursor: None,
94        }
95    }
96
97    pub fn entity_type(mut self, entity_type: impl Into<String>) -> Self {
98        self.entity_type = Some(entity_type.into());
99        self
100    }
101
102    pub fn limit(mut self, limit: i64) -> Self {
103        self.limit = Some(limit);
104        self
105    }
106
107    pub fn cursor(mut self, cursor: impl Into<String>) -> Self {
108        self.cursor = Some(cursor.into());
109        self
110    }
111}
112
113impl SlackApiMethod for AdminAuthPolicyGetEntitiesRequest {
114    const METHOD: &'static str = "admin.auth.policy.getEntities";
115    type Response = AdminAuthPolicyGetEntitiesResponse;
116}
117
118impl CursorPaginated for AdminAuthPolicyGetEntitiesRequest {
119    fn set_cursor(&mut self, cursor: String) {
120        self.cursor = Some(cursor);
121    }
122}
123
124impl NextCursor for AdminAuthPolicyGetEntitiesResponse {
125    fn next_cursor(&self) -> Option<&str> {
126        self.response_metadata.as_ref()?.next_cursor.as_deref()
127    }
128}
129
130/// Successful response of the Slack Web API method [`admin.auth.policy.getEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.getEntities).
131#[doc(alias = "admin.auth.policy.getEntities")]
132#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
133pub struct AdminAuthPolicyGetEntitiesResponse {
134    #[serde(
135        default,
136        deserialize_with = "crate::de::vec",
137        skip_serializing_if = "Vec::is_empty"
138    )]
139    pub entities: Vec<AdminAuthPolicyGetEntitiesResponseEntities>,
140    #[serde(
141        default,
142        deserialize_with = "crate::de::opt_i64",
143        skip_serializing_if = "Option::is_none"
144    )]
145    pub entity_total_count: Option<i64>,
146    #[serde(
147        default,
148        deserialize_with = "crate::de::opt_object",
149        skip_serializing_if = "Option::is_none"
150    )]
151    pub response_metadata: Option<ResponseMetadata>,
152    #[serde(
153        default,
154        deserialize_with = "crate::de::opt_string",
155        skip_serializing_if = "Option::is_none"
156    )]
157    pub warning: Option<String>,
158}
159
160#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
161pub struct AdminAuthPolicyGetEntitiesResponseEntities {
162    #[serde(
163        default,
164        deserialize_with = "crate::de::opt_string",
165        skip_serializing_if = "Option::is_none"
166    )]
167    pub entity_type: Option<String>,
168    #[serde(
169        default,
170        deserialize_with = "crate::de::opt_string",
171        skip_serializing_if = "Option::is_none"
172    )]
173    pub entity_id: Option<String>,
174    #[serde(
175        default,
176        deserialize_with = "crate::de::opt_i64",
177        skip_serializing_if = "Option::is_none"
178    )]
179    pub date_added: Option<i64>,
180}
181
182/// Arguments for the Slack Web API method [`admin.auth.policy.removeEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.removeEntities): Remove specified entities from a specified authentication policy.
183///
184/// Send it with [`SlackClient::admin_auth_policy_remove_entities`].
185#[doc(alias = "admin.auth.policy.removeEntities")]
186#[derive(Debug, Clone, PartialEq, Serialize)]
187#[non_exhaustive]
188pub struct AdminAuthPolicyRemoveEntitiesRequest {
189    /// The name of the policy to remove entities from. Currently, `email_password` is the only policy that may be used with this method.
190    pub policy_name: String,
191    /// The type of entity to assign to the policy. Currently, `USER` is supported.
192    pub entity_type: String,
193    /// Encoded IDs of the entities you'd like to remove from the policy.
194    #[serde(serialize_with = "crate::form::as_json")]
195    pub entity_ids: Vec<String>,
196}
197
198impl AdminAuthPolicyRemoveEntitiesRequest {
199    pub fn new(
200        policy_name: impl Into<String>,
201        entity_type: impl Into<String>,
202        entity_ids: Vec<String>,
203    ) -> Self {
204        Self {
205            policy_name: policy_name.into(),
206            entity_type: entity_type.into(),
207            entity_ids,
208        }
209    }
210}
211
212impl SlackApiMethod for AdminAuthPolicyRemoveEntitiesRequest {
213    const METHOD: &'static str = "admin.auth.policy.removeEntities";
214    type Response = AdminAuthPolicyRemoveEntitiesResponse;
215}
216
217/// Successful response of the Slack Web API method [`admin.auth.policy.removeEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.removeEntities).
218#[doc(alias = "admin.auth.policy.removeEntities")]
219#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
220pub struct AdminAuthPolicyRemoveEntitiesResponse {
221    /// Fields returned by Slack. This method has no documented response example.
222    #[serde(flatten)]
223    pub extra: serde_json::Map<String, serde_json::Value>,
224    #[serde(
225        default,
226        deserialize_with = "crate::de::opt_object",
227        skip_serializing_if = "Option::is_none"
228    )]
229    pub response_metadata: Option<ResponseMetadata>,
230    #[serde(
231        default,
232        deserialize_with = "crate::de::opt_string",
233        skip_serializing_if = "Option::is_none"
234    )]
235    pub warning: Option<String>,
236}
237
238impl SlackClient {
239    /// Calls the Slack Web API method [`admin.auth.policy.assignEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.assignEntities): Assign entities to a particular authentication policy.
240    ///
241    /// Required scopes:
242    ///
243    /// - user token: `admin.users:write`
244    ///
245    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
246    ///
247    /// # Errors
248    ///
249    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
250    #[doc(alias = "admin.auth.policy.assignEntities")]
251    pub async fn admin_auth_policy_assign_entities(
252        &self,
253        request: &AdminAuthPolicyAssignEntitiesRequest,
254    ) -> Result<AdminAuthPolicyAssignEntitiesResponse, SlackError> {
255        self.call(request).await
256    }
257
258    /// Calls the Slack Web API method [`admin.auth.policy.getEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.getEntities): Fetch all the entities assigned to a particular authentication policy by name.
259    ///
260    /// Required scopes:
261    ///
262    /// - user token: `admin.users:read`
263    ///
264    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
265    ///
266    /// # Errors
267    ///
268    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
269    #[doc(alias = "admin.auth.policy.getEntities")]
270    pub async fn admin_auth_policy_get_entities(
271        &self,
272        request: &AdminAuthPolicyGetEntitiesRequest,
273    ) -> Result<AdminAuthPolicyGetEntitiesResponse, SlackError> {
274        self.call(request).await
275    }
276
277    /// Calls the Slack Web API method [`admin.auth.policy.removeEntities`](https://docs.slack.dev/reference/methods/admin.auth.policy.removeEntities): Remove specified entities from a specified authentication policy.
278    ///
279    /// Required scopes:
280    ///
281    /// - user token: `admin.users:write`
282    ///
283    /// Rate limit: Tier 4 (<https://docs.slack.dev/apis/web-api/rate-limits>).
284    ///
285    /// # Errors
286    ///
287    /// Returns [`SlackError::Api`] when Slack answers `"ok": false`; see [`SlackClient::call`] for the other cases.
288    #[doc(alias = "admin.auth.policy.removeEntities")]
289    pub async fn admin_auth_policy_remove_entities(
290        &self,
291        request: &AdminAuthPolicyRemoveEntitiesRequest,
292    ) -> Result<AdminAuthPolicyRemoveEntitiesResponse, SlackError> {
293        self.call(request).await
294    }
295}