use of com.axelor.auth.db.Role in project axelor-open-suite by axelor.
the class ImportPermission method importPermissionToRole.
@Transactional
public Object importPermissionToRole(Object bean, Map<String, Object> values) {
assert bean instanceof Permission;
Permission permission = (Permission) bean;
String roleName = values.get("roleName").toString();
if (Strings.isNullOrEmpty(roleName)) {
return bean;
}
RoleRepository roleRepository = Beans.get(RoleRepository.class);
Role role = roleRepository.findByName(roleName);
if (role == null) {
return bean;
}
role.addPermission(permission);
return bean;
}
use of com.axelor.auth.db.Role 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.auth.db.Role in project axelor-open-suite by axelor.
the class AccessConfigImportServiceImpl method addRole.
@Transactional
public void addRole(AccessConfig config, Permission permission) {
String name = config.getApp().getCode() + "." + config.getName();
Role role = roleRepo.findByName(name);
if (role == null) {
role = new Role(name);
}
role.addPermission(permission);
role = roleRepo.save(role);
config.addRoleSetItem(role);
accessConfigRepo.save(config);
}
use of com.axelor.auth.db.Role in project axelor-open-suite by axelor.
the class PermissionAssistantService method checkBadRoles.
private Map<String, Role> checkBadRoles(String[] roleRow) {
List<String> badroles = new ArrayList<>();
Map<String, Role> roleMap = new HashMap<>();
for (Integer len = header.size() + 1; len < roleRow.length; len += groupHeader.size()) {
String roleName = roleRow[len];
Role role = roleRepo.all().filter("self.name = ?1", roleName).fetchOne();
if (roleName == null) {
badroles.add(roleName);
} else {
roleMap.put(roleName, role);
}
}
if (!badroles.isEmpty()) {
errorLog += "\n" + String.format(I18n.get(IMessage.NO_ROLE), badroles);
}
return roleMap;
}
use of com.axelor.auth.db.Role 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