Search in sources :

Example 11 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationServiceImpl method buildAuthorizedSectionsList.

protected List<AdminSection> buildAuthorizedSectionsList(AdminUser adminUser, AdminModule module) {
    List<AdminSection> authorizedSections = new ArrayList<AdminSection>();
    BroadleafRequestContext broadleafRequestContext = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = broadleafRequestContext.getNonPersistentSite();
    Long siteId = site == null ? null : site.getId();
    for (AdminSection section : module.getSections()) {
        if (isUserAuthorizedToViewSection(adminUser, section)) {
            if (section instanceof SiteDiscriminator) {
                Long sectionSiteId = ((SiteDiscriminator) section).getSiteDiscriminator();
                if (sectionSiteId == null || sectionSiteId.equals(siteId)) {
                    authorizedSections.add(section);
                }
            } else {
                authorizedSections.add(section);
            }
        }
    }
    Collections.sort(authorizedSections, SECTION_COMPARATOR);
    return authorizedSections;
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) SiteDiscriminator(org.broadleafcommerce.common.extensibility.jpa.SiteDiscriminator) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ArrayList(java.util.ArrayList)

Example 12 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationServiceImpl method getClassNameForSection.

@Override
public String getClassNameForSection(String sectionKey) {
    AdminSection section = findAdminSectionByURI("/" + sectionKey);
    ExtensionResultHolder erh = new ExtensionResultHolder();
    extensionManager.getProxy().overrideClassNameForSection(erh, sectionKey, section);
    if (erh.getContextMap().get(AbstractAdminAbstractControllerExtensionHandler.NEW_CLASS_NAME) != null) {
        return (String) erh.getContextMap().get(AbstractAdminAbstractControllerExtensionHandler.NEW_CLASS_NAME);
    }
    return (section == null) ? sectionKey : section.getCeilingEntity();
}
Also used : AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 13 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationServiceImpl method populateAdminMenu.

protected void populateAdminMenu(AdminUser adminUser, AdminMenu adminMenu, List<AdminModule> modules) {
    for (AdminModule module : modules) {
        List<AdminSection> authorizedSections = buildAuthorizedSectionsList(adminUser, module);
        if (authorizedSections != null && authorizedSections.size() > 0) {
            AdminModuleDTO adminModuleDto = ((AdminModuleImpl) module).getAdminModuleDTO();
            adminMenu.getAdminModules().add(adminModuleDto);
            adminModuleDto.setSections(authorizedSections);
        }
    }
    // Sort the authorized modules
    BeanComparator displayComparator = new BeanComparator("displayOrder");
    Collections.sort(adminMenu.getAdminModules(), displayComparator);
}
Also used : AdminModule(org.broadleafcommerce.openadmin.server.security.domain.AdminModule) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) AdminModuleDTO(org.broadleafcommerce.openadmin.server.security.domain.AdminModuleDTO) AdminModuleImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminModuleImpl) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 14 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminSectionHrefProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    String href = "#";
    AdminSection section = (AdminSection) context.parseExpression(attributeValue);
    if (section != null) {
        HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest();
        href = request.getContextPath() + section.getUrl();
    }
    Map<String, String> attrs = new HashMap<>();
    attrs.put("href", href);
    return new BroadleafAttributeModifier(attrs);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 15 with AdminSection

use of org.broadleafcommerce.openadmin.server.security.domain.AdminSection in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method viewCollectionItemDetails.

/**
 * Shows the modal popup for the current selected "to-one" field. For instance, if you are viewing a list of products
 * then this method is invoked when a user clicks on the name of the default category field.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param collectionField
 * @param id
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/{collectionField:.*}/{id}/view", method = RequestMethod.GET)
public String viewCollectionItemDetails(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "collectionField") String collectionField, @PathVariable(value = "id") String id) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String mainClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
    ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    BasicFieldMetadata md = (BasicFieldMetadata) collectionProperty.getMetadata();
    AdminSection section = adminNavigationService.findAdminSectionByClassAndSectionId(md.getForeignKeyClass(), sectionKey);
    String sectionUrlKey = (section.getUrl().startsWith("/")) ? section.getUrl().substring(1) : section.getUrl();
    Map<String, String> varsForField = new HashMap<>();
    varsForField.put("sectionKey", sectionUrlKey);
    return viewEntityForm(request, response, model, varsForField, id);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) HashMap(java.util.HashMap) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) Property(org.broadleafcommerce.openadmin.dto.Property) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AdminSection (org.broadleafcommerce.openadmin.server.security.domain.AdminSection)17 HashMap (java.util.HashMap)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 NoResultException (javax.persistence.NoResultException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)2 Property (org.broadleafcommerce.openadmin.dto.Property)2 AdminModule (org.broadleafcommerce.openadmin.server.security.domain.AdminModule)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 IOException (java.io.IOException)1 DateFormatSymbols (java.text.DateFormatSymbols)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1