Search in sources :

Example 6 with ModuleMenuSection

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

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

the class MenuBuilder method serverModulesMenuSection.

private ModuleMenuSection serverModulesMenuSection(List<String> userRoles) {
    ModuleMenuSection modulesSection = new ModuleMenuSection("server.modules", false);
    for (ModuleRegistrationData moduleRegistrationData : getModulesWithoutSubMenu(userRoles)) {
        String name = moduleRegistrationData.getModuleName();
        String angularName = getAngularModuleName(moduleRegistrationData);
        boolean needsAttention = moduleRegistrationData.isNeedsAttention();
        // these menu items don't make use of urls, the name is sufficient
        ModuleMenuLink link = new ModuleMenuLink(name, angularName, determineDefaultTab(moduleRegistrationData), needsAttention, moduleRegistrationData.getDocumentationUrl());
        modulesSection.addLink(link);
    }
    return modulesSection;
}
Also used : ModuleMenuLink(org.motechproject.server.web.dto.ModuleMenuLink) ModuleMenuSection(org.motechproject.server.web.dto.ModuleMenuSection) ModuleRegistrationData(org.motechproject.osgi.web.ModuleRegistrationData)

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