diff options
author | Vitaly Takmazov | 2018-01-11 11:29:09 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-01-11 11:29:09 +0300 |
commit | 76d4f5c19b6da9ac330921bad4c27fb3228329c5 (patch) | |
tree | 744ee6baf71774393b40ed745812f560d3121442 | |
parent | 449a1b5634127d47bfdd8ff5c98b99eac8541e73 (diff) |
www: do not show reply button when any user is in bl
-rw-r--r-- | juick-www/src/main/java/com/juick/www/controllers/Messages.java | 6 | ||||
-rw-r--r-- | juick-www/src/test/java/com/juick/www/WebAppTests.java | 38 |
2 files changed, 36 insertions, 8 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Messages.java b/juick-www/src/main/java/com/juick/www/controllers/Messages.java index 39e88b12..5a76256e 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/Messages.java +++ b/juick-www/src/main/java/com/juick/www/controllers/Messages.java @@ -515,7 +515,7 @@ public class Messages { fillUserModel(model, user, visitor); if (visitor.getUid() > 0) { boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); - boolean isInBL = userService.isInBL(msg.getUser().getUid(), visitor.getUid()); + boolean isInBL = userService.isInBLAny(msg.getUser().getUid(), visitor.getUid()); msg.VisitorCanComment = isMsgAuthor || !(msg.ReadOnly || isInBL); } model.addAttribute("msg", msg); @@ -604,8 +604,8 @@ public class Messages { if (visitor.getUid() > 0) { boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); boolean isReplyAuthor = visitor.getUid() == reply.getUser().getUid(); - BooleanSupplier isInBL2 = () -> userService.checkBL(visitor.getUid(), blUIDs).contains(reply.getUser().getUid()); - reply.VisitorCanComment = isMsgAuthor || (!msg.ReadOnly && (isReplyAuthor || !isInBL2.getAsBoolean())); + reply.VisitorCanComment = isMsgAuthor || (!msg.ReadOnly + && (isReplyAuthor || !userService.isInBLAny(visitor.getUid(), reply.getUser().getUid()))); } } diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java index 32bad137..c663ff6d 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -17,6 +17,7 @@ package com.juick.www; +import com.gargoylesoftware.htmlunit.CookieManager; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.css.StyleElement; @@ -29,6 +30,7 @@ import com.juick.configuration.RepositoryConfiguration; import com.juick.service.ImagesService; import com.juick.service.MessagesService; import com.juick.service.MockImagesService; +import com.juick.service.PrivacyQueriesService; import com.juick.service.UserService; import com.juick.util.MessageUtils; import com.juick.www.configuration.SapeConfiguration; @@ -110,16 +112,18 @@ public class WebAppTests { private static WebClient webClient; @Inject - UserService userService; + private UserService userService; @Inject - MessagesService messagesService; + private MessagesService messagesService; @Inject - JdbcTemplate jdbcTemplate; + private PrivacyQueriesService privacyQueriesService; + @Inject + private JdbcTemplate jdbcTemplate; @Inject - PebbleEngine pebbleEngine; + private PebbleEngine pebbleEngine; @Value("${img_path:/tmp}") - String imgPath; + private String imgPath; private static User ugnich, freefd; private static String ugnichName, ugnichPassword, freefdName, freefdPassword; @@ -201,6 +205,30 @@ public class WebAppTests { assertThat(visibleItems, equalTo(1L)); } @Test + public void userShouldNotSeeReplyButtonToBannedUser() throws Exception { + int mid = messagesService.createMessage(ugnich.getUid(), "freefd bl me", null, null); + messagesService.createReply(mid, 0, ugnich.getUid(), "yo", null); + MvcResult loginResult = mockMvc.perform(post("/login") + .param("username", freefdName) + .param("password", freefdPassword)).andReturn(); + Cookie loginCookie = loginResult.getResponse().getCookie("juick-remember-me"); + webClient.setCookieManager(new CookieManager()); + webClient.getCookieManager().addCookie( + new com.gargoylesoftware.htmlunit.util.Cookie(loginCookie.getDomain(), + loginCookie.getName(), + loginCookie.getValue())); + HtmlPage threadPage = webClient.getPage(String.format("http://localhost:8080/ugnich/%d", mid)); + assertThat(threadPage.getWebResponse().getStatusCode(), equalTo(200)); + assertThat(threadPage.querySelectorAll(".msg-comment-target").isEmpty(), equalTo(false)); + assertThat(threadPage.querySelectorAll(".a-thread-comment").isEmpty(), equalTo(false)); + privacyQueriesService.blacklistUser(freefd, ugnich); + assertThat(userService.isInBLAny(freefd.getUid(), ugnich.getUid()), equalTo(true)); + threadPage = webClient.getPage(String.format("http://localhost:8080/ugnich/%d", mid)); + assertThat(threadPage.getWebResponse().getStatusCode(), equalTo(200)); + assertThat(threadPage.querySelectorAll(".msg-comment-target").isEmpty(), equalTo(true)); + assertThat(threadPage.querySelectorAll(".a-thread-comment").isEmpty(), equalTo(true)); + } + @Test public void correctTagsEscaping() throws PebbleException, IOException { PebbleTemplate template = pebbleEngine.getTemplate("views/test"); Writer writer = new StringWriter(); |