use openlark_core::{
SDKResult,
api::{ApiRequest, ApiResponseTrait, ResponseFormat},
config::Config,
http::Transport,
req_option::RequestOption,
validate_required,
};
use crate::common::{api_endpoints::PermissionApiOld, api_utils::*};
pub mod models;
impl ApiResponseTrait for CheckMemberPermissionResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl ApiResponseTrait for TransferOwnerResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl ApiResponseTrait for GetPublicPermissionResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Clone)]
pub struct CheckMemberPermissionRequest {
config: Config,
params: CheckMemberPermissionParams,
}
impl CheckMemberPermissionRequest {
pub fn new(config: Config, params: CheckMemberPermissionParams) -> Self {
Self { config, params }
}
pub async fn execute(self) -> SDKResult<CheckMemberPermissionResponse> {
self.execute_with_options(RequestOption::default()).await
}
pub async fn execute_with_options(
self,
option: RequestOption,
) -> SDKResult<CheckMemberPermissionResponse> {
validate_required!(self.params.obj_token.trim(), "文件Token不能为空");
validate_required!(self.params.permission.trim(), "权限类型不能为空");
let api_endpoint = PermissionApiOld::MemberPermitted;
let api_request: ApiRequest<CheckMemberPermissionResponse> =
ApiRequest::post(&api_endpoint.to_url())
.body(serialize_params(&self.params, "检查成员权限")?);
let response = Transport::request(api_request, &self.config, Some(option)).await?;
extract_response_data(response, "检查成员权限")
}
}
#[derive(Debug, Clone)]
pub struct TransferOwnerRequest {
config: Config,
params: TransferOwnerParams,
}
impl TransferOwnerRequest {
pub fn new(config: Config, params: TransferOwnerParams) -> Self {
Self { config, params }
}
pub async fn execute(self) -> SDKResult<TransferOwnerResponse> {
self.execute_with_options(RequestOption::default()).await
}
pub async fn execute_with_options(
self,
option: RequestOption,
) -> SDKResult<TransferOwnerResponse> {
validate_required!(self.params.obj_token.trim(), "文件Token不能为空");
validate_required!(self.params.member_id.trim(), "新拥有者用户ID不能为空");
validate_required!(self.params.member_id_type.trim(), "用户ID类型不能为空");
let api_endpoint = PermissionApiOld::MemberTransfer;
let api_request: ApiRequest<TransferOwnerResponse> =
ApiRequest::post(&api_endpoint.to_url())
.body(serialize_params(&self.params, "转移拥有者")?);
let response = Transport::request(api_request, &self.config, Some(option)).await?;
extract_response_data(response, "转移拥有者")
}
}
#[derive(Debug, Clone)]
pub struct GetPublicPermissionRequest {
config: Config,
params: GetPublicPermissionParams,
}
impl GetPublicPermissionRequest {
pub fn new(config: Config, params: GetPublicPermissionParams) -> Self {
Self { config, params }
}
pub async fn execute(self) -> SDKResult<GetPublicPermissionResponse> {
self.execute_with_options(RequestOption::default()).await
}
pub async fn execute_with_options(
self,
option: RequestOption,
) -> SDKResult<GetPublicPermissionResponse> {
validate_required!(self.params.obj_token.trim(), "文件Token不能为空");
let api_endpoint = PermissionApiOld::Public;
let api_request: ApiRequest<GetPublicPermissionResponse> =
ApiRequest::post(&api_endpoint.to_url())
.body(serialize_params(&self.params, "获取公开权限设置")?);
let response = Transport::request(api_request, &self.config, Some(option)).await?;
extract_response_data(response, "获取公开权限设置")
}
}
pub use models::{
CheckMemberPermissionParams, CheckMemberPermissionResponse, GetPublicPermissionParams,
GetPublicPermissionResponse, PermissionCheckResult, PublicPermission, TransferOwnerParams,
TransferOwnerResponse, TransferResult, UserInfo,
};