Procházet zdrojové kódy

用户可绑定资源点

sunyj před 8 roky
rodič
revize
efd327f701

+ 1 - 1
kanban-auth/src/main/java/com/uas/kanban/filter/SecurityInterceptor.java

@@ -59,7 +59,7 @@ public class SecurityInterceptor extends HandlerInterceptorAdapter {
 		if (url.startsWith("/user/save") || url.startsWith("/user/update") || url.startsWith("/user/delete")
 				|| url.startsWith("/user/get")) {
 			if (user.getRole() != Role.Admin) {
-				throw new OperationException("不允许的操作");
+				throw new OperationException("没有权限");
 			}
 		}
 		SystemSession.setUser(user);

+ 18 - 2
kanban-auth/src/main/java/com/uas/kanban/model/User.java

@@ -1,5 +1,7 @@
 package com.uas.kanban.model;
 
+import java.util.List;
+
 import org.mongodb.morphia.annotations.Entity;
 
 import com.uas.kanban.annotation.FieldProperty;
@@ -34,6 +36,11 @@ public class User extends BaseEntity {
 	@FieldProperty(nullable = false)
 	private Role role;
 
+	/**
+	 * 绑定的资源点 code
+	 */
+	private List<String> resourcePointCodes;
+
 	public String getName() {
 		return name;
 	}
@@ -58,10 +65,19 @@ public class User extends BaseEntity {
 		this.role = role;
 	}
 
+	public List<String> getResourcePointCodes() {
+		return resourcePointCodes;
+	}
+
+	public void setResourcePointCodes(List<String> resourcePointCodes) {
+		this.resourcePointCodes = resourcePointCodes;
+	}
+
 	@Override
 	public String toString() {
-		return "User [name=" + name + ", password=" + password + ", role=" + role + ", id=" + id + ", createTime="
-				+ createTime + ", lastModified=" + lastModified + ", version=" + version + ", code=" + code + "]";
+		return "User [name=" + name + ", password=" + password + ", resourcePointCodes=" + resourcePointCodes
+				+ ", role=" + role + ", id=" + id + ", createTime=" + createTime + ", lastModified=" + lastModified
+				+ ", version=" + version + ", code=" + code + "]";
 	}
 
 	/**

+ 28 - 0
kanban-auth/src/main/java/com/uas/kanban/service/impl/UserServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.kanban.service.impl;
 
+import java.util.List;
 import java.util.Objects;
 
 import org.mongodb.morphia.query.Query;
@@ -9,12 +10,15 @@ import org.springframework.stereotype.Service;
 
 import com.uas.kanban.annotation.NotEmpty;
 import com.uas.kanban.base.BaseService;
+import com.uas.kanban.dao.ResourcePointDao;
 import com.uas.kanban.dao.UserDao;
 import com.uas.kanban.exception.OperationException;
+import com.uas.kanban.model.ResourcePoint;
 import com.uas.kanban.model.User;
 import com.uas.kanban.model.User.Role;
 import com.uas.kanban.service.UserService;
 import com.uas.kanban.support.SystemSession;
+import com.uas.kanban.util.CollectionUtils;
 
 /**
  * 用户
@@ -28,6 +32,9 @@ public class UserServiceImpl extends BaseService<User> implements UserService {
 	@Autowired
 	private UserDao userDao;
 
+	@Autowired
+	private ResourcePointDao resourcePointDao;
+
 	@Override
 	public User save(@NotEmpty("json") String json) {
 		User user = userDao.parse(json);
@@ -89,6 +96,27 @@ public class UserServiceImpl extends BaseService<User> implements UserService {
 		if (password != null && password.trim().length() < 3) {
 			throw new IllegalArgumentException("密码过短");
 		}
+		checkResourcePointCodes(user.getResourcePointCodes());
+	}
+
+	/**
+	 * 检查资源点是否存在
+	 * 
+	 * @param resourcePointCodes
+	 *            资源点的 code
+	 * @throws IllegalArgumentException
+	 *             资源点不存在
+	 */
+	private void checkResourcePointCodes(List<String> resourcePointCodes) throws IllegalArgumentException {
+		if (CollectionUtils.isEmpty(resourcePointCodes)) {
+			return;
+		}
+		for (String resourcePointCode : resourcePointCodes) {
+			ResourcePoint resourcePoint = resourcePointDao.findOne(resourcePointCode);
+			if (resourcePoint == null) {
+				throw new IllegalArgumentException("资源点不存在:" + resourcePointCode);
+			}
+		}
 	}
 
 	@Override

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

@@ -25,10 +25,10 @@
 			</ol>
 			<strong><li class="title">资源点</li></strong>
 			<ol>
-				<li><a target="_blank">resourcePoint/save?json={"name": "name","password": "password"}</a></li>
-				<li><a target="_blank">resourcePoint/savePart?json={"name": "name","password": "password"}</a></li>
-				<li><a target="_blank">resourcePoint/update?json={"code":"4EC2735D343","name": "name","password": "password"}</a></li>
-				<li><a target="_blank">resourcePoint/updatePart?json={"code":"4EC2735D343","name": "name","password": "password"}</a></li>
+				<li><a target="_blank">resourcePoint/save?json={"name": "name"}</a></li>
+				<li><a target="_blank">resourcePoint/savePart?json={"name": "name"}</a></li>
+				<li><a target="_blank">resourcePoint/update?json={"code":"4EC2735D343","name": "name"}</a></li>
+				<li><a target="_blank">resourcePoint/updatePart?json={"code":"4EC2735D343","name": "name"}</a></li>
 				<li><a target="_blank">resourcePoint/delete/4EC2735D343</a></li>
 				<li><a target="_blank">resourcePoint/get/all</a></li>
 				<li><a target="_blank">resourcePoint/get/4EC2735D343</a></li>