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;
}
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);
}
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();
}
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, "重新发布中");
}
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;
}
Aggregations