"deploy/cloud/vscode:/vscode.git/clone" did not exist on "31ff23704bc416ef9106a269855d7a3af30cb498"
users.rs 2.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
// Based on https://github.com/64bit/async-openai/ by Himanshu Neema
// Original Copyright (c) 2022 Himanshu Neema
// Licensed under MIT License (see ATTRIBUTIONS-Rust.md)
//
// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
// Licensed under Apache 2.0

use serde::Serialize;

use crate::{
    config::Config,
    error::OpenAIError,
    types::{User, UserDeleteResponse, UserListResponse, UserRoleUpdateRequest},
    Client,
};

/// Manage users and their role in an organization. Users will be automatically added to the Default project.
pub struct Users<'c, C: Config> {
    client: &'c Client<C>,
}

impl<'c, C: Config> Users<'c, C> {
    pub fn new(client: &'c Client<C>) -> Self {
        Self { client }
    }

    /// Lists all of the users in the organization.
    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
    pub async fn list<Q>(&self, query: &Q) -> Result<UserListResponse, OpenAIError>
    where
        Q: Serialize + ?Sized,
    {
        self.client
            .get_with_query("/organization/users", &query)
            .await
    }

    /// Modifies a user's role in the organization.
    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
    pub async fn modify(
        &self,
        user_id: &str,
        request: UserRoleUpdateRequest,
    ) -> Result<User, OpenAIError> {
        self.client
            .post(format!("/organization/users/{user_id}").as_str(), request)
            .await
    }

    /// Retrieve a user by their identifier
    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
    pub async fn retrieve(&self, user_id: &str) -> Result<User, OpenAIError> {
        self.client
            .get(format!("/organization/users/{user_id}").as_str())
            .await
    }

    /// Deletes a user from the organization.
    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
    pub async fn delete(&self, user_id: &str) -> Result<UserDeleteResponse, OpenAIError> {
        self.client
            .delete(format!("/organizations/users/{user_id}").as_str())
            .await
    }
}