Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement reports for private messages #2433

Merged
merged 10 commits into from Sep 19, 2022
Merged

Implement reports for private messages #2433

merged 10 commits into from Sep 19, 2022

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented Sep 7, 2022

No description provided.

@Nutomic Nutomic force-pushed the pm-reports branch 2 times, most recently from 79df8c2 to 5f6f33e Compare September 8, 2022 09:47
@Nutomic Nutomic marked this pull request as ready for review September 8, 2022 09:47
@Nutomic
Copy link
Member Author

Nutomic commented Sep 8, 2022

Should be finished, though i havent done any testing of the api code.

I really dislike how much copy-pasting of code this involves. I think at least all the ListReports API calls should be merged into one, because they wont be used separately (similar to how mod log entries of all types are listed with a single api call).

Edit: Merged the list report endpoints into a single one now, and moved report count to site. I would also consider merging create/resolve report endpoints into one (with a type param) to simplify the api, but that probably wouldnt simplify the code.

@Nutomic Nutomic force-pushed the pm-reports branch 2 times, most recently from 5a6dd39 to 3bf3b06 Compare September 8, 2022 10:17
@Nutomic
Copy link
Member Author

Nutomic commented Sep 8, 2022

Merging list report endpoints broke api tests.

///
/// If called by an admin, private message reports are also included.
#[async_trait::async_trait(?Send)]
impl Perform for ListReports {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally sure I agree with combining all of them, as that would take away this functionality. Its kinda nice having individual ones in addition to all. Esp in the future where admins have to prioritize and need to care more about post reports than comments.

Screenshot_2022-09-09-17-47-51-298_mark via gp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, reverted the last commit. Still i think the api should look somewhat different.

@@ -18,7 +26,9 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
.route("", web::get().to(route_get_crud::<GetSite>))
// Admin Actions
.route("", web::post().to(route_post_crud::<CreateSite>))
.route("", web::put().to(route_post_crud::<EditSite>)),
.route("", web::put().to(route_post_crud::<EditSite>))
.route("/report_count", web::get().to(route_get::<GetReportCount>))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so report_count is just getting moved from user -> admin scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also reverted

@@ -96,7 +106,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
"/report/resolve",
web::put().to(route_post::<ResolvePostReport>),
)
.route("/report/list", web::get().to(route_get::<ListPostReports>))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above, but yeah I think its probably best to preserve these as individual endpoints, so that the front end can still filter on the types.

unique(private_message_id, creator_id) -- users should only be able to report a pm once
);

create or replace view private_message_report_view as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No SQL views anymore, this must be done in diesel. There are already examples for how this works for post and comment report views.

edit: ah I see you maybe just copied this as a template from the other examples, but its not necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, i copied this from other report migrations, but didnt notice that its not used anymore. Removed.

migrations/2022-09-07-114618_pm-reports/down.sql Outdated Show resolved Hide resolved
};

// TODO: should send message about new report to admins via websocket, but there is only op
// for community mods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just copy paste from the others, 0 is the admin room for "SendModRoomMessage". I don't think I fully tested that on the front end, but might as well have it here to be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that wasnt documented anywhere. Btw, as far as i can tell there arent any checks in the code to ensure that JoinModRoom can only be called by moderators for that community (or admin in case of 0). Am i missing something? Otherwise this would be a security issue.

private_message_report_view,
};

// TODO: should send message about new report to admins via websocket, but there is only op
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, copy paste from the createpostreport example.

assert_eq!(
inserted_admin.name,
reports[0].resolver.as_ref().unwrap().name
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, this looks good.

pub private_message_report: PrivateMessageReport,
pub private_message: PrivateMessage,
pub private_message_creator: PersonSafe,
pub creator: PersonSafeAlias1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once I have some time to work on diesel 2.0, we won't need these aliases anymore :)

crates/db_schema/src/schema.rs Show resolved Hide resolved
Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a few suggestions.

crates/api/src/comment_report/create.rs Outdated Show resolved Hide resolved
migrations/2022-09-07-114618_pm-reports/down.sql Outdated Show resolved Hide resolved
crates/websocket/src/messages.rs Outdated Show resolved Hide resolved
crates/websocket/src/chat_server.rs Outdated Show resolved Hide resolved
crates/api_common/src/person.rs Show resolved Hide resolved
@Nutomic
Copy link
Member Author

Nutomic commented Sep 19, 2022

Adressed all the comments.

@dessalines dessalines merged commit 004efd5 into main Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants