diff options
author | Vitaly Takmazov | 2018-08-29 17:28:11 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-08-29 17:28:11 +0300 |
commit | 70963f3c8a616039a442362e778825f4fe85e4c5 (patch) | |
tree | 7a85efc93ce242ba196a49195cc55f36a86ce1c9 /juick-server | |
parent | bdf6c8ff1eb67d320684df025632ebf72966db37 (diff) |
shadow banned users from recommendations list
Diffstat (limited to 'juick-server')
-rw-r--r-- | juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java | 11 | ||||
-rw-r--r-- | juick-server/src/test/java/com/juick/server/tests/ServerTests.java | 17 |
2 files changed, 24 insertions, 4 deletions
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java index 913ee747..e2958112 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -423,10 +423,13 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Override public List<String> getMessageRecommendations(final int mid) { return getJdbcTemplate().queryForList( - "SELECT DISTINCT users.nick FROM favorites INNER JOIN users " + - "ON (favorites.message_id = ? AND favorites.user_id = users.id) WHERE favorites.like_id=1", - new Object[]{mid}, - String.class); + "SELECT DISTINCT users.nick FROM favorites " + + "INNER JOIN users ON (favorites.message_id = ? AND favorites.user_id = users.id) " + + "INNER JOIN messages m ON favorites.message_id=m.message_id WHERE favorites.like_id=1 " + + "AND NOT EXISTS (SELECT 1 FROM bl_users WHERE " + + "(user_id = favorites.user_id AND bl_user_id = m.user_id) " + + "OR (user_id = m.user_id AND bl_user_id = favorites.user_id))", + String.class, mid); } @Transactional(readOnly = true) diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index 95f459b4..70555fca 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -35,6 +35,7 @@ import com.juick.service.*; import com.juick.util.DateFormattersHolder; import com.juick.util.MessageUtils; import org.apache.commons.codec.CharEncoding; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.junit.After; @@ -1286,4 +1287,20 @@ public class ServerTests { mockMvc.perform(get("/auth").with(httpBasic(userName, userPassword))).andExpect(status().isUnauthorized()); } + @Test + public void bannedUserShouldBeShadowedFromRecommendationsList() throws IOException { + int ermineId = userService.createUser("ermine", "secret"); + int monstreekId = userService.createUser("monstreek", "secret"); + int pogoId = userService.createUser("pogo", "secret"); + int fmapId = userService.createUser("fmap", "secret"); + int mid = messagesService.createMessage(monstreekId, "KURWA", null, null); + assertThat(messagesService.recommendMessage(mid, ermineId), is(MessagesService.RecommendStatus.Added)); + assertThat(messagesService.recommendMessage(mid, fmapId), is(MessagesService.RecommendStatus.Added)); + assertThat(messagesService.recommendMessage(mid, pogoId), is(MessagesService.RecommendStatus.Added)); + assertThat(messagesService.getMessage(mid).getLikes(), is(3)); + assertThat(CollectionUtils.isEqualCollection(messagesService.getMessageRecommendations(mid), Arrays.asList("fmap", "ermine", "pogo")), is(true)); + privacyQueriesService.blacklistUser(userService.getUserByName("monstreek"), userService.getUserByName("pogo")); + assertThat(messagesService.getMessage(mid).getLikes(), is(3)); + assertThat(CollectionUtils.isEqualCollection(messagesService.getMessageRecommendations(mid), Arrays.asList("fmap", "ermine")), is(true)); + } } |