jirav2/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;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`get_bulk_permissions`]
18#[derive(Clone, Debug, Default)]
19pub struct GetBulkPermissionsParams {
20    /// Details of the permissions to check.
21    pub bulk_permissions_request_bean: crate::models::BulkPermissionsRequestBean
22}
23
24/// struct for passing parameters to the method [`get_my_permissions`]
25#[derive(Clone, Debug, Default)]
26pub struct GetMyPermissionsParams {
27    /// The key of project. Ignored if `projectId` is provided.
28    pub project_key: Option<String>,
29    /// The ID of project.
30    pub project_id: Option<String>,
31    /// The key of the issue. Ignored if `issueId` is provided.
32    pub issue_key: Option<String>,
33    /// The ID of the issue.
34    pub issue_id: Option<String>,
35    /// A list of permission keys. (Required) This parameter accepts a comma-separated list. To get the list of available permissions, use [Get all permissions](#api-rest-api-2-permissions-get).
36    pub permissions: Option<String>,
37    pub project_uuid: Option<String>,
38    pub project_configuration_uuid: Option<String>
39}
40
41/// struct for passing parameters to the method [`get_permitted_projects`]
42#[derive(Clone, Debug, Default)]
43pub struct GetPermittedProjectsParams {
44    pub permissions_keys_bean: crate::models::PermissionsKeysBean
45}
46
47
48/// struct for typed successes of method [`get_all_permissions`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetAllPermissionsSuccess {
52    Status200(crate::models::Permissions),
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed successes of method [`get_bulk_permissions`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum GetBulkPermissionsSuccess {
60    Status200(crate::models::BulkPermissionGrants),
61    UnknownValue(serde_json::Value),
62}
63
64/// struct for typed successes of method [`get_my_permissions`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum GetMyPermissionsSuccess {
68    Status200(crate::models::Permissions),
69    UnknownValue(serde_json::Value),
70}
71
72/// struct for typed successes of method [`get_permitted_projects`]
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum GetPermittedProjectsSuccess {
76    Status200(crate::models::PermittedProjects),
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`get_all_permissions`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum GetAllPermissionsError {
84    Status401(),
85    Status403(),
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`get_bulk_permissions`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum GetBulkPermissionsError {
93    Status400(crate::models::ErrorCollection),
94    Status403(crate::models::ErrorCollection),
95    UnknownValue(serde_json::Value),
96}
97
98/// struct for typed errors of method [`get_my_permissions`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum GetMyPermissionsError {
102    Status400(crate::models::ErrorCollection),
103    Status401(crate::models::ErrorCollection),
104    Status404(crate::models::ErrorCollection),
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`get_permitted_projects`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum GetPermittedProjectsError {
112    Status400(),
113    Status401(),
114    UnknownValue(serde_json::Value),
115}
116
117
118/// 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).
119pub async fn get_all_permissions(configuration: &configuration::Configuration) -> Result<ResponseContent<GetAllPermissionsSuccess>, Error<GetAllPermissionsError>> {
120    let local_var_configuration = configuration;
121
122    // unbox the parameters
123
124
125    let local_var_client = &local_var_configuration.client;
126
127    let local_var_uri_str = format!("{}/rest/api/2/permissions", local_var_configuration.base_path);
128    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
129
130    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
131        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
132    }
133    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
134        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
135    };
136    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
137        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
138    };
139
140    let local_var_req = local_var_req_builder.build()?;
141    let local_var_resp = local_var_client.execute(local_var_req).await?;
142
143    let local_var_status = local_var_resp.status();
144    let local_var_content = local_var_resp.text().await?;
145
146    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
147        let local_var_entity: Option<GetAllPermissionsSuccess> = serde_json::from_str(&local_var_content).ok();
148        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
149        Ok(local_var_result)
150    } else {
151        let local_var_entity: Option<GetAllPermissionsError> = serde_json::from_str(&local_var_content).ok();
152        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
153        Err(Error::ResponseError(local_var_error))
154    }
155}
156
157/// 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.
158pub async fn get_bulk_permissions(configuration: &configuration::Configuration, params: GetBulkPermissionsParams) -> Result<ResponseContent<GetBulkPermissionsSuccess>, Error<GetBulkPermissionsError>> {
159    let local_var_configuration = configuration;
160
161    // unbox the parameters
162    let bulk_permissions_request_bean = params.bulk_permissions_request_bean;
163
164
165    let local_var_client = &local_var_configuration.client;
166
167    let local_var_uri_str = format!("{}/rest/api/2/permissions/check", local_var_configuration.base_path);
168    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
169
170    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
171        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
172    }
173    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
174        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
175    };
176    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
177        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
178    };
179    local_var_req_builder = local_var_req_builder.json(&bulk_permissions_request_bean);
180
181    let local_var_req = local_var_req_builder.build()?;
182    let local_var_resp = local_var_client.execute(local_var_req).await?;
183
184    let local_var_status = local_var_resp.status();
185    let local_var_content = local_var_resp.text().await?;
186
187    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
188        let local_var_entity: Option<GetBulkPermissionsSuccess> = serde_json::from_str(&local_var_content).ok();
189        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
190        Ok(local_var_result)
191    } else {
192        let local_var_entity: Option<GetBulkPermissionsError> = serde_json::from_str(&local_var_content).ok();
193        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
194        Err(Error::ResponseError(local_var_error))
195    }
196}
197
198/// 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.
199pub async fn get_my_permissions(configuration: &configuration::Configuration, params: GetMyPermissionsParams) -> Result<ResponseContent<GetMyPermissionsSuccess>, Error<GetMyPermissionsError>> {
200    let local_var_configuration = configuration;
201
202    // unbox the parameters
203    let project_key = params.project_key;
204    let project_id = params.project_id;
205    let issue_key = params.issue_key;
206    let issue_id = params.issue_id;
207    let permissions = params.permissions;
208    let project_uuid = params.project_uuid;
209    let project_configuration_uuid = params.project_configuration_uuid;
210
211
212    let local_var_client = &local_var_configuration.client;
213
214    let local_var_uri_str = format!("{}/rest/api/2/mypermissions", local_var_configuration.base_path);
215    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
216
217    if let Some(ref local_var_str) = project_key {
218        local_var_req_builder = local_var_req_builder.query(&[("projectKey", &local_var_str.to_string())]);
219    }
220    if let Some(ref local_var_str) = project_id {
221        local_var_req_builder = local_var_req_builder.query(&[("projectId", &local_var_str.to_string())]);
222    }
223    if let Some(ref local_var_str) = issue_key {
224        local_var_req_builder = local_var_req_builder.query(&[("issueKey", &local_var_str.to_string())]);
225    }
226    if let Some(ref local_var_str) = issue_id {
227        local_var_req_builder = local_var_req_builder.query(&[("issueId", &local_var_str.to_string())]);
228    }
229    if let Some(ref local_var_str) = permissions {
230        local_var_req_builder = local_var_req_builder.query(&[("permissions", &local_var_str.to_string())]);
231    }
232    if let Some(ref local_var_str) = project_uuid {
233        local_var_req_builder = local_var_req_builder.query(&[("projectUuid", &local_var_str.to_string())]);
234    }
235    if let Some(ref local_var_str) = project_configuration_uuid {
236        local_var_req_builder = local_var_req_builder.query(&[("projectConfigurationUuid", &local_var_str.to_string())]);
237    }
238    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
239        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
240    }
241    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
242        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
243    };
244    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
245        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
246    };
247
248    let local_var_req = local_var_req_builder.build()?;
249    let local_var_resp = local_var_client.execute(local_var_req).await?;
250
251    let local_var_status = local_var_resp.status();
252    let local_var_content = local_var_resp.text().await?;
253
254    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
255        let local_var_entity: Option<GetMyPermissionsSuccess> = serde_json::from_str(&local_var_content).ok();
256        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
257        Ok(local_var_result)
258    } else {
259        let local_var_entity: Option<GetMyPermissionsError> = serde_json::from_str(&local_var_content).ok();
260        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
261        Err(Error::ResponseError(local_var_error))
262    }
263}
264
265/// Returns all the projects where the user is granted a list of project permissions.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
266pub async fn get_permitted_projects(configuration: &configuration::Configuration, params: GetPermittedProjectsParams) -> Result<ResponseContent<GetPermittedProjectsSuccess>, Error<GetPermittedProjectsError>> {
267    let local_var_configuration = configuration;
268
269    // unbox the parameters
270    let permissions_keys_bean = params.permissions_keys_bean;
271
272
273    let local_var_client = &local_var_configuration.client;
274
275    let local_var_uri_str = format!("{}/rest/api/2/permissions/project", local_var_configuration.base_path);
276    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
277
278    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
279        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
280    }
281    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
282        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
283    };
284    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
285        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
286    };
287    local_var_req_builder = local_var_req_builder.json(&permissions_keys_bean);
288
289    let local_var_req = local_var_req_builder.build()?;
290    let local_var_resp = local_var_client.execute(local_var_req).await?;
291
292    let local_var_status = local_var_resp.status();
293    let local_var_content = local_var_resp.text().await?;
294
295    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
296        let local_var_entity: Option<GetPermittedProjectsSuccess> = serde_json::from_str(&local_var_content).ok();
297        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
298        Ok(local_var_result)
299    } else {
300        let local_var_entity: Option<GetPermittedProjectsError> = serde_json::from_str(&local_var_content).ok();
301        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
302        Err(Error::ResponseError(local_var_error))
303    }
304}
305