Search in sources :

Example 1 with Role

use of com.axelor.auth.db.Role in project axelor-open-suite by axelor.

the class CalendarConfigurationService method deleteEntryMenu.

@Transactional
public void deleteEntryMenu(CalendarConfiguration calendarConfiguration) {
    MetaAction metaAction = calendarConfiguration.getMetaAction();
    Role role = calendarConfiguration.getRole();
    Group group = calendarConfiguration.getCalendarGroup();
    calendarConfiguration.setMetaAction(null);
    calendarConfiguration.setRole(null);
    calendarConfiguration.getCalendarUser().removeRole(role);
    if (group != null) {
        group.removeRole(role);
    }
    String menuName = NAME + calendarConfiguration.getName().toLowerCase() + "-" + calendarConfiguration.getId();
    MetaMenuRepository metaMenuRepository = Beans.get(MetaMenuRepository.class);
    MetaMenu metaMenu = metaMenuRepository.findByName(menuName);
    metaMenuRepository.remove(metaMenu);
    MetaActionRepository metaActionRepository = Beans.get(MetaActionRepository.class);
    metaActionRepository.remove(metaAction);
    RoleRepository roleRepository = Beans.get(RoleRepository.class);
    roleRepository.remove(role);
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaMenuRepository(com.axelor.meta.db.repo.MetaMenuRepository) MetaActionRepository(com.axelor.meta.db.repo.MetaActionRepository) MetaMenu(com.axelor.meta.db.MetaMenu) MetaAction(com.axelor.meta.db.MetaAction) RoleRepository(com.axelor.auth.db.repo.RoleRepository) Transactional(com.google.inject.persist.Transactional)

Example 2 with Role

use of com.axelor.auth.db.Role in project axelor-open-suite by axelor.

the class CalendarConfigurationService method createEntryMenu.

@Transactional
public void createEntryMenu(CalendarConfiguration calendarConfiguration) {
    String menuName = NAME + calendarConfiguration.getName().toLowerCase() + "-" + calendarConfiguration.getId();
    String subName = menuName.replaceAll("[-\\s]", ".");
    String title = calendarConfiguration.getName();
    User user = calendarConfiguration.getCalendarUser();
    Group group = calendarConfiguration.getCalendarGroup();
    MetaAction metaAction = this.createMetaAction("action." + subName, title);
    MetaMenu metaMenu = this.createMetaMenu(menuName, title, metaAction, calendarConfiguration.getParentMetaMenu());
    Beans.get(MetaMenuRepository.class).save(metaMenu);
    Role role = new Role();
    role.setName("role." + subName);
    role.addMenu(metaMenu);
    Beans.get(RoleRepository.class).save(role);
    user.addRole(role);
    Beans.get(UserRepository.class).save(user);
    if (group != null) {
        group.addRole(role);
        Beans.get(GroupRepository.class).save(group);
    }
    calendarConfiguration.setRole(role);
    calendarConfiguration.setMetaAction(metaAction);
    calendarConfigurationRepo.save(calendarConfiguration);
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaMenuRepository(com.axelor.meta.db.repo.MetaMenuRepository) User(com.axelor.auth.db.User) UserRepository(com.axelor.auth.db.repo.UserRepository) MetaMenu(com.axelor.meta.db.MetaMenu) MetaAction(com.axelor.meta.db.MetaAction) GroupRepository(com.axelor.auth.db.repo.GroupRepository) RoleRepository(com.axelor.auth.db.repo.RoleRepository) Transactional(com.google.inject.persist.Transactional)

Example 3 with Role

use of com.axelor.auth.db.Role in project axelor-open-suite by axelor.

the class PermissionAssistantService method writeGroup.

private void writeGroup(CSVWriter csvWriter, PermissionAssistant assistant) {
    String[] groupRow = null;
    Integer count = header.size();
    ResourceBundle bundle = I18n.getBundle(new Locale(assistant.getLanguage()));
    List<String> headerRow = new ArrayList<>();
    headerRow.addAll(getTranslatedStrings(header, bundle));
    if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_GROUPS) {
        groupRow = new String[header.size() + (assistant.getGroupSet().size() * groupHeader.size())];
        for (Group group : assistant.getGroupSet()) {
            groupRow[count + 1] = group.getCode();
            headerRow.addAll(getTranslatedStrings(groupHeader, bundle));
            count += groupHeader.size();
        }
    } else if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_ROLES) {
        groupRow = new String[header.size() + (assistant.getRoleSet().size() * groupHeader.size())];
        for (Role role : assistant.getRoleSet()) {
            groupRow[count + 1] = role.getName();
            headerRow.addAll(getTranslatedStrings(groupHeader, bundle));
            count += groupHeader.size();
        }
    }
    LOG.debug("Header row created: {}", headerRow);
    csvWriter.writeNext(groupRow);
    csvWriter.writeNext(headerRow.toArray(groupRow));
    writeObject(csvWriter, assistant, groupRow.length, bundle);
}
Also used : Locale(java.util.Locale) Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) ArrayList(java.util.ArrayList) ResourceBundle(java.util.ResourceBundle)

Example 4 with Role

use of com.axelor.auth.db.Role in project axelor-open-suite by axelor.

the class PermissionAssistantService method writeObject.

private void writeObject(CSVWriter csvWriter, PermissionAssistant assistant, Integer size, ResourceBundle bundle) {
    MetaField userField = assistant.getMetaField();
    for (MetaModel object : assistant.getObjectSet()) {
        int colIndex = header.size() + 1;
        String[] row = new String[size];
        row[0] = object.getFullName();
        if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_GROUPS) {
            for (Group group : assistant.getGroupSet()) {
                String permName = getPermissionName(userField, object.getName(), group.getCode());
                colIndex = writePermission(object, userField, row, colIndex, permName);
                colIndex++;
            }
        } else if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_ROLES) {
            for (Role role : assistant.getRoleSet()) {
                String permName = getPermissionName(userField, object.getName(), role.getName());
                colIndex = writePermission(object, userField, row, colIndex, permName);
                colIndex++;
            }
        }
        csvWriter.writeNext(row);
        if (!assistant.getFieldPermission()) {
            continue;
        }
        List<MetaField> fieldList = object.getMetaFields();
        Collections.sort(fieldList, compareField());
        for (MetaField field : fieldList) {
            colIndex = header.size() + 1;
            row = new String[size];
            row[1] = field.getName();
            row[2] = getFieldTitle(field, bundle);
            if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_GROUPS) {
                for (Group group : assistant.getGroupSet()) {
                    String permName = getPermissionName(null, object.getName(), group.getCode());
                    colIndex = writeFieldPermission(field, row, colIndex, permName);
                    colIndex++;
                }
            } else if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_ROLES) {
                for (Role role : assistant.getRoleSet()) {
                    String permName = getPermissionName(null, object.getName(), role.getName());
                    colIndex = writeFieldPermission(field, row, colIndex, permName);
                    colIndex++;
                }
            }
            csvWriter.writeNext(row);
        }
    }
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField)

Example 5 with Role

use of com.axelor.auth.db.Role 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)

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