use of org.motechproject.server.web.dto.ModuleMenuLink in project motech by motech.
the class MenuBuilderTest method verifyModulesSection.
private void verifyModulesSection(ModuleMenuSection modulesSection, boolean emailExpected, boolean schedulerExpected) {
assertNotNull(modulesSection);
assertEquals("server.modules", modulesSection.getName());
assertFalse(modulesSection.isNeedsAttention());
List<ModuleMenuLink> moduleLinks = modulesSection.getLinks();
assertNotNull(moduleLinks);
int expectedModules = 1;
if (emailExpected) {
expectedModules++;
}
if (schedulerExpected) {
expectedModules++;
}
assertEquals(expectedModules, moduleLinks.size());
int index = 0;
if (emailExpected) {
ModuleMenuLink emailLink = moduleLinks.get(index);
index++;
assertNotNull(emailLink);
assertEquals("email", emailLink.getName());
assertEquals("email", emailLink.getModuleName());
assertEquals("/email/send", emailLink.getUrl());
}
if (schedulerExpected) {
ModuleMenuLink schedulerLink = moduleLinks.get(index);
index++;
assertNotNull(schedulerLink);
assertEquals("scheduler", schedulerLink.getName());
assertEquals("scheduler", schedulerLink.getModuleName());
assertEquals("/scheduler", schedulerLink.getUrl());
}
ModuleMenuLink metricsLink = moduleLinks.get(index);
assertNotNull(metricsLink);
assertEquals("metrics", metricsLink.getName());
assertEquals("metrics", metricsLink.getModuleName());
assertEquals("/metrics", metricsLink.getUrl());
}
use of org.motechproject.server.web.dto.ModuleMenuLink in project motech by motech.
the class MenuBuilder method getModuleMenuSection.
private ModuleMenuSection getModuleMenuSection(String username, List<String> userRoles, ModuleRegistrationData moduleRegistrationData) {
String moduleName = moduleRegistrationData.getModuleName();
ModuleMenuSection menuSection = new ModuleMenuSection(moduleName, moduleRegistrationData.isNeedsAttention());
menuSection.setModuleDocsUrl(moduleRegistrationData.getDocumentationUrl());
for (Map.Entry<String, SubmenuInfo> submenuEntry : moduleRegistrationData.getSubMenu().entrySet()) {
SubmenuInfo submenuInfo = submenuEntry.getValue();
if (isSubMenuLinkAccessibleByCurrentUser(username, userRoles, submenuInfo)) {
String name = submenuEntry.getKey();
String angularName = getAngularModuleName(moduleRegistrationData);
ModuleMenuLink link = new ModuleMenuLink(name, angularName, submenuInfo.getUrl(), submenuInfo.isNeedsAttention(), null);
menuSection.addLink(link);
}
}
return menuSection;
}
use of org.motechproject.server.web.dto.ModuleMenuLink in project motech by motech.
the class MenuBuilderTest method shouldNotAddLinksForSubMenusForWhichUserDoesNotHaveRequisiteRole.
@Test
public void shouldNotAddLinksForSubMenusForWhichUserDoesNotHaveRequisiteRole() {
setUpToTestAccessControlledSubMenuLinks(true);
when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("fooRole"));
when(bundle.getHeaders().get(DOC_URL)).thenReturn("http://grameenfoundation.org/");
ModuleMenu menu = menuBuilder.buildMenu(USERNAME);
assertNotNull(menu);
List<ModuleMenuSection> menuSections = menu.getSections();
assertNotNull(menuSections);
ModuleMenuLink onlyFooHasAccessToLink = new ModuleMenuLink("Foo", "foo", "#/foo", false, null);
ModuleMenuLink onlyBarHasAccessToLink = new ModuleMenuLink("Bar", "foo", "#/bar", false, null);
ModuleMenuLink linkIsNotAccessControlled = new ModuleMenuLink("Random", "foo", "#/random", false, null);
ModuleMenuSection fooMenuSection = menuSections.get(0);
assertNotNull(fooMenuSection);
assertTrue(fooMenuSection.hasLinkFor(onlyFooHasAccessToLink.getUrl()));
assertTrue(fooMenuSection.hasLinkFor(linkIsNotAccessControlled.getUrl()));
assertFalse(fooMenuSection.hasLinkFor(onlyBarHasAccessToLink.getUrl()));
}
use of org.motechproject.server.web.dto.ModuleMenuLink in project motech by motech.
the class MenuBuilderTest method verifyWsSection.
private void verifyWsSection(ModuleMenuSection wsSection) {
assertNotNull(wsSection);
assertEquals("web-security", wsSection.getName());
assertFalse(wsSection.isNeedsAttention());
List<ModuleMenuLink> wsLinks = wsSection.getLinks();
assertNotNull(wsLinks);
assertEquals(2, wsLinks.size());
ModuleMenuLink roleLink = wsLinks.get(0);
assertNotNull(roleLink);
assertEquals("webSecurity", roleLink.getModuleName());
assertEquals("Roles", roleLink.getName());
assertEquals("#/roles", roleLink.getUrl());
ModuleMenuLink usersLink = wsLinks.get(1);
assertNotNull(usersLink);
assertEquals("webSecurity", usersLink.getModuleName());
assertEquals("Users", usersLink.getName());
assertEquals("#/users", usersLink.getUrl());
}
use of org.motechproject.server.web.dto.ModuleMenuLink in project motech by motech.
the class MenuBuilderTest method verifyAdminSection.
private void verifyAdminSection(ModuleMenuSection adminSection) {
assertNotNull(adminSection);
assertEquals("admin", adminSection.getName());
assertTrue(adminSection.isNeedsAttention());
List<ModuleMenuLink> adminLinks = adminSection.getLinks();
assertNotNull(adminLinks);
assertEquals(3, adminLinks.size());
ModuleMenuLink logLink = adminLinks.get(0);
assertNotNull(logLink);
assertEquals("admin", logLink.getModuleName());
assertEquals("Log", logLink.getName());
assertEquals("#/log", logLink.getUrl());
ModuleMenuLink settingsLink = adminLinks.get(1);
assertNotNull(settingsLink);
assertEquals("admin", settingsLink.getModuleName());
assertEquals("Settings", settingsLink.getName());
assertEquals("#/settings", settingsLink.getUrl());
ModuleMenuLink manageLink = adminLinks.get(2);
assertNotNull(manageLink);
assertEquals("admin", manageLink.getModuleName());
assertEquals("manage.modules", manageLink.getName());
assertEquals("#/manage", manageLink.getUrl());
}
Aggregations