Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use URL type in most outstanding struct fields #1468

Merged
merged 7 commits into from Mar 2, 2021

Conversation

ajyoon
Copy link
Contributor

@ajyoon ajyoon commented Feb 28, 2021

This fixes all known remaining cases where url fields are stored as
plain strings, with the exception of form fields where empty strings
are used as sentinels (see diesel_option_overwrite_to_url).

This also adds a small migration cleaning up bad post.url data,
converting all instances of empty strings to nulls.

Tested for regressions in the federated docker setup attempting to
exercise all changed fields, including through apub federation.

Fixes #1385 and fixes #602

This fixes all known remaining cases where url fields are stored as
plain strings, with the exception of form fields where empty strings
are used as sentinels (see `diesel_option_overwrite_to_url`).

Tested for regressions in the federated docker setup attempting to
exercise all changed fields, including through apub federation.

Fixes LemmyNet#1385
@@ -46,12 +46,14 @@ pub async fn get_activity(
context: web::Data<LemmyContext>,
) -> Result<HttpResponse<Body>, LemmyError> {
let settings = Settings::get();
let activity_id = format!(
let activity_id = url::Url::parse(&format!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor, but please import the type instead of doing this.

"{}/activities/{}/{}",
settings.get_protocol_and_hostname(),
info.type_,
info.id
);
))
.unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont use unwrap.

avatar,
banner,
avatar: avatar.map(|outer| outer.map(|inner| inner.into())),
banner: banner.map(|outer| outer.map(|inner| inner.into())),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be simplified, at least use shorter variable names.

// An empty string is an erase
Some(unwrapped) => {
if !unwrapped.eq("") {
Some(Some(url::Url::parse(unwrapped)?.into()))
Copy link
Member

@Nutomic Nutomic Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import Url.

Edit: Ah its probably because of lemmy_db_schema::Url, thats annoying. I guess we should rename our Url type, but dunno whats a good alternative name. LemmyUrl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that's the reason, I guess this newtype is needed to workaround the orphan rule? maybe DbUrl would be most self-explanatory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good. You can change it as part of this PR if you dont mind.

crates/apub/src/http/mod.rs Outdated Show resolved Hide resolved
crates/utils/src/request.rs Outdated Show resolved Hide resolved
@Nutomic
Copy link
Member

Nutomic commented Mar 1, 2021

CI didnt run, it seems like it was misconfigured. I changed the settings and hopefully it should run for your next push. Thanks for the PR!

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job, just a few fixes needed.

crates/api/src/lib.rs Show resolved Hide resolved
crates/db_queries/src/lib.rs Outdated Show resolved Hide resolved
@dessalines
Copy link
Member

dessalines commented Mar 1, 2021

Don't worry about the conflicts, we'll fix them once the above changes are made ( and the CI passes )

- Fixed some unwraps and err message formatting
- Bumped the `url` library to 2.2.1 to fix a bug with serde error
  messages
- Add unit tests for the two diesel option override functions
- Fix migration teardown by adding a no-op
@ajyoon
Copy link
Contributor Author

ajyoon commented Mar 1, 2021

i went ahead and merged since the build was unhappy with the conflicts, it seems to compile at least

@ajyoon
Copy link
Contributor Author

ajyoon commented Mar 1, 2021

hmm clippy is blocking on some warnings unrelated to this change. I was hitting this locally too so I've been committing with --no-verify (but running checks manually to make sure my changes didn't introduce anything new)

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, once we figure out the clippy issues I'm good to merge.

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, nice job! I def prefer the DbUrl change to avoid the name conflict too.

@dessalines dessalines requested a review from Nutomic March 1, 2021 20:29
@Nutomic Nutomic merged commit e78ba38 into LemmyNet:main Mar 2, 2021
@Nutomic
Copy link
Member

Nutomic commented Mar 2, 2021

Looks good, thank you :)

@ajyoon ajyoon deleted the more-url-types branch March 2, 2021 16:04
Mart-Bogdan added a commit to Mart-Bogdan/lemmy that referenced this pull request Mar 13, 2021
…n-pwd-change

* origin/main:
  revert Compose file version from 3.3 to 2.2
  Adding more mem limits
  bump memory limit of iframely
  Remove extra category_id s . Fixes LemmyNet#1429
  Fixing wrong user_ and community icon and banner urls.
  Remove category from activitypub context
  Adding a password length check to other API actions. (LemmyNet#1474)
  Update test script
  Use URL type in most outstanding struct fields (LemmyNet#1468)
  Forbid usage of unwrap
  Upgrade Rust version
  Rewrite settings implementation. Fixes LemmyNet#1270 (LemmyNet#1433)
  Rename `lemmy_structs` to `lemmy_api_structs`

# Conflicts:
#	crates/db_schema/src/source/user.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Url type in remaining database structs Invalid value in PostView.url
3 participants