jira_api_v2/apis/
permission_schemes_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 [`create_permission_grant`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreatePermissionGrantError {
22    Status400(),
23    Status401(),
24    Status403(),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`create_permission_scheme`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CreatePermissionSchemeError {
32    Status400(),
33    Status401(),
34    Status403(),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`delete_permission_scheme`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum DeletePermissionSchemeError {
42    Status401(),
43    Status403(),
44    Status404(),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`delete_permission_scheme_entity`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum DeletePermissionSchemeEntityError {
52    Status400(),
53    Status401(),
54    Status403(),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`get_all_permission_schemes`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetAllPermissionSchemesError {
62    Status401(),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`get_permission_scheme`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetPermissionSchemeError {
70    Status401(),
71    Status404(),
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`get_permission_scheme_grant`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum GetPermissionSchemeGrantError {
79    Status401(),
80    Status404(),
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`get_permission_scheme_grants`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum GetPermissionSchemeGrantsError {
88    Status401(),
89    Status404(),
90    UnknownValue(serde_json::Value),
91}
92
93/// struct for typed errors of method [`update_permission_scheme`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum UpdatePermissionSchemeError {
97    Status401(),
98    Status403(),
99    Status404(),
100    UnknownValue(serde_json::Value),
101}
102
103
104/// Creates a permission grant in a permission scheme.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
105pub async fn create_permission_grant(configuration: &configuration::Configuration, scheme_id: i64, permission_grant: models::PermissionGrant, expand: Option<&str>) -> Result<models::PermissionGrant, Error<CreatePermissionGrantError>> {
106    // add a prefix to parameters to efficiently prevent name collisions
107    let p_scheme_id = scheme_id;
108    let p_permission_grant = permission_grant;
109    let p_expand = expand;
110
111    let uri_str = format!("{}/rest/api/2/permissionscheme/{schemeId}/permission", configuration.base_path, schemeId=p_scheme_id);
112    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
113
114    if let Some(ref param_value) = p_expand {
115        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
116    }
117    if let Some(ref user_agent) = configuration.user_agent {
118        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119    }
120    if let Some(ref token) = configuration.oauth_access_token {
121        req_builder = req_builder.bearer_auth(token.to_owned());
122    };
123    if let Some(ref auth_conf) = configuration.basic_auth {
124        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
125    };
126    req_builder = req_builder.json(&p_permission_grant);
127
128    let req = req_builder.build()?;
129    let resp = configuration.client.execute(req).await?;
130
131    let status = resp.status();
132
133    if !status.is_client_error() && !status.is_server_error() {
134        let content = resp.text().await?;
135        serde_json::from_str(&content).map_err(Error::from)
136    } else {
137        let content = resp.text().await?;
138        let entity: Option<CreatePermissionGrantError> = serde_json::from_str(&content).ok();
139        Err(Error::ResponseError(ResponseContent { status, content, entity }))
140    }
141}
142
143/// Creates a new permission scheme. You can create a permission scheme with or without defining a set of permission grants.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
144pub async fn create_permission_scheme(configuration: &configuration::Configuration, permission_scheme: models::PermissionScheme, expand: Option<&str>) -> Result<models::PermissionScheme, Error<CreatePermissionSchemeError>> {
145    // add a prefix to parameters to efficiently prevent name collisions
146    let p_permission_scheme = permission_scheme;
147    let p_expand = expand;
148
149    let uri_str = format!("{}/rest/api/2/permissionscheme", configuration.base_path);
150    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
151
152    if let Some(ref param_value) = p_expand {
153        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
154    }
155    if let Some(ref user_agent) = configuration.user_agent {
156        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157    }
158    if let Some(ref token) = configuration.oauth_access_token {
159        req_builder = req_builder.bearer_auth(token.to_owned());
160    };
161    if let Some(ref auth_conf) = configuration.basic_auth {
162        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
163    };
164    req_builder = req_builder.json(&p_permission_scheme);
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<CreatePermissionSchemeError> = serde_json::from_str(&content).ok();
177        Err(Error::ResponseError(ResponseContent { status, content, entity }))
178    }
179}
180
181/// Deletes a permission scheme.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
182pub async fn delete_permission_scheme(configuration: &configuration::Configuration, scheme_id: i64) -> Result<(), Error<DeletePermissionSchemeError>> {
183    // add a prefix to parameters to efficiently prevent name collisions
184    let p_scheme_id = scheme_id;
185
186    let uri_str = format!("{}/rest/api/2/permissionscheme/{schemeId}", configuration.base_path, schemeId=p_scheme_id);
187    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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
199    let req = req_builder.build()?;
200    let resp = configuration.client.execute(req).await?;
201
202    let status = resp.status();
203
204    if !status.is_client_error() && !status.is_server_error() {
205        Ok(())
206    } else {
207        let content = resp.text().await?;
208        let entity: Option<DeletePermissionSchemeError> = serde_json::from_str(&content).ok();
209        Err(Error::ResponseError(ResponseContent { status, content, entity }))
210    }
211}
212
213/// Deletes a permission grant from a permission scheme. See [About permission schemes and grants](../api-group-permission-schemes/#about-permission-schemes-and-grants) for more details.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
214pub async fn delete_permission_scheme_entity(configuration: &configuration::Configuration, scheme_id: i64, permission_id: i64) -> Result<(), Error<DeletePermissionSchemeEntityError>> {
215    // add a prefix to parameters to efficiently prevent name collisions
216    let p_scheme_id = scheme_id;
217    let p_permission_id = permission_id;
218
219    let uri_str = format!("{}/rest/api/2/permissionscheme/{schemeId}/permission/{permissionId}", configuration.base_path, schemeId=p_scheme_id, permissionId=p_permission_id);
220    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
221
222    if let Some(ref user_agent) = configuration.user_agent {
223        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224    }
225    if let Some(ref token) = configuration.oauth_access_token {
226        req_builder = req_builder.bearer_auth(token.to_owned());
227    };
228    if let Some(ref auth_conf) = configuration.basic_auth {
229        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
230    };
231
232    let req = req_builder.build()?;
233    let resp = configuration.client.execute(req).await?;
234
235    let status = resp.status();
236
237    if !status.is_client_error() && !status.is_server_error() {
238        Ok(())
239    } else {
240        let content = resp.text().await?;
241        let entity: Option<DeletePermissionSchemeEntityError> = serde_json::from_str(&content).ok();
242        Err(Error::ResponseError(ResponseContent { status, content, entity }))
243    }
244}
245
246/// Returns all permission schemes.  ### About permission schemes and grants ###  A permission scheme is a collection of permission grants. A permission grant consists of a `holder` and a `permission`.  #### Holder object ####  The `holder` object contains information about the user or group being granted the permission. For example, the *Administer projects* permission is granted to a group named *Teams in space administrators*. In this case, the type is `\"type\": \"group\"`, and the parameter is the group name, `\"parameter\": \"Teams in space administrators\"`. The `holder` object is defined by the following properties:   *  `type` Identifies the user or group (see the list of types below).  *  `parameter` The value of this property depends on the `type`. For example, if the `type` is a group, then you need to specify the group name.  The following `types` are available. The expected values for the `parameter` are given in parenthesis (some `types` may not have a `parameter`):   *  `anyone` Grant for anonymous users.  *  `applicationRole` Grant for users with access to the specified application (application name). See [Update product access settings](https://confluence.atlassian.com/x/3YxjL) for more information.  *  `assignee` Grant for the user currently assigned to an issue.  *  `group` Grant for the specified group (group name).  *  `groupCustomField` Grant for a user in the group selected in the specified custom field (custom field ID).  *  `projectLead` Grant for a project lead.  *  `projectRole` Grant for the specified project role (project role ID).  *  `reporter` Grant for the user who reported the issue.  *  `sd.customer.portal.only` Jira Service Desk only. Grants customers permission to access the customer portal but not Jira. See [Customizing Jira Service Desk permissions](https://confluence.atlassian.com/x/24dKLg) for more information.  *  `user` Grant for the specified user (user ID - historically this was the userkey but that is deprecated and the account ID should be used).  *  `userCustomField` Grant for a user selected in the specified custom field (custom field ID).  #### Built-in permissions ####  The [built-in Jira permissions](https://confluence.atlassian.com/x/yodKLg) are listed below. Apps can also define custom permissions. See the [project permission](https://developer.atlassian.com/cloud/jira/platform/modules/project-permission/) and [global permission](https://developer.atlassian.com/cloud/jira/platform/modules/global-permission/) module documentation for more information.  **Project permissions**   *  `ADMINISTER_PROJECTS`  *  `BROWSE_PROJECTS`  *  `MANAGE_SPRINTS_PERMISSION` (Jira Software only)  *  `SERVICEDESK_AGENT` (Jira Service Desk only)  *  `VIEW_DEV_TOOLS` (Jira Software only)  *  `VIEW_READONLY_WORKFLOW`  **Issue permissions**   *  `ASSIGNABLE_USER`  *  `ASSIGN_ISSUES`  *  `CLOSE_ISSUES`  *  `CREATE_ISSUES`  *  `DELETE_ISSUES`  *  `EDIT_ISSUES`  *  `LINK_ISSUES`  *  `MODIFY_REPORTER`  *  `MOVE_ISSUES`  *  `RESOLVE_ISSUES`  *  `SCHEDULE_ISSUES`  *  `SET_ISSUE_SECURITY`  *  `TRANSITION_ISSUES`  **Voters and watchers permissions**   *  `MANAGE_WATCHERS`  *  `VIEW_VOTERS_AND_WATCHERS`  **Comments permissions**   *  `ADD_COMMENTS`  *  `DELETE_ALL_COMMENTS`  *  `DELETE_OWN_COMMENTS`  *  `EDIT_ALL_COMMENTS`  *  `EDIT_OWN_COMMENTS`  **Attachments permissions**   *  `CREATE_ATTACHMENTS`  *  `DELETE_ALL_ATTACHMENTS`  *  `DELETE_OWN_ATTACHMENTS`  **Time tracking permissions**   *  `DELETE_ALL_WORKLOGS`  *  `DELETE_OWN_WORKLOGS`  *  `EDIT_ALL_WORKLOGS`  *  `EDIT_OWN_WORKLOGS`  *  `WORK_ON_ISSUES`  **[Permissions](#permissions) required:** Permission to access Jira.
247pub async fn get_all_permission_schemes(configuration: &configuration::Configuration, expand: Option<&str>) -> Result<models::PermissionSchemes, Error<GetAllPermissionSchemesError>> {
248    // add a prefix to parameters to efficiently prevent name collisions
249    let p_expand = expand;
250
251    let uri_str = format!("{}/rest/api/2/permissionscheme", configuration.base_path);
252    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
253
254    if let Some(ref param_value) = p_expand {
255        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
256    }
257    if let Some(ref user_agent) = configuration.user_agent {
258        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
259    }
260    if let Some(ref token) = configuration.oauth_access_token {
261        req_builder = req_builder.bearer_auth(token.to_owned());
262    };
263    if let Some(ref auth_conf) = configuration.basic_auth {
264        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
265    };
266
267    let req = req_builder.build()?;
268    let resp = configuration.client.execute(req).await?;
269
270    let status = resp.status();
271
272    if !status.is_client_error() && !status.is_server_error() {
273        let content = resp.text().await?;
274        serde_json::from_str(&content).map_err(Error::from)
275    } else {
276        let content = resp.text().await?;
277        let entity: Option<GetAllPermissionSchemesError> = serde_json::from_str(&content).ok();
278        Err(Error::ResponseError(ResponseContent { status, content, entity }))
279    }
280}
281
282/// Returns a permission scheme.  **[Permissions](#permissions) required:** Permission to access Jira.
283pub async fn get_permission_scheme(configuration: &configuration::Configuration, scheme_id: i64, expand: Option<&str>) -> Result<models::PermissionScheme, Error<GetPermissionSchemeError>> {
284    // add a prefix to parameters to efficiently prevent name collisions
285    let p_scheme_id = scheme_id;
286    let p_expand = expand;
287
288    let uri_str = format!("{}/rest/api/2/permissionscheme/{schemeId}", configuration.base_path, schemeId=p_scheme_id);
289    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
290
291    if let Some(ref param_value) = p_expand {
292        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
293    }
294    if let Some(ref user_agent) = configuration.user_agent {
295        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
296    }
297    if let Some(ref token) = configuration.oauth_access_token {
298        req_builder = req_builder.bearer_auth(token.to_owned());
299    };
300    if let Some(ref auth_conf) = configuration.basic_auth {
301        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
302    };
303
304    let req = req_builder.build()?;
305    let resp = configuration.client.execute(req).await?;
306
307    let status = resp.status();
308
309    if !status.is_client_error() && !status.is_server_error() {
310        let content = resp.text().await?;
311        serde_json::from_str(&content).map_err(Error::from)
312    } else {
313        let content = resp.text().await?;
314        let entity: Option<GetPermissionSchemeError> = serde_json::from_str(&content).ok();
315        Err(Error::ResponseError(ResponseContent { status, content, entity }))
316    }
317}
318
319/// Returns a permission grant.  **[Permissions](#permissions) required:** Permission to access Jira.
320pub async fn get_permission_scheme_grant(configuration: &configuration::Configuration, scheme_id: i64, permission_id: i64, expand: Option<&str>) -> Result<models::PermissionGrant, Error<GetPermissionSchemeGrantError>> {
321    // add a prefix to parameters to efficiently prevent name collisions
322    let p_scheme_id = scheme_id;
323    let p_permission_id = permission_id;
324    let p_expand = expand;
325
326    let uri_str = format!("{}/rest/api/2/permissionscheme/{schemeId}/permission/{permissionId}", configuration.base_path, schemeId=p_scheme_id, permissionId=p_permission_id);
327    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
328
329    if let Some(ref param_value) = p_expand {
330        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
331    }
332    if let Some(ref user_agent) = configuration.user_agent {
333        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
334    }
335    if let Some(ref token) = configuration.oauth_access_token {
336        req_builder = req_builder.bearer_auth(token.to_owned());
337    };
338    if let Some(ref auth_conf) = configuration.basic_auth {
339        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
340    };
341
342    let req = req_builder.build()?;
343    let resp = configuration.client.execute(req).await?;
344
345    let status = resp.status();
346
347    if !status.is_client_error() && !status.is_server_error() {
348        let content = resp.text().await?;
349        serde_json::from_str(&content).map_err(Error::from)
350    } else {
351        let content = resp.text().await?;
352        let entity: Option<GetPermissionSchemeGrantError> = serde_json::from_str(&content).ok();
353        Err(Error::ResponseError(ResponseContent { status, content, entity }))
354    }
355}
356
357/// Returns all permission grants for a permission scheme.  **[Permissions](#permissions) required:** Permission to access Jira.
358pub async fn get_permission_scheme_grants(configuration: &configuration::Configuration, scheme_id: i64, expand: Option<&str>) -> Result<models::PermissionGrants, Error<GetPermissionSchemeGrantsError>> {
359    // add a prefix to parameters to efficiently prevent name collisions
360    let p_scheme_id = scheme_id;
361    let p_expand = expand;
362
363    let uri_str = format!("{}/rest/api/2/permissionscheme/{schemeId}/permission", configuration.base_path, schemeId=p_scheme_id);
364    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
365
366    if let Some(ref param_value) = p_expand {
367        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
368    }
369    if let Some(ref user_agent) = configuration.user_agent {
370        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
371    }
372    if let Some(ref token) = configuration.oauth_access_token {
373        req_builder = req_builder.bearer_auth(token.to_owned());
374    };
375    if let Some(ref auth_conf) = configuration.basic_auth {
376        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
377    };
378
379    let req = req_builder.build()?;
380    let resp = configuration.client.execute(req).await?;
381
382    let status = resp.status();
383
384    if !status.is_client_error() && !status.is_server_error() {
385        let content = resp.text().await?;
386        serde_json::from_str(&content).map_err(Error::from)
387    } else {
388        let content = resp.text().await?;
389        let entity: Option<GetPermissionSchemeGrantsError> = serde_json::from_str(&content).ok();
390        Err(Error::ResponseError(ResponseContent { status, content, entity }))
391    }
392}
393
394/// Updates a permission scheme. Below are some important things to note when using this resource:   *  If a permissions list is present in the request, then it is set in the permission scheme, overwriting *all existing* grants.  *  If you want to update only the name and description, then do not send a permissions list in the request.  *  Sending an empty list will remove all permission grants from the permission scheme.  If you want to add or delete a permission grant instead of updating the whole list, see [Create permission grant](#api-rest-api-2-permissionscheme-schemeId-permission-post) or [Delete permission scheme entity](#api-rest-api-2-permissionscheme-schemeId-permission-permissionId-delete).  See [About permission schemes and grants](../api-group-permission-schemes/#about-permission-schemes-and-grants) for more details.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
395pub async fn update_permission_scheme(configuration: &configuration::Configuration, scheme_id: i64, permission_scheme: models::PermissionScheme, expand: Option<&str>) -> Result<models::PermissionScheme, Error<UpdatePermissionSchemeError>> {
396    // add a prefix to parameters to efficiently prevent name collisions
397    let p_scheme_id = scheme_id;
398    let p_permission_scheme = permission_scheme;
399    let p_expand = expand;
400
401    let uri_str = format!("{}/rest/api/2/permissionscheme/{schemeId}", configuration.base_path, schemeId=p_scheme_id);
402    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
403
404    if let Some(ref param_value) = p_expand {
405        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
406    }
407    if let Some(ref user_agent) = configuration.user_agent {
408        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
409    }
410    if let Some(ref token) = configuration.oauth_access_token {
411        req_builder = req_builder.bearer_auth(token.to_owned());
412    };
413    if let Some(ref auth_conf) = configuration.basic_auth {
414        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
415    };
416    req_builder = req_builder.json(&p_permission_scheme);
417
418    let req = req_builder.build()?;
419    let resp = configuration.client.execute(req).await?;
420
421    let status = resp.status();
422
423    if !status.is_client_error() && !status.is_server_error() {
424        let content = resp.text().await?;
425        serde_json::from_str(&content).map_err(Error::from)
426    } else {
427        let content = resp.text().await?;
428        let entity: Option<UpdatePermissionSchemeError> = serde_json::from_str(&content).ok();
429        Err(Error::ResponseError(ResponseContent { status, content, entity }))
430    }
431}
432