jira_api_v2/apis/
group_and_user_picker_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 [`find_users_and_groups`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum FindUsersAndGroupsError {
22    Status400(),
23    Status401(),
24    Status403(),
25    UnknownValue(serde_json::Value),
26}
27
28
29/// Returns a list of users and groups matching a string. The string is used:   *  for users, to find a case-insensitive match with display name and e-mail address. Note that if a user has hidden their email address in their user profile, partial matches of the email address will not find the user. An exact match is required.  *  for groups, to find a case-sensitive match with group name.  For example, if the string *tin* is used, records with the display name *Tina*, email address *sarah@tinplatetraining.com*, and the group *accounting* would be returned.  Optionally, the search can be refined to:   *  the projects and issue types associated with a custom field, such as a user picker. The search can then be further refined to return only users and groups that have permission to view specific:           *  projects.      *  issue types.          If multiple projects or issue types are specified, they must be a subset of those enabled for the custom field or no results are returned. For example, if a field is enabled for projects A, B, and C then the search could be limited to projects B and C. However, if the search is limited to projects B and D, nothing is returned.  *  not return Connect app users and groups.  *  return groups that have a case-insensitive match with the query.  The primary use case for this resource is to populate a picker field suggestion list with users or groups. To this end, the returned object includes an `html` field for each list. This field highlights the matched query term in the item name with the HTML strong tag. Also, each list is wrapped in a response object that contains a header for use in a picker, specifically *Showing X of Y matching groups*.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Browse users and groups* [global permission](https://confluence.atlassian.com/x/yodKLg).
30pub async fn find_users_and_groups(configuration: &configuration::Configuration, query: &str, max_results: Option<i32>, show_avatar: Option<bool>, field_id: Option<&str>, project_id: Option<Vec<String>>, issue_type_id: Option<Vec<String>>, avatar_size: Option<&str>, case_insensitive: Option<bool>, exclude_connect_addons: Option<bool>) -> Result<models::FoundUsersAndGroups, Error<FindUsersAndGroupsError>> {
31    // add a prefix to parameters to efficiently prevent name collisions
32    let p_query = query;
33    let p_max_results = max_results;
34    let p_show_avatar = show_avatar;
35    let p_field_id = field_id;
36    let p_project_id = project_id;
37    let p_issue_type_id = issue_type_id;
38    let p_avatar_size = avatar_size;
39    let p_case_insensitive = case_insensitive;
40    let p_exclude_connect_addons = exclude_connect_addons;
41
42    let uri_str = format!("{}/rest/api/2/groupuserpicker", configuration.base_path);
43    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
44
45    req_builder = req_builder.query(&[("query", &p_query.to_string())]);
46    if let Some(ref param_value) = p_max_results {
47        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
48    }
49    if let Some(ref param_value) = p_show_avatar {
50        req_builder = req_builder.query(&[("showAvatar", &param_value.to_string())]);
51    }
52    if let Some(ref param_value) = p_field_id {
53        req_builder = req_builder.query(&[("fieldId", &param_value.to_string())]);
54    }
55    if let Some(ref param_value) = p_project_id {
56        req_builder = match "multi" {
57            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("projectId".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
58            _ => req_builder.query(&[("projectId", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
59        };
60    }
61    if let Some(ref param_value) = p_issue_type_id {
62        req_builder = match "multi" {
63            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("issueTypeId".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
64            _ => req_builder.query(&[("issueTypeId", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
65        };
66    }
67    if let Some(ref param_value) = p_avatar_size {
68        req_builder = req_builder.query(&[("avatarSize", &param_value.to_string())]);
69    }
70    if let Some(ref param_value) = p_case_insensitive {
71        req_builder = req_builder.query(&[("caseInsensitive", &param_value.to_string())]);
72    }
73    if let Some(ref param_value) = p_exclude_connect_addons {
74        req_builder = req_builder.query(&[("excludeConnectAddons", &param_value.to_string())]);
75    }
76    if let Some(ref user_agent) = configuration.user_agent {
77        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78    }
79    if let Some(ref token) = configuration.oauth_access_token {
80        req_builder = req_builder.bearer_auth(token.to_owned());
81    };
82    if let Some(ref auth_conf) = configuration.basic_auth {
83        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
84    };
85
86    let req = req_builder.build()?;
87    let resp = configuration.client.execute(req).await?;
88
89    let status = resp.status();
90
91    if !status.is_client_error() && !status.is_server_error() {
92        let content = resp.text().await?;
93        serde_json::from_str(&content).map_err(Error::from)
94    } else {
95        let content = resp.text().await?;
96        let entity: Option<FindUsersAndGroupsError> = serde_json::from_str(&content).ok();
97        Err(Error::ResponseError(ResponseContent { status, content, entity }))
98    }
99}
100