openlark_platform/admin/v1/
users.rs1use crate::PlatformConfig;
10use openlark_core::{SDKResult, error::business_error, req_option::RequestOption};
11use std::sync::Arc;
12
13#[derive(Debug, Clone)]
15pub struct UsersApi {
16 config: Arc<PlatformConfig>,
17}
18
19impl UsersApi {
20 pub fn new(config: Arc<PlatformConfig>) -> Self {
22 Self { config }
23 }
24
25 pub fn list(&self) -> ListAdminUsersRequest {
27 ListAdminUsersRequest::new(self.config.clone())
28 }
29
30 pub fn disable(&self) -> DisableUserRequest {
32 DisableUserRequest::new(self.config.clone())
33 }
34
35 pub fn enable(&self) -> EnableUserRequest {
37 EnableUserRequest::new(self.config.clone())
38 }
39}
40
41pub struct ListAdminUsersRequest {
43 _config: Arc<PlatformConfig>,
45 page_size: Option<u32>,
46}
47
48impl ListAdminUsersRequest {
49 fn new(config: Arc<PlatformConfig>) -> Self {
50 Self {
51 _config: config,
52 page_size: None,
53 }
54 }
55
56 pub fn page_size(mut self, size: u32) -> Self {
58 self.page_size = Some(size);
59 self
60 }
61
62 pub async fn execute(self) -> SDKResult<serde_json::Value> {
64 self.execute_with_options(RequestOption::default()).await
65 }
66
67 pub async fn execute_with_options(
69 self,
70 _option: RequestOption,
71 ) -> SDKResult<serde_json::Value> {
72 Err(business_error(
73 "admin.users.list: openlark-platform 尚未接入该 facade,请改用已实现的 admin_user_stat.list 等真实端点",
74 ))
75 }
76}
77
78pub struct DisableUserRequest {
80 _config: Arc<PlatformConfig>,
82 user_id: Option<String>,
83}
84
85impl DisableUserRequest {
86 fn new(config: Arc<PlatformConfig>) -> Self {
87 Self {
88 _config: config,
89 user_id: None,
90 }
91 }
92
93 pub fn user_id(mut self, user_id: impl Into<String>) -> Self {
95 self.user_id = Some(user_id.into());
96 self
97 }
98
99 pub async fn execute(self) -> SDKResult<serde_json::Value> {
101 self.execute_with_options(RequestOption::default()).await
102 }
103
104 pub async fn execute_with_options(
106 self,
107 _option: RequestOption,
108 ) -> SDKResult<serde_json::Value> {
109 Err(business_error(
110 "admin.users.disable: openlark-platform 尚未接入该 facade,请等待后续真实端点支持",
111 ))
112 }
113}
114
115pub struct EnableUserRequest {
117 _config: Arc<PlatformConfig>,
119 user_id: Option<String>,
120}
121
122impl EnableUserRequest {
123 fn new(config: Arc<PlatformConfig>) -> Self {
124 Self {
125 _config: config,
126 user_id: None,
127 }
128 }
129
130 pub fn user_id(mut self, user_id: impl Into<String>) -> Self {
132 self.user_id = Some(user_id.into());
133 self
134 }
135
136 pub async fn execute(self) -> SDKResult<serde_json::Value> {
138 self.execute_with_options(RequestOption::default()).await
139 }
140
141 pub async fn execute_with_options(
143 self,
144 _option: RequestOption,
145 ) -> SDKResult<serde_json::Value> {
146 Err(business_error(
147 "admin.users.enable: openlark-platform 尚未接入该 facade,请等待后续真实端点支持",
148 ))
149 }
150}
151
152#[cfg(test)]
153mod tests {
154 use super::*;
155
156 #[tokio::test]
157 async fn test_users_stub_returns_explicit_error() {
158 let config = Arc::new(PlatformConfig::default());
159 let err = UsersApi::new(config)
160 .list()
161 .page_size(20)
162 .execute()
163 .await
164 .expect_err("users stub should now fail explicitly");
165 assert!(err.to_string().contains("尚未接入"));
166 }
167}