Search in sources :

Example 1 with CustomEntityPrivileges

use of com.rebuild.core.privileges.bizz.CustomEntityPrivileges in project rebuild by getrebuild.

the class RoleBaseQueryFilter method buildCustomFilter.

/**
 * 自定义权限
 *
 * @param ep
 * @param dtmField
 * @return
 * @see PrivilegesManager#andPassCustomFilter(ID, ID, Permission, Privileges)
 */
private String buildCustomFilter(Privileges ep, Field dtmField) {
    if (user == null || useAction == null || !(ep instanceof CustomEntityPrivileges))
        return null;
    JSONObject hasFilter = ((CustomEntityPrivileges) ep).getCustomFilter(useAction);
    if (hasFilter == null)
        return null;
    // 兼容转换(明细实体)
    if (dtmField != null) {
        final JSONArray items = hasFilter.getJSONArray("items");
        JSONArray items2 = new JSONArray();
        for (Object item : items) {
            JSONObject c = (JSONObject) JSONUtils.clone((JSON) item);
            c.put("field", String.format("%s.%s", dtmField.getName(), c.getString("field")));
            items2.add(c);
        }
        hasFilter = JSONUtils.toJSONObject(new String[] { "entity", "items" }, new Object[] { dtmField.getOwnEntity().getName(), items2 });
    }
    AdvFilterParser advFilterParser = new AdvFilterParser(hasFilter);
    advFilterParser.setUser(user.getId());
    return advFilterParser.toSqlWhere();
}
Also used : CustomEntityPrivileges(com.rebuild.core.privileges.bizz.CustomEntityPrivileges) AdvFilterParser(com.rebuild.core.service.query.AdvFilterParser) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) JSON(com.alibaba.fastjson.JSON)

Example 2 with CustomEntityPrivileges

use of com.rebuild.core.privileges.bizz.CustomEntityPrivileges in project rebuild by getrebuild.

the class RoleBaseQueryFilter method buildCustomFilter.

/**
 * 自定义权限
 *
 * @param ep
 * @return
 * @see PrivilegesManager#andPassCustomFilter(ID, ID, Permission, Privileges)
 */
private String buildCustomFilter(Privileges ep) {
    if (user == null || useAction == null || !ep.getClass().isAssignableFrom(CustomEntityPrivileges.class))
        return null;
    JSONObject hasFilter = ((CustomEntityPrivileges) ep).getCustomFilter(useAction);
    if (hasFilter == null)
        return null;
    AdvFilterParser advFilterParser = new AdvFilterParser(hasFilter);
    advFilterParser.setUser(user.getId());
    return advFilterParser.toSqlWhere();
}
Also used : CustomEntityPrivileges(com.rebuild.core.privileges.bizz.CustomEntityPrivileges) AdvFilterParser(com.rebuild.core.service.query.AdvFilterParser) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)2 CustomEntityPrivileges (com.rebuild.core.privileges.bizz.CustomEntityPrivileges)2 AdvFilterParser (com.rebuild.core.service.query.AdvFilterParser)2 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1