2022-04-13 18:12:25 +00:00
|
|
|
use crate::Perform;
|
|
|
|
use actix_web::web::Data;
|
|
|
|
use lemmy_api_common::{
|
|
|
|
site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{get_local_user_view_from_jwt, is_admin},
|
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;
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
2022-04-13 18:12:25 +00:00
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
|
|
|
|
/// Lists registration applications, filterable by undenied only.
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl Perform for ListRegistrationApplications {
|
|
|
|
type Response = ListRegistrationApplicationsResponse;
|
|
|
|
|
|
|
|
async fn perform(
|
|
|
|
&self,
|
|
|
|
context: &Data<LemmyContext>,
|
|
|
|
_websocket_id: Option<ConnectionId>,
|
|
|
|
) -> Result<Self::Response, LemmyError> {
|
|
|
|
let data = self;
|
|
|
|
let local_user_view =
|
|
|
|
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
2022-11-09 10:05:00 +00:00
|
|
|
let local_site = LocalSite::read(context.pool()).await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
// Make sure user is an admin
|
|
|
|
is_admin(&local_user_view)?;
|
|
|
|
|
|
|
|
let unread_only = data.unread_only;
|
2022-10-27 09:24:07 +00:00
|
|
|
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;
|
2022-11-09 10:05:00 +00:00
|
|
|
let registration_applications = RegistrationApplicationQuery::builder()
|
|
|
|
.pool(context.pool())
|
|
|
|
.unread_only(unread_only)
|
|
|
|
.verified_email_only(Some(verified_email_only))
|
|
|
|
.page(page)
|
|
|
|
.limit(limit)
|
|
|
|
.build()
|
|
|
|
.list()
|
|
|
|
.await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
let res = Self::Response {
|
|
|
|
registration_applications,
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
}
|