Search in sources :

Example 1 with ModuleMenuSection

use of org.motechproject.server.web.dto.ModuleMenuSection 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"));
}
Also used : ModuleMenuSection(org.motechproject.server.web.dto.ModuleMenuSection) ModuleMenu(org.motechproject.server.web.dto.ModuleMenu) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ModuleMenuSection

use of org.motechproject.server.web.dto.ModuleMenuSection 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;
}
Also used : ModuleMenuLink(org.motechproject.server.web.dto.ModuleMenuLink) ModuleMenuSection(org.motechproject.server.web.dto.ModuleMenuSection) SubmenuInfo(org.motechproject.osgi.web.SubmenuInfo) Map(java.util.Map)

Example 3 with ModuleMenuSection

use of org.motechproject.server.web.dto.ModuleMenuSection 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;
}
Also used : ModuleMenuSection(org.motechproject.server.web.dto.ModuleMenuSection) ModuleRegistrationData(org.motechproject.osgi.web.ModuleRegistrationData) ModuleMenu(org.motechproject.server.web.dto.ModuleMenu)

Example 4 with ModuleMenuSection

use of org.motechproject.server.web.dto.ModuleMenuSection 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);
}
Also used : ModuleMenuSection(org.motechproject.server.web.dto.ModuleMenuSection) ModuleMenu(org.motechproject.server.web.dto.ModuleMenu) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ModuleMenuSection

use of org.motechproject.server.web.dto.ModuleMenuSection in project motech by motech.

the class MenuBuilderTest method shouldBuildMenuWithAllLinks.

@Test
public void shouldBuildMenuWithAllLinks() {
    setUpRest();
    when(userService.getRoles(USERNAME)).thenReturn(Arrays.asList("emailRole", "adminRole", "schedulerRole", "mcRole", "mdsRole", "viewRestRole"));
    when(dictionary.get(DOC_URL)).thenReturn("http://grameenfoundation.org/");
    ModuleMenu menu = menuBuilder.buildMenu(USERNAME);
    assertNotNull(menu);
    List<ModuleMenuSection> menuSections = menu.getSections();
    assertNotNull(menuSections);
    assertEquals(4, menuSections.size());
    ModuleMenuSection adminSection = menu.getSections().get(0);
    verifyAdminSection(adminSection);
    ModuleMenuSection wsSection = menu.getSections().get(1);
    verifyWsSection(wsSection);
    ModuleMenuSection modulesSection = menu.getSections().get(2);
    verifyModulesSection(modulesSection, true, true);
    ModuleMenuSection restSection = menu.getSections().get(3);
    verifyRestSection(restSection, true, true);
}
Also used : ModuleMenuSection(org.motechproject.server.web.dto.ModuleMenuSection) ModuleMenu(org.motechproject.server.web.dto.ModuleMenu) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ModuleMenuSection (org.motechproject.server.web.dto.ModuleMenuSection)7 ModuleMenu (org.motechproject.server.web.dto.ModuleMenu)5 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ModuleMenuLink (org.motechproject.server.web.dto.ModuleMenuLink)3 ModuleRegistrationData (org.motechproject.osgi.web.ModuleRegistrationData)2 Map (java.util.Map)1 SubmenuInfo (org.motechproject.osgi.web.SubmenuInfo)1