Search in sources :

Example 21 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class MonitorListController method deleteMonitor.

/**
 * 删除列表
 *
 * @param id id
 * @return json
 */
@RequestMapping(value = "deleteMonitor", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String deleteMonitor(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "删除失败") String id) throws SQLException {
    // 
    HttpServletRequest request = getRequest();
    int delByKey = monitorService.delByKey(id, request);
    if (delByKey > 0) {
        // 删除日志
        dbMonitorNotifyLogService.delByWorkspace(request, entity -> entity.set("monitorId", id));
    }
    return JsonMessage.getString(200, "删除成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class MonitorListController method updateMonitor.

/**
 * 增加或修改监控
 *
 * @param id         id
 * @param name       name
 * @param notifyUser user
 * @return json
 */
@RequestMapping(value = "updateMonitor", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String updateMonitor(String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "监控名称不能为空") String name, @ValidatorItem(msg = "请配置监控周期") String execCron, String notifyUser, String webhook) {
    String status = getParameter("status");
    String autoRestart = getParameter("autoRestart");
    JSONArray jsonArray = JSONArray.parseArray(notifyUser);
    // List<String> notifyUsers = jsonArray.toJavaList(String.class);
    List<String> notifyUserList = jsonArray.toJavaList(String.class);
    if (CollUtil.isNotEmpty(notifyUserList)) {
        for (String userId : notifyUserList) {
            Assert.state(userService.exists(new UserModel(userId)), "没有对应的用户:" + userId);
        }
    }
    String projects = getParameter("projects");
    JSONArray projectsArray = JSONArray.parseArray(projects);
    List<MonitorModel.NodeProject> nodeProjects = projectsArray.toJavaList(MonitorModel.NodeProject.class);
    Assert.notEmpty(nodeProjects, "请至少选择一个节点");
    for (MonitorModel.NodeProject nodeProject : nodeProjects) {
        Assert.notEmpty(nodeProject.getProjects(), "请至少选择一个项目");
        for (String project : nodeProject.getProjects()) {
            boolean exists = projectInfoCacheService.exists(nodeProject.getNode(), project);
            Assert.state(exists, "没有对应的项目:" + project);
        }
    }
    // 设置参数
    if (StrUtil.isNotEmpty(webhook)) {
        Validator.validateMatchRegex(RegexPool.URL_HTTP, webhook, "WebHooks 地址不合法");
    }
    Assert.state(CollUtil.isNotEmpty(notifyUserList) || StrUtil.isNotEmpty(webhook), "请选择一位报警联系人或者填写webhook");
    boolean start = "on".equalsIgnoreCase(status);
    MonitorModel monitorModel = monitorService.getByKey(id);
    if (monitorModel == null) {
        monitorModel = new MonitorModel();
    }
    monitorModel.setAutoRestart("on".equalsIgnoreCase(autoRestart));
    monitorModel.setExecCron(this.checkCron(execCron));
    monitorModel.projects(nodeProjects);
    monitorModel.setStatus(start);
    monitorModel.setWebhook(webhook);
    monitorModel.notifyUser(notifyUserList);
    monitorModel.setName(name);
    if (StrUtil.isEmpty(id)) {
        // 添加监控
        monitorService.insert(monitorModel);
        return JsonMessage.getString(200, "添加成功");
    }
    HttpServletRequest request = getRequest();
    monitorService.updateById(monitorModel, request);
    return JsonMessage.getString(200, "修改成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) HttpServletRequest(javax.servlet.http.HttpServletRequest) MonitorModel(io.jpom.model.data.MonitorModel) JSONArray(com.alibaba.fastjson.JSONArray) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class MonitorUserOptListController method changeStatus.

/**
 * 开启或关闭监控
 *
 * @param id     id
 * @param status 状态
 * @return json
 */
@RequestMapping(value = "changeStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String changeStatus(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "id不能为空") String id, String status) {
    MonitorUserOptModel monitorModel = monitorUserOptService.getByKey(id);
    Assert.notNull(monitorModel, "不存在监控项啦");
    boolean bStatus = Convert.toBool(status, false);
    monitorModel.setStatus(bStatus);
    monitorUserOptService.update(monitorModel);
    return JsonMessage.getString(200, "修改成功");
}
Also used : MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class NodeEditController method del.

/**
 * 删除节点
 *
 * @param id 节点id
 * @return json
 */
@PostMapping(value = "del.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String del(@ValidatorItem String id) {
    HttpServletRequest request = getRequest();
    this.checkDataBind(id, request);
    // 
    {
        ProjectInfoCacheModel projectInfoCacheModel = new ProjectInfoCacheModel();
        projectInfoCacheModel.setNodeId(id);
        projectInfoCacheModel.setWorkspaceId(projectInfoCacheService.getCheckUserWorkspace(request));
        boolean exists = projectInfoCacheService.exists(projectInfoCacheModel);
        Assert.state(!exists, "该节点下还存在项目,不能删除");
    }
    // 
    {
        ScriptCacheModel scriptCacheModel = new ScriptCacheModel();
        scriptCacheModel.setNodeId(id);
        scriptCacheModel.setWorkspaceId(nodeScriptServer.getCheckUserWorkspace(request));
        boolean exists = nodeScriptServer.exists(scriptCacheModel);
        Assert.state(!exists, "该节点下还存在脚本模版,不能删除");
    }
    // 
    this.delNodeData(id, request);
    return JsonMessage.getString(200, "操作成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ProjectInfoCacheModel(io.jpom.model.node.ProjectInfoCacheModel) ScriptCacheModel(io.jpom.model.node.ScriptCacheModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 25 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class NodeEditController method unbind.

/**
 * 解绑
 *
 * @param id 分发id
 * @return json
 */
@GetMapping(value = "unbind.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String unbind(String id) {
    HttpServletRequest request = getRequest();
    this.checkDataBind(id, request);
    // 
    projectInfoCacheService.delCache(id, request);
    nodeScriptServer.delCache(id, request);
    this.delNodeData(id, request);
    return JsonMessage.getString(200, "操作成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

Feature (io.jpom.permission.Feature)129 MethodFeature (io.jpom.permission.MethodFeature)129 ClassFeature (io.jpom.permission.ClassFeature)128 JSONObject (com.alibaba.fastjson.JSONObject)49 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 File (java.io.File)36 PostMapping (org.springframework.web.bind.annotation.PostMapping)25 DockerInfoModel (io.jpom.model.docker.DockerInfoModel)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)22 NodeModel (io.jpom.model.data.NodeModel)21 GetMapping (org.springframework.web.bind.annotation.GetMapping)21 UserModel (io.jpom.model.data.UserModel)14 SystemPermission (io.jpom.permission.SystemPermission)14 BuildInfoModel (io.jpom.model.data.BuildInfoModel)12 SshModel (io.jpom.model.data.SshModel)10 Entity (cn.hutool.db.Entity)8 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)8 JSONArray (com.alibaba.fastjson.JSONArray)8 JsonMessage (cn.jiangzeyin.common.JsonMessage)7 List (java.util.List)7