Search in sources :

Example 11 with MetaMenu

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

the class AccessConfigImportServiceImpl method addRole.

@Transactional
public void addRole(AccessConfig config, String menu) {
    String name = config.getApp().getCode() + "." + config.getName();
    Role role = roleRepo.findByName(name);
    if (role == null) {
        role = new Role(name);
    }
    MetaMenu metaMenu = metaMenuRepo.findByName(menu);
    if (metaMenu != null) {
        metaMenu.addRole(role);
        metaMenuRepo.save(metaMenu);
    }
    config.addRoleSetItem(role);
    accessConfigRepo.save(config);
}
Also used : Role(com.axelor.auth.db.Role) MetaMenu(com.axelor.meta.db.MetaMenu) Transactional(com.google.inject.persist.Transactional)

Example 12 with MetaMenu

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

the class AccessTemplateServiceImpl method getApp.

private String getApp(MetaMenu menu) {
    String appCode = null;
    String condition = menu.getConditionToCheck();
    if (condition != null) {
        String[] cond = condition.split("__config__\\.app\\.isApp\\('");
        if (cond.length > 1) {
            App app = Beans.get(AppRepository.class).findByCode(cond[1].split("'")[0]);
            if (app != null) {
                if (condition.trim().equals("__config__.app.isApp('" + app.getCode() + "')") && menu.getAction() == null) {
                    appMenus.add(menu.getName());
                }
                appCode = app.getCode();
            }
        }
    }
    MetaMenu parent = menu.getParent();
    if (appCode == null && parent != null && menuApp.containsKey(parent.getName())) {
        appCode = menuApp.get(parent.getName());
    }
    if (parent == null && appCode == null) {
        configMenus.add(menu.getName());
    }
    if (menu.getTitle().equals("Configuration") || menu.getTitle().equals("Configurations")) {
        configMenus.add(menu.getName());
        appMenus.remove(menu.getName());
    }
    if (appCode == null) {
        return defaultApp;
    }
    return appCode;
}
Also used : App(com.axelor.apps.base.db.App) AppRepository(com.axelor.apps.base.db.repo.AppRepository) MetaMenu(com.axelor.meta.db.MetaMenu)

Example 13 with MetaMenu

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

the class AccessTemplateServiceImpl method processMenu.

private void processMenu(Iterator<MetaMenu> menuIter) {
    if (!menuIter.hasNext()) {
        return;
    }
    MetaMenu menu = menuIter.next();
    String app = getApp(menu);
    menuApp.put(menu.getName(), app);
    MetaAction action = menu.getAction();
    if (action != null && action.getType().equals("action-view")) {
        String model = action.getModel();
        if (validModel(model)) {
            String menuName = getObjMenu(menu);
            if (menuName != null) {
                objMenu.put(model, menuName);
            }
        }
    }
    List<MetaMenu> menus = metaMenuRepo.all().filter("self.parent = ?1", menu).order("id").fetch();
    processMenu(menus.iterator());
    processMenu(menuIter);
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu) MetaAction(com.axelor.meta.db.MetaAction)

Example 14 with MetaMenu

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

the class WkfMenuService method createOrUpdateMenu.

@Transactional
public void createOrUpdateMenu(WkfTaskConfig wkfTaskConfig) {
    String name = MENU_PREFIX + wkfTaskConfig.getId();
    MetaMenu metaMenu = findOrCreateMenu(name);
    metaMenu.setTitle(wkfTaskConfig.getMenuName());
    metaMenu.setAction(createOrUpdateAction(metaMenu, wkfTaskConfig, false));
    metaMenu.setParent(null);
    metaMenu.setTagCount(wkfTaskConfig.getDisplayTagCount());
    if (wkfTaskConfig.getParentMenuName() != null) {
        metaMenu.setParent(metaMenuRepository.findByName(wkfTaskConfig.getParentMenuName()));
    }
    if (wkfTaskConfig.getPositionMenuName() != null) {
        MetaMenu positionMenu = metaMenuRepository.findByName(wkfTaskConfig.getPositionMenuName());
        if (positionMenu != null) {
            if (wkfTaskConfig.getMenuPosition() != null && wkfTaskConfig.getMenuPosition().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 15 with MetaMenu

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

the class MetaGroupMenuAssistantService method addGroupAccess.

private void addGroupAccess(List<String[]> rows) {
    ListIterator<String[]> rowIter = rows.listIterator();
    String[] header = rowIter.next();
    while (rowIter.hasNext()) {
        String[] row = rowIter.next();
        MetaMenu menu = menuRepository.all().filter("self.name = ?1", row[0]).order("-priority").fetchOne();
        if (row.length < header.length) {
            row = Arrays.copyOf(row, header.length);
            rowIter.set(row);
        }
        for (int i = 2; i < header.length; i++) {
            for (Group group : menu.getGroups()) {
                if (header[i] != null && header[i].equals(group.getCode())) {
                    row[i] = "x";
                }
            }
            for (Role role : menu.getRoles()) {
                if (header[i] != null && header[i].equals(role.getName())) {
                    row[i] = "x";
                }
            }
        }
    }
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaMenu(com.axelor.meta.db.MetaMenu)

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