Search in sources :

Example 6 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class MetaGroupMenuAssistantService method addMenuRows.

private void addMenuRows(MetaGroupMenuAssistant groupMenuAssistant, List<String[]> rows) {
    String[] groupRow = rows.get(0);
    rows.remove(0);
    Set<String> names = new HashSet<>();
    for (String[] line : rows) {
        names.add(line[0]);
    }
    for (MetaMenu metaMenu : groupMenuAssistant.getMenuSet()) {
        String name = metaMenu.getName();
        if (names.contains(name)) {
            continue;
        }
        String title = metaMenu.getTitle();
        String translation = getBundle().getString(title);
        if (!Strings.isNullOrEmpty(translation)) {
            title = translation;
        }
        String[] menu = new String[groupRow.length];
        menu[0] = name;
        menu[1] = title;
        rows.add(menu);
    }
    Collections.sort(rows, (first, second) -> first[0].compareTo(second[0]));
    rows.add(0, groupRow);
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu) HashSet(java.util.HashSet)

Example 7 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class MetaGroupMenuAssistantService method importMenus.

private void importMenus(String[] row, String[] groupRow, Map<String, Object> groupMap, Group admin) {
    List<MetaMenu> menus = menuRepository.all().filter("self.name = ?1", row[0]).order("-priority").fetch();
    if (menus.isEmpty()) {
        errorLog += "\n" + String.format(I18n.get(IMessage.NO_MENU), row[0]);
        return;
    }
    for (MetaMenu menu : menus) {
        boolean noAccess = true;
        for (Integer mIndex = 2; mIndex < row.length; mIndex++) {
            String code = groupRow[mIndex];
            Object object = groupMap.get(code);
            Role role = null;
            Group group = null;
            if (object instanceof Group) {
                group = (Group) object;
            } else if (object instanceof Role) {
                role = (Role) object;
            }
            if (row[mIndex].equalsIgnoreCase("x")) {
                noAccess = false;
                if (group != null) {
                    menu.addGroup(group);
                }
                if (role != null) {
                    menu.addRole(role);
                }
                updatedMenus.add(menu);
            } else if (group != null && menu.getGroups().contains(group)) {
                menu.removeGroup(group);
                updatedMenus.add(menu);
            } else if (role != null && menu.getRoles().contains(role)) {
                menu.removeRole(role);
                updatedMenus.add(menu);
            }
        }
        if (noAccess && admin != null) {
            menu.addGroup(admin);
        }
    }
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaMenu(com.axelor.meta.db.MetaMenu)

Example 8 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class WkfMenuService method createOrUpdateUserMenu.

@Transactional
public void createOrUpdateUserMenu(WkfTaskConfig wkfTaskConfig) {
    String name = USER_MENU_PREFIX + wkfTaskConfig.getId();
    MetaMenu metaMenu = findOrCreateMenu(name);
    metaMenu.setTitle(wkfTaskConfig.getUserMenuName());
    metaMenu.setAction(createOrUpdateAction(metaMenu, wkfTaskConfig, true));
    metaMenu.setParent(null);
    if (wkfTaskConfig.getUserParentMenuName() != null) {
        metaMenu.setParent(metaMenuRepository.findByName(wkfTaskConfig.getUserParentMenuName()));
    }
    metaMenu.setTagCount(wkfTaskConfig.getUserDisplayTagCount());
    if (wkfTaskConfig.getUserPositionMenuName() != null) {
        MetaMenu positionMenu = metaMenuRepository.findByName(wkfTaskConfig.getUserPositionMenuName());
        if (positionMenu != null) {
            if (wkfTaskConfig.getUserMenuPosition().equals("before")) {
                metaMenu.setOrder(positionMenu.getOrder() - 1);
            } else {
                metaMenu.setOrder(positionMenu.getOrder() + 1);
            }
        }
    }
    metaMenuRepository.save(metaMenu);
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu) Transactional(com.google.inject.persist.Transactional)

Example 9 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class WkfMenuService method removeUserMenu.

@Transactional
public void removeUserMenu(WkfTaskConfig wkfTaskConfig) {
    String name = USER_MENU_PREFIX + wkfTaskConfig.getId();
    MetaMenu metaMenu = metaMenuRepository.findByName(name);
    if (metaMenu != null) {
        metaMenuRepository.remove(metaMenu);
    }
    removeAction(name);
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu) Transactional(com.google.inject.persist.Transactional)

Example 10 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class WkfMenuService method removeMenu.

@Transactional
public void removeMenu(WkfTaskConfig wkfTaskConfig) {
    String name = MENU_PREFIX + wkfTaskConfig.getId();
    MetaMenu metaMenu = metaMenuRepository.findByName(name);
    if (metaMenu != null) {
        metaMenuRepository.remove(metaMenu);
    }
    removeAction(name);
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu) Transactional(com.google.inject.persist.Transactional)

Aggregations

MetaMenu (com.axelor.meta.db.MetaMenu)19 Transactional (com.google.inject.persist.Transactional)10 Role (com.axelor.auth.db.Role)6 Group (com.axelor.auth.db.Group)5 MetaAction (com.axelor.meta.db.MetaAction)4 MetaMenuRepository (com.axelor.meta.db.repo.MetaMenuRepository)3 RoleRepository (com.axelor.auth.db.repo.RoleRepository)2 ActionBuilder (com.axelor.studio.db.ActionBuilder)2 HashSet (java.util.HashSet)2 App (com.axelor.apps.base.db.App)1 AppRepository (com.axelor.apps.base.db.repo.AppRepository)1 User (com.axelor.auth.db.User)1 GroupRepository (com.axelor.auth.db.repo.GroupRepository)1 UserRepository (com.axelor.auth.db.repo.UserRepository)1 MetaActionRepository (com.axelor.meta.db.repo.MetaActionRepository)1 MenuBuilder (com.axelor.studio.db.MenuBuilder)1