atlassian_rust_api/jira/endpoints/application_roles/
update_roles.rs1use std::sync::Arc;
2
3use crate::{Jira, Result, rest_client::RestClient, web::{Endpoint, JsonFormParams}};
4
5#[derive(Debug, Clone)]
6pub struct UpdateApplicationRolesBuilder {
7 client: Arc<RestClient>,
8 request: UpdateApplicationRolesRequest,
9}
10
11#[derive(Debug, Clone, Default)]
12struct UpdateApplicationRolesRequest {
13 key: String,
14 groups: Vec<String>,
15 default_groups: Vec<String>,
16 }
18
19impl Endpoint for UpdateApplicationRolesRequest {
20 fn endpoint(&self) -> std::borrow::Cow<'static, str> {
21 "applicationrole".into()
22 }
23
24 fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>> {
27 let mut body = JsonFormParams::default();
28 body
29 .push("key", &self.key)
30 .push("groups", &self.groups)
31 .push("defaultGroups", &self.default_groups);
32 body.into_body()
33 }
34}
35
36impl UpdateApplicationRolesBuilder {
37 fn new(client: Arc<RestClient>) -> UpdateApplicationRolesBuilder {
38 UpdateApplicationRolesBuilder { client, request: UpdateApplicationRolesRequest::default() }
39 }
40
41 fn key(mut self, key: impl Into<String>) -> UpdateApplicationRolesBuilder {
42 self.request.key = key.into();
43 self
44 }
45
46 pub fn group(mut self, group: impl Into<String>) -> UpdateApplicationRolesBuilder {
48 self.request.groups.push(group.into());
49 self
50 }
51
52 pub fn groups<S>(mut self, groups: impl IntoIterator<Item = S>) -> UpdateApplicationRolesBuilder
54 where
55 S: Into<String>,
56 {
57 let groups = groups.into_iter().map(|f| f.into()).collect::<Vec<String>>();
58 self.request.groups.extend(groups);
59 self
60 }
61
62 pub fn default_group(mut self, default_group: impl Into<String>) -> UpdateApplicationRolesBuilder {
64 self.request.default_groups.push(default_group.into());
65 self
66 }
67
68 pub fn default_groups<S>(mut self, default_groups: impl IntoIterator<Item = S>) -> UpdateApplicationRolesBuilder
70 where
71 S: Into<String>,
72 {
73 let default_groups = default_groups.into_iter().map(|f| f.into()).collect::<Vec<String>>();
74 self.request.default_groups.extend(default_groups);
75 self
76 }
77
78 pub async fn send(self) -> Result<serde_json::Value> {
79 self.client.put(self.request).await
80 }
81}
82
83impl Jira {
84 pub fn update_roles(&self, key: impl Into<String>) -> UpdateApplicationRolesBuilder {
91 UpdateApplicationRolesBuilder::new(Arc::clone(&self.client)).key(key)
92 }
93}