2022-04-13 18:12:25 +00:00
|
|
|
use crate::Perform;
|
|
|
|
use actix_web::web::Data;
|
|
|
|
use lemmy_api_common::{
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2022-04-13 18:12:25 +00:00
|
|
|
site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
|
2023-05-25 14:50:07 +00:00
|
|
|
utils::{is_admin, local_user_view_from_jwt},
|
2022-04-13 18:12:25 +00:00
|
|
|
};
|
2022-10-27 09:24:07 +00:00
|
|
|
use lemmy_db_schema::source::local_site::LocalSite;
|
2022-08-04 19:30:17 +00:00
|
|
|
use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
|
2023-06-06 16:27:22 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
/// Lists registration applications, filterable by undenied only.
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl Perform for ListRegistrationApplications {
|
|
|
|
type Response = ListRegistrationApplicationsResponse;
|
|
|
|
|
2023-06-06 16:27:22 +00:00
|
|
|
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
2022-04-13 18:12:25 +00:00
|
|
|
let data = self;
|
2023-05-25 14:50:07 +00:00
|
|
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
2023-07-11 13:09:59 +00:00
|
|
|
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)?;
|
|
|
|
|
2023-08-11 09:13:14 +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;
|
2023-07-17 10:20:25 +00:00
|
|
|
let registration_applications = RegistrationApplicationQuery {
|
|
|
|
unread_only,
|
|
|
|
verified_email_only,
|
|
|
|
page,
|
|
|
|
limit,
|
|
|
|
}
|
|
|
|
.list(&mut context.pool())
|
|
|
|
.await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-06-06 16:27:22 +00:00
|
|
|
Ok(Self::Response {
|
2022-04-13 18:12:25 +00:00
|
|
|
registration_applications,
|
2023-06-06 16:27:22 +00:00
|
|
|
})
|
2022-04-13 18:12:25 +00:00
|
|
|
}
|
|
|
|
}
|