Skip to content

Commit

Permalink
Merge branch 'main' into user-block-instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Aug 29, 2023
2 parents fe40cdf + c93bde9 commit 0131eab
Show file tree
Hide file tree
Showing 32 changed files with 274 additions and 158 deletions.
4 changes: 2 additions & 2 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ variables:
- "**/Cargo.toml"
- "Cargo.lock"
# database migrations
- "migrations"
- "migrations/**"
# typescript tests
- "api_tests"
- "api_tests/**"
# config files and scripts used by ci
- ".woodpecker.yml"
- ".rustfmt.toml"
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion api_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"eslint": "^8.40.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^29.5.0",
"lemmy-js-client": "0.18.3-rc.3",
"lemmy-js-client": "0.19.0-rc.2",
"prettier": "^3.0.0",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"
Expand Down
1 change: 1 addition & 0 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ export async function getPersonDetails(
export async function deleteUser(api: API): Promise<DeleteAccountResponse> {
let form: DeleteAccount = {
auth: api.auth,
delete_content: true,
password,
};
return api.client.deleteAccount(form);
Expand Down
8 changes: 4 additions & 4 deletions api_tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2174,10 +2174,10 @@ kleur@^3.0.3:
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==

lemmy-js-client@0.18.3-rc.3:
version "0.18.3-rc.3"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.18.3-rc.3.tgz#fc6489eb141bd09558bca38d9e46b40771a29f37"
integrity sha512-njixgXk4uMU4gGifnljwhSe9Kf445C4wAXcXhtpTtwPPLXpHQgxA1RASMb9Uq4zblfE6nC2JbrAka8y8N2N/Bw==
lemmy-js-client@0.19.0-rc.2:
version "0.19.0-rc.2"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.2.tgz#c3cb511b27f92538909a2b91a0f8527b1abad958"
integrity sha512-FXuf8s7bpBVkHL/OGWDb/0aGIrJ7uv3d4Xt1h6zmNDhw6MmmuD8RXgCHiS2jqhxjAEp96Dpl1NFXbpmKpix7tQ==
dependencies:
cross-fetch "^3.1.5"
form-data "^4.0.0"
Expand Down
8 changes: 1 addition & 7 deletions crates/api/src/local_user/ban_person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ pub async fn ban_from_site(
// Remove their data if that's desired
let remove_data = data.remove_data.unwrap_or(false);
if remove_data {
remove_user_data(
person.id,
&mut context.pool(),
context.settings(),
context.client(),
)
.await?;
remove_user_data(person.id, &context).await?;
}

// Mod tables
Expand Down
16 changes: 3 additions & 13 deletions crates/api/src/site/purge/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,14 @@ impl Perform for PurgeCommunity {
let community = Community::read(&mut context.pool(), community_id).await?;

if let Some(banner) = community.banner {
purge_image_from_pictrs(context.client(), context.settings(), &banner)
.await
.ok();
purge_image_from_pictrs(&banner, context).await.ok();
}

if let Some(icon) = community.icon {
purge_image_from_pictrs(context.client(), context.settings(), &icon)
.await
.ok();
purge_image_from_pictrs(&icon, context).await.ok();
}

purge_image_posts_for_community(
community_id,
&mut context.pool(),
context.settings(),
context.client(),
)
.await?;
purge_image_posts_for_community(community_id, context).await?;

Community::delete(&mut context.pool(), community_id).await?;

Expand Down
16 changes: 3 additions & 13 deletions crates/api/src/site/purge/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,14 @@ impl Perform for PurgePerson {
let person = Person::read(&mut context.pool(), person_id).await?;

if let Some(banner) = person.banner {
purge_image_from_pictrs(context.client(), context.settings(), &banner)
.await
.ok();
purge_image_from_pictrs(&banner, context).await.ok();
}

if let Some(avatar) = person.avatar {
purge_image_from_pictrs(context.client(), context.settings(), &avatar)
.await
.ok();
purge_image_from_pictrs(&avatar, context).await.ok();
}

purge_image_posts_for_person(
person_id,
&mut context.pool(),
context.settings(),
context.client(),
)
.await?;
purge_image_posts_for_person(person_id, context).await?;

Person::delete(&mut context.pool(), person_id).await?;

Expand Down
8 changes: 2 additions & 6 deletions crates/api/src/site/purge/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ impl Perform for PurgePost {

// Purge image
if let Some(url) = post.url {
purge_image_from_pictrs(context.client(), context.settings(), &url)
.await
.ok();
purge_image_from_pictrs(&url, context).await.ok();
}
// Purge thumbnail
if let Some(thumbnail_url) = post.thumbnail_url {
purge_image_from_pictrs(context.client(), context.settings(), &thumbnail_url)
.await
.ok();
purge_image_from_pictrs(&thumbnail_url, context).await.ok();
}

let community_id = post.community_id;
Expand Down
20 changes: 10 additions & 10 deletions crates/api/src/sitemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ use actix_web::{
web::Data,
HttpResponse,
};
use chrono::{DateTime, FixedOffset};
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{newtypes::DbUrl, source::post::Post};
use lemmy_utils::error::LemmyResult;
use sitemap_rs::{url::Url, url_set::UrlSet};
use tracing::info;

async fn generate_urlset(posts: Vec<(DbUrl, chrono::NaiveDateTime)>) -> LemmyResult<UrlSet> {
async fn generate_urlset(
posts: Vec<(DbUrl, chrono::DateTime<chrono::Utc>)>,
) -> LemmyResult<UrlSet> {
let urls = posts
.into_iter()
.map_while(|post| {
Url::builder(post.0.to_string())
.last_modified(DateTime::from_utc(
post.1,
FixedOffset::east_opt(0).expect("Error setting timezone offset"), // TODO what is the proper timezone offset here?
))
.last_modified(post.1.into())
.build()
.ok()
})
Expand Down Expand Up @@ -48,27 +46,29 @@ pub(crate) mod tests {
#![allow(clippy::unwrap_used)]

use crate::sitemap::generate_urlset;
use chrono::{NaiveDate, NaiveDateTime};
use chrono::{DateTime, NaiveDate, Utc};
use elementtree::Element;
use lemmy_db_schema::newtypes::DbUrl;
use url::Url;

#[tokio::test]
async fn test_generate_urlset() {
let posts: Vec<(DbUrl, NaiveDateTime)> = vec![
let posts: Vec<(DbUrl, DateTime<Utc>)> = vec![
(
Url::parse("https://example.com").unwrap().into(),
NaiveDate::from_ymd_opt(2022, 12, 1)
.unwrap()
.and_hms_opt(9, 10, 11)
.unwrap(),
.unwrap()
.and_utc(),
),
(
Url::parse("https://lemmy.ml").unwrap().into(),
NaiveDate::from_ymd_opt(2023, 1, 1)
.unwrap()
.and_hms_opt(1, 2, 3)
.unwrap(),
.unwrap()
.and_utc(),
),
];

Expand Down
1 change: 1 addition & 0 deletions crates/api_common/src/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ pub struct CommentReplyResponse {
/// Delete your account.
pub struct DeleteAccount {
pub password: Sensitive<String>,
pub delete_content: bool,
pub auth: Sensitive<String>,
}

Expand Down
12 changes: 6 additions & 6 deletions crates/api_common/src/request.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::post::SiteMetadata;
use crate::{context::LemmyContext, post::SiteMetadata};
use encoding::{all::encodings, DecoderTrap};
use lemmy_db_schema::newtypes::DbUrl;
use lemmy_utils::{
Expand Down Expand Up @@ -150,12 +150,11 @@ pub(crate) async fn fetch_pictrs(
/// - It might not be an image
/// - Pictrs might not be set up
pub async fn purge_image_from_pictrs(
client: &ClientWithMiddleware,
settings: &Settings,
image_url: &Url,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let pictrs_config = settings.pictrs_config()?;
is_image_content_type(client, image_url).await?;
let pictrs_config = context.settings().pictrs_config()?;
is_image_content_type(context.client(), image_url).await?;

let alias = image_url
.path_segments()
Expand All @@ -168,7 +167,8 @@ pub async fn purge_image_from_pictrs(
let pictrs_api_key = pictrs_config
.api_key
.ok_or(LemmyErrorType::PictrsApiKeyNotProvided)?;
let response = client
let response = context
.client()
.post(&purge_url)
.timeout(REQWEST_TIMEOUT)
.header("x-api-token", pictrs_api_key)
Expand Down
2 changes: 1 addition & 1 deletion crates/api_common/src/send_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum SendActivityData {
CreatePrivateMessage(PrivateMessageView),
UpdatePrivateMessage(PrivateMessageView),
DeletePrivateMessage(Person, PrivateMessage, bool),
DeleteUser(Person),
DeleteUser(Person, bool),
CreateReport(Url, Person, Community, String),
}

Expand Down
Loading

0 comments on commit 0131eab

Please sign in to comment.