use of io.jpom.permission.Feature in project Jpom by dromara.
the class UserListController method addUser.
/**
* 编辑用户
*
* @param type 操作类型
* @return String
*/
@PostMapping(value = "edit", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String addUser(String type) {
//
boolean create = StrUtil.equals(type, "add");
UserModel userModel = this.parseUser(create);
if (create) {
userService.insert(userModel);
} else {
UserModel model = userService.getByKey(userModel.getId());
Assert.notNull(model, "不存在对应的用户");
boolean systemUser = userModel.isSystemUser();
if (!systemUser) {
Assert.state(!model.isSuperSystemUser(), "不能取消超级管理员的权限");
}
UserModel optUser = getUser();
if (StrUtil.equals(model.getId(), optUser.getId())) {
Assert.state(optUser.isSuperSystemUser(), "不能修改自己的信息");
}
userService.update(userModel);
}
//
String workspace = getParameter("workspace");
JSONArray jsonArray = JSONArray.parseArray(workspace);
List<String> workspaceList = jsonArray.toJavaList(String.class);
userBindWorkspaceService.updateUserWorkspace(userModel.getId(), workspaceList);
return JsonMessage.getString(200, "操作成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class UserListController method unlock.
/**
* 解锁用户锁定状态
*
* @param id id
* @return json
*/
@GetMapping(value = "unlock", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String unlock(@ValidatorItem String id) {
UserModel update = UserModel.unLock(id);
userService.update(update);
return JsonMessage.getString(200, "解锁成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class UserListController method closeMfa.
/**
* 关闭用户 mfa
*
* @param id id
* @return json
*/
@GetMapping(value = "close_user_mfa", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
@SystemPermission(superUser = true)
public String closeMfa(@ValidatorItem String id) {
UserModel update = new UserModel(id);
update.setTwoFactorAuthKey(StrUtil.EMPTY);
userService.update(update);
return JsonMessage.getString(200, "关闭成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class OutGivingProjectController method remoteDownload.
/**
* 远程下载节点分发文件
*
* @param id 分发id
* @param afterOpt 之后的操作
* @return json
*/
@RequestMapping(value = "remote_download", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.REMOTE_DOWNLOAD)
public String remoteDownload(String id, String afterOpt, String clearOld, String url, String autoUnzip) {
OutGivingModel outGivingModel = this.check(id);
AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
Assert.notNull(afterOpt1, "请选择分发后的操作");
// 验证远程 地址
ServerWhitelist whitelist = outGivingWhitelistService.getServerWhitelistData(getRequest());
Set<String> allowRemoteDownloadHost = whitelist.getAllowRemoteDownloadHost();
Assert.state(CollUtil.isNotEmpty(allowRemoteDownloadHost), "还没有配置运行的远程地址");
List<String> collect = allowRemoteDownloadHost.stream().filter(s -> StrUtil.startWith(url, s)).collect(Collectors.toList());
Assert.state(CollUtil.isNotEmpty(collect), "不允许下载当前地址的文件");
try {
// outGivingModel = outGivingServer.getItem(id);
outGivingModel.setClearOld(Convert.toBool(clearOld, false));
outGivingModel.setAfterOpt(afterOpt1.getCode());
outGivingServer.update(outGivingModel);
// 下载
File file = FileUtil.file(ServerConfigBean.getInstance().getUserTempPath(), ServerConfigBean.OUTGIVING_FILE, id);
FileUtil.mkdir(file);
File downloadFile = HttpUtil.downloadFileFromUrl(url, file);
boolean unzip = BooleanUtil.toBoolean(autoUnzip);
//
this.checkZip(downloadFile, unzip);
// 开启
OutGivingRun.startRun(outGivingModel.getId(), downloadFile, getUser(), unzip);
return JsonMessage.getString(200, "分发成功");
} catch (Exception e) {
DefaultSystemLog.getLog().error("下载远程文件异常", e);
return JsonMessage.getString(500, "下载远程文件失败:" + e.getMessage());
}
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class ScriptController method save.
@RequestMapping(value = "save.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String save(String id, @ValidatorItem String context, @ValidatorItem String name, String autoExecCron, String defArgs, String description, String nodeIds) {
ScriptModel scriptModel = new ScriptModel();
scriptModel.setId(id);
scriptModel.setContext(context);
scriptModel.setName(name);
scriptModel.setNodeIds(nodeIds);
scriptModel.setDescription(description);
scriptModel.setDefArgs(defArgs);
Assert.hasText(scriptModel.getContext(), "内容为空");
//
scriptModel.setAutoExecCron(this.checkCron(autoExecCron));
//
String oldNodeIds = null;
if (StrUtil.isEmpty(id)) {
scriptServer.insert(scriptModel);
} else {
HttpServletRequest request = getRequest();
ScriptModel byKey = scriptServer.getByKey(id, request);
Assert.notNull(byKey, "没有对应的数据");
oldNodeIds = byKey.getNodeIds();
scriptServer.updateById(scriptModel, request);
}
this.syncNodeScript(scriptModel, oldNodeIds);
return JsonMessage.getString(200, "修改成功");
}
Aggregations