jira_api_v2/apis/
user_properties_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`delete_user_property`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteUserPropertyError {
22    Status400(),
23    Status401(),
24    Status403(),
25    Status404(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`get_user_property`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetUserPropertyError {
33    Status400(),
34    Status401(),
35    Status403(),
36    Status404(),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`get_user_property_keys`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum GetUserPropertyKeysError {
44    Status400(),
45    Status401(),
46    Status403(),
47    Status404(),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`set_user_property`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum SetUserPropertyError {
55    Status400(),
56    Status401(),
57    Status403(),
58    Status404(),
59    Status405(),
60    UnknownValue(serde_json::Value),
61}
62
63
64/// Deletes a property from a user.  Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira.  **[Permissions](#permissions) required:**   *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to delete a property from any user.  *  Access to Jira, to delete a property from the calling user's record.
65pub async fn delete_user_property(configuration: &configuration::Configuration, property_key: &str, account_id: Option<&str>, user_key: Option<&str>, username: Option<&str>) -> Result<(), Error<DeleteUserPropertyError>> {
66    // add a prefix to parameters to efficiently prevent name collisions
67    let p_property_key = property_key;
68    let p_account_id = account_id;
69    let p_user_key = user_key;
70    let p_username = username;
71
72    let uri_str = format!("{}/rest/api/2/user/properties/{propertyKey}", configuration.base_path, propertyKey=crate::apis::urlencode(p_property_key));
73    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
74
75    if let Some(ref param_value) = p_account_id {
76        req_builder = req_builder.query(&[("accountId", &param_value.to_string())]);
77    }
78    if let Some(ref param_value) = p_user_key {
79        req_builder = req_builder.query(&[("userKey", &param_value.to_string())]);
80    }
81    if let Some(ref param_value) = p_username {
82        req_builder = req_builder.query(&[("username", &param_value.to_string())]);
83    }
84    if let Some(ref user_agent) = configuration.user_agent {
85        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86    }
87    if let Some(ref token) = configuration.oauth_access_token {
88        req_builder = req_builder.bearer_auth(token.to_owned());
89    };
90    if let Some(ref auth_conf) = configuration.basic_auth {
91        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
92    };
93
94    let req = req_builder.build()?;
95    let resp = configuration.client.execute(req).await?;
96
97    let status = resp.status();
98
99    if !status.is_client_error() && !status.is_server_error() {
100        Ok(())
101    } else {
102        let content = resp.text().await?;
103        let entity: Option<DeleteUserPropertyError> = serde_json::from_str(&content).ok();
104        Err(Error::ResponseError(ResponseContent { status, content, entity }))
105    }
106}
107
108/// Returns the value of a user's property. If no property key is provided [Get user property keys](#api-rest-api-2-user-properties-get) is called.  Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira.  **[Permissions](#permissions) required:**   *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to get a property from any user.  *  Access to Jira, to get a property from the calling user's record.
109pub async fn get_user_property(configuration: &configuration::Configuration, property_key: &str, account_id: Option<&str>, user_key: Option<&str>, username: Option<&str>) -> Result<models::EntityProperty, Error<GetUserPropertyError>> {
110    // add a prefix to parameters to efficiently prevent name collisions
111    let p_property_key = property_key;
112    let p_account_id = account_id;
113    let p_user_key = user_key;
114    let p_username = username;
115
116    let uri_str = format!("{}/rest/api/2/user/properties/{propertyKey}", configuration.base_path, propertyKey=crate::apis::urlencode(p_property_key));
117    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
118
119    if let Some(ref param_value) = p_account_id {
120        req_builder = req_builder.query(&[("accountId", &param_value.to_string())]);
121    }
122    if let Some(ref param_value) = p_user_key {
123        req_builder = req_builder.query(&[("userKey", &param_value.to_string())]);
124    }
125    if let Some(ref param_value) = p_username {
126        req_builder = req_builder.query(&[("username", &param_value.to_string())]);
127    }
128    if let Some(ref user_agent) = configuration.user_agent {
129        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130    }
131    if let Some(ref token) = configuration.oauth_access_token {
132        req_builder = req_builder.bearer_auth(token.to_owned());
133    };
134    if let Some(ref auth_conf) = configuration.basic_auth {
135        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
136    };
137
138    let req = req_builder.build()?;
139    let resp = configuration.client.execute(req).await?;
140
141    let status = resp.status();
142
143    if !status.is_client_error() && !status.is_server_error() {
144        let content = resp.text().await?;
145        serde_json::from_str(&content).map_err(Error::from)
146    } else {
147        let content = resp.text().await?;
148        let entity: Option<GetUserPropertyError> = serde_json::from_str(&content).ok();
149        Err(Error::ResponseError(ResponseContent { status, content, entity }))
150    }
151}
152
153/// Returns the keys of all properties for a user.  Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira.  **[Permissions](#permissions) required:**   *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to access the property keys on any user.  *  Access to Jira, to access the calling user's property keys.
154pub async fn get_user_property_keys(configuration: &configuration::Configuration, account_id: Option<&str>, user_key: Option<&str>, username: Option<&str>) -> Result<models::PropertyKeys, Error<GetUserPropertyKeysError>> {
155    // add a prefix to parameters to efficiently prevent name collisions
156    let p_account_id = account_id;
157    let p_user_key = user_key;
158    let p_username = username;
159
160    let uri_str = format!("{}/rest/api/2/user/properties", configuration.base_path);
161    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
162
163    if let Some(ref param_value) = p_account_id {
164        req_builder = req_builder.query(&[("accountId", &param_value.to_string())]);
165    }
166    if let Some(ref param_value) = p_user_key {
167        req_builder = req_builder.query(&[("userKey", &param_value.to_string())]);
168    }
169    if let Some(ref param_value) = p_username {
170        req_builder = req_builder.query(&[("username", &param_value.to_string())]);
171    }
172    if let Some(ref user_agent) = configuration.user_agent {
173        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174    }
175    if let Some(ref token) = configuration.oauth_access_token {
176        req_builder = req_builder.bearer_auth(token.to_owned());
177    };
178    if let Some(ref auth_conf) = configuration.basic_auth {
179        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
180    };
181
182    let req = req_builder.build()?;
183    let resp = configuration.client.execute(req).await?;
184
185    let status = resp.status();
186
187    if !status.is_client_error() && !status.is_server_error() {
188        let content = resp.text().await?;
189        serde_json::from_str(&content).map_err(Error::from)
190    } else {
191        let content = resp.text().await?;
192        let entity: Option<GetUserPropertyKeysError> = serde_json::from_str(&content).ok();
193        Err(Error::ResponseError(ResponseContent { status, content, entity }))
194    }
195}
196
197/// Sets the value of a user's property. Use this resource to store custom data against a user.  Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira.  **[Permissions](#permissions) required:**   *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to set a property on any user.  *  Access to Jira, to set a property on the calling user's record.
198pub async fn set_user_property(configuration: &configuration::Configuration, property_key: &str, body: Option<serde_json::Value>, account_id: Option<&str>, user_key: Option<&str>, username: Option<&str>) -> Result<serde_json::Value, Error<SetUserPropertyError>> {
199    // add a prefix to parameters to efficiently prevent name collisions
200    let p_property_key = property_key;
201    let p_body = body;
202    let p_account_id = account_id;
203    let p_user_key = user_key;
204    let p_username = username;
205
206    let uri_str = format!("{}/rest/api/2/user/properties/{propertyKey}", configuration.base_path, propertyKey=crate::apis::urlencode(p_property_key));
207    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
208
209    if let Some(ref param_value) = p_account_id {
210        req_builder = req_builder.query(&[("accountId", &param_value.to_string())]);
211    }
212    if let Some(ref param_value) = p_user_key {
213        req_builder = req_builder.query(&[("userKey", &param_value.to_string())]);
214    }
215    if let Some(ref param_value) = p_username {
216        req_builder = req_builder.query(&[("username", &param_value.to_string())]);
217    }
218    if let Some(ref user_agent) = configuration.user_agent {
219        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
220    }
221    if let Some(ref token) = configuration.oauth_access_token {
222        req_builder = req_builder.bearer_auth(token.to_owned());
223    };
224    if let Some(ref auth_conf) = configuration.basic_auth {
225        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
226    };
227    req_builder = req_builder.json(&p_body);
228
229    let req = req_builder.build()?;
230    let resp = configuration.client.execute(req).await?;
231
232    let status = resp.status();
233
234    if !status.is_client_error() && !status.is_server_error() {
235        let content = resp.text().await?;
236        serde_json::from_str(&content).map_err(Error::from)
237    } else {
238        let content = resp.text().await?;
239        let entity: Option<SetUserPropertyError> = serde_json::from_str(&content).ok();
240        Err(Error::ResponseError(ResponseContent { status, content, entity }))
241    }
242}
243