jira_api_v2/apis/
permissions_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 [`get_all_permissions`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAllPermissionsError {
22    Status401(),
23    Status403(),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`get_bulk_permissions`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetBulkPermissionsError {
31    Status400(models::ErrorCollection),
32    Status403(models::ErrorCollection),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`get_my_permissions`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetMyPermissionsError {
40    Status400(models::ErrorCollection),
41    Status401(models::ErrorCollection),
42    Status404(models::ErrorCollection),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_permitted_projects`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetPermittedProjectsError {
50    Status400(),
51    Status401(),
52    UnknownValue(serde_json::Value),
53}
54
55
56/// Returns all permissions, including:   *  global permissions.  *  project permissions.  *  global permissions added by plugins.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
57pub async fn get_all_permissions(configuration: &configuration::Configuration, ) -> Result<models::Permissions, Error<GetAllPermissionsError>> {
58
59    let uri_str = format!("{}/rest/api/2/permissions", configuration.base_path);
60    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
61
62    if let Some(ref user_agent) = configuration.user_agent {
63        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64    }
65    if let Some(ref token) = configuration.oauth_access_token {
66        req_builder = req_builder.bearer_auth(token.to_owned());
67    };
68    if let Some(ref auth_conf) = configuration.basic_auth {
69        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
70    };
71
72    let req = req_builder.build()?;
73    let resp = configuration.client.execute(req).await?;
74
75    let status = resp.status();
76
77    if !status.is_client_error() && !status.is_server_error() {
78        let content = resp.text().await?;
79        serde_json::from_str(&content).map_err(Error::from)
80    } else {
81        let content = resp.text().await?;
82        let entity: Option<GetAllPermissionsError> = serde_json::from_str(&content).ok();
83        Err(Error::ResponseError(ResponseContent { status, content, entity }))
84    }
85}
86
87/// Returns:   *  for a list of global permissions, the global permissions granted to a user.  *  for a list of project permissions and lists of projects and issues, for each project permission a list of the projects and issues a user can access or manipulate.  If no account ID is provided, the operation returns details for the logged in user.  Note that:   *  Invalid project and issue IDs are ignored.  *  A maximum of 1000 projects and 1000 issues can be checked.  *  Null values in `globalPermissions`, `projectPermissions`, `projectPermissions.projects`, and `projectPermissions.issues` are ignored.  *  Empty strings in `projectPermissions.permissions` are ignored.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg) to check the permissions for other users, otherwise none. However, Connect apps can make a call from the app server to the product to obtain permission details for any user, without admin permission. This Connect app ability doesn't apply to calls made using AP.request() in a browser.
88pub async fn get_bulk_permissions(configuration: &configuration::Configuration, bulk_permissions_request_bean: models::BulkPermissionsRequestBean) -> Result<models::BulkPermissionGrants, Error<GetBulkPermissionsError>> {
89    // add a prefix to parameters to efficiently prevent name collisions
90    let p_bulk_permissions_request_bean = bulk_permissions_request_bean;
91
92    let uri_str = format!("{}/rest/api/2/permissions/check", configuration.base_path);
93    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
94
95    if let Some(ref user_agent) = configuration.user_agent {
96        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
97    }
98    if let Some(ref token) = configuration.oauth_access_token {
99        req_builder = req_builder.bearer_auth(token.to_owned());
100    };
101    if let Some(ref auth_conf) = configuration.basic_auth {
102        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
103    };
104    req_builder = req_builder.json(&p_bulk_permissions_request_bean);
105
106    let req = req_builder.build()?;
107    let resp = configuration.client.execute(req).await?;
108
109    let status = resp.status();
110
111    if !status.is_client_error() && !status.is_server_error() {
112        let content = resp.text().await?;
113        serde_json::from_str(&content).map_err(Error::from)
114    } else {
115        let content = resp.text().await?;
116        let entity: Option<GetBulkPermissionsError> = serde_json::from_str(&content).ok();
117        Err(Error::ResponseError(ResponseContent { status, content, entity }))
118    }
119}
120
121/// Returns a list of permissions indicating which permissions the user has. Details of the user's permissions can be obtained in a global, project, or issue context.  The user is reported as having a project permission:   *  in the global context, if the user has the project permission in any project.  *  for a project, where the project permission is determined using issue data, if the user meets the permission's criteria for any issue in the project. Otherwise, if the user has the project permission in the project.  *  for an issue, where a project permission is determined using issue data, if the user has the permission in the issue. Otherwise, if the user has the project permission in the project containing the issue.  This means that users may be shown as having an issue permission (such as EDIT\\_ISSUES) in the global context or a project context but may not have the permission for any or all issues. For example, if Reporters have the EDIT\\_ISSUES permission a user would be shown as having this permission in the global context or the context of a project, because any user can be a reporter. However, if they are not the user who reported the issue queried they would not have EDIT\\_ISSUES permission for that issue.  Global permissions are unaffected by context.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
122pub async fn get_my_permissions(configuration: &configuration::Configuration, project_key: Option<&str>, project_id: Option<&str>, issue_key: Option<&str>, issue_id: Option<&str>, permissions: Option<&str>, project_uuid: Option<&str>, project_configuration_uuid: Option<&str>) -> Result<models::Permissions, Error<GetMyPermissionsError>> {
123    // add a prefix to parameters to efficiently prevent name collisions
124    let p_project_key = project_key;
125    let p_project_id = project_id;
126    let p_issue_key = issue_key;
127    let p_issue_id = issue_id;
128    let p_permissions = permissions;
129    let p_project_uuid = project_uuid;
130    let p_project_configuration_uuid = project_configuration_uuid;
131
132    let uri_str = format!("{}/rest/api/2/mypermissions", configuration.base_path);
133    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
134
135    if let Some(ref param_value) = p_project_key {
136        req_builder = req_builder.query(&[("projectKey", &param_value.to_string())]);
137    }
138    if let Some(ref param_value) = p_project_id {
139        req_builder = req_builder.query(&[("projectId", &param_value.to_string())]);
140    }
141    if let Some(ref param_value) = p_issue_key {
142        req_builder = req_builder.query(&[("issueKey", &param_value.to_string())]);
143    }
144    if let Some(ref param_value) = p_issue_id {
145        req_builder = req_builder.query(&[("issueId", &param_value.to_string())]);
146    }
147    if let Some(ref param_value) = p_permissions {
148        req_builder = req_builder.query(&[("permissions", &param_value.to_string())]);
149    }
150    if let Some(ref param_value) = p_project_uuid {
151        req_builder = req_builder.query(&[("projectUuid", &param_value.to_string())]);
152    }
153    if let Some(ref param_value) = p_project_configuration_uuid {
154        req_builder = req_builder.query(&[("projectConfigurationUuid", &param_value.to_string())]);
155    }
156    if let Some(ref user_agent) = configuration.user_agent {
157        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
158    }
159    if let Some(ref token) = configuration.oauth_access_token {
160        req_builder = req_builder.bearer_auth(token.to_owned());
161    };
162    if let Some(ref auth_conf) = configuration.basic_auth {
163        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
164    };
165
166    let req = req_builder.build()?;
167    let resp = configuration.client.execute(req).await?;
168
169    let status = resp.status();
170
171    if !status.is_client_error() && !status.is_server_error() {
172        let content = resp.text().await?;
173        serde_json::from_str(&content).map_err(Error::from)
174    } else {
175        let content = resp.text().await?;
176        let entity: Option<GetMyPermissionsError> = serde_json::from_str(&content).ok();
177        Err(Error::ResponseError(ResponseContent { status, content, entity }))
178    }
179}
180
181/// Returns all the projects where the user is granted a list of project permissions.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
182pub async fn get_permitted_projects(configuration: &configuration::Configuration, permissions_keys_bean: models::PermissionsKeysBean) -> Result<models::PermittedProjects, Error<GetPermittedProjectsError>> {
183    // add a prefix to parameters to efficiently prevent name collisions
184    let p_permissions_keys_bean = permissions_keys_bean;
185
186    let uri_str = format!("{}/rest/api/2/permissions/project", configuration.base_path);
187    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
188
189    if let Some(ref user_agent) = configuration.user_agent {
190        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
191    }
192    if let Some(ref token) = configuration.oauth_access_token {
193        req_builder = req_builder.bearer_auth(token.to_owned());
194    };
195    if let Some(ref auth_conf) = configuration.basic_auth {
196        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
197    };
198    req_builder = req_builder.json(&p_permissions_keys_bean);
199
200    let req = req_builder.build()?;
201    let resp = configuration.client.execute(req).await?;
202
203    let status = resp.status();
204
205    if !status.is_client_error() && !status.is_server_error() {
206        let content = resp.text().await?;
207        serde_json::from_str(&content).map_err(Error::from)
208    } else {
209        let content = resp.text().await?;
210        let entity: Option<GetPermittedProjectsError> = serde_json::from_str(&content).ok();
211        Err(Error::ResponseError(ResponseContent { status, content, entity }))
212    }
213}
214