async_openai/admin/
group_roles.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::admin::groups::{GroupRoleAssignment, PublicAssignOrganizationGroupRoleBody},
5    types::admin::roles::{DeletedRoleAssignmentResource, RoleListResource},
6    Client, RequestOptions,
7};
8
9/// Manage role assignments for groups in the organization.
10pub struct GroupRoles<'c, C: Config> {
11    client: &'c Client<C>,
12    pub group_id: String,
13    pub(crate) request_options: RequestOptions,
14}
15
16impl<'c, C: Config> GroupRoles<'c, C> {
17    pub fn new(client: &'c Client<C>, group_id: &str) -> Self {
18        Self {
19            client,
20            group_id: group_id.into(),
21            request_options: RequestOptions::new(),
22        }
23    }
24
25    /// Lists all role assignments for a group.
26    #[crate::byot(R = serde::de::DeserializeOwned)]
27    pub async fn list(&self) -> Result<RoleListResource, OpenAIError> {
28        self.client
29            .get(
30                format!("/organization/groups/{}/roles", self.group_id).as_str(),
31                &self.request_options,
32            )
33            .await
34    }
35
36    /// Assigns a role to a group.
37    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
38    pub async fn assign(
39        &self,
40        request: PublicAssignOrganizationGroupRoleBody,
41    ) -> Result<GroupRoleAssignment, OpenAIError> {
42        self.client
43            .post(
44                format!("/organization/groups/{}/roles", self.group_id).as_str(),
45                request,
46                &self.request_options,
47            )
48            .await
49    }
50
51    /// Unassigns a role from a group.
52    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
53    pub async fn unassign(
54        &self,
55        role_id: &str,
56    ) -> Result<DeletedRoleAssignmentResource, OpenAIError> {
57        self.client
58            .delete(
59                format!("/organization/groups/{}/roles/{}", self.group_id, role_id).as_str(),
60                &self.request_options,
61            )
62            .await
63    }
64}