async_openai/types/admin/
roles.rs

1use crate::types::OpenAIError;
2use derive_builder::Builder;
3use serde::{Deserialize, Serialize};
4
5/// Sort order for listing roles.
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7#[serde(rename_all = "lowercase")]
8pub enum ListRolesOrder {
9    /// Ascending order
10    Asc,
11    /// Descending order
12    Desc,
13}
14
15/// Query parameters for listing roles.
16#[derive(Debug, Serialize, Default, Clone, Builder, PartialEq)]
17#[builder(name = "ListRolesQueryArgs")]
18#[builder(pattern = "mutable")]
19#[builder(setter(into, strip_option), default)]
20#[builder(derive(Debug))]
21#[builder(build_fn(error = "OpenAIError"))]
22pub struct ListRolesQuery {
23    /// A limit on the number of roles to return. Defaults to 1000.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub limit: Option<u32>,
26    /// Cursor for pagination. Provide the value from the previous response's `next` field to continue listing roles.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub after: Option<String>,
29    /// Sort order for the returned roles.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub order: Option<ListRolesOrder>,
32}
33
34/// Details about a role that can be assigned through the public Roles API.
35#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
36pub struct Role {
37    /// The object type, which is always `role`.
38    pub object: String,
39    /// Identifier for the role.
40    pub id: String,
41    /// Unique name for the role.
42    pub name: String,
43    /// Optional description of the role.
44    pub description: Option<String>,
45    /// Permissions granted by the role.
46    pub permissions: Vec<String>,
47    /// Resource type the role is bound to (for example `api.organization` or `api.project`).
48    pub resource_type: String,
49    /// Whether the role is predefined and managed by OpenAI.
50    pub predefined_role: bool,
51}
52
53/// Paginated list of roles available on an organization or project.
54#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
55pub struct PublicRoleListResource {
56    /// The object type, which is always `list`.
57    pub object: String,
58    /// Roles returned in the current page.
59    pub data: Vec<Role>,
60    /// Whether more roles are available when paginating.
61    pub has_more: bool,
62    /// Cursor to fetch the next page of results, or `null` when there are no additional roles.
63    pub next: Option<String>,
64}
65
66/// Request payload for creating a custom role.
67#[derive(Debug, Serialize, Deserialize, Builder, Clone, PartialEq)]
68#[builder(name = "CreateOrganizationRoleRequestArgs")]
69#[builder(pattern = "mutable")]
70#[builder(setter(into, strip_option))]
71#[builder(derive(Debug))]
72#[builder(build_fn(error = "OpenAIError"))]
73pub struct PublicCreateOrganizationRoleBody {
74    /// Unique name for the role.
75    pub role_name: String,
76    /// Permissions to grant to the role.
77    pub permissions: Vec<String>,
78    /// Optional description of the role.
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub description: Option<String>,
81}
82
83/// Request payload for updating an existing role.
84#[derive(Debug, Serialize, Deserialize, Builder, Clone, PartialEq)]
85#[builder(name = "UpdateOrganizationRoleRequestArgs")]
86#[builder(pattern = "mutable")]
87#[builder(setter(into, strip_option))]
88#[builder(derive(Debug))]
89#[builder(build_fn(error = "OpenAIError"))]
90pub struct PublicUpdateOrganizationRoleBody {
91    /// Updated set of permissions for the role.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub permissions: Option<Vec<String>>,
94    /// New description for the role.
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub description: Option<String>,
97    /// New name for the role.
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub role_name: Option<String>,
100}
101
102/// Confirmation payload returned after deleting a role.
103#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
104pub struct RoleDeletedResource {
105    /// The object type, which is always `role.deleted`.
106    pub object: String,
107    /// Identifier of the deleted role.
108    pub id: String,
109    /// Whether the role was deleted.
110    pub deleted: bool,
111}
112
113/// Detailed information about a role assignment entry returned when listing assignments.
114#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
115pub struct AssignedRoleDetails {
116    /// Identifier for the role.
117    pub id: String,
118    /// Name of the role.
119    pub name: String,
120    /// Permissions associated with the role.
121    pub permissions: Vec<String>,
122    /// Resource type the role applies to.
123    pub resource_type: String,
124    /// Whether the role is predefined by OpenAI.
125    pub predefined_role: bool,
126    /// Description of the role.
127    pub description: Option<String>,
128    /// When the role was created.
129    pub created_at: Option<u64>,
130    /// When the role was last updated.
131    pub updated_at: Option<u64>,
132    /// Identifier of the actor who created the role.
133    pub created_by: Option<String>,
134    /// User details for the actor that created the role, when available.
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub created_by_user_obj: Option<serde_json::Value>,
137    /// Arbitrary metadata stored on the role.
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub metadata: Option<serde_json::Value>,
140}
141
142/// Paginated list of roles assigned to a principal.
143#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
144pub struct RoleListResource {
145    /// The object type, which is always `list`.
146    pub object: String,
147    /// Role assignments returned in the current page.
148    pub data: Vec<AssignedRoleDetails>,
149    /// Whether additional assignments are available when paginating.
150    pub has_more: bool,
151    /// Cursor to fetch the next page of results, or `null` when there are no more assignments.
152    pub next: Option<String>,
153}
154
155/// Confirmation payload returned after unassigning a role.
156#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
157pub struct DeletedRoleAssignmentResource {
158    /// Identifier for the deleted assignment, such as `group.role.deleted` or `user.role.deleted`.
159    pub object: String,
160    /// Whether the assignment was removed.
161    pub deleted: bool,
162}