mirror of https://github.com/LemmyNet/lemmy.git
Add email overwrite on user settings save. Fixes #1069
- Also add get_user_secure to other locations.pull/1071/head
parent
52ac4f70e1
commit
221db1bd1b
|
@ -46,7 +46,7 @@ pub struct UserForm {
|
|||
pub password_encrypted: String,
|
||||
pub admin: bool,
|
||||
pub banned: bool,
|
||||
pub email: Option<String>,
|
||||
pub email: Option<Option<String>>,
|
||||
pub avatar: Option<Option<String>>,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub show_nsfw: bool,
|
||||
|
|
|
@ -710,7 +710,7 @@ impl Perform for Oper<BanFromCommunity> {
|
|||
blocking(pool, move |conn| ModBanFromCommunity::create(conn, &form)).await??;
|
||||
|
||||
let user_id = data.user_id;
|
||||
let user_view = blocking(pool, move |conn| UserView::read(conn, user_id)).await??;
|
||||
let user_view = blocking(pool, move |conn| UserView::get_user_secure(conn, user_id)).await??;
|
||||
|
||||
let res = BanFromCommunityResponse {
|
||||
user: user_view,
|
||||
|
|
|
@ -395,7 +395,7 @@ impl Perform for Oper<Register> {
|
|||
// Register the new user
|
||||
let user_form = UserForm {
|
||||
name: data.username.to_owned(),
|
||||
email: data.email.to_owned(),
|
||||
email: Some(data.email.to_owned()),
|
||||
matrix_user_id: None,
|
||||
avatar: None,
|
||||
banner: None,
|
||||
|
@ -559,11 +559,6 @@ impl Perform for Oper<SaveUserSettings> {
|
|||
let user_id = user.id;
|
||||
let read_user = blocking(pool, move |conn| User_::read(conn, user_id)).await??;
|
||||
|
||||
let email = match &data.email {
|
||||
Some(email) => Some(email.to_owned()),
|
||||
None => read_user.email,
|
||||
};
|
||||
|
||||
let bio = match &data.bio {
|
||||
Some(bio) => {
|
||||
if bio.chars().count() <= 300 {
|
||||
|
@ -577,6 +572,7 @@ impl Perform for Oper<SaveUserSettings> {
|
|||
|
||||
let avatar = diesel_option_overwrite(&data.avatar);
|
||||
let banner = diesel_option_overwrite(&data.banner);
|
||||
let email = diesel_option_overwrite(&data.email);
|
||||
|
||||
// The DB constraint should stop too many characters
|
||||
let preferred_username = match &data.preferred_username {
|
||||
|
@ -700,7 +696,10 @@ impl Perform for Oper<GetUserDetails> {
|
|||
}
|
||||
};
|
||||
|
||||
let mut user_view = blocking(pool, move |conn| UserView::read(conn, user_details_id)).await??;
|
||||
let user_view = blocking(pool, move |conn| {
|
||||
UserView::get_user_secure(conn, user_details_id)
|
||||
})
|
||||
.await??;
|
||||
|
||||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
|
@ -747,13 +746,6 @@ impl Perform for Oper<GetUserDetails> {
|
|||
})
|
||||
.await??;
|
||||
|
||||
// If its not the same user, remove the email, and settings
|
||||
// TODO an if let chain would be better here, but can't figure it out
|
||||
// TODO separate out settings into its own thing
|
||||
if user_id.is_none() || user_details_id != user_id.unwrap_or(0) {
|
||||
user_view.email = None;
|
||||
}
|
||||
|
||||
// Return the jwt
|
||||
Ok(GetUserDetailsResponse {
|
||||
user: user_view,
|
||||
|
|
|
@ -151,7 +151,8 @@ pub async fn search_by_apub_id(
|
|||
|
||||
let user = get_or_fetch_and_upsert_user(&user_uri, client, pool).await?;
|
||||
|
||||
response.users = vec![blocking(pool, move |conn| UserView::read(conn, user.id)).await??];
|
||||
response.users =
|
||||
vec![blocking(pool, move |conn| UserView::get_user_secure(conn, user.id)).await??];
|
||||
|
||||
response
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
|
|||
|
||||
let form = UserForm {
|
||||
name: cuser.name.to_owned(),
|
||||
email: cuser.email.to_owned(),
|
||||
email: Some(cuser.email.to_owned()),
|
||||
matrix_user_id: cuser.matrix_user_id.to_owned(),
|
||||
avatar: Some(cuser.avatar.to_owned()),
|
||||
banner: Some(cuser.banner.to_owned()),
|
||||
|
|
|
@ -90,8 +90,6 @@ export class User extends Component<any, UserState> {
|
|||
comment_score: null,
|
||||
banned: null,
|
||||
avatar: null,
|
||||
show_avatars: null,
|
||||
send_notifications_to_email: null,
|
||||
actor_id: null,
|
||||
local: null,
|
||||
},
|
||||
|
@ -143,6 +141,7 @@ export class User extends Component<any, UserState> {
|
|||
creator_preferred_username: undefined,
|
||||
},
|
||||
version: undefined,
|
||||
my_user: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -724,7 +723,7 @@ export class User extends Component<any, UserState> {
|
|||
class="form-check-input"
|
||||
id="user-send-notifications-to-email"
|
||||
type="checkbox"
|
||||
disabled={!this.state.user.email}
|
||||
disabled={!this.state.userSettingsForm.email}
|
||||
checked={
|
||||
this.state.userSettingsForm.send_notifications_to_email
|
||||
}
|
||||
|
@ -922,9 +921,6 @@ export class User extends Component<any, UserState> {
|
|||
|
||||
handleUserSettingsEmailChange(i: User, event: any) {
|
||||
i.state.userSettingsForm.email = event.target.value;
|
||||
if (i.state.userSettingsForm.email == '' && !i.state.user.email) {
|
||||
i.state.userSettingsForm.email = undefined;
|
||||
}
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
|
@ -1063,12 +1059,14 @@ export class User extends Component<any, UserState> {
|
|||
this.state.userSettingsForm.banner = UserService.Instance.user.banner;
|
||||
this.state.userSettingsForm.preferred_username =
|
||||
UserService.Instance.user.preferred_username;
|
||||
this.state.userSettingsForm.email = this.state.user.email;
|
||||
this.state.userSettingsForm.bio = this.state.user.bio;
|
||||
this.state.userSettingsForm.send_notifications_to_email = this.state.user.send_notifications_to_email;
|
||||
this.state.userSettingsForm.show_avatars =
|
||||
UserService.Instance.user.show_avatars;
|
||||
this.state.userSettingsForm.matrix_user_id = this.state.user.matrix_user_id;
|
||||
this.state.userSettingsForm.email = UserService.Instance.user.email;
|
||||
this.state.userSettingsForm.bio = UserService.Instance.user.bio;
|
||||
this.state.userSettingsForm.send_notifications_to_email =
|
||||
UserService.Instance.user.send_notifications_to_email;
|
||||
this.state.userSettingsForm.matrix_user_id =
|
||||
UserService.Instance.user.matrix_user_id;
|
||||
}
|
||||
this.state.loading = false;
|
||||
this.setState(this.state);
|
||||
|
|
|
@ -139,7 +139,6 @@ export interface UserView {
|
|||
preferred_username?: string;
|
||||
avatar?: string;
|
||||
banner?: string;
|
||||
email?: string;
|
||||
matrix_user_id?: string;
|
||||
bio?: string;
|
||||
local: boolean;
|
||||
|
@ -149,8 +148,6 @@ export interface UserView {
|
|||
number_of_comments: number;
|
||||
comment_score: number;
|
||||
banned: boolean;
|
||||
show_avatars: boolean;
|
||||
send_notifications_to_email: boolean;
|
||||
}
|
||||
|
||||
export interface CommunityUser {
|
||||
|
|
Loading…
Reference in New Issue