Bläddra i källkod

去掉原有角色权限判断,去掉模块维护人字段,增加模块类型与相关查询条件

luoshi 2 år sedan
förälder
incheckning
b888a29f58

+ 0 - 5
pom.xml

@@ -64,11 +64,6 @@
                 <artifactId>starter-api</artifactId>
                 <version>${qmth.boot.version}</version>
             </dependency>
-            <dependency>
-                <groupId>com.qmth.boot</groupId>
-                <artifactId>data-redis</artifactId>
-                <version>${qmth.boot.version}</version>
-            </dependency>
             <dependency>
                 <groupId>com.qmth.boot</groupId>
                 <artifactId>data-mybatis-plus</artifactId>

+ 2 - 7
src/main/java/com/qmth/ops/api/controller/admin/AppController.java

@@ -2,15 +2,12 @@ package com.qmth.ops.api.controller.admin;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.ops.api.constants.OpsApiConstants;
-import com.qmth.ops.api.security.AdminSession;
 import com.qmth.ops.api.vo.AppVersionVO;
 import com.qmth.ops.biz.domain.App;
-import com.qmth.ops.biz.domain.Role;
 import com.qmth.ops.biz.query.AppQuery;
 import com.qmth.ops.biz.service.AppService;
 import com.qmth.ops.biz.service.VersionService;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -40,15 +37,13 @@ public class AppController {
     }
 
     @PostMapping("/insert")
-    public AppVersionVO insert(@RequestAttribute AdminSession adminSession, App app) {
-        adminSession.validateRole(Role.ADMIN);
+    public AppVersionVO insert(App app) {
         appService.insert(app);
         return new AppVersionVO(appService.getById(app.getId()), versionService);
     }
 
     @PostMapping("/update")
-    public AppVersionVO update(@RequestAttribute AdminSession adminSession, App app) {
-        adminSession.validateRole(Role.ADMIN);
+    public AppVersionVO update(App app) {
         appService.update(app);
         return new AppVersionVO(appService.getById(app.getId()), versionService);
     }

+ 3 - 15
src/main/java/com/qmth/ops/api/controller/admin/EnvController.java

@@ -8,10 +8,7 @@ import com.qmth.ops.api.vo.CodeNameVO;
 import com.qmth.ops.api.vo.EnvVO;
 import com.qmth.ops.biz.domain.Env;
 import com.qmth.ops.biz.domain.EnvType;
-import com.qmth.ops.biz.domain.Role;
-import com.qmth.ops.biz.service.AppService;
 import com.qmth.ops.biz.service.EnvService;
-import com.qmth.ops.biz.service.UserService;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -26,15 +23,9 @@ import java.util.stream.Collectors;
 @RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/env")
 public class EnvController {
 
-    @Resource
-    private AppService appService;
-
     @Resource
     private EnvService envService;
 
-    @Resource
-    private UserService userService;
-
     @RequestMapping("/types")
     @Aac(auth = BOOL.FALSE)
     public Object types() {
@@ -43,22 +34,19 @@ public class EnvController {
 
     @PostMapping("/insert")
     public EnvVO insert(@RequestAttribute AdminSession adminSession, Env env) {
-        adminSession.validateRole(Role.ADMIN);
         env = envService.insert(env);
-        return new EnvVO(env, userService.getById(env.getUserId()));
+        return new EnvVO(env);
     }
 
     @PostMapping("/update")
     public EnvVO update(@RequestAttribute AdminSession adminSession, Env env) {
-        adminSession.validateRole(Role.ADMIN);
         env = envService.update(env);
-        return new EnvVO(env, userService.getById(env.getUserId()));
+        return new EnvVO(env);
     }
 
     @PostMapping("/list")
     public List<EnvVO> list(@RequestAttribute AdminSession adminSession, Long appId) {
-        return envService.list(appId).stream().map(env -> new EnvVO(env, userService.getById(env.getUserId())))
-                .collect(Collectors.toList());
+        return envService.list(appId).stream().map(EnvVO::new).collect(Collectors.toList());
     }
 
 }

+ 12 - 8
src/main/java/com/qmth/ops/api/controller/admin/ModuleController.java

@@ -1,11 +1,13 @@
 package com.qmth.ops.api.controller.admin;
 
+import com.qmth.boot.api.annotation.Aac;
+import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.api.security.AdminSession;
+import com.qmth.ops.api.vo.ModuleTypeVO;
 import com.qmth.ops.biz.domain.Module;
-import com.qmth.ops.biz.domain.Role;
+import com.qmth.ops.biz.domain.ModuleType;
 import com.qmth.ops.biz.query.ModuleQuery;
-import com.qmth.ops.biz.service.AppService;
 import com.qmth.ops.biz.service.ModuleService;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestAttribute;
@@ -13,32 +15,34 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.Arrays;
 import java.util.List;
 
 @RestController
 @RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/module")
 public class ModuleController {
 
-    @Resource
-    private AppService appService;
-
     @Resource
     private ModuleService moduleService;
 
+    @RequestMapping("/types")
+    @Aac(auth = BOOL.FALSE)
+    public Object types() {
+        return Arrays.stream(ModuleType.values()).map(ModuleTypeVO::new).toArray();
+    }
+
     @PostMapping("/insert")
     public Module insert(@RequestAttribute AdminSession adminSession, Module module) {
-        adminSession.validateRole(Role.ADMIN);
         return moduleService.insert(module);
     }
 
     @PostMapping("/update")
     public Module update(@RequestAttribute AdminSession adminSession, Module module) {
-        adminSession.validateRole(Role.ADMIN);
         return moduleService.update(module);
     }
 
     @PostMapping("/list")
-    public List<Module> list(@RequestAttribute AdminSession adminSession, ModuleQuery query) {
+    public List<Module> list(ModuleQuery query) {
         return moduleService.list(query);
     }
 

+ 0 - 6
src/main/java/com/qmth/ops/api/controller/admin/NginxConfigController.java

@@ -3,7 +3,6 @@ package com.qmth.ops.api.controller.admin;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.api.security.AdminSession;
 import com.qmth.ops.biz.domain.NginxConfig;
-import com.qmth.ops.biz.domain.Role;
 import com.qmth.ops.biz.service.AppService;
 import com.qmth.ops.biz.service.EnvService;
 import com.qmth.ops.biz.service.ModuleService;
@@ -39,11 +38,6 @@ public class NginxConfigController {
     public Object update(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
             @RequestParam(required = false) Long envId, @RequestParam(required = false) Long moduleId,
             @RequestParam String content) {
-        if (envId != null) {
-            adminSession.validateEnv(envService.getById(envId));
-        } else {
-            adminSession.validateRole(Role.DEV, Role.ADMIN);
-        }
         return nginxConfigService.update(appService.getById(appId), envId != null ? envService.getById(envId) : null,
                 moduleId != null ? moduleService.getById(moduleId) : null, content);
     }

+ 1 - 6
src/main/java/com/qmth/ops/api/controller/admin/PropertyController.java

@@ -70,7 +70,6 @@ public class PropertyController {
             @RequestParam Long versionId, @RequestParam Long moduleId, @RequestParam MultipartFile file,
             @RequestParam FileFormat extension, @RequestParam(required = false) Long inheritVersionId)
             throws IOException {
-        adminSession.validateRole(Role.ADMIN, Role.DEV);
         return propertyService.updateBaseline(appService.getById(appId), versionService.getById(versionId),
                 moduleService.getById(moduleId), file.getInputStream(), extension,
                 inheritVersionId != null ? versionService.getById(inheritVersionId) : null);
@@ -78,7 +77,6 @@ public class PropertyController {
 
     @PostMapping("/baseline/item/update")
     public PropertyItem updateBaselineItem(@RequestAttribute AdminSession adminSession, PropertyItem item) {
-        adminSession.validateRole(Role.ADMIN, Role.DEV);
         return propertyService.updateBaselineItem(item);
     }
 
@@ -88,8 +86,7 @@ public class PropertyController {
         Env env = envService.getById(envId);
         List<PropertyItem> list = propertyService.listPropertyItem(appId, versionId, moduleId, env.getId());
         //非管理员/运维角色,且非环境维护用户,需要隐藏机密信息
-        if (!adminSession.getUser().hasRole(Role.ADMIN, Role.OPS) && !adminSession.getUser().getId()
-                .equals(env.getUserId())) {
+        if (!adminSession.getUser().hasRole(Role.ADMIN, Role.OPS)) {
             for (PropertyItem item : list) {
                 //包含密钥/密码类信息
                 if (item.getKey().contains("secret") || item.getKey().contains("password")) {
@@ -119,13 +116,11 @@ public class PropertyController {
 
     @PostMapping("/item/update")
     public PropertyItem updatePropertyItem(@RequestAttribute AdminSession adminSession, PropertyItem item) {
-        adminSession.validateEnv(envService.getById(item.getEnvId()));
         return propertyService.updatePropertyItem(item);
     }
 
     @PostMapping("/item/delete")
     public Object deletePropertyItem(@RequestAttribute AdminSession adminSession, PropertyItem item) {
-        adminSession.validateEnv(envService.getById(item.getEnvId()));
         propertyService.deletePropertyItem(item);
         Map<String, Object> map = new HashMap<>();
         map.put("success", true);

+ 0 - 4
src/main/java/com/qmth/ops/api/controller/admin/UserController.java

@@ -55,27 +55,23 @@ public class UserController {
 
     @PostMapping("/query")
     public IPage<User> query(@RequestAttribute AdminSession adminSession, UserQuery query) {
-        adminSession.validateRole(Role.ADMIN);
         return userService.query(query);
     }
 
     @PostMapping("/list")
     public List<User> list(@RequestAttribute AdminSession adminSession, UserQuery query) {
-        adminSession.validateRole(Role.ADMIN);
         return userService.list(query);
     }
 
     @PostMapping("/insert")
     public User insert(@RequestAttribute AdminSession adminSession,
             @Validated(UserForm.InsertGroup.class) UserForm form) {
-        adminSession.validateRole(Role.ADMIN);
         return userService.insert(form.build());
     }
 
     @PostMapping("/update")
     public User update(@RequestAttribute AdminSession adminSession,
             @Validated(UserForm.UpdateGroup.class) UserForm form) {
-        adminSession.validateRole(Role.ADMIN);
         return userService.update(form.build());
     }
 

+ 0 - 3
src/main/java/com/qmth/ops/api/controller/admin/VersionController.java

@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.ops.api.binder.VersionNumberBinder;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.api.security.AdminSession;
-import com.qmth.ops.biz.domain.Role;
 import com.qmth.ops.biz.domain.Version;
 import com.qmth.ops.biz.query.VersionQuery;
 import com.qmth.ops.biz.service.AppService;
@@ -33,13 +32,11 @@ public class VersionController {
     @PostMapping("/insert")
     public Version insert(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
             @RequestParam VersionNumber name) {
-        adminSession.validateRole(Role.ADMIN, Role.DEV);
         return versionService.insert(appService.getById(appId), name);
     }
 
     @PostMapping("/update")
     public Version list(@RequestAttribute AdminSession adminSession, Version version) {
-        adminSession.validateRole(Role.ADMIN, Role.DEV);
         return versionService.update(version);
     }
 

+ 0 - 15
src/main/java/com/qmth/ops/api/security/AdminSession.java

@@ -1,10 +1,7 @@
 package com.qmth.ops.api.security;
 
-import com.qmth.boot.core.exception.UnauthorizedException;
 import com.qmth.boot.core.security.model.AccessEntity;
 import com.qmth.ops.api.dto.LoginResult;
-import com.qmth.ops.biz.domain.Env;
-import com.qmth.ops.biz.domain.Role;
 import com.qmth.ops.biz.domain.User;
 
 public class AdminSession implements AccessEntity {
@@ -30,18 +27,6 @@ public class AdminSession implements AccessEntity {
         return user;
     }
 
-    public void validateRole(Role... roles) {
-        if (!user.hasRole(roles)) {
-            throw new UnauthorizedException("没有操作权限");
-        }
-    }
-
-    public void validateEnv(Env env) {
-        if (!user.hasRole(Role.ADMIN) && !user.getId().equals(env.getUserId())) {
-            throw new UnauthorizedException("没有环境操作权限");
-        }
-    }
-
     @Override
     public String getIdentity() {
         return user.getId().toString();

+ 1 - 12
src/main/java/com/qmth/ops/api/vo/EnvVO.java

@@ -2,7 +2,6 @@ package com.qmth.ops.api.vo;
 
 import com.qmth.ops.biz.domain.Env;
 import com.qmth.ops.biz.domain.EnvType;
-import com.qmth.ops.biz.domain.User;
 
 public class EnvVO {
 
@@ -14,14 +13,11 @@ public class EnvVO {
 
     private EnvType type;
 
-    private UserVO user;
-
-    public EnvVO(Env env, User user) {
+    public EnvVO(Env env) {
         this.id = env.getId();
         this.code = env.getCode();
         this.name = env.getName();
         this.type = env.getType();
-        this.user = new UserVO(user);
     }
 
     public Long getId() {
@@ -56,11 +52,4 @@ public class EnvVO {
         this.type = type;
     }
 
-    public UserVO getUser() {
-        return user;
-    }
-
-    public void setUser(UserVO user) {
-        this.user = user;
-    }
 }

+ 32 - 0
src/main/java/com/qmth/ops/api/vo/ModuleTypeVO.java

@@ -0,0 +1,32 @@
+package com.qmth.ops.api.vo;
+
+import com.qmth.ops.biz.domain.ModuleType;
+
+public class ModuleTypeVO extends CodeNameVO {
+
+    private Boolean property;
+
+    private Boolean nginx;
+
+    public ModuleTypeVO(ModuleType type) {
+        super(type.getCode(), type.getName());
+        property = type == ModuleType.SERVER;
+        nginx = type == ModuleType.WEB;
+    }
+
+    public Boolean getProperty() {
+        return property;
+    }
+
+    public void setProperty(Boolean property) {
+        this.property = property;
+    }
+
+    public Boolean getNginx() {
+        return nginx;
+    }
+
+    public void setNginx(Boolean nginx) {
+        this.nginx = nginx;
+    }
+}

+ 0 - 10
src/main/java/com/qmth/ops/biz/domain/Env.java

@@ -22,8 +22,6 @@ public class Env implements Serializable {
 
     private EnvType type;
 
-    private Long userId;
-
     private Long createTime;
 
     private Long updateTime;
@@ -68,14 +66,6 @@ public class Env implements Serializable {
         this.type = type;
     }
 
-    public Long getUserId() {
-        return userId;
-    }
-
-    public void setUserId(Long userId) {
-        this.userId = userId;
-    }
-
     public Long getCreateTime() {
         return createTime;
     }

+ 11 - 0
src/main/java/com/qmth/ops/biz/domain/Module.java

@@ -20,6 +20,8 @@ public class Module implements Serializable {
 
     private String name;
 
+    private ModuleType type;
+
     private Boolean enable;
 
     private Long createTime;
@@ -58,6 +60,14 @@ public class Module implements Serializable {
         this.name = name;
     }
 
+    public ModuleType getType() {
+        return type;
+    }
+
+    public void setType(ModuleType type) {
+        this.type = type;
+    }
+
     public Boolean getEnable() {
         return enable;
     }
@@ -81,4 +91,5 @@ public class Module implements Serializable {
     public void setUpdateTime(Long updateTime) {
         this.updateTime = updateTime;
     }
+
 }

+ 21 - 0
src/main/java/com/qmth/ops/biz/domain/ModuleType.java

@@ -0,0 +1,21 @@
+package com.qmth.ops.biz.domain;
+
+public enum ModuleType {
+
+    SERVER("服务端"), WEB("WEB前端");
+
+    private String name;
+
+    ModuleType(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getCode() {
+        return toString().toUpperCase();
+    }
+
+}

+ 12 - 1
src/main/java/com/qmth/ops/biz/query/ModuleQuery.java

@@ -3,6 +3,7 @@ package com.qmth.ops.biz.query;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.qmth.boot.mybatis.query.BaseQuery;
 import com.qmth.ops.biz.domain.Module;
+import com.qmth.ops.biz.domain.ModuleType;
 
 public class ModuleQuery extends BaseQuery<Module> {
 
@@ -18,6 +19,8 @@ public class ModuleQuery extends BaseQuery<Module> {
 
     private Boolean enable;
 
+    private ModuleType type;
+
     public Long getId() {
         return id;
     }
@@ -58,10 +61,18 @@ public class ModuleQuery extends BaseQuery<Module> {
         this.enable = enable;
     }
 
+    public ModuleType getType() {
+        return type;
+    }
+
+    public void setType(ModuleType type) {
+        this.type = type;
+    }
+
     public LambdaQueryWrapper<Module> build() {
         return new LambdaQueryWrapper<Module>().eq(id != null, Module::getId, id)
                 .eq(appId != null, Module::getAppId, appId).eq(code != null, Module::getCode, code)
                 .eq(enable != null, Module::getEnable, enable).eq(name != null, Module::getName, name)
-                .orderByAsc(Module::getCode);
+                .eq(type != null, Module::getType, type).orderByAsc(Module::getCode);
     }
 }

+ 0 - 1
src/main/java/com/qmth/ops/biz/service/EnvService.java

@@ -30,7 +30,6 @@ public class EnvService extends ServiceImpl<EnvDao, Env> {
         envDao.update(env, new LambdaUpdateWrapper<Env>().set(env.getCode() != null, Env::getCode, env.getCode())
                 .set(env.getName() != null, Env::getName, env.getName())
                 .set(env.getType() != null, Env::getType, env.getType())
-                .set(env.getUserId() != null, Env::getUserId, env.getUserId())
                 .set(Env::getUpdateTime, System.currentTimeMillis()).eq(Env::getId, env.getId()));
         return envDao.selectById(env.getId());
     }

+ 1 - 0
src/main/java/com/qmth/ops/biz/service/ModuleService.java

@@ -32,6 +32,7 @@ public class ModuleService extends ServiceImpl<ModuleDao, Module> {
                 new LambdaUpdateWrapper<Module>().set(module.getCode() != null, Module::getCode, module.getCode())
                         .set(module.getName() != null, Module::getName, module.getName())
                         .set(module.getEnable() != null, Module::getEnable, module.getEnable())
+                        .set(module.getType() != null, Module::getType, module.getType())
                         .set(Module::getUpdateTime, System.currentTimeMillis()).eq(Module::getId, module.getId()));
         return moduleDao.selectById(module.getId());
     }

+ 0 - 5
src/main/java/com/qmth/ops/biz/utils/OpsUtils.java

@@ -1,5 +0,0 @@
-package com.qmth.ops.biz.utils;
-
-public class OpsUtils {
-
-}

+ 1 - 1
src/main/java/com/qmth/ops/biz/wxapp/api/WxappApiClient.java

@@ -6,7 +6,7 @@ import com.qmth.ops.biz.wxapp.dto.Code2SessionResult;
 import retrofit2.http.GET;
 import retrofit2.http.Query;
 
-@RetrofitClient(configuration = WxappApiConfiguration.class)
+@RetrofitClient(baseUrl = "https://api.weixin.qq.com/")
 public interface WxappApiClient {
 
     @GET("cgi-bin/token")

+ 0 - 17
src/main/java/com/qmth/ops/biz/wxapp/api/WxappApiConfiguration.java

@@ -1,17 +0,0 @@
-package com.qmth.ops.biz.wxapp.api;
-
-import com.qmth.boot.core.retrofit.interfaces.CustomizeRetrofitConfiguration;
-import com.qmth.boot.core.retrofit.interfaces.SignatureProvider;
-import org.springframework.stereotype.Component;
-
-@Component
-public class WxappApiConfiguration implements CustomizeRetrofitConfiguration {
-
-    public String getBaseUrl() {
-        return "https://api.weixin.qq.com/";
-    }
-
-    public SignatureProvider getSignature() {
-        return null;
-    }
-}

+ 1 - 2
src/main/resources/application.properties

@@ -1,8 +1,7 @@
 server.port=8080
 
-management.endpoints.web.exposure.include=health,metrics,prometheus
-
 com.qmth.api.global-auth=false
+com.qmth.api.http-trace=true
 
 com.qmth.datasource.url=jdbc:mysql://192.168.10.83:3306/ops_db?useUnicode=true&characterEncoding=UTF-8
 com.qmth.datasource.username=scan

+ 1 - 1
src/main/resources/script/init.sql

@@ -36,7 +36,6 @@ CREATE TABLE IF NOT EXISTS `env`
     `code`        varchar(64)         NOT NULL,
     `name`        varchar(64)         NOT NULL,
     `type`        varchar(16)         NOT NULL,
-    `user_id`     bigint(20) unsigned NOT NULL,
     `create_time` bigint(20)          NOT NULL,
     `update_time` bigint(20)          NOT NULL,
     PRIMARY KEY (`id`),
@@ -51,6 +50,7 @@ CREATE TABLE IF NOT EXISTS `module`
     `app_id`      bigint(20) unsigned NOT NULL,
     `code`        varchar(64)         NOT NULL,
     `name`        varchar(64)         NOT NULL,
+    `type`        varchar(16)         NOT NULL,
     `enable`      tinyint(1)          NOT NULL,
     `create_time` bigint(20)          NOT NULL,
     `update_time` bigint(20)          NOT NULL,