use reqwest::Method;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::{
core::{
api_req::ApiRequest,
api_resp::{ApiResponseTrait, BaseResponse, EmptyResponse, ResponseFormat},
config::Config,
constants::AccessTokenType,
http::Transport,
req_option::RequestOption,
SDKResult,
},
service::application::models::*,
};
pub struct AdminService {
config: Config,
}
impl AdminService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn list_installed_apps(
&self,
user_id_type: Option<UserIdType>,
lang: Option<String>,
page_size: Option<i32>,
page_token: Option<String>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<ListInstalledAppsResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
if let Some(lang) = lang {
query_params.insert("lang".to_string(), lang);
}
if let Some(page_size) = page_size {
query_params.insert("page_size".to_string(), page_size.to_string());
}
if let Some(page_token) = page_token {
query_params.insert("page_token".to_string(), page_token);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: "/open-apis/application/v6/admin/apps".to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn get_user_available_apps(
&self,
user_id: &str,
user_id_type: Option<UserIdType>,
lang: Option<String>,
page_size: Option<i32>,
page_token: Option<String>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<GetUserAvailableAppsResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
if let Some(lang) = lang {
query_params.insert("lang".to_string(), lang);
}
if let Some(page_size) = page_size {
query_params.insert("page_size".to_string(), page_size.to_string());
}
if let Some(page_token) = page_token {
query_params.insert("page_token".to_string(), page_token);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: format!("/open-apis/application/v6/admin/user_available_apps/{user_id}"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn contacts_range_configuration(
&self,
app_id: &str,
department_id_type: Option<DepartmentIdType>,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<ContactsRangeConfigurationResponse>> {
let mut query_params = HashMap::new();
if let Some(department_id_type) = department_id_type {
query_params.insert(
"department_id_type".to_string(),
department_id_type.as_str().to_string(),
);
}
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: format!(
"/open-apis/application/v6/admin/apps/{app_id}/contacts_range_configuration"
),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn update_contacts_range_configuration(
&self,
app_id: &str,
request: UpdateContactsRangeConfigurationRequest,
department_id_type: Option<DepartmentIdType>,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<EmptyResponse>> {
let mut query_params = HashMap::new();
if let Some(department_id_type) = department_id_type {
query_params.insert(
"department_id_type".to_string(),
department_id_type.as_str().to_string(),
);
}
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::PATCH,
api_path: format!(
"/open-apis/application/v6/admin/apps/{app_id}/contacts_range_configuration"
),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
body: serde_json::to_vec(&request)?,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn get_app_availability(
&self,
app_id: &str,
user_id_type: Option<UserIdType>,
department_id_type: Option<DepartmentIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<GetAppAvailabilityResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
if let Some(department_id_type) = department_id_type {
query_params.insert(
"department_id_type".to_string(),
department_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: format!("/open-apis/application/v6/admin/apps/{app_id}/visibility"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn check_white_black_list(
&self,
app_id: &str,
request: CheckWhiteBlackListRequest,
user_id_type: Option<UserIdType>,
department_id_type: Option<DepartmentIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<CheckWhiteBlackListResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
if let Some(department_id_type) = department_id_type {
query_params.insert(
"department_id_type".to_string(),
department_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::POST,
api_path: format!(
"/open-apis/application/v6/admin/apps/{app_id}/check_white_black_list"
),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
body: serde_json::to_vec(&request)?,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn update_app_availability(
&self,
app_id: &str,
request: UpdateAppAvailabilityRequest,
user_id_type: Option<UserIdType>,
department_id_type: Option<DepartmentIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<EmptyResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
if let Some(department_id_type) = department_id_type {
query_params.insert(
"department_id_type".to_string(),
department_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::PATCH,
api_path: format!("/open-apis/application/v6/admin/apps/{app_id}/visibility"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
body: serde_json::to_vec(&request)?,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn enable_disable_app(
&self,
app_id: &str,
request: EnableDisableAppRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<EmptyResponse>> {
let api_req = ApiRequest {
http_method: Method::PATCH,
api_path: format!("/open-apis/application/v6/admin/apps/{app_id}/enable"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
body: serde_json::to_vec(&request)?,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn list_app_admins(
&self,
app_id: &str,
user_id_type: Option<UserIdType>,
page_size: Option<i32>,
page_token: Option<String>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<ListAppAdminsResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
if let Some(page_size) = page_size {
query_params.insert("page_size".to_string(), page_size.to_string());
}
if let Some(page_token) = page_token {
query_params.insert("page_token".to_string(), page_token);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: format!("/open-apis/application/v6/admin/apps/{app_id}/admins"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn get_app_admin_permissions(
&self,
app_id: &str,
user_id: &str,
user_id_type: Option<UserIdType>,
department_id_type: Option<DepartmentIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<GetAppAdminPermissionsResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
if let Some(department_id_type) = department_id_type {
query_params.insert(
"department_id_type".to_string(),
department_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: format!(
"/open-apis/application/v6/admin/apps/{app_id}/admins/{user_id}/management_permissions"
),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn verify_app_admin(
&self,
app_id: &str,
user_id: &str,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<VerifyAppAdminResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: format!(
"/open-apis/application/v6/admin/apps/{app_id}/admins/{user_id}/verify"
),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ListInstalledAppsResponse {
pub apps: Vec<Application>,
pub page_token: Option<String>,
pub has_more: bool,
}
impl ApiResponseTrait for ListInstalledAppsResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GetUserAvailableAppsResponse {
pub apps: Vec<Application>,
pub page_token: Option<String>,
pub has_more: bool,
}
impl ApiResponseTrait for GetUserAvailableAppsResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ContactsRangeConfigurationResponse {
pub contacts_range: ContactsRange,
}
impl ApiResponseTrait for ContactsRangeConfigurationResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateContactsRangeConfigurationRequest {
pub contacts_range: ContactsRange,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GetAppAvailabilityResponse {
pub availability: AppAvailability,
}
impl ApiResponseTrait for GetAppAvailabilityResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CheckWhiteBlackListRequest {
pub user_list: Option<Vec<String>>,
pub department_list: Option<Vec<String>>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CheckWhiteBlackListResponse {
pub is_in_list: bool,
}
impl ApiResponseTrait for CheckWhiteBlackListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateAppAvailabilityRequest {
pub availability: AppAvailability,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EnableDisableAppRequest {
pub enable: bool,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ListAppAdminsResponse {
pub admins: Vec<AppAdmin>,
pub page_token: Option<String>,
pub has_more: bool,
}
impl ApiResponseTrait for ListAppAdminsResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GetAppAdminPermissionsResponse {
pub permissions: Vec<AdminPermission>,
}
impl ApiResponseTrait for GetAppAdminPermissionsResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VerifyAppAdminResponse {
pub is_admin: bool,
}
impl ApiResponseTrait for VerifyAppAdminResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}