- Also add get_user_secure to other locations.
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,
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,
// 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,
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 {
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 {
}
};
- 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;
})
.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,
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
}
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()),
comment_score: null,
banned: null,
avatar: null,
- show_avatars: null,
- send_notifications_to_email: null,
actor_id: null,
local: null,
},
creator_preferred_username: undefined,
},
version: undefined,
+ my_user: undefined,
},
};
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
}
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);
}
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);
preferred_username?: string;
avatar?: string;
banner?: string;
- email?: string;
matrix_user_id?: string;
bio?: string;
local: boolean;
number_of_comments: number;
comment_score: number;
banned: boolean;
- show_avatars: boolean;
- send_notifications_to_email: boolean;
}
export interface CommunityUser {