Skip to main content

outfox_openai/admin/
project_groups.rs

1use crate::config::Config;
2use crate::error::OpenAIError;
3use crate::spec::admin::projects::{
4    InviteProjectGroupBody, ProjectGroup, ProjectGroupDeletedResource, ProjectGroupListResource,
5};
6use crate::{Client, RequestOptions};
7
8/// Manage which groups have access to a project and the role they receive.
9pub struct ProjectGroups<'c, C: Config> {
10    client: &'c Client<C>,
11    pub project_id: String,
12    pub(crate) request_options: RequestOptions,
13}
14
15impl<'c, C: Config> ProjectGroups<'c, C> {
16    pub fn new(client: &'c Client<C>, project_id: &str) -> Self {
17        Self {
18            client,
19            project_id: project_id.into(),
20            request_options: RequestOptions::new(),
21        }
22    }
23
24    /// Lists all groups that have access to a project.
25    #[crate::byot(R = serde::de::DeserializeOwned)]
26    pub async fn list(&self) -> Result<ProjectGroupListResource, OpenAIError> {
27        self.client
28            .get(
29                format!("/organization/projects/{}/groups", self.project_id).as_str(),
30                &self.request_options,
31            )
32            .await
33    }
34
35    /// Grants a group access to a project.
36    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
37    pub async fn add(&self, request: InviteProjectGroupBody) -> Result<ProjectGroup, OpenAIError> {
38        self.client
39            .post(
40                format!("/organization/projects/{}/groups", self.project_id).as_str(),
41                request,
42                &self.request_options,
43            )
44            .await
45    }
46
47    /// Removes a group from a project.
48    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
49    pub async fn remove(&self, group_id: &str) -> Result<ProjectGroupDeletedResource, OpenAIError> {
50        self.client
51            .delete(
52                format!(
53                    "/organization/projects/{}/groups/{group_id}",
54                    self.project_id
55                )
56                .as_str(),
57                &self.request_options,
58            )
59            .await
60    }
61}