1
0

Decouple project deletion from thread deletion (#4673)

* Decouple project deletion from thread deletion

* Allow a thread to exist without a project

* attempt 2

* Modify migration to set orphaned threads' mods to NULL instead of removing constraint entirely

* Use mod PAT for mod threads
This commit is contained in:
aecsocket
2025-10-31 12:04:01 -07:00
committed by GitHub
parent 4c1020d2ba
commit b7f0988399
3 changed files with 49 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
ALTER TABLE threads
DROP CONSTRAINT threads_mod_id_fkey,
ADD CONSTRAINT threads_mod_id_fkey
FOREIGN KEY (mod_id) REFERENCES mods(id)
ON DELETE SET NULL;

View File

@@ -384,9 +384,6 @@ impl DBProject {
.execute(&mut **transaction)
.await?;
models::DBThread::remove_full(project.thread_id, transaction)
.await?;
sqlx::query!(
"
UPDATE reports

View File

@@ -1355,6 +1355,50 @@ async fn projects_various_visibility() {
.await;
}
#[actix_rt::test]
async fn test_thread_deleted_with_project() {
with_test_environment(
None,
|test_env: TestEnvironment<ApiV3>| async move {
let api = &test_env.api;
let alpha_project_id = &test_env.dummy.project_alpha.project_id;
let alpha_thread_id = &test_env.dummy.project_alpha.thread_id;
// Verify the thread exists initially
let resp = api.get_thread(alpha_thread_id, USER_USER_PAT).await;
assert_status!(&resp, StatusCode::OK);
// Write a message to the thread to confirm it's working
let resp = api
.write_to_thread(
alpha_thread_id,
"text",
"Test message before project deletion",
USER_USER_PAT,
)
.await;
assert_status!(&resp, StatusCode::NO_CONTENT);
// Check that the thread exists before project deletion
// Use a moderator PAT since moderation threads are not visible to users
let resp = api.get_thread(alpha_thread_id, MOD_USER_PAT).await;
assert_status!(&resp, StatusCode::OK);
// Delete the project
let resp =
api.remove_project(alpha_project_id, USER_USER_PAT).await;
assert_status!(&resp, StatusCode::NO_CONTENT);
// Check that the thread still exists after project deletion
// Also use mod PAT here
let resp = api.get_thread(alpha_thread_id, MOD_USER_PAT).await;
assert_status!(&resp, StatusCode::OK);
},
)
.await;
}
// Route tests:
// TODO: Missing routes on projects
// TODO: using permissions/scopes, can we SEE projects existence that we are not allowed to? (ie 401 instead of 404)