Skip to content

Commit 5d949fd

Browse files
authored
Merge pull request #174 from LemmyNet/main
[pull] master from LemmyNet:main
2 parents 635ee99 + f6a24e1 commit 5d949fd

File tree

99 files changed

+613
-481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+613
-481
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api_tests/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
},
2222
"devDependencies": {
2323
"@types/jest": "^29.5.12",
24-
"@types/node": "^22.0.2",
25-
"@typescript-eslint/eslint-plugin": "^8.0.0",
26-
"@typescript-eslint/parser": "^8.0.0",
27-
"eslint": "^9.8.0",
24+
"@types/node": "^22.3.0",
25+
"@typescript-eslint/eslint-plugin": "^8.1.0",
26+
"@typescript-eslint/parser": "^8.1.0",
27+
"eslint": "^9.9.0",
2828
"eslint-plugin-prettier": "^5.1.3",
2929
"jest": "^29.5.0",
3030
"lemmy-js-client": "0.20.0-alpha.11",
3131
"prettier": "^3.2.5",
3232
"ts-jest": "^29.1.0",
3333
"typescript": "^5.5.4",
34-
"typescript-eslint": "^8.0.0"
34+
"typescript-eslint": "^8.1.0"
3535
}
3636
}

api_tests/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api_tests/src/post.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ test("Enforce community ban for federated user", async () => {
628628
// Alpha tries to make post on beta, but it fails because of ban
629629
await expect(
630630
createPost(alpha, betaCommunity.community.id),
631-
).rejects.toStrictEqual(Error("banned_from_community"));
631+
).rejects.toStrictEqual(Error("person_is_banned_from_community"));
632632

633633
// Unban alpha
634634
let unBanAlpha = await banPersonFromCommunity(

crates/api/src/community/add_mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,12 @@ pub async fn add_mod_to_community(
5252
// moderator. This is necessary because otherwise the action would be rejected
5353
// by the community's home instance.
5454
if local_user_view.local_user.admin && !community.local {
55-
let is_mod = CommunityModeratorView::is_community_moderator(
55+
CommunityModeratorView::check_is_community_moderator(
5656
&mut context.pool(),
5757
community.id,
5858
local_user_view.person.id,
5959
)
6060
.await?;
61-
if !is_mod {
62-
Err(LemmyErrorType::NotAModerator)?
63-
}
6461
}
6562

6663
// Update in local database

crates/api/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ pub async fn local_user_view_from_jwt(
265265
}
266266

267267
#[cfg(test)]
268-
#[allow(clippy::unwrap_used)]
269-
#[allow(clippy::indexing_slicing)]
270268
mod tests {
271269

272270
use super::*;

crates/api/src/local_user/save_settings.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ pub async fn save_user_settings(
6363
let previous_email = local_user_view.local_user.email.clone().unwrap_or_default();
6464
// if email was changed, check that it is not taken and send verification mail
6565
if previous_email.deref() != email {
66-
if LocalUser::is_email_taken(&mut context.pool(), email).await? {
67-
return Err(LemmyErrorType::EmailAlreadyExists)?;
68-
}
66+
LocalUser::check_is_email_taken(&mut context.pool(), email).await?;
6967
send_verification_email(
7068
&local_user_view,
7169
email,
@@ -132,7 +130,6 @@ pub async fn save_user_settings(
132130
send_notifications_to_email: data.send_notifications_to_email,
133131
show_nsfw: data.show_nsfw,
134132
blur_nsfw: data.blur_nsfw,
135-
auto_expand: data.auto_expand,
136133
show_bot_accounts: data.show_bot_accounts,
137134
default_post_sort_type,
138135
default_comment_sort_type,

crates/api/src/site/registration_applications/tests.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use lemmy_db_views::structs::LocalUserView;
3434
use lemmy_utils::{error::LemmyResult, LemmyErrorType, CACHE_DURATION_API};
3535
use serial_test::serial;
3636

37-
#[allow(clippy::unwrap_used)]
37+
#[expect(clippy::unwrap_used)]
3838
async fn create_test_site(context: &Data<LemmyContext>) -> LemmyResult<(Instance, LocalUserView)> {
3939
let pool = &mut context.pool();
4040

@@ -109,7 +109,7 @@ async fn signup(
109109
Ok((local_user, application))
110110
}
111111

112-
#[allow(clippy::unwrap_used)]
112+
#[expect(clippy::unwrap_used)]
113113
async fn get_application_statuses(
114114
context: &Data<LemmyContext>,
115115
admin: LocalUserView,
@@ -138,10 +138,9 @@ async fn get_application_statuses(
138138
Ok((application_count, unread_applications, all_applications))
139139
}
140140

141-
#[allow(clippy::indexing_slicing)]
142-
#[allow(clippy::unwrap_used)]
143-
#[tokio::test]
144141
#[serial]
142+
#[tokio::test]
143+
#[expect(clippy::indexing_slicing)]
145144
async fn test_application_approval() -> LemmyResult<()> {
146145
let context = LemmyContext::init_test_context().await;
147146
let pool = &mut context.pool();

crates/api/src/sitemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub async fn get_sitemap(context: Data<LemmyContext>) -> LemmyResult<HttpRespons
4242
}
4343

4444
#[cfg(test)]
45-
#[allow(clippy::unwrap_used)]
45+
#[expect(clippy::unwrap_used)]
4646
pub(crate) mod tests {
4747

4848
use crate::sitemap::generate_urlset;

crates/api_common/src/claims.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ impl Claims {
2929
let claims =
3030
decode::<Claims>(jwt, &key, &validation).with_lemmy_type(LemmyErrorType::NotLoggedIn)?;
3131
let user_id = LocalUserId(claims.claims.sub.parse()?);
32-
let is_valid = LoginToken::validate(&mut context.pool(), user_id, jwt).await?;
33-
if !is_valid {
34-
Err(LemmyErrorType::NotLoggedIn)?
35-
} else {
36-
Ok(user_id)
37-
}
32+
LoginToken::validate(&mut context.pool(), user_id, jwt).await?;
33+
Ok(user_id)
3834
}
3935

4036
pub async fn generate(
@@ -73,8 +69,7 @@ impl Claims {
7369
}
7470

7571
#[cfg(test)]
76-
#[allow(clippy::unwrap_used)]
77-
#[allow(clippy::indexing_slicing)]
72+
#[expect(clippy::unwrap_used)]
7873
mod tests {
7974

8075
use crate::{claims::Claims, context::LemmyContext};

crates/api_common/src/person.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ pub struct CaptchaResponse {
8484
pub struct SaveUserSettings {
8585
/// Show nsfw posts.
8686
pub show_nsfw: Option<bool>,
87+
/// Blur nsfw posts.
8788
pub blur_nsfw: Option<bool>,
88-
pub auto_expand: Option<bool>,
8989
/// Your user's theme.
9090
pub theme: Option<String>,
9191
/// The default post listing type, usually "local"

crates/api_common/src/post.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct CreatePost {
3030
pub language_id: Option<LanguageId>,
3131
/// Instead of fetching a thumbnail, use a custom one.
3232
pub custom_thumbnail: Option<String>,
33+
/// Time when this post should be scheduled. Null means publish immediately.
34+
pub scheduled_publish_time: Option<i64>,
3335
}
3436

3537
#[derive(Debug, Serialize, Deserialize, Clone)]
@@ -124,6 +126,8 @@ pub struct EditPost {
124126
pub language_id: Option<LanguageId>,
125127
/// Instead of fetching a thumbnail, use a custom one.
126128
pub custom_thumbnail: Option<String>,
129+
/// Time when this post should be scheduled. Null means publish immediately.
130+
pub scheduled_publish_time: Option<i64>,
127131
}
128132

129133
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]

crates/api_common/src/request.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,7 @@ pub async fn replace_image(
485485
}
486486

487487
#[cfg(test)]
488-
#[allow(clippy::unwrap_used)]
489-
#[allow(clippy::indexing_slicing)]
488+
#[expect(clippy::unwrap_used)]
490489
mod tests {
491490

492491
use crate::{

crates/api_common/src/site.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub struct Search {
7878
pub listing_type: Option<ListingType>,
7979
pub page: Option<i64>,
8080
pub limit: Option<i64>,
81-
pub post_title_only: Option<bool>,
81+
pub title_only: Option<bool>,
8282
pub post_url_only: Option<bool>,
8383
pub saved_only: Option<bool>,
8484
pub liked_only: Option<bool>,

crates/api_common/src/utils.rs

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ pub async fn is_mod_or_admin(
7373
community_id: CommunityId,
7474
) -> LemmyResult<()> {
7575
check_user_valid(person)?;
76-
77-
let is_mod_or_admin = CommunityView::is_mod_or_admin(pool, person.id, community_id).await?;
78-
if !is_mod_or_admin {
79-
Err(LemmyErrorType::NotAModOrAdmin)?
80-
} else {
81-
Ok(())
82-
}
76+
CommunityView::check_is_mod_or_admin(pool, person.id, community_id).await
8377
}
8478

8579
#[tracing::instrument(skip_all)]
@@ -110,13 +104,7 @@ pub async fn check_community_mod_of_any_or_admin_action(
110104
let person = &local_user_view.person;
111105

112106
check_user_valid(person)?;
113-
114-
let is_mod_of_any_or_admin = CommunityView::is_mod_of_any_or_admin(pool, person.id).await?;
115-
if !is_mod_of_any_or_admin {
116-
Err(LemmyErrorType::NotAModOrAdmin)?
117-
} else {
118-
Ok(())
119-
}
107+
CommunityView::check_is_mod_of_any_or_admin(pool, person.id).await
120108
}
121109

122110
pub fn is_admin(local_user_view: &LocalUserView) -> LemmyResult<()> {
@@ -242,7 +230,7 @@ pub async fn check_community_user_action(
242230
) -> LemmyResult<()> {
243231
check_user_valid(person)?;
244232
check_community_deleted_removed(community_id, pool).await?;
245-
check_community_ban(person, community_id, pool).await?;
233+
CommunityPersonBanView::check(pool, person.id, community_id).await?;
246234
Ok(())
247235
}
248236

@@ -257,19 +245,6 @@ async fn check_community_deleted_removed(
257245
Ok(())
258246
}
259247

260-
async fn check_community_ban(
261-
person: &Person,
262-
community_id: CommunityId,
263-
pool: &mut DbPool<'_>,
264-
) -> LemmyResult<()> {
265-
// check if user was banned from site or community
266-
let is_banned = CommunityPersonBanView::get(pool, person.id, community_id).await?;
267-
if is_banned {
268-
Err(LemmyErrorType::BannedFromCommunity)?
269-
}
270-
Ok(())
271-
}
272-
273248
/// Check that the given user can perform a mod action in the community.
274249
///
275250
/// In particular it checks that he is an admin or mod, wasn't banned and the community isn't
@@ -281,7 +256,7 @@ pub async fn check_community_mod_action(
281256
pool: &mut DbPool<'_>,
282257
) -> LemmyResult<()> {
283258
is_mod_or_admin(pool, person, community_id).await?;
284-
check_community_ban(person, community_id, pool).await?;
259+
CommunityPersonBanView::check(pool, person.id, community_id).await?;
285260

286261
// it must be possible to restore deleted community
287262
if !allow_deleted {
@@ -307,51 +282,6 @@ pub fn check_comment_deleted_or_removed(comment: &Comment) -> LemmyResult<()> {
307282
}
308283
}
309284

310-
/// Throws an error if a recipient has blocked a person.
311-
#[tracing::instrument(skip_all)]
312-
pub async fn check_person_block(
313-
my_id: PersonId,
314-
potential_blocker_id: PersonId,
315-
pool: &mut DbPool<'_>,
316-
) -> LemmyResult<()> {
317-
let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id).await?;
318-
if is_blocked {
319-
Err(LemmyErrorType::PersonIsBlocked)?
320-
} else {
321-
Ok(())
322-
}
323-
}
324-
325-
/// Throws an error if a recipient has blocked a community.
326-
#[tracing::instrument(skip_all)]
327-
async fn check_community_block(
328-
community_id: CommunityId,
329-
person_id: PersonId,
330-
pool: &mut DbPool<'_>,
331-
) -> LemmyResult<()> {
332-
let is_blocked = CommunityBlock::read(pool, person_id, community_id).await?;
333-
if is_blocked {
334-
Err(LemmyErrorType::CommunityIsBlocked)?
335-
} else {
336-
Ok(())
337-
}
338-
}
339-
340-
/// Throws an error if a recipient has blocked an instance.
341-
#[tracing::instrument(skip_all)]
342-
async fn check_instance_block(
343-
instance_id: InstanceId,
344-
person_id: PersonId,
345-
pool: &mut DbPool<'_>,
346-
) -> LemmyResult<()> {
347-
let is_blocked = InstanceBlock::read(pool, person_id, instance_id).await?;
348-
if is_blocked {
349-
Err(LemmyErrorType::InstanceIsBlocked)?
350-
} else {
351-
Ok(())
352-
}
353-
}
354-
355285
#[tracing::instrument(skip_all)]
356286
pub async fn check_person_instance_community_block(
357287
my_id: PersonId,
@@ -360,9 +290,9 @@ pub async fn check_person_instance_community_block(
360290
community_id: CommunityId,
361291
pool: &mut DbPool<'_>,
362292
) -> LemmyResult<()> {
363-
check_person_block(my_id, potential_blocker_id, pool).await?;
364-
check_instance_block(community_instance_id, potential_blocker_id, pool).await?;
365-
check_community_block(community_id, potential_blocker_id, pool).await?;
293+
PersonBlock::read(pool, potential_blocker_id, my_id).await?;
294+
InstanceBlock::read(pool, potential_blocker_id, community_instance_id).await?;
295+
CommunityBlock::read(pool, potential_blocker_id, community_id).await?;
366296
Ok(())
367297
}
368298

@@ -846,12 +776,13 @@ pub async fn remove_or_restore_user_data_in_community(
846776

847777
// Comments
848778
// TODO Diesel doesn't allow updates with joins, so this has to be a loop
779+
let site = Site::read_local(pool).await?;
849780
let comments = CommentQuery {
850781
creator_id: Some(banned_person_id),
851782
community_id: Some(community_id),
852783
..Default::default()
853784
}
854-
.list(pool)
785+
.list(&site, pool)
855786
.await?;
856787

857788
for comment_view in &comments {
@@ -1136,8 +1067,7 @@ fn build_proxied_image_url(
11361067
}
11371068

11381069
#[cfg(test)]
1139-
#[allow(clippy::unwrap_used)]
1140-
#[allow(clippy::indexing_slicing)]
1070+
#[expect(clippy::unwrap_used)]
11411071
mod tests {
11421072

11431073
use super::*;

crates/api_crud/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ futures.workspace = true
2727
uuid = { workspace = true }
2828
moka.workspace = true
2929
anyhow.workspace = true
30+
chrono.workspace = true
3031
webmention = "0.6.0"
3132
accept-language = "3.1.0"
3233
serde_json = { workspace = true }

0 commit comments

Comments
 (0)