Skip to content

Commit

Permalink
Merge branch 'main' into structured-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Jul 3, 2023
2 parents edf1e9e + e1494d4 commit 02959b5
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Each Lemmy server can set its own moderation policy; appointing site-wide admins

## Lemmy Projects

- [awesome-lemmy - A community driven list of apps and tools for lemmy](https://github.com/LemmyNet/awesome-lemmy)
- [awesome-lemmy - A community driven list of apps and tools for lemmy](https://github.com/dbeley/awesome-lemmy)

## Support / Donate

Expand Down
1 change: 1 addition & 0 deletions crates/api/src/local_user/save_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl Perform for SaveUserSettings {
.interface_language(data.interface_language.clone())
.totp_2fa_secret(totp_2fa_secret)
.totp_2fa_url(totp_2fa_url)
.open_links_in_new_tab(data.open_links_in_new_tab)
.build();

let local_user_res = LocalUser::update(context.pool(), local_user_id, &local_user_form).await;
Expand Down
8 changes: 5 additions & 3 deletions crates/api_common/src/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ pub struct GetCaptchaResponse {
#[cfg_attr(feature = "full", ts(export))]
/// A captcha response.
pub struct CaptchaResponse {
/// A Base64 encoded png
/// A Base64 encoded png
pub png: String,
/// A Base64 encoded wav audio
/// A Base64 encoded wav audio
pub wav: String,
/// The UUID for the captcha item.
pub uuid: String,
Expand Down Expand Up @@ -109,7 +109,7 @@ pub struct SaveUserSettings {
pub email: Option<Sensitive<String>>,
/// Your bio / info, in markdown.
pub bio: Option<String>,
/// Your matrix user id. Ex: @my_user:matrix.org
/// Your matrix user id. Ex: @my_user:matrix.org
pub matrix_user_id: Option<String>,
/// Whether to show or hide avatars.
pub show_avatars: Option<bool>,
Expand All @@ -131,6 +131,8 @@ pub struct SaveUserSettings {
/// None leaves it as is, true will generate or regenerate it, false clears it out.
pub generate_totp_2fa: Option<bool>,
pub auth: Sensitive<String>,
/// Open links in a new tab
pub open_links_in_new_tab: Option<bool>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
Expand Down
15 changes: 3 additions & 12 deletions crates/api_crud/src/post/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,9 @@ impl PerformCrud for CreatePost {
.thumbnail_url(thumbnail_url)
.build();

let inserted_post = match Post::create(context.pool(), &post_form).await {
Ok(post) => post,
Err(e) => {
let err_type = if e.to_string() == "value too long for type character varying(200)" {
"post_title_too_long"
} else {
"couldnt_create_post"
};

return Err(LemmyError::from_error_message(e, err_type));
}
};
let inserted_post = Post::create(context.pool(), &post_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;

let inserted_post_id = inserted_post.id;
let protocol_and_hostname = context.settings().get_protocol_and_hostname();
Expand Down
13 changes: 3 additions & 10 deletions crates/api_crud/src/post/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,9 @@ impl PerformCrud for EditPost {
.build();

let post_id = data.post_id;
let res = Post::update(context.pool(), post_id, &post_form).await;
if let Err(e) = res {
let err_type = if e.to_string() == "value too long for type character varying(200)" {
"post_title_too_long"
} else {
"couldnt_update_post"
};

return Err(LemmyError::from_error_message(e, err_type));
}
Post::update(context.pool(), post_id, &post_form)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;

build_post_response(
context,
Expand Down
1 change: 1 addition & 0 deletions crates/db_schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ diesel::table! {
accepted_application -> Bool,
totp_2fa_secret -> Nullable<Text>,
totp_2fa_url -> Nullable<Text>,
open_links_in_new_tab -> Bool,
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/db_schema/src/source/local_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub struct LocalUser {
pub totp_2fa_secret: Option<String>,
/// A URL to add their 2-factor auth.
pub totp_2fa_url: Option<String>,
/// Open links in a new tab.
pub open_links_in_new_tab: bool,
}

#[derive(Clone, TypedBuilder)]
Expand Down Expand Up @@ -78,6 +80,7 @@ pub struct LocalUserInsertForm {
pub accepted_application: Option<bool>,
pub totp_2fa_secret: Option<Option<String>>,
pub totp_2fa_url: Option<Option<String>>,
pub open_links_in_new_tab: Option<bool>,
}

#[derive(Clone, TypedBuilder)]
Expand All @@ -102,4 +105,5 @@ pub struct LocalUserUpdateForm {
pub accepted_application: Option<bool>,
pub totp_2fa_secret: Option<Option<String>>,
pub totp_2fa_url: Option<Option<String>>,
pub open_links_in_new_tab: Option<bool>,
}
1 change: 1 addition & 0 deletions crates/db_views/src/registration_application_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ mod tests {
totp_2fa_secret: inserted_sara_local_user.totp_2fa_secret,
totp_2fa_url: inserted_sara_local_user.totp_2fa_url,
password_encrypted: inserted_sara_local_user.password_encrypted,
open_links_in_new_tab: inserted_sara_local_user.open_links_in_new_tab,
},
creator: Person {
id: inserted_sara_person.id,
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/src/utils/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use url::Url;
static VALID_ACTOR_NAME_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex"));
static VALID_POST_TITLE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r".*\S{3,}.*").expect("compile regex"));
Lazy::new(|| Regex::new(r".*\S{3,200}.*").expect("compile regex"));
static VALID_MATRIX_ID_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex")
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table local_user drop column open_links_in_new_tab;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table local_user add column open_links_in_new_tab boolean default false not null;

0 comments on commit 02959b5

Please sign in to comment.