Skip to content

Commit 5e78ef9

Browse files
committed
feat: lock logic in place in rev endpoint + fetch rev
1 parent 9609206 commit 5e78ef9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

apps/labrinth/src/routes/internal/moderation/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,5 +611,7 @@ async fn release_lock(
611611
let released =
612612
DBModerationLock::release(db_project_id, db_user_id, &pool).await?;
613613

614+
let _ = DBModerationLock::cleanup_expired(&pool).await;
615+
614616
Ok(web::Json(LockReleaseResponse { success: released }))
615617
}

apps/labrinth/src/routes/v3/projects.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use crate::auth::{filter_visible_projects, get_user_from_headers};
66
use crate::database::models::notification_item::NotificationBuilder;
77
use crate::database::models::project_item::{DBGalleryItem, DBModCategory};
88
use crate::database::models::thread_item::ThreadMessageBuilder;
9-
use crate::database::models::{DBTeamMember, ids as db_ids, image_item};
9+
use crate::database::models::{
10+
DBModerationLock, DBTeamMember, ids as db_ids, image_item,
11+
};
1012
use crate::database::redis::RedisPool;
1113
use crate::database::{self, models as db_models};
1214
use crate::file_hosting::{FileHost, FileHostPublicity};
@@ -368,6 +370,23 @@ pub async fn project_edit(
368370
));
369371
}
370372

373+
// If a moderator is completing a review (changing from Processing to another status),
374+
// check if another moderator holds an active lock on this project
375+
if user.role.is_mod()
376+
&& project_item.inner.status == ProjectStatus::Processing
377+
&& status != &ProjectStatus::Processing
378+
&& let Some(lock) =
379+
DBModerationLock::get_with_user(project_item.inner.id, &pool)
380+
.await?
381+
&& lock.moderator_id != db_ids::DBUserId::from(user.id)
382+
&& !lock.expired
383+
{
384+
return Err(ApiError::CustomAuthentication(format!(
385+
"This project is currently being moderated by @{}. Please wait for them to finish or for the lock to expire.",
386+
lock.moderator_username
387+
)));
388+
}
389+
371390
if status == &ProjectStatus::Processing {
372391
if project_item.versions.is_empty() {
373392
return Err(ApiError::InvalidInput(String::from(

0 commit comments

Comments
 (0)