use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.
the class DepartmentController method deptTreeGet.
@GetMapping("dept-tree")
public JSON deptTreeGet() {
JSONArray dtree = new JSONArray();
Department[] ds = Application.getUserStore().getTopDepartments();
sortByName(ds);
for (Department root : ds) {
dtree.add(recursiveDeptTree(root));
}
return dtree;
}
use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.
the class RoleBaseQueryFilter method evaluate.
@Override
public String evaluate(final Entity entity) {
if (user == null || !user.isActive()) {
return DENIED.evaluate(null);
} else if (user.isAdmin()) {
return ALLOWED.evaluate(null);
}
Entity useMainEntity = null;
if (!MetadataHelper.hasPrivilegesField(entity)) {
// NOTE BIZZ 实体全部用户可见
if (MetadataHelper.isBizzEntity(entity) || EasyMetaFactory.valueOf(entity).isPlainEntity()) {
return ALLOWED.evaluate(null);
} else if (entity.getMainEntity() != null) {
useMainEntity = entity.getMainEntity();
} else {
log.warn("None privileges entity use `Application#createQueryNoFilter` please : {} \n\t{}", entity, StringUtils.join(Thread.currentThread().getStackTrace(), "\n\t"));
return DENIED.evaluate(null);
}
}
// 未配置权限的默认拒绝
// 明细实体使用主实体权限
final Privileges ep = user.getOwningRole().getPrivileges(useMainEntity != null ? useMainEntity.getEntityCode() : entity.getEntityCode());
if (ep == Privileges.NONE) {
return DENIED.evaluate(null);
}
String owningFormat = "%s = '%s'";
Field dtmField = null;
if (useMainEntity != null) {
dtmField = MetadataHelper.getDetailToMainField(entity);
owningFormat = dtmField.getName() + "." + owningFormat;
}
final String customFilter = buildCustomFilter(ep, dtmField);
final String shareFilter = buildShareFilter(entity, dtmField);
final DepthEntry depth = ep.superlative(useAction);
if (depth == BizzDepthEntry.GLOBAL) {
if (customFilter == null) {
return ALLOWED.evaluate(null);
} else {
return String.format("(%s or %s)", customFilter, shareFilter);
}
}
if (depth == BizzDepthEntry.PRIVATE) {
String baseFilter = String.format(owningFormat, EntityHelper.OwningUser, user.getIdentity());
return joinFilters(baseFilter, customFilter, shareFilter);
}
// 部门
Department dept = user.getOwningDept();
String deptFilter = String.format(owningFormat, EntityHelper.OwningDept, dept.getIdentity());
if (depth == BizzDepthEntry.LOCAL) {
return joinFilters(deptFilter, customFilter, shareFilter);
} else if (depth == BizzDepthEntry.DEEPDOWN) {
Set<String> set = new HashSet<>();
set.add(deptFilter);
for (BusinessUnit ch : dept.getAllChildren()) {
set.add(String.format(owningFormat, EntityHelper.OwningDept, ch.getIdentity()));
}
deptFilter = StringUtils.join(set, " or ");
return joinFilters(deptFilter, customFilter, shareFilter);
}
return DENIED.evaluate(null);
}
use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.
the class UserController method deleteChecks.
@RequestMapping("delete-checks")
public JSON deleteChecks(@IdParam ID bizzId) {
int hasMember = 0;
int hasChild = 0;
if (bizzId.getEntityCode() == EntityHelper.Department) {
Department dept = Application.getUserStore().getDepartment(bizzId);
hasMember = dept.getMembers().size();
hasChild = dept.getChildren().size();
} else if (bizzId.getEntityCode() == EntityHelper.Role) {
hasMember = UserHelper.getMembers(bizzId).length;
hasMember += UserHelper.getRoleMembers(bizzId).size();
} else if (bizzId.getEntityCode() == EntityHelper.User) {
// NOTE 仅检查是否登陆过。严谨些还应该检查是否有其他业务数据
Object[] hasLogin = Application.createQueryNoFilter("select count(logId) from LoginLog where user = ?").setParameter(1, bizzId).unique();
hasMember = ObjectUtils.toInt(hasLogin[0]);
}
return JSONUtils.toJSONObject(new String[] { "hasMember", "hasChild" }, new Object[] { hasMember, hasChild });
}
use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.
the class DepartmentController method recursiveDeptTree.
private JSONObject recursiveDeptTree(Department parent) {
JSONObject parentJson = new JSONObject();
parentJson.put("id", parent.getIdentity());
parentJson.put("name", parent.getName());
parentJson.put("disabled", parent.isDisabled());
JSONArray children = new JSONArray();
BusinessUnit[] ds = parent.getChildren().toArray(new BusinessUnit[0]);
sortByName(ds);
for (BusinessUnit child : ds) {
children.add(recursiveDeptTree((Department) child));
}
if (!children.isEmpty()) {
parentJson.put("children", children);
}
return parentJson;
}
use of com.rebuild.core.privileges.bizz.Department in project rebuild by getrebuild.
the class UserHelperTest method test.
@Test
public void test() {
UserHelper.getDepartment(UserService.ADMIN_USER);
UserHelper.getName(DepartmentService.ROOT_DEPT);
UserHelper.isActive(UserService.SYSTEM_USER);
UserHelper.isAdmin(SIMPLE_USER);
UserHelper.getMembers(RoleService.ADMIN_ROLE);
UserHelper.getMembers(DepartmentService.ROOT_DEPT);
Department dept = Application.getUserStore().getDepartment(DepartmentService.ROOT_DEPT);
UserHelper.getAllChildren(dept);
Application.getUserStore().getUser(SIMPLE_USER).isActive();
}
Aggregations