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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(1.x,approval): correct PostWasApproved event trigger condition #3925

Merged
merged 5 commits into from
Nov 17, 2023

Conversation

rafaucau
Copy link
Contributor

@rafaucau rafaucau commented Nov 6, 2023

Fixes #3921

Changes proposed in this pull request:

Ensure the PostWasApproved event is only raised for posts that are not hidden and introduce the PostWasUnapproved event to handle scenarios where a post is unapproved, particularly when it's the first post and the discussion needs to be hidden as a result.

QA

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Backend changes.
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Ensure the PostWasApproved event is only raised for posts that are not hidden. This fixes the issue where the event was incorrectly triggered for hidden posts. Additionally, the post's approval status is set to true upon deletion to remove any pending approval status.
@rafaucau rafaucau requested a review from a team as a code owner November 6, 2023 15:40
@rafaucau
Copy link
Contributor Author

rafaucau commented Nov 6, 2023

I have noticed a problem (not introduced in this PR) with hiding discussions. When a post is hidden, the discussion is left empty. I will add a fix to this PR.

@rafaucau rafaucau marked this pull request as draft November 6, 2023 17:30
…ng discussions for unapproved initial posts

Introduces the PostWasUnapproved event, fired upon every post unapproval. Specifically, when the unapproved post is the initial post of a discussion, this event also hides the entire discussion. This change ensures that unapproved initial posts do not leave their discussions visible on the forum.
@rafaucau rafaucau marked this pull request as ready for review November 6, 2023 20:37
@rafaucau rafaucau changed the title [1.x] fix(approval): correct PostWasApproved event trigger condition [1.x] fix(approval): correct PostWasApproved event trigger condition and introduce PostWasUnapproved Nov 6, 2023
Copy link
Member

@SychO9 SychO9 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I have dived into the issue to understand the flow, and the main problem is that the PostWasApproved event is triggered always when hiding or restoring a post, regardless of actual approval status/action. Which does not make sense. If I am listening to the post approval even, I expect that there was a state change from approved to unapproved. But right now even if you hide any approved post, the event is triggered.

The changes here seem close but based on testing I feel this is closer to what we would want: bed386f

What do you think?

I don't understand the second commit though:

  • When the first post is hidden and the discussion is empty, the entire discussion is hidden away from other users so I don't think we need to change anything about it.
  • The PostWasUnpproved even is identical to the Hidden event in terms of when it is triggered so a bit redundant.

@rafaucau
Copy link
Contributor Author

When the first post is hidden and the discussion is empty, the entire discussion is hidden away from other users so I don't think we need to change anything about it.

I thought everyone could see the discussion without any post:

2023-11-10.11-31-02.mp4

Now I see that other users except the admin and the author don't see it.


The PostWasUnpproved even is identical to the Hidden event in terms of when it is triggered so a bit redundant.

Maybe so, but it is more specific and can be useful in some cases such as here: https://github.com/flarum/framework/pull/3925/files#diff-dd866324feaa8087e4ee73330d8affaf8352fd52dde6ca007a837e49179957e7R27

@SychO9
Copy link
Member

SychO9 commented Nov 10, 2023

I'm afraid it only seems to add more confusion, because the reason the PostWasUnapproved would get triggered is because isHidden was set true, which is what the Hidden event is for.

Also hiding != unapproving thought the two are already confusing right now

@rafaucau
Copy link
Contributor Author

rafaucau commented Nov 10, 2023

hiding != unapproving but unapproving = hiding so it's more specific and can be useful in cases where someone wants to listen for a post unapproval event only

@SychO9
Copy link
Member

SychO9 commented Nov 10, 2023

there is no unapproving. You can only change is_approved to true. The endpoint will not change it to false even with isApproved: false. Triggering PostWasUnapproved when the state change is from hidden=false;approved=any to hidden=true;approved=unchanged is misleading. It only means what you actually intend to use is the Hidden event

@rafaucau
Copy link
Contributor Author

I have reverted the commit that added the PostWasUnapproved event and incorporated your changes.

@rafaucau rafaucau changed the title [1.x] fix(approval): correct PostWasApproved event trigger condition and introduce PostWasUnapproved [1.x] fix(approval): correct PostWasApproved event trigger condition Nov 13, 2023
@rafaucau rafaucau requested a review from SychO9 November 13, 2023 11:17
@rafaucau
Copy link
Contributor Author

@SychO9 Can this be merged and released as v1.8.4? By sending real spam as false-positive it messes up Akismet's spam detection a bit (#3921), so it's worth releasing.

@SychO9
Copy link
Member

SychO9 commented Nov 17, 2023

@rafaucau that's the plan, I should be able to get around to it today

@SychO9 SychO9 changed the title [1.x] fix(approval): correct PostWasApproved event trigger condition fix(1.x, approval): correct PostWasApproved event trigger condition Nov 17, 2023
@SychO9 SychO9 changed the title fix(1.x, approval): correct PostWasApproved event trigger condition fix(1.x,approval): correct PostWasApproved event trigger condition Nov 17, 2023
@SychO9 SychO9 merged commit 1c421fc into flarum:1.x Nov 17, 2023
224 checks passed
@SychO9 SychO9 added this to the 1.8.1 milestone Nov 17, 2023
@rafaucau rafaucau deleted the fix/approved-event branch November 17, 2023 17:13
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.

2 participants