Skip to content

Commit

Permalink
Merge branch 'main' into local-only-community
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Jan 22, 2024
2 parents e434d18 + e78fe5a commit 8d70cc4
Show file tree
Hide file tree
Showing 38 changed files with 156 additions and 174 deletions.
64 changes: 0 additions & 64 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,21 @@ steps:
- git submodule update

prettier_check:
group: format
image: tmknom/prettier:3.0.0
commands:
- prettier -c . '!**/volumes' '!**/dist' '!target' '!**/translations'

toml_fmt:
group: format
image: tamasfe/taplo:0.8.1
commands:
- taplo format --check

sql_fmt:
group: format
image: backplane/pgformatter:latest
commands:
- ./scripts/sql_format_check.sh

cargo_fmt:
group: format
image: rustlang/rust:nightly
environment:
# store cargo data in repo folder so that it gets cached between steps
Expand All @@ -67,7 +63,6 @@ steps:
- cargo +nightly fmt -- --check

cargo_machete:
group: format
image: rustlang/rust:nightly
commands:
- wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz
Expand All @@ -77,40 +72,12 @@ steps:
- cargo machete

ignored_files:
group: format
image: alpine:3
commands:
- apk add git
- IGNORED=$(git ls-files --cached -i --exclude-standard)
- if [[ "$IGNORED" ]]; then echo "Ignored files present:\n$IGNORED\n"; exit 1; fi

restore-cache:
image: meltwater/drone-cache:v1
pull: true
settings:
restore: true
endpoint:
from_secret: MINIO_ENDPOINT
access-key:
from_secret: MINIO_WRITE_USER
secret-key:
from_secret: MINIO_WRITE_PASSWORD
bucket:
from_secret: MINIO_BUCKET
region: us-east-1
cache_key: "rust-cache"
path-style: true
backend_operation_timeout: 30m
compression_level: 0
exit_code: true
mount:
- ".cargo_home"
- "target"
- "api_tests/node_modules"
secrets:
[MINIO_ENDPOINT, MINIO_WRITE_USER, MINIO_WRITE_PASSWORD, MINIO_BUCKET]
when: *slow_check_paths

# make sure api builds with default features (used by other crates relying on lemmy api)
check_api_common_default_features:
image: *rust_image
Expand Down Expand Up @@ -188,7 +155,6 @@ steps:
when: *slow_check_paths

cargo_test:
group: tests
image: *rust_image
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
Expand All @@ -200,7 +166,6 @@ steps:
when: *slow_check_paths

run_federation_tests:
group: tests
image: node:20-bookworm-slim
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432
Expand All @@ -213,35 +178,6 @@ steps:
- yarn api-test
when: *slow_check_paths

rebuild-cache:
image: meltwater/drone-cache:v1
pull: true
settings:
rebuild: true
endpoint:
from_secret: MINIO_ENDPOINT
access-key:
from_secret: MINIO_WRITE_USER
secret-key:
from_secret: MINIO_WRITE_PASSWORD
bucket:
from_secret: MINIO_BUCKET
cache_key: "rust-cache"
region: us-east-1
path-style: true
backend_operation_timeout: 60m
compression_level: 0
exit_code: true
mount:
- ".cargo_home"
- "target"
- "api_tests/node_modules"
secrets:
[MINIO_ENDPOINT, MINIO_WRITE_USER, MINIO_WRITE_PASSWORD, MINIO_BUCKET]
when:
- event: push
branch: main

publish_release_docker:
image: woodpeckerci/plugin-docker-buildx
secrets: [docker_username, docker_password]
Expand Down
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace.package]
version = "0.19.2-rc.5"
publish = false
version = "0.19.3-rc.1"
edition = "2021"
description = "A link aggregator for the fediverse"
license = "AGPL-3.0"
Expand All @@ -17,6 +16,7 @@ license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true
publish = false

[lib]
doctest = false
Expand Down Expand Up @@ -85,16 +85,16 @@ unused_self = "deny"
unwrap_used = "deny"

[workspace.dependencies]
lemmy_api = { version = "=0.19.2-rc.5", path = "./crates/api" }
lemmy_api_crud = { version = "=0.19.2-rc.5", path = "./crates/api_crud" }
lemmy_apub = { version = "=0.19.2-rc.5", path = "./crates/apub" }
lemmy_utils = { version = "=0.19.2-rc.5", path = "./crates/utils" }
lemmy_db_schema = { version = "=0.19.2-rc.5", path = "./crates/db_schema" }
lemmy_api_common = { version = "=0.19.2-rc.5", path = "./crates/api_common" }
lemmy_routes = { version = "=0.19.2-rc.5", path = "./crates/routes" }
lemmy_db_views = { version = "=0.19.2-rc.5", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.2-rc.5", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.2-rc.5", path = "./crates/db_views_moderator" }
lemmy_api = { version = "=0.19.3-rc.1", path = "./crates/api" }
lemmy_api_crud = { version = "=0.19.3-rc.1", path = "./crates/api_crud" }
lemmy_apub = { version = "=0.19.3-rc.1", path = "./crates/apub" }
lemmy_utils = { version = "=0.19.3-rc.1", path = "./crates/utils" }
lemmy_db_schema = { version = "=0.19.3-rc.1", path = "./crates/db_schema" }
lemmy_api_common = { version = "=0.19.3-rc.1", path = "./crates/api_common" }
lemmy_routes = { version = "=0.19.3-rc.1", path = "./crates/routes" }
lemmy_db_views = { version = "=0.19.3-rc.1", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.3-rc.1", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.3-rc.1", path = "./crates/db_views_moderator" }
activitypub_federation = { version = "0.5.1-beta.1", default-features = false, features = [
"actix-web",
] }
Expand Down Expand Up @@ -166,7 +166,7 @@ lemmy_utils = { workspace = true }
lemmy_db_schema = { workspace = true }
lemmy_api_common = { workspace = true }
lemmy_routes = { workspace = true }
lemmy_federate = { version = "0.19.2-rc.5", path = "crates/federate" }
lemmy_federate = { version = "0.19.3-rc.1", path = "crates/federate" }
activitypub_federation = { workspace = true }
diesel = { workspace = true }
diesel-async = { workspace = true }
Expand Down
7 changes: 6 additions & 1 deletion api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ test("Create a post", async () => {
throw "Missing beta community";
}

let postRes = await createPost(alpha, betaCommunity.community.id);
let postRes = await createPost(
alpha,
betaCommunity.community.id,
"https://example.com/",
"აშშ ითხოვს ირანს დაუყოვნებლივ გაანთავისუფლოს დაკავებული ნავთობის ტანკერი",
);
expect(postRes.post_view.post).toBeDefined();
expect(postRes.post_view.community.local).toBe(false);
expect(postRes.post_view.creator.local).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ export async function setupLogins() {
export async function createPost(
api: LemmyHttp,
community_id: number,
// use example.com for consistent title and embed description
url: string = "https://example.com/",
// use example.com for consistent title and embed description
name: string = randomString(5),
): Promise<PostResponse> {
let name = randomString(5);
let body = randomString(10);
let form: CreatePost = {
name,
Expand Down
13 changes: 6 additions & 7 deletions api_tests/src/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,18 @@ test("Delete user", async () => {
).toBe(true);
});

test("Requests with invalid auth should throw error", async () => {
test("Requests with invalid auth should be treated as unauthenticated", async () => {
let invalid_auth = new LemmyHttp(alphaUrl, {
headers: { Authorization: "Bearer foobar" },
fetchFunction,
});
await expect(getSite(invalid_auth)).rejects.toStrictEqual(
Error("incorrect_login"),
);
let site = await getSite(invalid_auth);
expect(site.my_user).toBeUndefined();
expect(site.site_view).toBeDefined();

let form: GetPosts = {};
await expect(invalid_auth.getPosts(form)).rejects.toStrictEqual(
Error("incorrect_login"),
);
let posts = invalid_auth.getPosts(form);
expect((await posts).posts).toBeDefined();
});

test("Create user with Arabic name", async () => {
Expand Down
22 changes: 20 additions & 2 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ use actix_web::{http::header::Header, HttpRequest};
use actix_web_httpauth::headers::authorization::{Authorization, Bearer};
use base64::{engine::general_purpose::STANDARD_NO_PAD as base64, Engine};
use captcha::Captcha;
use lemmy_api_common::utils::{local_site_to_slur_regex, AUTH_COOKIE_NAME};
use lemmy_api_common::{
claims::Claims,
context::LemmyContext,
utils::{check_user_valid, local_site_to_slur_regex, AUTH_COOKIE_NAME},
};
use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
error::{LemmyError, LemmyErrorExt, LemmyErrorExt2, LemmyErrorType, LemmyResult},
utils::slurs::check_slurs,
};
use std::io::Cursor;
Expand Down Expand Up @@ -137,6 +141,20 @@ pub(crate) fn build_totp_2fa(
.with_lemmy_type(LemmyErrorType::CouldntGenerateTotp)
}

#[tracing::instrument(skip_all)]
pub async fn local_user_view_from_jwt(
jwt: &str,
context: &LemmyContext,
) -> Result<LocalUserView, LemmyError> {
let local_user_id = Claims::validate(jwt, context)
.await
.with_lemmy_type(LemmyErrorType::NotLoggedIn)?;
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
check_user_valid(&local_user_view.person)?;

Ok(local_user_view)
}

#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
Expand Down
Loading

0 comments on commit 8d70cc4

Please sign in to comment.