From 3b29d480e3915ad9ff30945ff8598d74588ed20c Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 10 Feb 2020 12:34:40 +0100 Subject: [PATCH 1/3] Display unblock feature only for blocking user - add hasBlocked query to check if userA initiated the blocking and, if true, only them to unblock userB. - add cypress tests to make sure we don't break this in the future. --- backend/src/schema/types/type/User.gql | 7 ++++- cypress/integration/common/steps.js | 30 +++++++++++++++++++ .../user_profile/BlockUser.feature | 11 +++++++ webapp/components/ContentMenu/ContentMenu.vue | 2 +- webapp/pages/profile/_id/_slug.vue | 4 +-- 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/backend/src/schema/types/type/User.gql b/backend/src/schema/types/type/User.gql index 71cc1edb0..ec9bfeba7 100644 --- a/backend/src/schema/types/type/User.gql +++ b/backend/src/schema/types/type/User.gql @@ -68,7 +68,12 @@ type User { RETURN COUNT(u) >= 1 """ ) - + hasBlocked: Boolean! @cypher( + statement: """ + MATCH (this)<-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId}) + RETURN COUNT(user) >= 1 + """ + ) blocked: Boolean! @cypher( statement: """ MATCH (this)-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId}) diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 36dbb50d4..753160b84 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -558,6 +558,20 @@ When("I block the user {string}", name => { }); }); +When("a user has blocked me", () => { + cy.neode() + .first("User", { + name: narratorParams.name + }) + .then(blockedUser => { + cy.neode() + .first("User", { + name: 'Harassing User' + }) + .relateTo(blockedUser, "blocked"); + }); +}); + When("I log in with:", table => { const [firstRow] = table.hashes(); const { @@ -583,4 +597,20 @@ Then("they should not see the comment from", () => { Then("they should see a text explaining commenting is not possible", () => { cy.get('.ds-placeholder').should('contain', "Commenting is not possible at this time on this post.") +}) + +Then("I should see no users in my blocked users list", () => { + cy.get('.ds-placeholder') + .should('contain', "So far, you have not blocked anybody.") +}) + +Then("I should not see {string} from the content menu in the user info box", link => { + cy.get(".user-content-menu .base-button").click() + cy.get(".popover .ds-menu-item-link") + .should('not.contain', link) +}) + +Then('I should not see {string} button', button => { + cy.get('.ds-card-content') + .should('not.contain', '.action-buttons') }) \ No newline at end of file diff --git a/cypress/integration/user_profile/BlockUser.feature b/cypress/integration/user_profile/BlockUser.feature index 43efe7807..50b90ee62 100644 --- a/cypress/integration/user_profile/BlockUser.feature +++ b/cypress/integration/user_profile/BlockUser.feature @@ -44,3 +44,14 @@ Feature: Block a User Then I should see the following posts in the select dropdown: | title | | previously created post | + + Scenario: Blocked users cannot see they are blocked in their list + Given a user has blocked me + And I navigate to my "Blocked users" settings page + Then I should see no users in my blocked users list + + Scenario: Blocked users should not see link or button to unblock, only blocking users + Given a user has blocked me + When I visit the profile page of the annoying user + And I should not see "Unblock user" from the content menu in the user info box + And I should not see "Unblock user" button \ No newline at end of file diff --git a/webapp/components/ContentMenu/ContentMenu.vue b/webapp/components/ContentMenu/ContentMenu.vue index ee2bd4a62..2be51c6ac 100644 --- a/webapp/components/ContentMenu/ContentMenu.vue +++ b/webapp/components/ContentMenu/ContentMenu.vue @@ -172,7 +172,7 @@ export default { icon: 'microphone-slash', }) } - if (this.resource.blocked) { + if (this.resource.hasBlocked) { routes.push({ label: this.$t(`settings.blocked-users.unblock`), callback: () => { diff --git a/webapp/pages/profile/_id/_slug.vue b/webapp/pages/profile/_id/_slug.vue index 80471fff4..4d9653dcb 100644 --- a/webapp/pages/profile/_id/_slug.vue +++ b/webapp/pages/profile/_id/_slug.vue @@ -67,14 +67,14 @@
- + {{ $t('settings.blocked-users.unblock') }} {{ $t('settings.muted-users.unmute') }} Date: Mon, 10 Feb 2020 14:33:49 +0100 Subject: [PATCH 2/3] Add type resolver for hasBlocked --- backend/src/schema/resolvers/users.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index d1d9111b6..55e4165b7 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -252,9 +252,11 @@ export default { followedByCurrentUser: 'MATCH (this)<-[:FOLLOWS]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1', blocked: - 'MATCH (this)<-[:BLOCKED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1', + 'MATCH (this)-[:BLOCKED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1', isMuted: 'MATCH (this)<-[:MUTED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1', + hasBlocked: + 'MATCH (this)<-[:BLOCKED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1', }, count: { contributionsCount: From 5347f734af524c18565f0cf0e8497d074d77c40c Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 10 Feb 2020 16:25:00 +0100 Subject: [PATCH 3/3] Fix cypress tests/frontend implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Co-authored-by: Wolfgang Huß --- backend/src/schema/resolvers/users.js | 2 +- backend/src/schema/types/type/User.gql | 2 +- cypress/integration/common/steps.js | 13 +++++++++---- cypress/integration/user_profile/BlockUser.feature | 5 ++++- webapp/components/ContentMenu/ContentMenu.vue | 2 +- webapp/graphql/User.js | 1 + webapp/pages/post/_id/_slug/index.vue | 2 +- webapp/pages/profile/_id/_slug.vue | 4 ++-- 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/backend/src/schema/resolvers/users.js b/backend/src/schema/resolvers/users.js index 55e4165b7..cbdc683e8 100644 --- a/backend/src/schema/resolvers/users.js +++ b/backend/src/schema/resolvers/users.js @@ -255,7 +255,7 @@ export default { 'MATCH (this)-[:BLOCKED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1', isMuted: 'MATCH (this)<-[:MUTED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1', - hasBlocked: + isBlocked: 'MATCH (this)<-[:BLOCKED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1', }, count: { diff --git a/backend/src/schema/types/type/User.gql b/backend/src/schema/types/type/User.gql index ec9bfeba7..baefc9d29 100644 --- a/backend/src/schema/types/type/User.gql +++ b/backend/src/schema/types/type/User.gql @@ -68,7 +68,7 @@ type User { RETURN COUNT(u) >= 1 """ ) - hasBlocked: Boolean! @cypher( + isBlocked: Boolean! @cypher( statement: """ MATCH (this)<-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId}) RETURN COUNT(user) >= 1 diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 52e8d7bba..c51290537 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -591,13 +591,18 @@ Then("I should see no users in my blocked users list", () => { .should('contain', "So far, you have not blocked anybody.") }) -Then("I should not see {string} from the content menu in the user info box", link => { +Then("I {string} see {string} from the content menu in the user info box", (condition, link) => { cy.get(".user-content-menu .base-button").click() cy.get(".popover .ds-menu-item-link") - .should('not.contain', link) + .should(condition === 'should' ? 'contain' : 'not.contain', link) }) Then('I should not see {string} button', button => { - cy.get('.ds-card-content') - .should('not.contain', '.action-buttons') + cy.get('.ds-card-content .action-buttons') + .should('have.length', 1) +}) + +Then('I should see the {string} button', button => { + cy.get('.ds-card-content .action-buttons .base-button') + .should('contain', button) }) diff --git a/cypress/integration/user_profile/BlockUser.feature b/cypress/integration/user_profile/BlockUser.feature index bf56e2b02..256d79dfb 100644 --- a/cypress/integration/user_profile/BlockUser.feature +++ b/cypress/integration/user_profile/BlockUser.feature @@ -11,6 +11,7 @@ Feature: Block a User Scenario: Block a user Given I am on the profile page of the annoying user When I click on "Block user" from the content menu in the user info box + And I "should" see "Unblock user" from the content menu in the user info box And I navigate to my "Blocked users" settings page Then I can see the following table: | Avatar | Name | @@ -28,6 +29,7 @@ Feature: Block a User When I visit the profile page of the annoying user And I click on "Block user" from the content menu in the user info box And I get removed from his follower collection + And I "should" see "Unblock user" from the content menu in the user info box Scenario: Posts of blocked users are not filtered from search results Given "Harassing User" wrote a post "You can still see my posts" @@ -53,5 +55,6 @@ Feature: Block a User Scenario: Blocked users should not see link or button to unblock, only blocking users Given a user has blocked me When I visit the profile page of the annoying user - And I should not see "Unblock user" from the content menu in the user info box + And I "should not" see "Unblock user" from the content menu in the user info box + And I should see the "Follow" button And I should not see "Unblock user" button \ No newline at end of file diff --git a/webapp/components/ContentMenu/ContentMenu.vue b/webapp/components/ContentMenu/ContentMenu.vue index 2be51c6ac..cee8a6f5c 100644 --- a/webapp/components/ContentMenu/ContentMenu.vue +++ b/webapp/components/ContentMenu/ContentMenu.vue @@ -172,7 +172,7 @@ export default { icon: 'microphone-slash', }) } - if (this.resource.hasBlocked) { + if (this.resource.isBlocked) { routes.push({ label: this.$t(`settings.blocked-users.unblock`), callback: () => { diff --git a/webapp/graphql/User.js b/webapp/graphql/User.js index a73941794..c36383a95 100644 --- a/webapp/graphql/User.js +++ b/webapp/graphql/User.js @@ -24,6 +24,7 @@ export default i18n => { createdAt followedByCurrentUser isMuted + isBlocked blocked following(first: 7) { ...user diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index 1d107941a..8115294c5 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -97,7 +97,7 @@ :post="post" @createComment="createComment" /> - + {{ $t('settings.blocked-users.explanation.commenting-disabled') }}
{{ $t('settings.blocked-users.explanation.commenting-explanation') }} diff --git a/webapp/pages/profile/_id/_slug.vue b/webapp/pages/profile/_id/_slug.vue index 4d9653dcb..372b73b40 100644 --- a/webapp/pages/profile/_id/_slug.vue +++ b/webapp/pages/profile/_id/_slug.vue @@ -67,14 +67,14 @@
- + {{ $t('settings.blocked-users.unblock') }} {{ $t('settings.muted-users.unmute') }}