Search in sources :

Example 36 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProjectTaskController method getProjectAndPlans.

// -- for General Entity
@GetMapping("alist")
public RespBody getProjectAndPlans(HttpServletRequest request) {
    final ID user = getRequestUser(request);
    ConfigBean[] ps = ProjectManager.instance.getAvailable(user);
    JSONArray alist = new JSONArray();
    for (ConfigBean p : ps) {
        // 已归档
        if (p.getInteger("status") == ProjectManager.STATUS_ARCHIVED)
            continue;
        // 非成员
        if (!p.get("members", Set.class).contains(user))
            continue;
        JSONObject item = (JSONObject) p.toJSON("id", "projectName");
        // 面板
        ConfigBean[] plans = ProjectManager.instance.getPlansOfProject(p.getID("id"));
        JSONArray plansList = new JSONArray();
        for (ConfigBean plan : plans) {
            plansList.add(plan.toJSON("id", "planName", "flowStatus"));
        }
        item.put("plans", plansList);
        alist.add(item);
    }
    return RespBody.ok(alist);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 37 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProjectHelper method isManageable.

/**
 * 对 任务/评论/标签 是否有管理权
 *
 * @param taskOrCommentOrTag
 * @param user
 * @return
 */
public static boolean isManageable(ID taskOrCommentOrTag, ID user) {
    // 管理员
    if (UserHelper.isAdmin(user))
        return true;
    // 项目配置信息
    ConfigBean pcfg;
    if (taskOrCommentOrTag.getEntityCode() == EntityHelper.ProjectTaskTag) {
        Object[] projectId = Application.getQueryFactory().uniqueNoFilter(taskOrCommentOrTag, "projectId");
        pcfg = ProjectManager.instance.getProject((ID) projectId[0], null);
    } else {
        pcfg = ProjectManager.instance.getProjectByX(convert2Task(taskOrCommentOrTag), null);
    }
    // 负责人
    if (user.equals(pcfg.getID("principal")))
        return true;
    // 非成员
    if (!pcfg.get("members", Set.class).contains(user))
        return false;
    // 创建人
    Object[] createdBy = Application.getQueryFactory().uniqueNoFilter(taskOrCommentOrTag, "createdBy");
    return createdBy != null && createdBy[0].equals(user);
}
Also used : ConfigBean(com.rebuild.core.configuration.ConfigBean) ID(cn.devezhao.persist4j.engine.ID)

Example 38 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProjectManager method getProjects.

/**
 * 获取全部项目
 *
 * @return
 */
private ConfigBean[] getProjects() {
    ConfigBean[] cached = (ConfigBean[]) Application.getCommonsCache().getx(CKEY_PROJECTS);
    if (cached == null) {
        Object[][] array = Application.createQueryNoFilter("select configId,projectCode,projectName,iconName,scope,members,principal,extraDefinition,status from ProjectConfig").array();
        List<ConfigBean> alist = new ArrayList<>();
        for (Object[] o : array) {
            String members = (String) o[5];
            if (o[6] != null) {
                members = StringUtils.isBlank(members) ? o[6].toString() : members + "," + o[6];
            }
            ConfigBean e = new ConfigBean().set("id", o[0]).set("projectCode", o[1]).set("projectName", o[2]).set("iconName", StringUtils.defaultIfBlank((String) o[3], "texture")).set("scope", o[4]).set("_members", members).set("principal", o[6]).set("status", ObjectUtils.toInt(o[8], 1));
            // 扩展配置
            String extraDefinition = (String) o[7];
            if (JSONUtils.wellFormat(extraDefinition)) {
                JSONObject extraDefinitionJson = JSON.parseObject(extraDefinition);
                for (String name : extraDefinitionJson.keySet()) {
                    e.set(name, extraDefinitionJson.get(name));
                }
            }
            alist.add(e);
        }
        cached = alist.toArray(new ConfigBean[0]);
        Application.getCommonsCache().putx(CKEY_PROJECTS, cached);
    }
    for (ConfigBean p : cached) {
        Set<ID> members = Collections.emptySet();
        String userDefs = p.getString("_members");
        if (StringUtils.isNotBlank(userDefs) && userDefs.length() >= 20) {
            members = UserHelper.parseUsers(Arrays.asList(userDefs.split(",")), null);
        }
        p.set("members", members);
    }
    return cached;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) ConfigBean(com.rebuild.core.configuration.ConfigBean) ID(cn.devezhao.persist4j.engine.ID)

Example 39 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProjectManager method getAvailable.

/**
 * 获取指定用户可用项目
 *
 * @param user
 * @return
 */
public ConfigBean[] getAvailable(ID user) {
    ConfigBean[] projects = getProjects();
    // 管理员可见全部
    boolean isAdmin = UserHelper.isAdmin(user);
    List<ConfigBean> alist = new ArrayList<>();
    for (ConfigBean e : projects) {
        boolean isMember = e.get("members", Set.class).contains(user);
        boolean isPublic = e.getInteger("scope") == ProjectConfigService.SCOPE_ALL;
        if (isAdmin || isMember || isPublic) {
            boolean isArchived = e.getInteger("status") == STATUS_ARCHIVED;
            if (isArchived) {
                // 仅负责人
                boolean isPrincipal = user.equals(e.getID("principal"));
                if (isAdmin || isPrincipal)
                    alist.add(e.clone());
            } else {
                alist.add(e.clone());
            }
        }
    }
    return alist.toArray(new ConfigBean[0]);
}
Also used : ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 40 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProjectManager method getPlanOfProject.

/**
 * @param planId
 * @param projectId
 * @return
 */
public ConfigBean getPlanOfProject(ID planId, ID projectId) {
    if (projectId == null) {
        Object[] o = Application.getQueryFactory().uniqueNoFilter(planId, "projectId");
        projectId = o != null ? (ID) o[0] : null;
    }
    for (ConfigBean e : getPlansOfProject(projectId)) {
        if (e.getID("id").equals(planId))
            return e;
    }
    throw new ConfigurationException(Language.L("无效任务面板 (%s)", planId));
}
Also used : ConfigurationException(com.rebuild.core.configuration.ConfigurationException) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Aggregations

ConfigBean (com.rebuild.core.configuration.ConfigBean)52 ID (cn.devezhao.persist4j.engine.ID)26 JSONObject (com.alibaba.fastjson.JSONObject)23 JSONArray (com.alibaba.fastjson.JSONArray)16 JSON (com.alibaba.fastjson.JSON)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)9 Entity (cn.devezhao.persist4j.Entity)8 ArrayList (java.util.ArrayList)7 Field (cn.devezhao.persist4j.Field)6 Record (cn.devezhao.persist4j.Record)5 ConfigurationException (com.rebuild.core.configuration.ConfigurationException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 DataSpecificationException (com.rebuild.core.service.DataSpecificationException)2 AdvFilterParser (com.rebuild.core.service.query.AdvFilterParser)2 List (java.util.List)2 Set (java.util.Set)2 Test (org.junit.jupiter.api.Test)2 Permission (cn.devezhao.bizz.privileges.Permission)1 BizzPermission (cn.devezhao.bizz.privileges.impl.BizzPermission)1