From 8aa7f376b6e720c5b3a90fbcd3f458c52e59cdad Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 1 Oct 2019 17:45:09 +0200 Subject: [PATCH 1/6] Update Post query for blockedByUsers - Admin/Moderators see Posts even if they are blocked --- backend/src/schema/resolvers/users.js | 1 + cypress/integration/common/report.js | 11 +++++++- cypress/integration/common/steps.js | 15 +++++++++++ .../moderation/ReportContent.feature | 26 ++++++++++++++----- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index ea9220d5e..057e52435 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -30,6 +30,7 @@ export const getBlockedByUsers = async context => { .relationship(userModel.relationships().get('blocked')) .to('blocked', userModel) .where('blocked.id', context.user.id) + .where('blocked.user', 'user') .return('user') blockedByUsers = await blockedByUsers.execute() blockedByUsers = blockedByUsers.records.map(r => r.get('user').properties) diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js index fb395d361..a60068f04 100644 --- a/cypress/integration/common/report.js +++ b/cypress/integration/common/report.js @@ -116,7 +116,7 @@ When(/^I confirm the reporting dialog .*:$/, message => { Given('somebody reported the following posts:', table => { table.hashes().forEach(({ id }) => { const submitter = { - email: `submitter${id}@example.org`, + email: `submitter${id}@example.org`, password: '1234' } cy.factory() @@ -143,3 +143,12 @@ Then('each list item links to the post page', () => { cy.contains(davidIrvingPostTitle).click() cy.location('pathname').should('contain', '/post') }) + +When("they have a post someone has reported", () => { + cy.factory() + .create("Post", { + authorId: 'annnoying-user', + title, + }); + +}) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index a25200667..f04f43b26 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -410,6 +410,21 @@ Given("there is an annoying user called {string}", name => { }); }); +Given("there is an annoying user who has blocked me", () => { + cy.login({ email: 'i-blocked-a-moderator-ha-ha-ha@example.org', password: '1234' }) + .neode() + .first("User", { + role: 'moderator' + }) + .then(blocked => { + cy.neode() + .first("User", { + name + }) + .relateTo(blocked, "blocked"); + }); +}); + Given("I am on the profile page of the annoying user", name => { cy.openPage("/profile/annoying-user/spammy-spammer"); }); diff --git a/cypress/integration/moderation/ReportContent.feature b/cypress/integration/moderation/ReportContent.feature index 0181dc7a6..566209346 100644 --- a/cypress/integration/moderation/ReportContent.feature +++ b/cypress/integration/moderation/ReportContent.feature @@ -8,13 +8,15 @@ Feature: Report and Moderate So I can look into it and decide what to do Background: - Given we have this user in our database: - | id | name | - | u67 | David Irving| + Given we have the following user accounts: + | id | name | email | password | + | u67 | David Irving | david-irving@example.org | 1234 | + | annoying-user | I'm gonna block Moderators and Admins HA HA HA | i-blocked-a-moderator-ha-ha-ha@example.org | 1234 | + Given we have the following posts in our database: - | authorId | id | title | content | - | u67 | p1 | The Truth about the Holocaust | It never existed! | - + | authorId | id | title | content | + | u67 | p1 | The Truth about the Holocaust | It never existed! | + | annoying-user | p2 | Fake news | This content is demonstratably infactual in some way | Scenario Outline: Report a post from various pages Given I am logged in with a "user" role When I see David Irving's post on the @@ -56,6 +58,18 @@ Feature: Report and Moderate Then I see all the reported posts including the one from above And each list item links to the post page + Scenario: Even if a user has blocked me, I can see their reported posts + Given somebody reported the following posts: + | id | + | p2 | + And my user account has the role "moderator" + And there is an annoying user who has blocked me + And I am logged in + When I click on the avatar menu in the top right corner + And I click on "Moderation" + Then I see all the reported posts including the one from above + And each list item links to the post page + Scenario: Normal user can't see the moderation page Given I am logged in with a "user" role When I click on the avatar menu in the top right corner From 3dee2137d47448151360a2e1f71e686bdd046402 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 1 Oct 2019 20:05:34 +0200 Subject: [PATCH 2/6] Find annoying user by id --- cypress/integration/common/steps.js | 5 ++--- cypress/integration/moderation/ReportContent.feature | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index f04f43b26..ab1790756 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -411,15 +411,14 @@ Given("there is an annoying user called {string}", name => { }); Given("there is an annoying user who has blocked me", () => { - cy.login({ email: 'i-blocked-a-moderator-ha-ha-ha@example.org', password: '1234' }) - .neode() + cy.neode() .first("User", { role: 'moderator' }) .then(blocked => { cy.neode() .first("User", { - name + id: 'annoying-user' }) .relateTo(blocked, "blocked"); }); diff --git a/cypress/integration/moderation/ReportContent.feature b/cypress/integration/moderation/ReportContent.feature index 566209346..c35099fd8 100644 --- a/cypress/integration/moderation/ReportContent.feature +++ b/cypress/integration/moderation/ReportContent.feature @@ -9,9 +9,9 @@ Feature: Report and Moderate Background: Given we have the following user accounts: - | id | name | email | password | - | u67 | David Irving | david-irving@example.org | 1234 | - | annoying-user | I'm gonna block Moderators and Admins HA HA HA | i-blocked-a-moderator-ha-ha-ha@example.org | 1234 | + | id | name | + | u67 | David Irving | + | annoying-user | I'm gonna block Moderators and Admins HA HA HA | Given we have the following posts in our database: | authorId | id | title | content | From 478f6fef1cfb5b9c59684cf276122a223d038aa3 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 1 Oct 2019 20:57:45 +0200 Subject: [PATCH 3/6] Fix query builder/test --- backend/src/schema/resolvers/users.js | 2 +- cypress/integration/common/report.js | 8 +++++++- cypress/integration/moderation/ReportContent.feature | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index 057e52435..616e1d194 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -30,7 +30,7 @@ export const getBlockedByUsers = async context => { .relationship(userModel.relationships().get('blocked')) .to('blocked', userModel) .where('blocked.id', context.user.id) - .where('blocked.user', 'user') + .where('blocked.role', 'user') .return('user') blockedByUsers = await blockedByUsers.execute() blockedByUsers = blockedByUsers.records.map(r => r.get('user').properties) diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js index a60068f04..c22651385 100644 --- a/cypress/integration/common/report.js +++ b/cypress/integration/common/report.js @@ -5,7 +5,7 @@ import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps' let lastReportTitle let davidIrvingPostTitle = 'The Truth about the Holocaust' let davidIrvingPostSlug = 'the-truth-about-the-holocaust' -let davidIrvingName = 'David Irving' +let annoyingUserWhoBlockedModeratorTitle = 'Fake news' const savePostTitle = $post => { return $post @@ -139,6 +139,12 @@ Then('I see all the reported posts including the one from above', () => { }) }) +Then('I see all the reported posts including from the user who blocked me', () => { + cy.get('table tbody').within(() => { + cy.contains('tr', annoyingUserWhoBlockedModeratorTitle) + }) +}) + Then('each list item links to the post page', () => { cy.contains(davidIrvingPostTitle).click() cy.location('pathname').should('contain', '/post') diff --git a/cypress/integration/moderation/ReportContent.feature b/cypress/integration/moderation/ReportContent.feature index c35099fd8..351f087fb 100644 --- a/cypress/integration/moderation/ReportContent.feature +++ b/cypress/integration/moderation/ReportContent.feature @@ -67,7 +67,7 @@ Feature: Report and Moderate And I am logged in When I click on the avatar menu in the top right corner And I click on "Moderation" - Then I see all the reported posts including the one from above + Then I see all the reported posts including from the user who blocked me And each list item links to the post page Scenario: Normal user can't see the moderation page From 624922b0e6563b6575bbc82995ea8787095b6388 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 1 Oct 2019 21:29:48 +0200 Subject: [PATCH 4/6] Check that reported post can be visited - want to verify that it is not a post not found 402 --- cypress/integration/common/report.js | 6 ++++++ cypress/integration/moderation/ReportContent.feature | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js index c22651385..c51c6b42e 100644 --- a/cypress/integration/common/report.js +++ b/cypress/integration/common/report.js @@ -150,6 +150,12 @@ Then('each list item links to the post page', () => { cy.location('pathname').should('contain', '/post') }) +Then('I can visit the post page', () => { + cy.contains(annoyingUserWhoBlockedModeratorTitle).click() + cy.location('pathname').should('contain', '/post') + .get('h3').should('contain', annoyingUserWhoBlockedModeratorTitle) +}) + When("they have a post someone has reported", () => { cy.factory() .create("Post", { diff --git a/cypress/integration/moderation/ReportContent.feature b/cypress/integration/moderation/ReportContent.feature index 351f087fb..a18b07796 100644 --- a/cypress/integration/moderation/ReportContent.feature +++ b/cypress/integration/moderation/ReportContent.feature @@ -68,7 +68,7 @@ Feature: Report and Moderate When I click on the avatar menu in the top right corner And I click on "Moderation" Then I see all the reported posts including from the user who blocked me - And each list item links to the post page + And I can visit the post page Scenario: Normal user can't see the moderation page Given I am logged in with a "user" role From d9bfad68a907e26fa1ec8dc066d3f3c2e30c6d43 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Tue, 1 Oct 2019 21:59:25 +0200 Subject: [PATCH 5/6] Update scenario description - to be more similar to other descriptions of the file --- cypress/integration/moderation/ReportContent.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/moderation/ReportContent.feature b/cypress/integration/moderation/ReportContent.feature index a18b07796..0f8eec0e3 100644 --- a/cypress/integration/moderation/ReportContent.feature +++ b/cypress/integration/moderation/ReportContent.feature @@ -58,7 +58,7 @@ Feature: Report and Moderate Then I see all the reported posts including the one from above And each list item links to the post page - Scenario: Even if a user has blocked me, I can see their reported posts + Scenario: Review reported posts of a user who's blocked a moderator Given somebody reported the following posts: | id | | p2 | From f0d096fcab392cca1abbbe0f644a11489f63dee1 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Wed, 2 Oct 2019 09:20:13 +0200 Subject: [PATCH 6/6] Prefer guard clause to avoid database call - follow @roschaefer's PR review --- backend/src/schema/resolvers/users.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index 616e1d194..b5df8111e 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -22,6 +22,7 @@ export const getBlockedUsers = async context => { } export const getBlockedByUsers = async context => { + if (context.user.role === 'moderator' || context.user.role === 'admin') return [] const { neode } = context const userModel = neode.model('User') let blockedByUsers = neode @@ -30,7 +31,6 @@ export const getBlockedByUsers = async context => { .relationship(userModel.relationships().get('blocked')) .to('blocked', userModel) .where('blocked.id', context.user.id) - .where('blocked.role', 'user') .return('user') blockedByUsers = await blockedByUsers.execute() blockedByUsers = blockedByUsers.records.map(r => r.get('user').properties)