Search in sources :

Example 1 with RoleRepository

use of com.axelor.auth.db.repo.RoleRepository 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 RoleRepository

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

Aggregations

Role (com.axelor.auth.db.Role)2 RoleRepository (com.axelor.auth.db.repo.RoleRepository)2 Transactional (com.google.inject.persist.Transactional)2 Group (com.axelor.auth.db.Group)1 Permission (com.axelor.auth.db.Permission)1 MetaAction (com.axelor.meta.db.MetaAction)1 MetaMenu (com.axelor.meta.db.MetaMenu)1 MetaActionRepository (com.axelor.meta.db.repo.MetaActionRepository)1 MetaMenuRepository (com.axelor.meta.db.repo.MetaMenuRepository)1