From b7c24a372bfe80057d71edef856afd985714f660 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 26 Dec 2019 20:48:13 +0100 Subject: [PATCH] Fix review comments --- .gitignore | 1 - docker/dev/Dockerfile | 2 +- docker/dev/Dockerfile.aarch64 | 2 +- docker/dev/Dockerfile.armv7hf | 2 +- docker/dev/Dockerfile.libc | 2 +- server/config/defaults.hjson | 26 +++++++------- server/src/db/community.rs | 4 +-- server/src/db/password_reset_request.rs | 2 +- server/src/db/user.rs | 4 +-- server/src/feeds.rs | 4 +-- server/src/lib.rs | 2 +- server/src/webfinger.rs | 45 +++++++++++++++---------- 12 files changed, 53 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index e36af1295..4cb8939f5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ ansible/inventory ansible/passwords/ build/ .idea/ -docker/dev/config/config.hjson diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index 080b7fb3e..d62e7b279 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -38,7 +38,7 @@ FROM alpine:3.10 RUN apk add libpq # Copy resources -COPY server/config /config +COPY server/config/defaults.hjson /config/defaults.hjson COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/lemmy_server /app/lemmy COPY --from=node /app/ui/dist /app/dist diff --git a/docker/dev/Dockerfile.aarch64 b/docker/dev/Dockerfile.aarch64 index 1b08c64e5..15810f785 100644 --- a/docker/dev/Dockerfile.aarch64 +++ b/docker/dev/Dockerfile.aarch64 @@ -69,7 +69,7 @@ RUN addgroup --gid 1000 lemmy RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy # Copy resources -COPY server/config /app/config +COPY server/config/defaults.hjson /config/defaults.hjson COPY --from=rust /app/server/ready /app/lemmy COPY --from=node /app/ui/dist /app/dist diff --git a/docker/dev/Dockerfile.armv7hf b/docker/dev/Dockerfile.armv7hf index 67067a18a..c2c9084c1 100644 --- a/docker/dev/Dockerfile.armv7hf +++ b/docker/dev/Dockerfile.armv7hf @@ -69,7 +69,7 @@ RUN addgroup --gid 1000 lemmy RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy # Copy resources -COPY server/config /config +COPY server/config/defaults.hjson /config/defaults.hjson COPY --from=rust /app/server/ready /app/lemmy COPY --from=node /app/ui/dist /app/dist diff --git a/docker/dev/Dockerfile.libc b/docker/dev/Dockerfile.libc index 22d8d9100..6b9b347ef 100644 --- a/docker/dev/Dockerfile.libc +++ b/docker/dev/Dockerfile.libc @@ -65,7 +65,7 @@ RUN addgroup --gid 1000 lemmy RUN adduser --disabled-password --shell /bin/sh --uid 1000 --ingroup lemmy lemmy # Copy resources -COPY server/config /app/config +COPY server/config/defaults.hjson /config/defaults.hjson COPY --from=rust /app/server/ready /app/lemmy COPY --from=node /app/ui/dist /app/dist diff --git a/server/config/defaults.hjson b/server/config/defaults.hjson index ceb21db0e..e5a8f6dc0 100644 --- a/server/config/defaults.hjson +++ b/server/config/defaults.hjson @@ -1,19 +1,19 @@ { # settings related to the postgresql database database: { - # username to connect to postgres - user: "lemmy" - # password to connect to postgres - password: "password" - # host where postgres is running - host: "localhost" - # port where postgres can be accessed - port: 5432 - # name of the postgres database for lemmy - database: "lemmy" - # maximum number of active sql connections - pool_size: 5 - } + # username to connect to postgres + user: "lemmy" + # password to connect to postgres + password: "password" + # host where postgres is running + host: "localhost" + # port where postgres can be accessed + port: 5432 + # name of the postgres database for lemmy + database: "lemmy" + # maximum number of active sql connections + pool_size: 5 + } # the domain name of your instance (eg "dev.lemmy.ml") hostname: "rrr" # address where lemmy should listen for incoming requests diff --git a/server/src/db/community.rs b/server/src/db/community.rs index 74579535e..e8bf5bbc4 100644 --- a/server/src/db/community.rs +++ b/server/src/db/community.rs @@ -69,8 +69,8 @@ impl Community { .first::(conn) } - pub fn get_community_url(community_name: &str) -> String { - format!("https://{}/c/{}", Settings::get().hostname, community_name) + pub fn get_url(&self) -> String { + format!("https://{}/c/{}", Settings::get().hostname, self.name) } } diff --git a/server/src/db/password_reset_request.rs b/server/src/db/password_reset_request.rs index d620f1794..337b2e6b0 100644 --- a/server/src/db/password_reset_request.rs +++ b/server/src/db/password_reset_request.rs @@ -1,7 +1,7 @@ use super::*; use crate::schema::password_reset_request; use crate::schema::password_reset_request::dsl::*; -use sha2::{Sha256, Digest}; +use sha2::{Digest, Sha256}; #[derive(Queryable, Identifiable, PartialEq, Debug)] #[table_name = "password_reset_request"] diff --git a/server/src/db/user.rs b/server/src/db/user.rs index 21407e58c..c636f4e67 100644 --- a/server/src/db/user.rs +++ b/server/src/db/user.rs @@ -151,8 +151,8 @@ impl User_ { } } - pub fn get_user_profile_url(username: &str) -> String { - format!("https://{}/u/{}", Settings::get().hostname, username) + pub fn get_profile_url(&self) -> String { + format!("https://{}/u/{}", Settings::get().hostname, self.name) } pub fn find_by_jwt(conn: &PgConnection, jwt: &str) -> Result { diff --git a/server/src/feeds.rs b/server/src/feeds.rs index c735688be..c624bcc53 100644 --- a/server/src/feeds.rs +++ b/server/src/feeds.rs @@ -111,7 +111,7 @@ fn get_feed_user(sort_type: &SortType, user_name: String) -> Result Result) -> HttpResponse { - // NOTE: Calling the parameter "account" maybe doesn't really make sense, but should give us the - // best compatibility with existing implementations. We could also support an alternative name - // like "group", and encourage others to use that. - let community_identifier = info.resource.replace("acct:", ""); - let split_identifier: Vec<&str> = community_identifier.split("@").collect(); - let community_name = split_identifier[0]; - // It looks like Mastodon does not return webfinger requests for users from other instances, so we - // don't do that either. - if split_identifier.len() != 2 || split_identifier[1] != Settings::get().hostname { - return HttpResponse::NotFound().finish(); - } + let regex_parsed = WEBFINGER_COMMUNITY_REGEX + .captures(&info.resource) + .map(|c| c.get(1)); + // TODO: replace this with .flatten() once we are running rust 1.40 + let regex_parsed_flattened = match regex_parsed { + Some(s) => s, + None => None, + }; + let community_name = match regex_parsed_flattened { + Some(c) => c.as_str(), + None => return HttpResponse::NotFound().finish(), + }; // Make sure the requested community exists. let conn = establish_connection(); - match Community::read_from_name(&conn, community_name.to_owned()) { + let community = match Community::read_from_name(&conn, community_name.to_string()) { + Ok(o) => o, Err(_) => return HttpResponse::NotFound().finish(), - Ok(c) => c, }; - let community_url = Community::get_community_url(&community_name); + let community_url = community.get_url(); let json = json!({ "subject": info.resource, @@ -54,7 +64,8 @@ pub fn get_webfinger_response(info: Query) -> HttpResponse { { "rel": "self", "type": "application/activity+json", - "href": community_url // Yes this is correct, this link doesn't include the `.json` extension + // Yes this is correct, this link doesn't include the `.json` extension + "href": community_url } // TODO: this also needs to return the subscribe link once that's implemented //{ @@ -63,7 +74,7 @@ pub fn get_webfinger_response(info: Query) -> HttpResponse { //} ] }); - return HttpResponse::Ok() + HttpResponse::Ok() .content_type("application/activity+json") - .body(json.to_string()); + .body(json.to_string()) }