use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
- blocking,
- get_local_user_view_from_jwt,
- is_admin,
- send_application_approved_email,
- site::*,
+ context::LemmyContext,
+ site::{ApproveRegistrationApplication, RegistrationApplicationResponse},
+ utils::{is_admin, local_user_view_from_jwt, send_application_approved_email},
};
use lemmy_db_schema::{
- diesel_option_overwrite,
source::{
- local_user::{LocalUser, LocalUserForm},
- registration_application::{RegistrationApplication, RegistrationApplicationForm},
+ local_user::{LocalUser, LocalUserUpdateForm},
+ registration_application::{RegistrationApplication, RegistrationApplicationUpdateForm},
},
traits::Crud,
+ utils::diesel_option_overwrite,
};
-use lemmy_db_views::{
- local_user_view::LocalUserView,
- registration_application_view::RegistrationApplicationView,
-};
-use lemmy_utils::{ConnectionId, LemmyError};
-use lemmy_websocket::LemmyContext;
+use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
+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;
// Update the registration with reason, admin_id
let deny_reason = diesel_option_overwrite(&data.deny_reason);
- let app_form = RegistrationApplicationForm {
- admin_id: Some(local_user_view.person.id),
+ let app_form = RegistrationApplicationUpdateForm {
+ admin_id: Some(Some(local_user_view.person.id)),
deny_reason,
- ..RegistrationApplicationForm::default()
};
- 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 = LocalUserForm {
- accepted_application: Some(data.approve),
- ..LocalUserForm::default()
- };
+ let local_user_form = LocalUserUpdateForm::builder()
+ .accepted_application(Some(data.approve))
+ .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,