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);
}
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;
}
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);
}
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);
}
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";
}
}
}
}
}
Aggregations