forked from didirus/AstralRinth
GDPR export route (#969)
* GDPR export route * make users able to access
This commit is contained in:
@@ -355,31 +355,12 @@ impl Project {
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
// Notably joins with report id and not thread.mod_id directly, as
|
||||
// this is set to null for threads that are reports.
|
||||
let report_threads = sqlx::query!(
|
||||
"
|
||||
SELECT t.id
|
||||
FROM threads t
|
||||
INNER JOIN reports r ON t.report_id = r.id
|
||||
WHERE r.mod_id = $1 AND report_id IS NOT NULL
|
||||
",
|
||||
id as ProjectId,
|
||||
)
|
||||
.fetch(&mut **transaction)
|
||||
.map_ok(|x| ThreadId(x.id))
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
for thread_id in report_threads {
|
||||
models::Thread::remove_full(thread_id, transaction).await?;
|
||||
}
|
||||
|
||||
models::Thread::remove_full(project.thread_id, transaction).await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM reports
|
||||
UPDATE reports
|
||||
SET mod_id = NULL
|
||||
WHERE mod_id = $1
|
||||
",
|
||||
id as ProjectId,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::ids::{ProjectId, UserId};
|
||||
use super::{CollectionId, ThreadId};
|
||||
use super::{CollectionId, ReportId, ThreadId};
|
||||
use crate::database::models;
|
||||
use crate::database::models::{DatabaseError, OrganizationId};
|
||||
use crate::database::redis::RedisPool;
|
||||
@@ -323,6 +323,48 @@ impl User {
|
||||
Ok(projects)
|
||||
}
|
||||
|
||||
pub async fn get_follows<'a, E>(user_id: UserId, exec: E) -> Result<Vec<ProjectId>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
let projects = sqlx::query!(
|
||||
"
|
||||
SELECT mf.mod_id FROM mod_follows mf
|
||||
WHERE mf.follower_id = $1
|
||||
",
|
||||
user_id as UserId,
|
||||
)
|
||||
.fetch(exec)
|
||||
.map_ok(|m| ProjectId(m.mod_id))
|
||||
.try_collect::<Vec<ProjectId>>()
|
||||
.await?;
|
||||
|
||||
Ok(projects)
|
||||
}
|
||||
|
||||
pub async fn get_reports<'a, E>(user_id: UserId, exec: E) -> Result<Vec<ReportId>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
let reports = sqlx::query!(
|
||||
"
|
||||
SELECT r.id FROM reports r
|
||||
WHERE r.user_id = $1
|
||||
",
|
||||
user_id as UserId,
|
||||
)
|
||||
.fetch(exec)
|
||||
.map_ok(|m| ReportId(m.id))
|
||||
.try_collect::<Vec<ReportId>>()
|
||||
.await?;
|
||||
|
||||
Ok(reports)
|
||||
}
|
||||
|
||||
pub async fn get_backup_codes<'a, E>(
|
||||
user_id: UserId,
|
||||
exec: E,
|
||||
|
||||
@@ -335,7 +335,8 @@ impl Version {
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM reports
|
||||
UPDATE reports
|
||||
SET version_id = NULL
|
||||
WHERE version_id = $1
|
||||
",
|
||||
id as VersionId,
|
||||
|
||||
Reference in New Issue
Block a user