Search in sources :

Example 26 with UserModel

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

the class BaseServerController method getUser.

protected UserModel getUser() {
    UserModel userByThreadLocal = getUserByThreadLocal();
    Assert.notNull(userByThreadLocal, ServerConfigBean.AUTHORIZE_TIME_OUT_CODE + StrUtil.EMPTY);
    return userByThreadLocal;
}
Also used : UserModel(io.jpom.model.data.UserModel)

Example 27 with UserModel

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

the class BaseServerController method checkCron.

/**
 * 验证 cron 表达式, demo 账号不能开启 cron
 *
 * @param cron cron
 * @return 原样返回
 */
protected String checkCron(String cron) {
    if (StrUtil.isNotEmpty(cron)) {
        UserModel user = getUser();
        Assert.state(!user.isDemoUser(), PermissionInterceptor.DEMO_TIP);
        try {
            new CronPattern(cron);
        } catch (Exception e) {
            throw new IllegalArgumentException("cron 表达式格式不正确");
        }
    }
    return ObjectUtil.defaultIfNull(cron, StrUtil.EMPTY);
}
Also used : UserModel(io.jpom.model.data.UserModel) CronPattern(cn.hutool.cron.pattern.CronPattern)

Example 28 with UserModel

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

the class BuildInfoManageController method start.

/**
 * 开始构建
 *
 * @param id id
 * @return json
 */
@RequestMapping(value = "/build/manage/start", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String start(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String id, String buildRemark, String resultDirFile, String branchName, String branchTagName) {
    BuildInfoModel item = buildInfoService.getByKey(id, getRequest());
    Assert.notNull(item, "没有对应数据");
    // 更新数据
    BuildInfoModel update = new BuildInfoModel();
    if (StrUtil.isNotEmpty(resultDirFile)) {
        update.setResultDirFile(resultDirFile);
    }
    if (StrUtil.isNotEmpty(branchName)) {
        update.setBranchName(branchName);
    }
    if (StrUtil.isNotEmpty(branchTagName)) {
        update.setBranchTagName(branchTagName);
    }
    if (!StrUtil.isAllBlank(resultDirFile, branchName, branchTagName)) {
        update.setId(id);
        buildInfoService.update(update);
    }
    // userModel
    UserModel userModel = getUser();
    // 执行构建
    return buildExecuteService.start(item.getId(), userModel, null, 0, buildRemark).toString();
}
Also used : UserModel(io.jpom.model.data.UserModel) BuildInfoModel(io.jpom.model.data.BuildInfoModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with UserModel

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

the class BuildInfoManageController method reRelease.

/**
 * 重新发布
 *
 * @param logId logId
 * @return json
 */
@RequestMapping(value = "/build/manage/reRelease", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String reRelease(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据")) String logId) {
    BuildHistoryLog buildHistoryLog = dbBuildHistoryLogService.getByKey(logId, getRequest());
    Objects.requireNonNull(buildHistoryLog, "没有对应构建记录.");
    BuildInfoModel item = buildInfoService.getByKey(buildHistoryLog.getBuildDataId());
    Objects.requireNonNull(item, "没有对应数据");
    String e = buildExecuteService.checkStatus(item.getStatus());
    Assert.isNull(e, () -> e);
    UserModel userModel = getUser();
    BuildExtraModule buildExtraModule = BuildExtraModule.build(buildHistoryLog);
    // new BuildExtraModule();
    // buildExtraModule.updateValue(buildHistoryLog);
    ReleaseManage manage = ReleaseManage.builder().buildExtraModule(buildExtraModule).logId(buildHistoryLog.getId()).userModel(userModel).buildId(buildHistoryLog.getBuildNumberId()).buildExecuteService(buildExecuteService).build();
    // ReleaseManage releaseManage = new ReleaseManage(buildHistoryLog, userModel);
    // 标记发布中
    // releaseManage.updateStatus(BuildStatus.PubIng);
    ThreadUtil.execute(manage);
    return JsonMessage.getString(200, "重新发布中");
}
Also used : UserModel(io.jpom.model.data.UserModel) BuildHistoryLog(io.jpom.model.log.BuildHistoryLog) ReleaseManage(io.jpom.build.ReleaseManage) BuildExtraModule(io.jpom.build.BuildExtraModule) BuildInfoModel(io.jpom.model.data.BuildInfoModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with UserModel

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

the class LoginInterceptor method tryGetHeaderUser.

/**
 * 尝试获取 header 中的信息
 *
 * @param session ses
 * @param request req
 * @return true 获取成功
 */
private boolean tryGetHeaderUser(HttpServletRequest request, HttpSession session) {
    String header = request.getHeader(ServerOpenApi.USER_TOKEN_HEAD);
    if (StrUtil.isEmpty(header)) {
        // 兼容就版本 登录状态
        UserModel user = (UserModel) session.getAttribute(SESSION_NAME);
        return user != null;
    }
    UserService userService = SpringUtil.getBean(UserService.class);
    UserModel userModel = userService.checkUser(header);
    if (userModel == null) {
        return false;
    }
    session.setAttribute(LoginInterceptor.SESSION_NAME, userModel);
    return true;
}
Also used : UserModel(io.jpom.model.data.UserModel) UserService(io.jpom.service.user.UserService)

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