lemmy/crates/api/src/site/registration_applications/list.rs

40 lines
1.3 KiB
Rust
Raw Normal View History

use actix_web::web::{Data, Json, Query};
2022-04-13 18:12:25 +00:00
use lemmy_api_common::{
context::LemmyContext,
2022-04-13 18:12:25 +00:00
site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
utils::{is_admin, local_user_view_from_jwt},
2022-04-13 18:12:25 +00:00
};
use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
use lemmy_utils::error::LemmyError;
2022-04-13 18:12:25 +00:00
/// Lists registration applications, filterable by undenied only.
pub async fn list_registration_applications(
data: Query<ListRegistrationApplications>,
context: Data<LemmyContext>,
) -> Result<Json<ListRegistrationApplicationsResponse>, LemmyError> {
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
let local_site = LocalSite::read(&mut context.pool()).await?;
2022-04-13 18:12:25 +00:00
// Make sure user is an admin
is_admin(&local_user_view)?;
2022-04-13 18:12:25 +00:00
let unread_only = data.unread_only.unwrap_or_default();
let verified_email_only = local_site.require_email_verification;
2022-04-13 18:12:25 +00:00
let page = data.page;
let limit = data.limit;
let registration_applications = RegistrationApplicationQuery {
unread_only,
verified_email_only,
page,
limit,
2022-04-13 18:12:25 +00:00
}
.list(&mut context.pool())
.await?;
Ok(Json(ListRegistrationApplicationsResponse {
registration_applications,
}))
2022-04-13 18:12:25 +00:00
}