use of org.motechproject.server.web.dto.ModuleMenu in project motech by motech.
the class MenuBuilderTest method shouldAddDocumentationUrlForModulesTab.
@Test
public void shouldAddDocumentationUrlForModulesTab() {
setUpRest();
when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("emailRole", "mcRole"));
when(bundle.getHeaders().get(DOC_URL)).thenReturn("http://docs.motechproject.org/en/latest/modules/email.html");
ModuleMenu menu = menuBuilder.buildMenu(USERNAME);
assertEquals(null, menu.getSections().get(1).getModuleDocsUrl());
assertEquals("http://docs.motechproject.org/en/latest/modules/email.html", menu.getSections().get(1).getLinks().get(1).getModuleDocsUrl());
assertNotNull(menu);
}
use of org.motechproject.server.web.dto.ModuleMenu in project motech by motech.
the class MenuBuilderTest method shouldAddDocumentationUrls.
@Test
public void shouldAddDocumentationUrls() {
setUpRest();
when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("emailRole", "mcRole"));
when(bundle.getHeaders().get(DOC_URL)).thenReturn("www.docs.motechproject.org");
ModuleMenu menu = menuBuilder.buildMenu(USERNAME);
assertEquals(menu.getSections().get(0).getModuleDocsUrl(), "www.docs.motechproject.org");
assertNotNull(menu);
}
use of org.motechproject.server.web.dto.ModuleMenu in project motech by motech.
the class MenuBuilderTest method shouldNotAddMenuSectionIfUserDoesNotHaveAccessToAnySubMenu.
@Test
public void shouldNotAddMenuSectionIfUserDoesNotHaveAccessToAnySubMenu() {
setUpToTestAccessControlledSubMenuLinks(false);
when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("someOtherRole"));
when(bundle.getHeaders().get(DOC_URL)).thenReturn("http://grameenfoundation.org/");
ModuleMenu menu = menuBuilder.buildMenu(USERNAME);
assertNotNull(menu);
List<ModuleMenuSection> menuSections = menu.getSections();
assertFalse(menuSections.isEmpty());
assertThat(menuSections.size(), Is.is(1));
assertThat(menuSections.get(0).getName(), Is.is("server.modules"));
}
use of org.motechproject.server.web.dto.ModuleMenu in project motech by motech.
the class MenuBuilder method buildMenu.
/**
* Builds the menu for the given user. Modules are retrieved from {@code UIFrameworkService} and filtered
* based on permissions.
*
* @param username username of the user for which the menu should be built.
* @return the built menu object.
*/
public ModuleMenu buildMenu(String username) {
ModuleMenu moduleMenu = new ModuleMenu();
List<String> userRoles = userService.getRoles(username);
for (ModuleRegistrationData moduleRegistrationData : getModulesWithSubMenu(userRoles)) {
ModuleMenuSection menuSection = getModuleMenuSection(username, userRoles, moduleRegistrationData);
if (!menuSection.getLinks().isEmpty()) {
moduleMenu.addMenuSection(menuSection);
}
}
moduleMenu.addMenuSection(serverModulesMenuSection(userRoles));
if (checkUserPermission(userRoles, REST_API_PERMISSION)) {
ModuleMenuSection restSection = restDocumentationMenu();
if (CollectionUtils.isNotEmpty(restSection.getLinks())) {
moduleMenu.addMenuSection(restSection);
}
}
return moduleMenu;
}
use of org.motechproject.server.web.dto.ModuleMenu in project motech by motech.
the class MenuBuilderTest method shouldFilterMenuBasedOnRoles.
@Test
public void shouldFilterMenuBasedOnRoles() {
setUpRest();
when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("emailRole", "mcRole"));
when(bundle.getHeaders().get(DOC_URL)).thenReturn("www.docs.motechproject.org");
ModuleMenu menu = menuBuilder.buildMenu(USERNAME);
assertNotNull(menu);
List<ModuleMenuSection> menuSections = menu.getSections();
assertNotNull(menuSections);
assertEquals(2, menuSections.size());
ModuleMenuSection wsSection = menu.getSections().get(0);
verifyWsSection(wsSection);
ModuleMenuSection modulesSection = menu.getSections().get(1);
verifyModulesSection(modulesSection, true, false);
}
Aggregations