use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
+ context::LemmyContext,
site::{ApproveRegistrationApplication, RegistrationApplicationResponse},
- utils::{blocking, get_local_user_view_from_jwt, is_admin, send_application_approved_email},
+ utils::{is_admin, local_user_view_from_jwt, send_application_approved_email},
};
use lemmy_db_schema::{
source::{
utils::diesel_option_overwrite,
};
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
-use lemmy_websocket::LemmyContext;
+use lemmy_utils::error::LemmyError;
#[async_trait::async_trait(?Send)]
impl Perform for ApproveRegistrationApplication {
type Response = RegistrationApplicationResponse;
- async fn perform(
- &self,
- context: &Data<LemmyContext>,
- _websocket_id: Option<ConnectionId>,
- ) -> Result<Self::Response, LemmyError> {
+ async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let data = self;
- let local_user_view =
- get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
+ let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let app_id = data.id;
deny_reason,
};
- let registration_application = blocking(context.pool(), move |conn| {
- RegistrationApplication::update(conn, app_id, &app_form)
- })
- .await??;
+ let registration_application =
+ RegistrationApplication::update(&mut context.pool(), app_id, &app_form).await?;
// Update the local_user row
let local_user_form = LocalUserUpdateForm::builder()
.build();
let approved_user_id = registration_application.local_user_id;
- blocking(context.pool(), move |conn| {
- LocalUser::update(conn, approved_user_id, &local_user_form)
- })
- .await??;
+ LocalUser::update(&mut context.pool(), approved_user_id, &local_user_form).await?;
if data.approve {
- let approved_local_user_view = blocking(context.pool(), move |conn| {
- LocalUserView::read(conn, approved_user_id)
- })
- .await??;
+ let approved_local_user_view =
+ LocalUserView::read(&mut context.pool(), approved_user_id).await?;
if approved_local_user_view.local_user.email.is_some() {
- send_application_approved_email(&approved_local_user_view, context.settings())?;
+ send_application_approved_email(&approved_local_user_view, context.settings()).await?;
}
}
// Read the view
- let registration_application = blocking(context.pool(), move |conn| {
- RegistrationApplicationView::read(conn, app_id)
- })
- .await??;
+ let registration_application =
+ RegistrationApplicationView::read(&mut context.pool(), app_id).await?;
Ok(Self::Response {
registration_application,