Procházet zdrojové kódy

允许普通用户访问 /resourcePoint/get*/**

sunyj před 8 roky
rodič
revize
73f0a43a62

+ 1 - 2
kanban-auth/src/main/java/com/uas/kanban/SecurityConfiguration.java

@@ -37,8 +37,7 @@ public class SecurityConfiguration extends WebMvcConfigurerAdapter {
 		// 添加管理员才可访问的路径
 		// 用户、资源点管理
 		securityInterceptor.addAdminPatterns("/user/save*/**", "/user/update*/**", "/user/delete*/**", "/user/get*/**",
-				"/resourcePoint/save*/**", "/resourcePoint/update*/**", "/resourcePoint/delete*/**",
-				"/resourcePoint/get*/**");
+				"/resourcePoint/save*/**", "/resourcePoint/update*/**", "/resourcePoint/delete*/**");
 		// 模版设计
 		securityInterceptor.addAdminPatterns("/template/save*/**", "/template/update*/**", "/template/delete*/**",
 				"/board");

+ 24 - 2
kanban-auth/src/main/java/com/uas/kanban/dao/ResourcePointDao.java

@@ -1,9 +1,15 @@
 package com.uas.kanban.dao;
 
-import org.springframework.stereotype.Component;
-
 import com.uas.kanban.base.BaseDao;
 import com.uas.kanban.model.ResourcePoint;
+import com.uas.kanban.model.User;
+import com.uas.kanban.support.SystemSession;
+import com.uas.kanban.util.CollectionUtils;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 资源点
@@ -14,4 +20,20 @@ import com.uas.kanban.model.ResourcePoint;
 @Component
 public class ResourcePointDao extends BaseDao<ResourcePoint> {
 
+    @Override
+    protected Map<String, Object> globalFilter() {
+        User user = SystemSession.checkUser();
+        // 管理员可以看到所有资源点
+        if (user.getRole() == User.Role.Admin) {
+            return null;
+        }
+        // 关联的资源点
+        List<String> resourcePointCodes = user.getResourcePointCodes();
+        Map<String, Object> filters = new HashMap<>();
+        if (!CollectionUtils.isEmpty(resourcePointCodes)) {
+            // 普通用户只能操作关联的资源点
+            filters.put("code in", resourcePointCodes);
+        }
+        return filters;
+    }
 }

+ 22 - 7
kanban-console/src/main/java/com/uas/kanban/controller/TemplateController.java

@@ -1,12 +1,5 @@
 package com.uas.kanban.controller;
 
-import javax.servlet.http.HttpServletRequest;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-
 import com.alibaba.fastjson.JSONObject;
 import com.uas.kanban.annotation.NotEmpty;
 import com.uas.kanban.base.BaseController;
@@ -14,6 +7,14 @@ import com.uas.kanban.exception.OperationException;
 import com.uas.kanban.model.Template;
 import com.uas.kanban.model.TemplateParameter;
 import com.uas.kanban.service.TemplateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 
 /**
  * 用户
@@ -28,6 +29,20 @@ public class TemplateController extends BaseController<Template> {
 	@Autowired
 	private TemplateService templateService;
 
+	/**
+	 * 根据资源点 code 获取模版
+	 *
+	 * @param resourcePointCode
+	 *            资源点 code
+	 * @return 模版
+	 * @param request
+	 */
+	@RequestMapping("/get/resourcePointCode/{resourcePointCode}")
+	@ResponseBody
+	public List<Template> getByResourcePointCode(@PathVariable("resourcePointCode") String resourcePointCode, HttpServletRequest request) {
+		return templateService.getByResourcePointCode(resourcePointCode);
+	}
+
 	/**
 	 * 添加模版参数
 	 * 

+ 7 - 14
kanban-console/src/main/java/com/uas/kanban/dao/TemplateDao.java

@@ -1,23 +1,19 @@
 package com.uas.kanban.dao;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import com.uas.kanban.annotation.NotEmpty;
 import com.uas.kanban.base.BaseDao;
 import com.uas.kanban.model.ResourcePoint;
 import com.uas.kanban.model.Template;
 import com.uas.kanban.model.User;
 import com.uas.kanban.model.User.Role;
 import com.uas.kanban.support.SystemSession;
-import com.uas.kanban.support.TemplateParser;
 import com.uas.kanban.util.CollectionUtils;
-import com.uas.kanban.util.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 用户
@@ -31,9 +27,6 @@ public class TemplateDao extends BaseDao<Template> {
 	@Autowired
 	private ResourcePointDao resourePointDao;
 
-	@Autowired
-	private TemplateParser templateParser;
-
 	@Override
 	protected Map<String, Object> globalFilter() {
 		User user = SystemSession.checkUser();

+ 12 - 0
kanban-console/src/main/java/com/uas/kanban/service/TemplateService.java

@@ -2,8 +2,11 @@ package com.uas.kanban.service;
 
 import com.uas.kanban.annotation.NotEmpty;
 import com.uas.kanban.exception.OperationException;
+import com.uas.kanban.model.Template;
 import com.uas.kanban.model.TemplateParameter;
 
+import java.util.List;
+
 /**
  * 模版
  * 
@@ -12,6 +15,15 @@ import com.uas.kanban.model.TemplateParameter;
  */
 public interface TemplateService {
 
+	/**
+	 * 根据资源点 code 获取模版
+	 *
+	 * @param resourcePointCode
+	 *            资源点 code
+	 * @return 模版
+	 */
+	public List<Template> getByResourcePointCode(@NotEmpty("resourcePointCode") String resourcePointCode);
+
 	/**
 	 * 添加模版参数
 	 * 

+ 4 - 5
kanban-console/src/main/java/com/uas/kanban/service/impl/GlobalParameterServiceImpl.java

@@ -1,10 +1,5 @@
 package com.uas.kanban.service.impl;
 
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
 import com.uas.kanban.annotation.NotEmpty;
 import com.uas.kanban.base.BaseService;
 import com.uas.kanban.dao.GlobalParameterDao;
@@ -12,6 +7,10 @@ import com.uas.kanban.exception.OperationException;
 import com.uas.kanban.model.GlobalParameter;
 import com.uas.kanban.model.GlobalParameter.InputMode;
 import com.uas.kanban.util.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
 
 /**
  * 公共参数

+ 27 - 13
kanban-console/src/main/java/com/uas/kanban/service/impl/TemplateServiceImpl.java

@@ -1,27 +1,24 @@
 package com.uas.kanban.service.impl;
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.mongodb.morphia.query.Query;
-import org.mongodb.morphia.query.UpdateOperations;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
 import com.uas.kanban.annotation.NotEmpty;
 import com.uas.kanban.base.BaseService;
 import com.uas.kanban.dao.DataSourceDao;
 import com.uas.kanban.dao.GlobalParameterDao;
+import com.uas.kanban.dao.ResourcePointDao;
 import com.uas.kanban.dao.TemplateDao;
 import com.uas.kanban.exception.OperationException;
-import com.uas.kanban.model.DataSource;
-import com.uas.kanban.model.GlobalParameter;
-import com.uas.kanban.model.Template;
-import com.uas.kanban.model.TemplateParameter;
+import com.uas.kanban.model.*;
 import com.uas.kanban.service.TemplateService;
 import com.uas.kanban.util.CollectionUtils;
 import com.uas.kanban.util.StringUtils;
+import org.mongodb.morphia.query.Query;
+import org.mongodb.morphia.query.UpdateOperations;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * 模版
@@ -41,6 +38,9 @@ public class TemplateServiceImpl extends BaseService<Template> implements Templa
 	@Autowired
 	private GlobalParameterDao globalParameterDao;
 
+	@Autowired
+	private ResourcePointDao resourePointDao;
+
 	@Override
 	public Template save(@NotEmpty("json") String json) {
 		Template template = templateDao.parse(json);
@@ -142,6 +142,20 @@ public class TemplateServiceImpl extends BaseService<Template> implements Templa
 		}
 	}
 
+	@Override
+	public List<Template> getByResourcePointCode(@NotEmpty("resourcePointCode") String resourcePointCode) {
+		ResourcePoint resourcePoint = resourePointDao.findOne(resourcePointCode);
+		if (resourcePoint == null) {
+			throw new IllegalStateException("资源点不存在:" + resourcePointCode);
+		}
+		// 资源点所能查看的模版
+		List<String> resourcePointCodes = resourcePoint.getTemplateCodes();
+		if(CollectionUtils.isEmpty(resourcePointCodes)){
+			return null;
+		}
+		return templateDao.findListBy("code", resourcePointCodes);
+	}
+
 	@Override
 	public int addParameter(@NotEmpty("code") String code, @NotEmpty("parameter") TemplateParameter parameter) {
 		parameter.init();

+ 1 - 0
kanban-console/src/main/webapp/WEB-INF/views/console.html

@@ -73,6 +73,7 @@
 				<li><a target="_blank">template/get/4EC2735D343</a></li>
 				<li><a target="_blank">template/get?page=1&size=10</a></li>
 				<br/>
+				<li><a target="_blank">template/get/resourcePointCode/4F6BDFB4213</a></li>
 				<li><a target="_blank">template/parameter/add?code=4EC5D6B2716&amp;parameter={"name": "PU_NAME","type": "String"}</a></li>
 				<li><a target="_blank">template/parameter/delete?code=4EC5D6B2716&amp;parameterCode=4EC9340EE11</a></li>
 				<li><a target="_blank">template/parameter/update?code=4EC5D6B2716&amp;parameter={"code": "4EC9340EE11","name": "PU_NAME","type": "String"}</a></li>