Skip to main content

openlark_platform/admin/v1/
users.rs

1//! 用户管理 API
2//!
3//! 当前仍是 runtime stub。
4//!
5//! 平台 admin 已接入的真实用户统计接口是 `admin_user_stat/list.rs`,
6//! 但这里的 `users` facade 并没有对应的已接线服务端端点。
7//! 为避免继续返回占位 JSON,本模块现在会显式返回未接线错误。
8
9use crate::PlatformConfig;
10use openlark_core::{SDKResult, error::business_error, req_option::RequestOption};
11use std::sync::Arc;
12
13/// 用户管理 API
14#[derive(Debug, Clone)]
15pub struct UsersApi {
16    config: Arc<PlatformConfig>,
17}
18
19impl UsersApi {
20    /// 创建新的用户管理 facade。
21    pub fn new(config: Arc<PlatformConfig>) -> Self {
22        Self { config }
23    }
24
25    /// 获取用户列表
26    pub fn list(&self) -> ListAdminUsersRequest {
27        ListAdminUsersRequest::new(self.config.clone())
28    }
29
30    /// 禁用用户
31    pub fn disable(&self) -> DisableUserRequest {
32        DisableUserRequest::new(self.config.clone())
33    }
34
35    /// 启用用户
36    pub fn enable(&self) -> EnableUserRequest {
37        EnableUserRequest::new(self.config.clone())
38    }
39}
40
41/// 获取用户列表请求
42pub struct ListAdminUsersRequest {
43    // reserved:待装访问器/execute(见 #274,不完整脚手架)
44    _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    /// 设置页面大小
57    pub fn page_size(mut self, size: u32) -> Self {
58        self.page_size = Some(size);
59        self
60    }
61
62    /// 执行请求
63    pub async fn execute(self) -> SDKResult<serde_json::Value> {
64        self.execute_with_options(RequestOption::default()).await
65    }
66
67    /// 执行请求并传入请求选项。
68    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
78/// 禁用用户请求
79pub struct DisableUserRequest {
80    // reserved:待装访问器/execute(见 #274,不完整脚手架)
81    _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    /// 设置用户 ID
94    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    /// 执行请求
100    pub async fn execute(self) -> SDKResult<serde_json::Value> {
101        self.execute_with_options(RequestOption::default()).await
102    }
103
104    /// 执行请求并传入请求选项。
105    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
115/// 启用用户请求
116pub struct EnableUserRequest {
117    // reserved:待装访问器/execute(见 #274,不完整脚手架)
118    _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    /// 设置用户 ID
131    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    /// 执行请求
137    pub async fn execute(self) -> SDKResult<serde_json::Value> {
138        self.execute_with_options(RequestOption::default()).await
139    }
140
141    /// 执行请求并传入请求选项。
142    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}