A few additions:

- Add a DeleteAccount response.
- RegistrationApplicationView now has the safe LocalUserSettings.
- Adding VerifyEmail to websocket API, added a proper response type.
invite_instances
Dessalines 3 years ago
parent be8f79d700
commit b0385830ed

@ -84,6 +84,9 @@ pub async fn match_websocket_operation(
UserOperation::GetUnreadCount => { UserOperation::GetUnreadCount => {
do_websocket_operation::<GetUnreadCount>(context, id, op, data).await do_websocket_operation::<GetUnreadCount>(context, id, op, data).await
} }
UserOperation::VerifyEmail => {
do_websocket_operation::<VerifyEmail>(context, id, op, data).await
}
// Private Message ops // Private Message ops
UserOperation::MarkPrivateMessageAsRead => { UserOperation::MarkPrivateMessageAsRead => {

@ -935,7 +935,7 @@ impl Perform for GetUnreadCount {
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Perform for VerifyEmail { impl Perform for VerifyEmail {
type Response = (); type Response = VerifyEmailResponse;
async fn perform( async fn perform(
&self, &self,
@ -963,6 +963,6 @@ impl Perform for VerifyEmail {
}) })
.await??; .await??;
Ok(()) Ok(VerifyEmailResponse {})
} }
} }

@ -81,8 +81,7 @@ pub struct ChangePassword {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct LoginResponse { pub struct LoginResponse {
/// This is None in response to `Register` if email verification is enabled, and in response to /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
/// `DeleteAccount`.
pub jwt: Option<Sensitive<String>>, pub jwt: Option<Sensitive<String>>,
pub registration_created: bool, pub registration_created: bool,
pub verify_email_sent: bool, pub verify_email_sent: bool,
@ -201,6 +200,9 @@ pub struct DeleteAccount {
pub auth: Sensitive<String>, pub auth: Sensitive<String>,
} }
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DeleteAccountResponse {}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct PasswordReset { pub struct PasswordReset {
pub email: Sensitive<String>, pub email: Sensitive<String>,
@ -291,3 +293,6 @@ pub struct GetUnreadCountResponse {
pub struct VerifyEmail { pub struct VerifyEmail {
pub token: String, pub token: String,
} }
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct VerifyEmailResponse {}

@ -8,15 +8,15 @@ use lemmy_websocket::LemmyContext;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for DeleteAccount { impl PerformCrud for DeleteAccount {
type Response = LoginResponse; type Response = DeleteAccountResponse;
#[tracing::instrument(skip(self, context, _websocket_id))] #[tracing::instrument(skip(self, context, _websocket_id))]
async fn perform( async fn perform(
&self, &self,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>, _websocket_id: Option<ConnectionId>,
) -> Result<LoginResponse, LemmyError> { ) -> Result<Self::Response, LemmyError> {
let data: &DeleteAccount = self; let data = self;
let local_user_view = let local_user_view =
get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?; get_local_user_view_from_jwt(data.auth.as_ref(), context.pool(), context.secret()).await?;
@ -50,11 +50,6 @@ impl PerformCrud for DeleteAccount {
}) })
.await??; .await??;
// TODO rework this Ok(DeleteAccountResponse {})
Ok(LoginResponse {
jwt: None,
verify_email_sent: false,
registration_created: false,
})
} }
} }

@ -84,9 +84,7 @@ where
*request_counter += 1; *request_counter += 1;
if *request_counter > context.settings().http_fetch_retry_limit { if *request_counter > context.settings().http_fetch_retry_limit {
return Err(LemmyError::from(anyhow::anyhow!( return Err(LemmyError::from_message("Request retry limit reached"));
"Request retry limit reached"
)));
} }
let response = retry(|| context.client().get(&fetch_url).send()).await?; let response = retry(|| context.client().get(&fetch_url).send()).await?;

@ -31,6 +31,8 @@ mod safe_settings_type {
show_scores, show_scores,
show_read_posts, show_read_posts,
show_new_post_notifs, show_new_post_notifs,
email_verified,
accepted_application,
); );
impl ToSafeSettings for LocalUser { impl ToSafeSettings for LocalUser {
@ -54,6 +56,8 @@ mod safe_settings_type {
show_scores, show_scores,
show_read_posts, show_read_posts,
show_new_post_notifs, show_new_post_notifs,
email_verified,
accepted_application,
) )
} }
} }

@ -68,4 +68,6 @@ pub struct LocalUserSettings {
pub show_scores: bool, pub show_scores: bool,
pub show_read_posts: bool, pub show_read_posts: bool,
pub show_new_post_notifs: bool, pub show_new_post_notifs: bool,
pub email_verified: bool,
pub accepted_application: bool,
} }

@ -3,25 +3,25 @@ use lemmy_db_schema::{
limit_and_offset, limit_and_offset,
schema::{local_user, person, person_alias_1, registration_application}, schema::{local_user, person, person_alias_1, registration_application},
source::{ source::{
local_user::LocalUser, local_user::{LocalUser, LocalUserSettings},
person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1}, person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
registration_application::RegistrationApplication, registration_application::RegistrationApplication,
}, },
traits::{MaybeOptional, ToSafe, ViewToVec}, traits::{MaybeOptional, ToSafe, ToSafeSettings, ViewToVec},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct RegistrationApplicationView { pub struct RegistrationApplicationView {
pub registration_application: RegistrationApplication, pub registration_application: RegistrationApplication,
pub creator_local_user: LocalUser, pub creator_local_user: LocalUserSettings,
pub creator: PersonSafe, pub creator: PersonSafe,
pub admin: Option<PersonSafeAlias1>, pub admin: Option<PersonSafeAlias1>,
} }
type RegistrationApplicationViewTuple = ( type RegistrationApplicationViewTuple = (
RegistrationApplication, RegistrationApplication,
LocalUser, LocalUserSettings,
PersonSafe, PersonSafe,
Option<PersonSafeAlias1>, Option<PersonSafeAlias1>,
); );
@ -42,7 +42,7 @@ impl RegistrationApplicationView {
.order_by(registration_application::published.desc()) .order_by(registration_application::published.desc())
.select(( .select((
registration_application::all_columns, registration_application::all_columns,
local_user::all_columns, LocalUser::safe_settings_columns_tuple(),
Person::safe_columns_tuple(), Person::safe_columns_tuple(),
PersonAlias1::safe_columns_tuple().nullable(), PersonAlias1::safe_columns_tuple().nullable(),
)) ))
@ -128,7 +128,7 @@ impl<'a> RegistrationApplicationQueryBuilder<'a> {
.order_by(registration_application::published.desc()) .order_by(registration_application::published.desc())
.select(( .select((
registration_application::all_columns, registration_application::all_columns,
local_user::all_columns, LocalUser::safe_settings_columns_tuple(),
Person::safe_columns_tuple(), Person::safe_columns_tuple(),
PersonAlias1::safe_columns_tuple().nullable(), PersonAlias1::safe_columns_tuple().nullable(),
)) ))
@ -179,7 +179,7 @@ mod tests {
use lemmy_db_schema::{ use lemmy_db_schema::{
establish_unpooled_connection, establish_unpooled_connection,
source::{ source::{
local_user::{LocalUser, LocalUserForm}, local_user::{LocalUser, LocalUserForm, LocalUserSettings},
person::*, person::*,
registration_application::{RegistrationApplication, RegistrationApplicationForm}, registration_application::{RegistrationApplication, RegistrationApplicationForm},
}, },
@ -262,7 +262,25 @@ mod tests {
let mut expected_sara_app_view = RegistrationApplicationView { let mut expected_sara_app_view = RegistrationApplicationView {
registration_application: sara_app.to_owned(), registration_application: sara_app.to_owned(),
creator_local_user: inserted_sara_local_user.to_owned(), creator_local_user: LocalUserSettings {
id: inserted_sara_local_user.id,
person_id: inserted_sara_local_user.person_id,
email: inserted_sara_local_user.email,
show_nsfw: inserted_sara_local_user.show_nsfw,
theme: inserted_sara_local_user.theme,
default_sort_type: inserted_sara_local_user.default_sort_type,
default_listing_type: inserted_sara_local_user.default_listing_type,
lang: inserted_sara_local_user.lang,
show_avatars: inserted_sara_local_user.show_avatars,
send_notifications_to_email: inserted_sara_local_user.send_notifications_to_email,
validator_time: inserted_sara_local_user.validator_time,
show_bot_accounts: inserted_sara_local_user.show_bot_accounts,
show_scores: inserted_sara_local_user.show_scores,
show_read_posts: inserted_sara_local_user.show_read_posts,
show_new_post_notifs: inserted_sara_local_user.show_new_post_notifs,
email_verified: inserted_sara_local_user.email_verified,
accepted_application: inserted_sara_local_user.accepted_application,
},
creator: PersonSafe { creator: PersonSafe {
id: inserted_sara_person.id, id: inserted_sara_person.id,
name: inserted_sara_person.name.to_owned(), name: inserted_sara_person.name.to_owned(),

@ -118,6 +118,7 @@ pub enum UserOperation {
ListPostReports, ListPostReports,
GetReportCount, GetReportCount,
GetUnreadCount, GetUnreadCount,
VerifyEmail,
FollowCommunity, FollowCommunity,
GetReplies, GetReplies,
GetPersonMentions, GetPersonMentions,

@ -211,8 +211,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
) )
.route("/report_count", web::get().to(route_get::<GetReportCount>)) .route("/report_count", web::get().to(route_get::<GetReportCount>))
.route("/unread_count", web::get().to(route_get::<GetUnreadCount>)) .route("/unread_count", web::get().to(route_get::<GetUnreadCount>))
// TODO: currently GET for easier testing, but should probably be POST .route("/verify_email", web::post().to(route_post::<VerifyEmail>)),
.route("/verify_email", web::get().to(route_get::<VerifyEmail>)),
) )
// Admin Actions // Admin Actions
.service( .service(

Loading…
Cancel
Save