Search in sources :

Example 6 with Role

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;
}
Also used : Role(com.axelor.auth.db.Role) Permission(com.axelor.auth.db.Permission) RoleRepository(com.axelor.auth.db.repo.RoleRepository) Transactional(com.google.inject.persist.Transactional)

Example 7 with Role

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);
}
Also used : Role(com.axelor.auth.db.Role) MetaMenu(com.axelor.meta.db.MetaMenu) Transactional(com.google.inject.persist.Transactional)

Example 8 with Role

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);
}
Also used : Role(com.axelor.auth.db.Role) Transactional(com.google.inject.persist.Transactional)

Example 9 with Role

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;
}
Also used : Role(com.axelor.auth.db.Role) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 10 with Role

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";
                }
            }
        }
    }
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaMenu(com.axelor.meta.db.MetaMenu)

Aggregations

Role (com.axelor.auth.db.Role)12 Group (com.axelor.auth.db.Group)8 MetaMenu (com.axelor.meta.db.MetaMenu)6 Transactional (com.google.inject.persist.Transactional)5 RoleRepository (com.axelor.auth.db.repo.RoleRepository)3 ArrayList (java.util.ArrayList)3 MetaAction (com.axelor.meta.db.MetaAction)2 MetaMenuRepository (com.axelor.meta.db.repo.MetaMenuRepository)2 Permission (com.axelor.auth.db.Permission)1 User (com.axelor.auth.db.User)1 GroupRepository (com.axelor.auth.db.repo.GroupRepository)1 UserRepository (com.axelor.auth.db.repo.UserRepository)1 MetaField (com.axelor.meta.db.MetaField)1 MetaModel (com.axelor.meta.db.MetaModel)1 MetaActionRepository (com.axelor.meta.db.repo.MetaActionRepository)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 ResourceBundle (java.util.ResourceBundle)1