Search in sources :

Example 1 with Feature

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, "操作成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) JSONArray(com.alibaba.fastjson.JSONArray) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 2 with Feature

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, "解锁成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 3 with Feature

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, "关闭成功");
}
Also used : UserModel(io.jpom.model.data.UserModel) SystemPermission(io.jpom.permission.SystemPermission) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 4 with Feature

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());
    }
}
Also used : MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServerWhitelist(io.jpom.model.data.ServerWhitelist) ServerConfigBean(io.jpom.system.ServerConfigBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Feature(io.jpom.permission.Feature) ProjectInfoCacheService(io.jpom.service.node.ProjectInfoCacheService) JsonMessage(cn.jiangzeyin.common.JsonMessage) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtil(cn.hutool.http.HttpUtil) BaseEnum(io.jpom.model.BaseEnum) OutGivingRun(io.jpom.outgiving.OutGivingRun) BaseNodeModel(io.jpom.model.BaseNodeModel) OutGivingServer(io.jpom.service.node.OutGivingServer) MethodFeature(io.jpom.permission.MethodFeature) NodeForward(io.jpom.common.forward.NodeForward) ClassFeature(io.jpom.permission.ClassFeature) MediaType(org.springframework.http.MediaType) NodeModel(io.jpom.model.data.NodeModel) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) IOException(java.io.IOException) AfterOpt(io.jpom.model.AfterOpt) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) File(java.io.File) BooleanUtil(cn.hutool.core.util.BooleanUtil) OutGivingModel(io.jpom.model.data.OutGivingModel) NodeUrl(io.jpom.common.forward.NodeUrl) Objects(java.util.Objects) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) ValidatorRule(cn.jiangzeyin.common.validator.ValidatorRule) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) StringUtil(io.jpom.util.StringUtil) Convert(cn.hutool.core.convert.Convert) ConfigBean(io.jpom.system.ConfigBean) FileUtil(cn.hutool.core.io.FileUtil) JSONObject(com.alibaba.fastjson.JSONObject) BaseServerController(io.jpom.common.BaseServerController) Assert(org.springframework.util.Assert) ServerWhitelist(io.jpom.model.data.ServerWhitelist) AfterOpt(io.jpom.model.AfterOpt) OutGivingModel(io.jpom.model.data.OutGivingModel) File(java.io.File) IOException(java.io.IOException) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Feature

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, "修改成功");
}
Also used : ScriptModel(io.jpom.model.script.ScriptModel) 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)

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