This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from Human-Connection/blacklist_feature
Blacklist other user accounts
- Loading branch information
Showing
16 changed files
with
529 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Feature: Individual Blacklist | ||
As a user | ||
I want to click on a button to blacklist certain user profiles | ||
In order to stop seeing user content of this account, because I don't like them | ||
|
||
Background: | ||
Given this is your user account: | ||
| email | password | isVerified | | ||
| user@example.com | 1234 | true | | ||
And these user accounts exist: | ||
| name | email | isVerified | | ||
| Troll | troll@example.com | true | | ||
| Legit | legit@example.com | true | | ||
And you are authenticated | ||
|
||
|
||
Scenario: Blacklist a user | ||
When you create your user settings via POST request to "/usersettings" with: | ||
""" | ||
{ | ||
"blacklist": ["5b5863e8d47c14323165718b"] | ||
} | ||
""" | ||
Then you will stop seeing posts of the user with id "5b5863e8d47c14323165718b" | ||
|
||
Scenario: Filter out contributions of a blacklisted user | ||
Given you blacklisted the user "Troll" before | ||
When this user publishes a post | ||
And you read your current news feed | ||
Then this post is not included | ||
|
||
Scenario: Show but conceal comments of a blacklisted user | ||
Given you blacklisted the user "Troll" before | ||
And there is a post "Hello World" by user "Legit" | ||
And the blacklisted user wrote a comment on that post: | ||
""" | ||
I hate you | ||
""" | ||
When you read through the comments of that post | ||
Then you will see a hint instead of a comment: | ||
""" | ||
Comments of this blacklisted user are not visible. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Feature: Save preferred language settings | ||
As a user of human connection | ||
You would like to have my preferred language saved | ||
So when I log in the next time, the UI switches to my language automatically | ||
|
||
Background: | ||
Given this is your user account: | ||
| email | password | isVerified | | ||
| user@example.com | 1234 | true | | ||
|
||
Scenario: Save your language | ||
Given you are authenticated | ||
When you create your user settings via POST request to "/usersettings" with: | ||
""" | ||
{ | ||
"uiLanguage": "de" | ||
} | ||
""" | ||
Then your language "de" is stored in your user settings | ||
|
||
Scenario: Save your filter settings | ||
Given you are authenticated | ||
When you create your user settings via POST request to "/usersettings" with: | ||
""" | ||
{ | ||
"contentLanguages" : [ "en" ], | ||
"uiLanguage" : "en", | ||
"filter": { | ||
"categoryIds": [ | ||
"5b310ab8b801653c1eb6c426", | ||
"5b310ab8b801653c1eb6c427", | ||
"5b310ab8b801653c1eb6c428" | ||
] | ||
} | ||
} | ||
""" | ||
Then these category ids are stored in your user settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ module.exports = func => hook => { | |
} | ||
replaceItems(hook, items); | ||
return hook; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const alterItems = require('../helper/alter-items'); | ||
|
||
const defaults = { | ||
blacklist: [], | ||
data: { | ||
content: 'You have blacklisted this user' | ||
} | ||
}; | ||
|
||
const handleItem = options => item => { | ||
if (options.blacklist){ | ||
let found = options.blacklist.find((userId) => { | ||
return String(userId) === item.userId; | ||
}); | ||
if (found){ | ||
item = {...item, ...options.data}; | ||
} | ||
} | ||
return item; | ||
}; | ||
|
||
module.exports = function concealBlacklistedData(options = defaults) { | ||
return async function(hook){ | ||
if (hook.method === 'find' || hook.id === null) { | ||
const authenticatedUser = hook.params.user; | ||
if (!authenticatedUser){ | ||
return hook; | ||
} | ||
const usersettings = await hook.app.service('usersettings').find({query: {userId: authenticatedUser._id}}); | ||
if (usersettings.total <= 0){ | ||
return hook; | ||
} | ||
options.blacklist = usersettings.data[0].blacklist; | ||
return alterItems(handleItem(options))(hook); | ||
} | ||
|
||
return hook; | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = function excludeBlacklisted() { | ||
return async function (hook) { | ||
if (hook.type !== 'before') { | ||
throw new Error('The \'excludeBlacklisted\' hook should only be used as a \'before\' hook.'); | ||
} | ||
|
||
if (hook.method === 'find' || hook.id === null) { | ||
const authenticatedUser = hook.params.user; | ||
if (!authenticatedUser){ | ||
return hook; | ||
} | ||
const usersettings = await hook.app.service('usersettings').find({query: {userId: authenticatedUser._id}}); | ||
if (usersettings.total <= 0){ | ||
return hook; | ||
} | ||
const blacklist = usersettings.data[0].blacklist; | ||
hook.params.query.userId = {$nin: blacklist}; | ||
return hook; | ||
} | ||
|
||
return hook; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.