use of com.axelor.auth.db.Permission in project axelor-open-suite by axelor.
the class PermissionAssistantService method writePermission.
private int writePermission(MetaModel object, MetaField userField, String[] row, int colIndex, String permName) {
Permission perm = permissionRepository.findByName(permName);
if (perm != null && perm.getObject().equals(object.getFullName())) {
row[colIndex++] = !perm.getCanRead() ? "" : "x";
row[colIndex++] = !perm.getCanWrite() ? "" : "x";
row[colIndex++] = !perm.getCanCreate() ? "" : "x";
row[colIndex++] = !perm.getCanRemove() ? "" : "x";
row[colIndex++] = !perm.getCanExport() ? "" : "x";
row[colIndex++] = Strings.isNullOrEmpty(perm.getCondition()) ? "" : perm.getCondition();
row[colIndex++] = Strings.isNullOrEmpty(perm.getConditionParams()) ? "" : perm.getConditionParams();
// readonly if
row[colIndex++] = "";
// hide if
row[colIndex++] = "";
} else if (userField != null) {
MetaField objectField = fieldRepository.all().filter("self.typeName = ?1 and self.metaModel = ?2 and self.relationship = 'ManyToOne'", userField.getTypeName(), object).fetchOne();
if (objectField != null) {
String condition = "";
String conditionParams = "__user__." + userField.getName();
if (userField.getRelationship().contentEquals("ManyToOne")) {
condition = "self." + objectField.getName() + " = ?";
} else {
condition = "self." + objectField.getName() + " in (?)";
}
row[colIndex++] = "x";
row[colIndex++] = "x";
row[colIndex++] = "x";
row[colIndex++] = "x";
row[colIndex++] = "x";
row[colIndex++] = condition;
row[colIndex++] = conditionParams;
// readonly if
row[colIndex++] = "";
// hide if
row[colIndex++] = "";
}
}
return colIndex;
}
use of com.axelor.auth.db.Permission in project axelor-open-suite by axelor.
the class PermissionAssistantService method updatePermission.
public void updatePermission(Group group, String objectName, MetaField field, String[] row) {
String[] objectNames = objectName.split("\\.");
String permName = getPermissionName(field, objectNames[objectNames.length - 1], group.getCode());
Permission permission = permissionRepository.all().filter("self.name = ?1", permName).fetchOne();
boolean newPermission = false;
if (permission == null) {
newPermission = true;
permission = new Permission();
permission.setName(permName);
permission.setObject(objectName);
}
permission.setCanRead(row[0].equalsIgnoreCase("x"));
permission.setCanWrite(row[1].equalsIgnoreCase("x"));
permission.setCanCreate(row[2].equalsIgnoreCase("x"));
permission.setCanRemove(row[3].equalsIgnoreCase("x"));
permission.setCanExport(row[4].equalsIgnoreCase("x"));
if (newPermission) {
group.addPermission(permission);
}
}
use of com.axelor.auth.db.Permission in project axelor-open-suite by axelor.
the class AccessConfigImportServiceImpl method getPermission.
@Transactional
public Permission getPermission(String model, String value, AccessConfig config) {
String[] objs = model.split("\\.");
String obj = objs[objs.length - 1];
String pkg = objs[objs.length - 3];
String name = "perm." + pkg + "." + obj + "." + value;
Permission permission = permissionRepo.all().filter("self.name = ?1 and self.object = ?2", name, model).fetchOne();
if (permission == null) {
permission = new Permission(name);
permission.setObject(model);
}
boolean defaultRight = value.equals("all");
permission.setCanCreate(defaultRight);
permission.setCanRead(defaultRight);
permission.setCanWrite(defaultRight);
permission.setCanRemove(defaultRight);
permission.setCanExport(defaultRight);
if (!defaultRight) {
for (char c : value.toCharArray()) {
switch(c) {
case 'r':
{
permission.setCanRead(true);
break;
}
case 'c':
{
permission.setCanCreate(true);
break;
}
case 'w':
{
permission.setCanWrite(true);
break;
}
case 'd':
{
permission.setCanRemove(true);
break;
}
case 'e':
{
permission.setCanExport(true);
break;
}
}
}
}
return permissionRepo.save(permission);
}
use of com.axelor.auth.db.Permission in project axelor-open-suite by axelor.
the class ImportPermission method importPermission.
@Transactional
public Object importPermission(Object bean, Map<String, Object> values) {
assert bean instanceof Permission;
try {
GroupRepository groupRepository = Beans.get(GroupRepository.class);
Permission permission = (Permission) bean;
String groups = (String) values.get("group");
if (permission.getId() != null) {
if (groups != null && !groups.isEmpty()) {
for (Group group : groupRepository.all().filter("code in ?1", Arrays.asList(groups.split("\\|"))).fetch()) {
Set<Permission> permissions = group.getPermissions();
if (permissions == null)
permissions = new HashSet<Permission>();
permissions.add(permissionRepo.find(permission.getId()));
group.setPermissions(permissions);
groupRepository.save(group);
}
}
}
return permission;
} catch (Exception e) {
e.printStackTrace();
}
return bean;
}
use of com.axelor.auth.db.Permission 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;
}
Aggregations