aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java8
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java11
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java21
3 files changed, 29 insertions, 11 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
index 609b7e01..0ca30904 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -51,6 +51,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Inject
private UserService userService;
@Inject
+ private TagService tagService;
+ @Inject
private SearchService searchService;
@Inject
private ImagesService imagesService;
@@ -443,6 +445,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
" OR m.user_id = :visitorUid) AND NOT EXISTS (" +
" SELECT 1 FROM bl_users b WHERE b.user_id = :visitorUid AND b.bl_user_id = m.user_id)" :
")") +
+ " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN " +
+ "(SELECT tag_id FROM messages_tags WHERE message_id = m.message_id) and :visitorUid = bt.user_id)" +
" AND NOT EXISTS (SELECT 1 from users u WHERE u.banned = 1 and u.id = m.user_id) ORDER BY m.message_id DESC LIMIT 20",
sqlParameterSource,
Integer.class);
@@ -599,6 +603,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
(before > 0 ?
" AND m.message_id < :before " : StringUtils.EMPTY) +
" AND m.popular > 0 AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :vid and b.bl_user_id = m.user_id) " +
+ " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN " +
+ "(SELECT tag_id FROM messages_tags WHERE message_id = m.message_id) and :vid = bt.user_id)" +
" ORDER BY m.message_id DESC LIMIT 20",
sqlParameterSource,
Integer.class);
@@ -616,6 +622,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
(before > 0 ?
" AND m.message_id < :before " : StringUtils.EMPTY) +
" AND m.attach IS NOT NULL " +
+ " AND NOT EXISTS (SELECT 1 FROM bl_tags bt WHERE bt.tag_id IN " +
+ "(SELECT tag_id FROM messages_tags WHERE message_id = m.message_id) and :vid = bt.user_id)" +
" AND NOT EXISTS (SELECT 1 from users u WHERE u.banned = 1 and u.id = m.user_id) " +
" AND NOT EXISTS (SELECT 1 FROM bl_users b WHERE b.user_id = :vid and b.bl_user_id = m.user_id) " +
" ORDER BY m.message_id DESC LIMIT 20",
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
index 0e371ab5..880f18b9 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java
@@ -28,16 +28,13 @@ import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.Assert;
-import javax.inject.Inject;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
@@ -54,14 +51,6 @@ public class TagServiceImpl extends BaseJdbcService implements TagService {
private static final Pattern TAGS_PATTERN2 = Pattern.compile("^\\*([^ \\r\\n\\t]+)[\\s+]?([\\s\\S]+)?");
private static final Pattern TAG_PATTERN = Pattern.compile("\\*([^ \\r\\n\\t]+)");
- private final MessagesService messagesService;
-
- @Inject
- public TagServiceImpl(MessagesService messagesService) {
- Assert.notNull(messagesService, "MessagesService must be initialized");
- this.messagesService = messagesService;
- }
-
@Transactional(readOnly = true)
@Override
public com.juick.Tag getTag(final int tid) {
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 e8111239..087acbc4 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
@@ -879,4 +879,25 @@ public class ServerTests {
.andExpect(status().isOk());
assertThat(lastRead.apply(ugnich, mid), is(newfreefdrid));
}
+ @Test
+ public void feedsShouldNotContainMessagesWithBannedTags() {
+ Tag banned = tagService.getTag("banned", true);
+ int mid = messagesService.createMessage(ugnich.getUid(), "yo", "jpg",
+ Collections.singletonList(banned));
+ privacyQueriesService.blacklistTag(freefd, banned);
+ assertTrue(messagesService.getMessages(messagesService.getAll(freefd.getUid(), 0))
+ .stream().noneMatch(m -> m.getTags().contains(banned)));
+ assertFalse(messagesService.getMessages(messagesService.getAll(ugnich.getUid(), 0))
+ .stream().noneMatch(m -> m.getTags().contains(banned)));
+ assertTrue(messagesService.getMessages(messagesService.getPhotos(freefd.getUid(), 0))
+ .stream().noneMatch(m -> m.getTags().contains(banned)));
+ assertFalse(messagesService.getMessages(messagesService.getPhotos(ugnich.getUid(), 0))
+ .stream().noneMatch(m -> m.getTags().contains(banned)));
+ jdbcTemplate.update("UPDATE messages SET popular=1 WHERE message_id=?", mid);
+ assertTrue(messagesService.getMessages(messagesService.getPopular(freefd.getUid(), 0))
+ .stream().noneMatch(m -> m.getTags().contains(banned)));
+ assertFalse(messagesService.getMessages(messagesService.getPopular(ugnich.getUid(), 0))
+ .stream().noneMatch(m -> m.getTags().contains(banned)));
+
+ }
}