mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
feat(admin): move pending registrations to their own page (#1388)
This commit is contained in:
1 parent
97b2ac91ca
commit
abcb5cb814
31 files changed
+839
-328
No files matched your search
@@ -6,7 +6,8 @@ use super::client::{AdminApiClient, ApiResult};
|
||||
use super::types::{
|
||||
AccountIdentitySettings, CreateRegistrationUrlRequest, CreateRegistrationUrlResponse,
|
||||
InstanceAccountIdentityDiscovery, InstanceConfigResponse, InstanceConfigUpdateRequest,
|
||||
InstanceEmailSmtpTestResponse, InstancePremiumDiscovery,
|
||||
InstanceEmailSmtpTestResponse, InstancePremiumDiscovery, PendingRegistrationListResponse,
|
||||
PendingRegistrationResponse, PendingRegistrationStatus,
|
||||
};
|
||||
|
||||
impl AdminApiClient {
|
||||
@@ -74,35 +75,30 @@ impl AdminApiClient {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn approve_pending_registration(
|
||||
&self,
|
||||
user_id: &str,
|
||||
) -> ApiResult<InstanceConfigResponse> {
|
||||
self.decide_pending_registration(user_id, "approved").await
|
||||
pub async fn list_pending_registrations(&self) -> ApiResult<Vec<PendingRegistrationResponse>> {
|
||||
let response: PendingRegistrationListResponse = self
|
||||
.get("/admin/instance/pending-registrations", None)
|
||||
.await?;
|
||||
Ok(response.pending_registrations)
|
||||
}
|
||||
|
||||
pub async fn reject_pending_registration(
|
||||
pub async fn decide_pending_registration(
|
||||
&self,
|
||||
user_id: &str,
|
||||
) -> ApiResult<InstanceConfigResponse> {
|
||||
self.decide_pending_registration(user_id, "rejected").await
|
||||
}
|
||||
|
||||
async fn decide_pending_registration(
|
||||
&self,
|
||||
user_id: &str,
|
||||
status: &str,
|
||||
) -> ApiResult<InstanceConfigResponse> {
|
||||
let body = serde_json::json!({"status": status});
|
||||
self.send(
|
||||
Method::PATCH,
|
||||
&format!(
|
||||
"/admin/instance/pending-registrations/{}",
|
||||
urlencoding::encode(user_id)
|
||||
),
|
||||
Some(&body),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
status: PendingRegistrationStatus,
|
||||
) -> ApiResult<Vec<PendingRegistrationResponse>> {
|
||||
let body = serde_json::json!({"status": status.as_str()});
|
||||
let response: PendingRegistrationListResponse = self
|
||||
.send(
|
||||
Method::PATCH,
|
||||
&format!(
|
||||
"/admin/instance/pending-registrations/{}",
|
||||
urlencoding::encode(user_id)
|
||||
),
|
||||
Some(&body),
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
Ok(response.pending_registrations)
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ pub fn deserialize_string_or_u64<'de, D: Deserializer<'de>>(d: D) -> Result<u64,
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct AdminUserMeResponse {
|
||||
pub user: AdminUser,
|
||||
pub pending_registration_count: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
|
||||
@@ -701,8 +701,6 @@ pub struct InstanceRegistrationResponse {
|
||||
pub admin_registration_urls_enabled: bool,
|
||||
#[serde(default)]
|
||||
pub urls: Vec<RegistrationUrlResponse>,
|
||||
#[serde(default)]
|
||||
pub pending_registrations: Vec<PendingRegistrationResponse>,
|
||||
}
|
||||
|
||||
impl Default for InstanceRegistrationResponse {
|
||||
@@ -711,7 +709,6 @@ impl Default for InstanceRegistrationResponse {
|
||||
mode: RegistrationMode::Open,
|
||||
admin_registration_urls_enabled: true,
|
||||
urls: Vec::new(),
|
||||
pending_registrations: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -767,6 +764,26 @@ pub struct PendingRegistrationResponse {
|
||||
pub client_ip: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum PendingRegistrationStatus {
|
||||
Approved,
|
||||
Rejected,
|
||||
}
|
||||
|
||||
impl PendingRegistrationStatus {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Approved => "approved",
|
||||
Self::Rejected => "rejected",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct PendingRegistrationListResponse {
|
||||
pub pending_registrations: Vec<PendingRegistrationResponse>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize)]
|
||||
pub struct InstanceConfigUpdateRequest {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
||||
Reference in new issue
Block a user