mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-12 15:34:00 +00:00
Add email overwrite on user settings save. Fixes #1069
- Also add get_user_secure to other locations.
This commit is contained in:
parent
52ac4f70e1
commit
221db1bd1b
7 changed files with 19 additions and 31 deletions
|
@ -46,7 +46,7 @@ pub struct UserForm {
|
||||||
pub password_encrypted: String,
|
pub password_encrypted: String,
|
||||||
pub admin: bool,
|
pub admin: bool,
|
||||||
pub banned: bool,
|
pub banned: bool,
|
||||||
pub email: Option<String>,
|
pub email: Option<Option<String>>,
|
||||||
pub avatar: Option<Option<String>>,
|
pub avatar: Option<Option<String>>,
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
pub show_nsfw: bool,
|
pub show_nsfw: bool,
|
||||||
|
|
|
@ -710,7 +710,7 @@ impl Perform for Oper<BanFromCommunity> {
|
||||||
blocking(pool, move |conn| ModBanFromCommunity::create(conn, &form)).await??;
|
blocking(pool, move |conn| ModBanFromCommunity::create(conn, &form)).await??;
|
||||||
|
|
||||||
let user_id = data.user_id;
|
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 {
|
let res = BanFromCommunityResponse {
|
||||||
user: user_view,
|
user: user_view,
|
||||||
|
|
|
@ -395,7 +395,7 @@ impl Perform for Oper<Register> {
|
||||||
// Register the new user
|
// Register the new user
|
||||||
let user_form = UserForm {
|
let user_form = UserForm {
|
||||||
name: data.username.to_owned(),
|
name: data.username.to_owned(),
|
||||||
email: data.email.to_owned(),
|
email: Some(data.email.to_owned()),
|
||||||
matrix_user_id: None,
|
matrix_user_id: None,
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
|
@ -559,11 +559,6 @@ impl Perform for Oper<SaveUserSettings> {
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
let read_user = blocking(pool, move |conn| User_::read(conn, user_id)).await??;
|
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 {
|
let bio = match &data.bio {
|
||||||
Some(bio) => {
|
Some(bio) => {
|
||||||
if bio.chars().count() <= 300 {
|
if bio.chars().count() <= 300 {
|
||||||
|
@ -577,6 +572,7 @@ impl Perform for Oper<SaveUserSettings> {
|
||||||
|
|
||||||
let avatar = diesel_option_overwrite(&data.avatar);
|
let avatar = diesel_option_overwrite(&data.avatar);
|
||||||
let banner = diesel_option_overwrite(&data.banner);
|
let banner = diesel_option_overwrite(&data.banner);
|
||||||
|
let email = diesel_option_overwrite(&data.email);
|
||||||
|
|
||||||
// The DB constraint should stop too many characters
|
// The DB constraint should stop too many characters
|
||||||
let preferred_username = match &data.preferred_username {
|
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 page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
|
@ -747,13 +746,6 @@ impl Perform for Oper<GetUserDetails> {
|
||||||
})
|
})
|
||||||
.await??;
|
.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
|
// Return the jwt
|
||||||
Ok(GetUserDetailsResponse {
|
Ok(GetUserDetailsResponse {
|
||||||
user: user_view,
|
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?;
|
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
|
response
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
|
|
||||||
let form = UserForm {
|
let form = UserForm {
|
||||||
name: cuser.name.to_owned(),
|
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(),
|
matrix_user_id: cuser.matrix_user_id.to_owned(),
|
||||||
avatar: Some(cuser.avatar.to_owned()),
|
avatar: Some(cuser.avatar.to_owned()),
|
||||||
banner: Some(cuser.banner.to_owned()),
|
banner: Some(cuser.banner.to_owned()),
|
||||||
|
|
18
ui/src/components/user.tsx
vendored
18
ui/src/components/user.tsx
vendored
|
@ -90,8 +90,6 @@ export class User extends Component<any, UserState> {
|
||||||
comment_score: null,
|
comment_score: null,
|
||||||
banned: null,
|
banned: null,
|
||||||
avatar: null,
|
avatar: null,
|
||||||
show_avatars: null,
|
|
||||||
send_notifications_to_email: null,
|
|
||||||
actor_id: null,
|
actor_id: null,
|
||||||
local: null,
|
local: null,
|
||||||
},
|
},
|
||||||
|
@ -143,6 +141,7 @@ export class User extends Component<any, UserState> {
|
||||||
creator_preferred_username: undefined,
|
creator_preferred_username: undefined,
|
||||||
},
|
},
|
||||||
version: undefined,
|
version: undefined,
|
||||||
|
my_user: undefined,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -724,7 +723,7 @@ export class User extends Component<any, UserState> {
|
||||||
class="form-check-input"
|
class="form-check-input"
|
||||||
id="user-send-notifications-to-email"
|
id="user-send-notifications-to-email"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
disabled={!this.state.user.email}
|
disabled={!this.state.userSettingsForm.email}
|
||||||
checked={
|
checked={
|
||||||
this.state.userSettingsForm.send_notifications_to_email
|
this.state.userSettingsForm.send_notifications_to_email
|
||||||
}
|
}
|
||||||
|
@ -922,9 +921,6 @@ export class User extends Component<any, UserState> {
|
||||||
|
|
||||||
handleUserSettingsEmailChange(i: User, event: any) {
|
handleUserSettingsEmailChange(i: User, event: any) {
|
||||||
i.state.userSettingsForm.email = event.target.value;
|
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);
|
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.banner = UserService.Instance.user.banner;
|
||||||
this.state.userSettingsForm.preferred_username =
|
this.state.userSettingsForm.preferred_username =
|
||||||
UserService.Instance.user.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 =
|
this.state.userSettingsForm.show_avatars =
|
||||||
UserService.Instance.user.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.state.loading = false;
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
|
|
3
ui/src/interfaces.ts
vendored
3
ui/src/interfaces.ts
vendored
|
@ -139,7 +139,6 @@ export interface UserView {
|
||||||
preferred_username?: string;
|
preferred_username?: string;
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
banner?: string;
|
banner?: string;
|
||||||
email?: string;
|
|
||||||
matrix_user_id?: string;
|
matrix_user_id?: string;
|
||||||
bio?: string;
|
bio?: string;
|
||||||
local: boolean;
|
local: boolean;
|
||||||
|
@ -149,8 +148,6 @@ export interface UserView {
|
||||||
number_of_comments: number;
|
number_of_comments: number;
|
||||||
comment_score: number;
|
comment_score: number;
|
||||||
banned: boolean;
|
banned: boolean;
|
||||||
show_avatars: boolean;
|
|
||||||
send_notifications_to_email: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CommunityUser {
|
export interface CommunityUser {
|
||||||
|
|
Loading…
Reference in a new issue