-
-
Notifications
You must be signed in to change notification settings - Fork 888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add community reports (only the database part) #4996
Open
dullbananas
wants to merge
12
commits into
LemmyNet:main
Choose a base branch
from
dullbananas:community-report
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e8344a1
database stuff, not including tests
dullbananas cdc0be9
Merge remote-tracking branch 'upstream/main' into community-report
dullbananas d778803
change migration date
dullbananas 5660cb0
fix community_report_view
dullbananas 7df73eb
update stuff related to report_combined
dullbananas dc0d8d0
add db_schema/src/impls/community_report.rs
dullbananas 3529e2b
add report counts to community_aggregates
dullbananas a05998c
fix community_report columns and update report_combined_view::tests::…
dullbananas 0cc3657
add column for original sidebar; use None instead of clone; add repor…
dullbananas d1f3d73
use ts(optional) in CommunityReportView
dullbananas be4f8fa
Merge remote-tracking branch 'upstream/main' into community-report
dullbananas 8a578f4
remove CommunityReportView::read
dullbananas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::{ | ||
newtypes::{CommunityId, CommunityReportId, PersonId}, | ||
schema::community_report::{ | ||
community_id, | ||
dsl::{community_report, resolved, resolver_id, updated}, | ||
}, | ||
source::community_report::{CommunityReport, CommunityReportForm}, | ||
traits::Reportable, | ||
utils::{get_conn, DbPool}, | ||
}; | ||
use chrono::Utc; | ||
use diesel::{ | ||
dsl::{insert_into, update}, | ||
result::Error, | ||
ExpressionMethods, | ||
QueryDsl, | ||
}; | ||
use diesel_async::RunQueryDsl; | ||
|
||
#[async_trait] | ||
impl Reportable for CommunityReport { | ||
type Form = CommunityReportForm; | ||
type IdType = CommunityReportId; | ||
type ObjectIdType = CommunityId; | ||
/// creates a community report and returns it | ||
/// | ||
/// * `conn` - the postgres connection | ||
/// * `community_report_form` - the filled CommunityReportForm to insert | ||
async fn report( | ||
pool: &mut DbPool<'_>, | ||
community_report_form: &CommunityReportForm, | ||
) -> Result<Self, Error> { | ||
let conn = &mut get_conn(pool).await?; | ||
insert_into(community_report) | ||
.values(community_report_form) | ||
.get_result::<Self>(conn) | ||
.await | ||
} | ||
|
||
/// resolve a community report | ||
/// | ||
/// * `conn` - the postgres connection | ||
/// * `report_id` - the id of the report to resolve | ||
/// * `by_resolver_id` - the id of the user resolving the report | ||
async fn resolve( | ||
pool: &mut DbPool<'_>, | ||
report_id_: Self::IdType, | ||
by_resolver_id: PersonId, | ||
) -> Result<usize, Error> { | ||
let conn = &mut get_conn(pool).await?; | ||
update(community_report.find(report_id_)) | ||
.set(( | ||
resolved.eq(true), | ||
resolver_id.eq(by_resolver_id), | ||
updated.eq(Utc::now()), | ||
)) | ||
.execute(conn) | ||
.await | ||
} | ||
|
||
async fn resolve_all_for_object( | ||
pool: &mut DbPool<'_>, | ||
community_id_: CommunityId, | ||
by_resolver_id: PersonId, | ||
) -> Result<usize, Error> { | ||
let conn = &mut get_conn(pool).await?; | ||
update(community_report.filter(community_id.eq(community_id_))) | ||
.set(( | ||
resolved.eq(true), | ||
resolver_id.eq(by_resolver_id), | ||
updated.eq(Utc::now()), | ||
)) | ||
.execute(conn) | ||
.await | ||
} | ||
|
||
/// unresolve a community report | ||
/// | ||
/// * `conn` - the postgres connection | ||
/// * `report_id` - the id of the report to unresolve | ||
/// * `by_resolver_id` - the id of the user unresolving the report | ||
async fn unresolve( | ||
pool: &mut DbPool<'_>, | ||
report_id_: Self::IdType, | ||
by_resolver_id: PersonId, | ||
) -> Result<usize, Error> { | ||
let conn = &mut get_conn(pool).await?; | ||
update(community_report.find(report_id_)) | ||
.set(( | ||
resolved.eq(false), | ||
resolver_id.eq(by_resolver_id), | ||
updated.eq(Utc::now()), | ||
)) | ||
.execute(conn) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::newtypes::{CommunityId, CommunityReportId, DbUrl, PersonId}; | ||
#[cfg(feature = "full")] | ||
use crate::schema::community_report; | ||
use chrono::{DateTime, Utc}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with::skip_serializing_none; | ||
#[cfg(feature = "full")] | ||
use ts_rs::TS; | ||
|
||
#[skip_serializing_none] | ||
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)] | ||
#[cfg_attr( | ||
feature = "full", | ||
derive(Queryable, Selectable, Associations, Identifiable, TS) | ||
)] | ||
#[cfg_attr( | ||
feature = "full", | ||
diesel(belongs_to(crate::source::community::Community)) | ||
)] | ||
#[cfg_attr(feature = "full", diesel(table_name = community_report))] | ||
#[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] | ||
#[cfg_attr(feature = "full", ts(export))] | ||
/// A comment report. | ||
pub struct CommunityReport { | ||
pub id: CommunityReportId, | ||
pub creator_id: PersonId, | ||
pub community_id: CommunityId, | ||
pub original_community_name: String, | ||
pub original_community_title: String, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub original_community_description: Option<String>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub original_community_sidebar: Option<String>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub original_community_icon: Option<String>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub original_community_banner: Option<String>, | ||
pub reason: String, | ||
pub resolved: bool, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub resolver_id: Option<PersonId>, | ||
pub published: DateTime<Utc>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub updated: Option<DateTime<Utc>>, | ||
} | ||
|
||
#[derive(Clone)] | ||
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] | ||
#[cfg_attr(feature = "full", diesel(table_name = community_report))] | ||
pub struct CommunityReportForm { | ||
pub creator_id: PersonId, | ||
pub community_id: CommunityId, | ||
pub original_community_name: String, | ||
pub original_community_title: String, | ||
pub original_community_description: Option<String>, | ||
pub original_community_sidebar: Option<String>, | ||
pub original_community_icon: Option<DbUrl>, | ||
pub original_community_banner: Option<DbUrl>, | ||
pub reason: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if the icon and banner are totally necessary, but no reason not to have them I spose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, reports store the original content so the creator of the reported thing can't edit it to remove evidence of the offense. It's possible that a community's icon or banner is the reason for reporting, just like the url of a post.