2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse},
5 utils::{get_local_user_view_from_jwt, is_admin},
7 use lemmy_db_schema::source::local_site::LocalSite;
8 use lemmy_db_views::structs::RegistrationApplicationView;
9 use lemmy_utils::{error::LemmyError, ConnectionId};
10 use lemmy_websocket::LemmyContext;
12 #[async_trait::async_trait(?Send)]
13 impl Perform for GetUnreadRegistrationApplicationCount {
14 type Response = GetUnreadRegistrationApplicationCountResponse;
18 context: &Data<LemmyContext>,
19 _websocket_id: Option<ConnectionId>,
20 ) -> Result<Self::Response, LemmyError> {
23 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
24 let local_site = LocalSite::read(context.pool()).await?;
26 // Only let admins do this
27 is_admin(&local_user_view)?;
29 let verified_email_only = local_site.require_email_verification;
31 let registration_applications =
32 RegistrationApplicationView::get_unread_count(context.pool(), verified_email_only).await?;
35 registration_applications,