From 4d7af16b05bae485fbedf5d06d61aca1652d3b97 Mon Sep 17 00:00:00 2001 From: Loki <654612@qq.com> Date: Fri, 24 Jun 2022 13:58:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E9=A1=B9=E7=9B=AE=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=AD=97=E5=85=B8=EF=BC=8C=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=B1=95=E7=A4=BA=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/project/vo/ProjectBaseVO.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java index a1e8b55f..c3c833a8 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java @@ -1,12 +1,21 @@ package cn.iocoder.yudao.module.farm.controller.admin.project.vo; -import cn.hutool.json.JSON; +import cn.hutool.extra.spring.SpringUtil; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum; +import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; +import cn.iocoder.yudao.module.system.service.permission.RoleService; +import cn.iocoder.yudao.module.system.service.permission.RoleServiceImpl; import com.alibaba.fastjson.JSONArray; +import com.google.common.collect.Maps; import lombok.*; import java.util.*; import io.swagger.annotations.*; import javax.validation.constraints.*; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -16,7 +25,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class ProjectBaseVO { +public class ProjectBaseVO extends ProjectDO { + @ApiModelProperty(value = "") private String name; @@ -54,4 +64,27 @@ public class ProjectBaseVO { private Boolean pretendDelete; + private Map actions; + + public Map getActions() { + + actions = Maps.newHashMap(); + // 当前用户是否有资格编辑删除这个项目 + + RoleService roleService = SpringUtil.getBean("roleServiceImpl"); + + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + assert loginUser != null; + List roles = roleService.getRolesFromCache(loginUser.getRoleIds()); + + Optional admin = roles.stream().filter(roleDO -> roleDO.getName().contains("管理员") || roleDO.getCode().contains("admin")).findAny(); + // 是创建者 或者 是 租户的管理员,可以更改项目 + actions.put("edit",getCreator().equals(loginUser.getId().toString()) || admin.isPresent()); + + // 应该加上,项目下面没有运行中的任务才可以删除 ,或者是在删除部分再做判断 ,此处只做权限显示 + actions.put("delete",getCreator().equals(loginUser.getId().toString()) || admin.isPresent()); + + return actions; + } + }