async_openai/admin/
project_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 a project.
10pub struct ProjectGroupRoles<'c, C: Config> {
11    client: &'c Client<C>,
12    pub project_id: String,
13    pub group_id: String,
14    pub(crate) request_options: RequestOptions,
15}
16
17impl<'c, C: Config> ProjectGroupRoles<'c, C> {
18    pub fn new(client: &'c Client<C>, project_id: &str, group_id: &str) -> Self {
19        Self {
20            client,
21            project_id: project_id.into(),
22            group_id: group_id.into(),
23            request_options: RequestOptions::new(),
24        }
25    }
26
27    /// Lists all role assignments for a group in the project.
28    #[crate::byot(R = serde::de::DeserializeOwned)]
29    pub async fn list(&self) -> Result<RoleListResource, OpenAIError> {
30        self.client
31            .get(
32                format!(
33                    "/projects/{}/groups/{}/roles",
34                    self.project_id, self.group_id
35                )
36                .as_str(),
37                &self.request_options,
38            )
39            .await
40    }
41
42    /// Assigns a role to a group in the project.
43    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
44    pub async fn assign(
45        &self,
46        request: PublicAssignOrganizationGroupRoleBody,
47    ) -> Result<GroupRoleAssignment, OpenAIError> {
48        self.client
49            .post(
50                format!(
51                    "/projects/{}/groups/{}/roles",
52                    self.project_id, self.group_id
53                )
54                .as_str(),
55                request,
56                &self.request_options,
57            )
58            .await
59    }
60
61    /// Unassigns a role from a group in the project.
62    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
63    pub async fn unassign(
64        &self,
65        role_id: &str,
66    ) -> Result<DeletedRoleAssignmentResource, OpenAIError> {
67        self.client
68            .delete(
69                format!(
70                    "/projects/{}/groups/{}/roles/{}",
71                    self.project_id, self.group_id, role_id
72                )
73                .as_str(),
74                &self.request_options,
75            )
76            .await
77    }
78}