Skip to content

Commit cb33da1

Browse files
committed
Hide FAQ menu option if not set in application.properties (fix #79)
1 parent 92c0e0e commit cb33da1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/main/java/ubc/pavlab/rdp/controllers/UserController.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import ubc.pavlab.rdp.model.enums.PrivacyLevelType;
2525
import ubc.pavlab.rdp.model.enums.TierType;
2626
import ubc.pavlab.rdp.services.*;
27+
import ubc.pavlab.rdp.settings.ApplicationSettings;
2728

2829
import javax.mail.MessagingException;
2930
import javax.servlet.http.HttpServletRequest;
@@ -58,6 +59,9 @@ public class UserController {
5859
@Autowired
5960
private ApplicationEventPublisher eventPublisher;
6061

62+
@Autowired
63+
private ApplicationSettings applicationSettings;
64+
6165
@GetMapping(value = { "/user/home" })
6266
public ModelAndView userHome() {
6367
ModelAndView modelAndView = new ModelAndView( "user/home" );
@@ -123,8 +127,13 @@ public ModelAndView documentation() {
123127
@GetMapping(value = { "/user/faq" })
124128
public ModelAndView faq() {
125129
ModelAndView modelAndView = new ModelAndView( "user/faq" );
126-
User user = userService.findCurrentUser();
127-
modelAndView.addObject( "user", user );
130+
if ( applicationSettings.getFaqFile() == null ) {
131+
modelAndView.setStatus( HttpStatus.NOT_FOUND );
132+
modelAndView.setViewName( "error/404" );
133+
} else {
134+
User user = userService.findCurrentUser();
135+
modelAndView.addObject( "user", user );
136+
}
128137
return modelAndView;
129138
}
130139

src/main/resources/templates/layouts/common.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<li class="nav-item">
6969
<a class="nav-link" th:href="@{/user/documentation}" href="/user/documentation">Documentation</a>
7070
</li>
71-
<li class="nav-item">
71+
<li th:if="${@applicationSettings.faqFile}" class="nav-item">
7272
<a class="nav-link" th:href="@{/user/faq}" href="/user/faq">FAQ</a>
7373
</li>
7474
<li class="nav-item">

src/test/java/ubc/pavlab/rdp/controllers/UserControllerTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
1717
import org.springframework.boot.test.mock.mockito.MockBean;
1818
import org.springframework.context.annotation.Import;
19+
import org.springframework.core.io.ClassPathResource;
1920
import org.springframework.http.MediaType;
2021
import org.springframework.security.access.PermissionEvaluator;
2122
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -178,6 +179,7 @@ public void getTermsGenesForTaxon_thenReturnSuccess() throws Exception {
178179
public void getUserStaticEndpoints_thenReturnSuccess() throws Exception {
179180
User user = createUser( 1 );
180181
when( userService.findCurrentUser() ).thenReturn( user );
182+
when( applicationSettings.getFaqFile() ).thenReturn( new ClassPathResource( "faq.properties" ) );
181183
mvc.perform( get( "/user/home" ) )
182184
.andExpect( status().isOk() )
183185
.andExpect( view().name( "user/home" ) );
@@ -189,6 +191,15 @@ public void getUserStaticEndpoints_thenReturnSuccess() throws Exception {
189191
.andExpect( view().name( "user/faq" ) );
190192
}
191193

194+
@Test
195+
@WithMockUser
196+
public void getUserFaq_whenFaqIsDisabled_thenReturn404() throws Exception {
197+
when( applicationSettings.getFaqFile() ).thenReturn( null );
198+
mvc.perform( get( "/user/faq" ) )
199+
.andExpect( status().isNotFound() )
200+
.andExpect( view().name( "error/404" ) );
201+
}
202+
192203
@Test
193204
@WithMockUser
194205
public void contactSupport_thenReturnSuccess() throws Exception {

0 commit comments

Comments
 (0)