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

Do not render report flag for reviews by the current user #6620

Merged
merged 10 commits into from
Oct 18, 2018
Merged

Do not render report flag for reviews by the current user #6620

merged 10 commits into from
Oct 18, 2018

Conversation

seanprashad
Copy link
Contributor

@seanprashad seanprashad commented Oct 13, 2018

Fixes mozilla/addons#12433: "Flag" should be removed from the profile page

This PR prevents the "flag" button from being rendered for reviews made by the current user. Essentially, if Sean leaves a review, he should not be allowed to flag his own comment.

Before:

before_removing_flag

After:

after_removing_flag

@seanprashad seanprashad changed the title WIP - Do not render report flag for reviews by the current user [WIP] Do not render report flag for reviews by the current user Oct 13, 2018
@codecov-io
Copy link

codecov-io commented Oct 13, 2018

Codecov Report

Merging #6620 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    mozilla/addons-frontend#6620      +/-   ##
==========================================
+ Coverage   97.84%   97.84%   +<.01%     
==========================================
  Files         240      241       +1     
  Lines        6549     6553       +4     
  Branches     1242     1243       +1     
==========================================
+ Hits         6408     6412       +4     
  Misses        126      126              
  Partials       15       15
Impacted Files Coverage Δ
src/amo/components/AddonReviewCard/index.js 100% <ø> (ø) ⬆️
src/amo/pages/AddonReviewList/index.js 100% <0%> (ø) ⬆️
src/amo/reducers/versions.js 100% <0%> (ø) ⬆️
src/amo/components/AddonSummaryCard/index.js 100% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e7386e...54b1274. Read the comment docs.

@@ -562,11 +569,12 @@ describe(__filename, () => {
});

it('lets you flag a developer reply', () => {
const { reply } = _setReviewReply();
const root = renderReply({ reply });
const review = createReviewAndSignInAsUnrelatedUser();
Copy link
Contributor Author

@seanprashad seanprashad Oct 13, 2018

Choose a reason for hiding this comment

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

This test was checking a developer's reply to an existing review. I think I changed the logic behind it - would appreciate feedback.

Copy link
Contributor

Choose a reason for hiding this comment

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

This test was checking a developer's reply to an existing review. I think I changed the logic behind it - would appreciate feedback.

Why did you need to change the test? I put it back to how it was and it passed for me. Maybe it was related to not being signed in?

@seanprashad seanprashad changed the title [WIP] Do not render report flag for reviews by the current user Do not render report flag for reviews by the current user Oct 13, 2018
@bobsilverberg bobsilverberg self-requested a review October 16, 2018 13:04
@bobsilverberg bobsilverberg self-assigned this Oct 16, 2018
Copy link
Contributor

@bobsilverberg bobsilverberg left a comment

Choose a reason for hiding this comment

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

This is a good start, thanks @seanprashad, but I think we only want to remove the "Flag" option on the User Profile screen, and not on every screen. I had a discussion with @kumar303 about this awhile ago, but I cannot find the issue where we discussed it.

He felt that we should keep the "Flag" menu, even for reviews by the same user, on the Review Listing screen, but it was fine to remove it from the User Profile screen.

@kumar303 Can you confirm that is what we should be doing for this issue?

@kumar303
Copy link
Contributor

I think the direction of this patch is good -- hiding the flag menu for all screens. I'd rather implement this feature consistently rather than just for the user profile page. I personally don't like hidden UI controls because it can be confusing to know what state you're in but everyone else argued against that so I concede 😁

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

Thanks @seanprashad ! This mostly looks good. I have one change request.

@@ -481,7 +481,8 @@ export class AddonReviewCardBase extends React.Component<InternalProps> {
</a>
) : null}

{flaggable && review ? (
{/* Do not render the "flag" button for replies made by the current user */}
{flaggable && review && siteUser && siteUser.id !== review.userId ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

If the user is signed out, the Flag link should always be visible. Otherwise, if someone wants to flag a review, they might not know that they have to sign in first.

This is what it looks like (there is actually a style regression that I will fix right now! https://github.com/mozilla/addons-frontend/issues/6656)

screenshot 2018-10-16 11 45 43

Sean Prashad added 3 commits October 17, 2018 13:23
This test is responsible for making sure that the "flag" button is
hidden for replies made by the current user.
These tests are affected by the previous commit, which hides the "flag"
button for reviews made by the current user.
@seanprashad seanprashad deleted the issue-6416 branch October 17, 2018 18:00
@seanprashad seanprashad restored the issue-6416 branch October 17, 2018 18:01
@seanprashad seanprashad reopened this Oct 17, 2018
@seanprashad
Copy link
Contributor Author

seanprashad commented Oct 17, 2018

@kumar303 I've updated the logic to always render the flag button if the user isn't logged in:

post_feedback_from_kumar

We should always render the "flag" button if a user is not
authenticated because users should know that they have to sign in first
before flagging a review.
@kumar303 kumar303 self-requested a review October 17, 2018 21:02
Copy link
Contributor

@kumar303 kumar303 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 fix-ups. I have a few more change requests.

@@ -481,7 +486,7 @@ export class AddonReviewCardBase extends React.Component<InternalProps> {
</a>
) : null}

{flaggable && review ? (
{flaggable && review && showFlagButton ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

I liked how simple this was in your first patch. It was a lot easier to read. What about this?

Suggested change
{flaggable && review && showFlagButton ? (
{flaggable && review && (!siteUser || siteUser.id !== review.userId) ? (

@@ -481,7 +486,7 @@ export class AddonReviewCardBase extends React.Component<InternalProps> {
</a>
) : null}

{flaggable && review ? (
{flaggable && review && showFlagButton ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

You also need to add a test that makes sure the flag button is not hidden when the user is signed out. After writing the test, you can comment out the part that allowed non-signed in users to see the flag link; the test should fail. This helps you know that the test is working.

@@ -562,11 +569,12 @@ describe(__filename, () => {
});

it('lets you flag a developer reply', () => {
const { reply } = _setReviewReply();
const root = renderReply({ reply });
const review = createReviewAndSignInAsUnrelatedUser();
Copy link
Contributor

Choose a reason for hiding this comment

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

This test was checking a developer's reply to an existing review. I think I changed the logic behind it - would appreciate feedback.

Why did you need to change the test? I put it back to how it was and it passed for me. Maybe it was related to not being signed in?

@@ -547,7 +554,7 @@ describe(__filename, () => {
});

it('lets you flag a review', () => {
const review = _setReview(fakeReview);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can put this back now, too. The test passes for me.

@@ -423,6 +423,11 @@ export class AddonReviewCardBase extends React.Component<InternalProps> {
(review.userId === siteUser.id ||
(this.isReply() && this.siteUserCanManageReplies()));

/* Do not render the "flag" button for reviews made by the current user */
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefix comments with // (double slashes) when they don't need to span multiple lines.

@kumar303 kumar303 self-requested a review October 17, 2018 21:21
Sean Prashad added 3 commits October 17, 2018 19:48
These were initially changed as the new implementation hid the flag
button for users who weren't logged in. We can now revert these as we
display the flag button for all replies that do not belong to the
current user, regardless if they are signed in or not.
@seanprashad
Copy link
Contributor Author

seanprashad commented Oct 18, 2018

Thanks for the great feedback @kumar303! ✌🏽I've reverted the other tests back and added a new test to check for the flag button when the user wasn't authenticated. I think this should be good to 🚢

Edit: Not sure if it's just me, but I can't reply to the third comment you made for your review - there's no textbox. I don't think I've seen this behaviour before:

screen shot 2018-10-17 at 11 05 14 pm

@kumar303
Copy link
Contributor

Not sure if it's just me, but I can't reply to the third comment you made for your review

It's not just you. Github is buggy. I copied/pasted the quote of what I was replying to because I had actually pressed the reply button on your last comment and I knew Github is buggy around this behavior (for some reason). I guess they broke it further.

Copy link
Contributor

@kumar303 kumar303 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 quick fixes. Here is some more feedback.

expect(renderControls(root).find(FlagReviewMenu)).toHaveLength(1);
});

it('hides the flag button if you wrote the review', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

When I undo your patch, this test should fail but it does not. Try to make it fail.

Here's how I undid your patch:

diff --git a/src/amo/components/AddonReviewCard/index.js b/src/amo/components/AddonReviewCard/index.js
index 13013647a..ff535434a 100644
--- a/src/amo/components/AddonReviewCard/index.js
+++ b/src/amo/components/AddonReviewCard/index.js
@@ -482,7 +482,7 @@ export class AddonReviewCardBase extends React.Component<InternalProps> {
         ) : null}
 
         {/* Do not render the "flag" button for reviews made by the current user */}
-        {flaggable && review && (!siteUser || siteUser.id !== review.userId) ? (
+        {flaggable && review ? (
           <FlagReviewMenu
             isDeveloperReply={this.isReply()}
             openerClass="AddonReviewCard-control"

Copy link
Contributor Author

@seanprashad seanprashad Oct 18, 2018

Choose a reason for hiding this comment

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

Ok - here's how I think we should proceed:

The current test:

  • Signs the user in
  • Creates a review
  • Checks that the flag button isn't rendered

The ideal test:

  • Signs the user in
  • Creates a review
  • Checks that the flag button isn't rendered
  • Signs the user out
  • Checks that the flag button is rendered

Edit: This logout is just what we need!

@@ -576,6 +583,21 @@ describe(__filename, () => {
expect(root.find(FlagReviewMenu)).toHaveLength(0);
});

it('renders the flag button when not signed in', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I just realized that you don't need this test because we already have one:

it('lets you flag a review', () => {

However, I would suggest changing the spec from 'lets you flag a review' to 'shows FlagReviewMenu when signed out'

@kumar303 kumar303 self-requested a review October 18, 2018 14:46
Sean Prashad added 2 commits October 18, 2018 10:48
In addition to signing in the user and ensuring the "flag" button is
hidden for their own replies, the test now signs the user out to ensure
that all flag buttons are shown. This workflow allows unauthenticated
users to see that flagging a review is possible, only after signing in.
@seanprashad
Copy link
Contributor Author

seanprashad commented Oct 18, 2018

Your tip made me realize that I forgot to check if the flag button would be rendered after the user logged out! I've updated this in the test and removed the old helper function I had written.

updating_test_logic_logout_failing

After adding back in my patch, all tests passed 🎉

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

The test fails now without your patch (good!) but it needs some tweaks.


expect(renderControls(root).find(FlagReviewMenu)).toHaveLength(0);

store.dispatch(logOutUser());
Copy link
Contributor

Choose a reason for hiding this comment

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

You can delete this and the assertion below because it's a duplication of the logic covered by this test. In other words, signing out produces the exact same state as not signing in to begin with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ All done

it('hides the flag button if you wrote the review', () => {
const originalReviewId = 123;
const review = signInAndDispatchSavedReview({
siteUserId: originalReviewId,
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable name is confusing but I see what you are trying to do. You are letting the helper take over to set siteUserId and reviewUserId to the same value. Instead of letting the helper do this implicitly, your test should explicitly set these both to the same value so that the intention is clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I didn't want to introduce another helper that wrapped the signInAndDispatchSavedReview() helper so I just used it directly. I've updated the variable naming to siteUserId so it hopefully helps us recognize that this is an authenticated user.

@kumar303 kumar303 self-requested a review October 18, 2018 18:06
Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

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

This looks great. Thanks for all the quick turnarounds.

@kumar303 kumar303 merged commit fe9cefc into mozilla:master Oct 18, 2018
@seanprashad seanprashad deleted the issue-6416 branch October 18, 2018 19:19
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.

"Flag" should be removed from the profile page
4 participants