Search in sources :

Example 46 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class OutGivingController method releaseDel.

/**
 * 删除分发信息
 *
 * @param id 分发id
 * @return json
 */
@RequestMapping(value = "release_del.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String releaseDel(String id) {
    HttpServletRequest request = getRequest();
    // 判断构建
    boolean releaseMethod = buildService.checkReleaseMethod(id, request, BuildReleaseMethod.Outgiving);
    Assert.state(!releaseMethod, "当前分发存在构建项,不能删除");
    OutGivingModel outGivingServerItem = outGivingServer.getByKey(id, request);
    UserModel userModel = getUser();
    // 解除项目分发独立分发属性
    List<OutGivingNodeProject> outGivingNodeProjectList = outGivingServerItem.outGivingNodeProjectList();
    if (outGivingNodeProjectList != null) {
        outGivingNodeProjectList.forEach(outGivingNodeProject -> {
            NodeModel item = nodeService.getByKey(outGivingNodeProject.getNodeId());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id", outGivingNodeProject.getProjectId());
            NodeForward.request(item, NodeUrl.Manage_ReleaseOutGiving, userModel, jsonObject);
        });
    }
    int byKey = outGivingServer.delByKey(id, request);
    if (byKey > 0) {
        // 删除日志
        Entity where = new Entity();
        where.set("outGivingId", id);
        dbOutGivingLogService.del(where);
    }
    return JsonMessage.getString(200, "操作成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserModel(io.jpom.model.data.UserModel) Entity(cn.hutool.db.Entity) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) OutGivingModel(io.jpom.model.data.OutGivingModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 47 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class WorkspaceEnvVarController method syncNodeEnvVar.

private void syncNodeEnvVar(WorkspaceEnvVarModel workspaceEnvVarModel, String oldNode) {
    String workspaceId = workspaceEnvVarModel.getWorkspaceId();
    List<String> newNodeIds = StrUtil.splitTrim(workspaceEnvVarModel.getNodeIds(), StrUtil.COMMA);
    List<String> oldNodeIds = StrUtil.splitTrim(oldNode, StrUtil.COMMA);
    Collection<String> delNode = CollUtil.subtract(oldNodeIds, newNodeIds);
    UserModel user = getUser();
    // 删除
    this.syncDelNodeEnvVar(workspaceEnvVarModel.getName(), user, delNode, workspaceId);
    // 更新
    for (String newNodeId : newNodeIds) {
        NodeModel byKey = nodeService.getByKey(newNodeId);
        Assert.state(StrUtil.equals(workspaceId, byKey.getWorkspaceId()), "选择节点错误");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("description", workspaceEnvVarModel.getDescription());
        jsonObject.put("name", workspaceEnvVarModel.getName());
        if (StrUtil.isNotEmpty(workspaceEnvVarModel.getValue())) {
            jsonObject.put("value", workspaceEnvVarModel.getValue());
        } else {
            // 查询
            WorkspaceEnvVarModel byKeyExits = workspaceEnvVarService.getByKey(workspaceEnvVarModel.getId());
            jsonObject.put("value", byKeyExits.getValue());
        }
        JsonMessage<String> jsonMessage = NodeForward.request(byKey, NodeUrl.Workspace_EnvVar_Update, user, jsonObject);
        Assert.state(jsonMessage.getCode() == 200, "处理 " + byKey.getName() + " 节点同步脚本失败" + jsonMessage.getMsg());
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) WorkspaceEnvVarModel(io.jpom.model.data.WorkspaceEnvVarModel)

Example 48 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class BuildTriggerApiController method trigger2.

/**
 * 构建触发器
 *
 * @param id    构建ID
 * @param token 构建的token
 * @param delay 延迟时间(单位秒)
 * @return json
 */
@RequestMapping(value = ServerOpenApi.BUILD_TRIGGER_BUILD2, produces = MediaType.APPLICATION_JSON_VALUE)
public String trigger2(@PathVariable String id, @PathVariable String token, String delay, String buildRemark) {
    BuildInfoModel item = buildInfoService.getByKey(id);
    Assert.notNull(item, "没有对应数据");
    UserModel userModel = this.getByUrlToken(token);
    // 
    Assert.notNull(userModel, "没有对应数据:-1");
    Assert.state(StrUtil.equals(token, item.getTriggerToken()), "触发token错误,或者已经失效");
    BaseServerController.resetInfo(userModel);
    JsonMessage<Integer> start = buildExecuteService.start(id, userModel, Convert.toInt(delay, 0), 1, buildRemark);
    return start.toString();
}
Also used : UserModel(io.jpom.model.data.UserModel) BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Example 49 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class UserListController method parseUser.

private UserModel parseUser(boolean create) {
    String id = getParameter("id");
    boolean email = Validator.isEmail(id);
    if (email) {
        int length = id.length();
        Assert.state(length <= Const.ID_MAX_LEN && length >= UserModel.USER_NAME_MIN_LEN, "登录名如果为邮箱格式,长度必须" + UserModel.USER_NAME_MIN_LEN + "-" + Const.ID_MAX_LEN);
    } else {
        Validator.validateGeneral(id, UserModel.USER_NAME_MIN_LEN, Const.ID_MAX_LEN, "登录名不能为空,并且长度必须" + UserModel.USER_NAME_MIN_LEN + "-" + Const.ID_MAX_LEN);
    }
    Assert.state(!StrUtil.equalsAnyIgnoreCase(id, UserModel.SYSTEM_OCCUPY_NAME, UserModel.SYSTEM_ADMIN), "当前登录名已经被系统占用");
    UserModel userModel = new UserModel();
    UserModel optUser = getUser();
    if (create) {
        long size = userService.count();
        Assert.state(size <= ServerExtConfigBean.getInstance().userMaxCount, "当前用户个数超过系统上限");
        // 登录名重复
        boolean exists = userService.exists(new UserModel(id));
        Assert.state(!exists, "登录名已经存在");
        userModel.setParent(optUser.getId());
    }
    userModel.setId(id);
    // 
    String name = getParameter("name");
    Assert.hasText(name, "请输入账户昵称");
    int len = name.length();
    Assert.state(len <= 10 && len >= 2, "昵称长度只能是2-10");
    userModel.setName(name);
    String password = getParameter("password");
    if (create || StrUtil.isNotEmpty(password)) {
        Assert.hasText(password, "密码不能为空");
        // 修改用户
        Assert.state(create || optUser.isSystemUser(), "只有系统管理员才能重置用户密码");
        userModel.setSalt(userService.generateSalt());
        userModel.setPassword(SecureUtil.sha1(password + userModel.getSalt()));
    }
    int systemUser = getParameterInt("systemUser", 0);
    userModel.setSystemUser(systemUser);
    return userModel;
}
Also used : UserModel(io.jpom.model.data.UserModel)

Example 50 with UserModel

use of io.jpom.model.data.UserModel in project Jpom by dromara.

the class UserListController method deleteUser.

/**
 * 删除用户
 *
 * @param id 用户id
 * @return String
 */
@RequestMapping(value = "deleteUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String deleteUser(String id) {
    UserModel userName = getUser();
    Assert.state(!StrUtil.equals(userName.getId(), id), "不能删除自己");
    UserModel userModel = userService.getByKey(id);
    Assert.notNull(userModel, "非法访问");
    if (userModel.isSystemUser()) {
        // 如果是系统管理员,判断个数
        Assert.state(userService.systemUserCount() > 1, "系统中的系统管理员账号数量必须存在一个以上");
    }
    // 非系统管理员不支持删除演示账号
    Assert.state(!userModel.isDemoUser(), "演示账号不支持删除");
    userService.delByKey(id);
    // 删除工作空间
    userBindWorkspaceService.deleteByUserId(id);
    return JsonMessage.getString(200, "删除成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Aggregations

UserModel (io.jpom.model.data.UserModel)66 JSONObject (com.alibaba.fastjson.JSONObject)17 MethodFeature (io.jpom.permission.MethodFeature)15 ClassFeature (io.jpom.permission.ClassFeature)14 Feature (io.jpom.permission.Feature)14 NodeModel (io.jpom.model.data.NodeModel)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 NotLogin (io.jpom.common.interceptor.NotLogin)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserService (io.jpom.service.user.UserService)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 StrUtil (cn.hutool.core.util.StrUtil)4 Entity (cn.hutool.db.Entity)4 JSONArray (com.alibaba.fastjson.JSONArray)4 BuildInfoModel (io.jpom.model.data.BuildInfoModel)4 List (java.util.List)4 JsonMessage (cn.jiangzeyin.common.JsonMessage)3 BaseServerController (io.jpom.common.BaseServerController)3 WorkspaceModel (io.jpom.model.data.WorkspaceModel)3 UserLoginDto (io.jpom.model.dto.UserLoginDto)3