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