|
@@ -2,6 +2,7 @@ package cn.iselab.mooctest.site.web.ctrl;
|
|
|
|
|
|
|
|
import cn.iselab.mooctest.site.common.constant.UrlConstants;
|
|
import cn.iselab.mooctest.site.common.constant.UrlConstants;
|
|
|
import cn.iselab.mooctest.site.models.User;
|
|
import cn.iselab.mooctest.site.models.User;
|
|
|
|
|
+import cn.iselab.mooctest.site.models.instancePermission.GroupPermission;
|
|
|
import cn.iselab.mooctest.site.util.http.RequestUtils;
|
|
import cn.iselab.mooctest.site.util.http.RequestUtils;
|
|
|
import cn.iselab.mooctest.site.web.data.GroupVO;
|
|
import cn.iselab.mooctest.site.web.data.GroupVO;
|
|
|
import cn.iselab.mooctest.site.web.data.UserVO;
|
|
import cn.iselab.mooctest.site.web.data.UserVO;
|
|
@@ -11,6 +12,9 @@ import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.authz.UnauthorizedException;
|
|
import org.apache.shiro.authz.UnauthorizedException;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -36,9 +40,24 @@ public class GroupController extends BaseController {
|
|
|
@RequiresPermissions("groups:view")
|
|
@RequiresPermissions("groups:view")
|
|
|
@RequestMapping(value = UrlConstants.API + "group", method = RequestMethod.GET)
|
|
@RequestMapping(value = UrlConstants.API + "group", method = RequestMethod.GET)
|
|
|
public List<GroupVO> getOwnerGroups(@RequestParam(value = "ownerId", required = false) Long ownerId) {
|
|
public List<GroupVO> getOwnerGroups(@RequestParam(value = "ownerId", required = false) Long ownerId) {
|
|
|
|
|
+ ownerId = ((User)SecurityUtils.getSubject().getSession().getAttribute("User")).getId();
|
|
|
return groupLogic.getOwnerGroups(ownerId);
|
|
return groupLogic.getOwnerGroups(ownerId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @RequiresPermissions("groups:view")
|
|
|
|
|
+ @RequestMapping(value = UrlConstants.API + "pageableGroup", method = RequestMethod.GET)
|
|
|
|
|
+ public Page<GroupVO> getOwnerGroups(@RequestParam(value = "ownerId", required = false) Long ownerId,HttpServletRequest request) {
|
|
|
|
|
+ ownerId = ((User)SecurityUtils.getSubject().getSession().getAttribute("User")).getId();
|
|
|
|
|
+ String activePage = request.getHeader("activePage");
|
|
|
|
|
+ String rowsOnPage = request.getHeader("rowsOnPage");
|
|
|
|
|
+ if(activePage == null || rowsOnPage == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("缺少分页信息");
|
|
|
|
|
+ }
|
|
|
|
|
+ Pageable pageable = new PageRequest(Integer.parseInt(activePage) - 1, Integer.parseInt(rowsOnPage));
|
|
|
|
|
+ return groupLogic.getPageableGroups(ownerId,pageable);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@RequiresPermissions("group:create")
|
|
@RequiresPermissions("group:create")
|
|
|
@RequestMapping(value = UrlConstants.API + "group", method = RequestMethod.POST)
|
|
@RequestMapping(value = UrlConstants.API + "group", method = RequestMethod.POST)
|
|
|
public GroupVO createGroup(@RequestBody GroupVO groupVO){
|
|
public GroupVO createGroup(@RequestBody GroupVO groupVO){
|
|
@@ -50,7 +69,7 @@ public class GroupController extends BaseController {
|
|
|
public GroupVO getManagerGroupDetail(@PathVariable("id") long groupId) {
|
|
public GroupVO getManagerGroupDetail(@PathVariable("id") long groupId) {
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
String permission = user.getId() + ":group:view:" + groupId;
|
|
String permission = user.getId() + ":group:view:" + groupId;
|
|
|
- if(!SecurityUtils.getSubject().isPermitted(permission)) {
|
|
|
|
|
|
|
+ if(!SecurityUtils.getSubject().isPermitted(new GroupPermission(permission))) {
|
|
|
throw new UnauthorizedException("unauthorized");
|
|
throw new UnauthorizedException("unauthorized");
|
|
|
}
|
|
}
|
|
|
return groupLogic.getGroupDetail(groupId);
|
|
return groupLogic.getGroupDetail(groupId);
|
|
@@ -61,7 +80,7 @@ public class GroupController extends BaseController {
|
|
|
public List<UserVO> getManagerWorkersInGroup(@PathVariable("id") long groupId) {
|
|
public List<UserVO> getManagerWorkersInGroup(@PathVariable("id") long groupId) {
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
String permission = user.getId() + ":group:view:" + groupId;
|
|
String permission = user.getId() + ":group:view:" + groupId;
|
|
|
- if(!SecurityUtils.getSubject().isPermitted(permission)) {
|
|
|
|
|
|
|
+ if(!SecurityUtils.getSubject().isPermitted(new GroupPermission(permission))) {
|
|
|
throw new UnauthorizedException("unauthorized");
|
|
throw new UnauthorizedException("unauthorized");
|
|
|
}
|
|
}
|
|
|
return groupLogic.getManagerWorkersInGroup(groupId);
|
|
return groupLogic.getManagerWorkersInGroup(groupId);
|
|
@@ -72,7 +91,7 @@ public class GroupController extends BaseController {
|
|
|
public UserVO addUserToGroup(@PathVariable("id") long groupId,@RequestBody UserVO userVO){
|
|
public UserVO addUserToGroup(@PathVariable("id") long groupId,@RequestBody UserVO userVO){
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
String permission = user.getId() + ":group:update:" + groupId;
|
|
String permission = user.getId() + ":group:update:" + groupId;
|
|
|
- if(!SecurityUtils.getSubject().isPermitted(permission)) {
|
|
|
|
|
|
|
+ if(!SecurityUtils.getSubject().isPermitted(new GroupPermission(permission))) {
|
|
|
throw new UnauthorizedException("unauthorized");
|
|
throw new UnauthorizedException("unauthorized");
|
|
|
}
|
|
}
|
|
|
return groupLogic.addUserIntoGroup(userVO.getUserName(),groupId);
|
|
return groupLogic.addUserIntoGroup(userVO.getUserName(),groupId);
|
|
@@ -133,7 +152,7 @@ public class GroupController extends BaseController {
|
|
|
public GroupVO updateAllowJoin(@PathVariable("groupId") long groupId){
|
|
public GroupVO updateAllowJoin(@PathVariable("groupId") long groupId){
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
String permission = user.getId() + ":group:update:" + groupId;
|
|
String permission = user.getId() + ":group:update:" + groupId;
|
|
|
- if(!SecurityUtils.getSubject().isPermitted(permission)) {
|
|
|
|
|
|
|
+ if(!SecurityUtils.getSubject().isPermitted(new GroupPermission(permission))) {
|
|
|
throw new UnauthorizedException("unauthorized");
|
|
throw new UnauthorizedException("unauthorized");
|
|
|
}
|
|
}
|
|
|
return groupLogic.updateAllowJoin(groupId);
|
|
return groupLogic.updateAllowJoin(groupId);
|
|
@@ -162,6 +181,12 @@ public class GroupController extends BaseController {
|
|
|
return groupLogic.deleteUserFromGroup(userId,groupId);
|
|
return groupLogic.deleteUserFromGroup(userId,groupId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @RequestMapping(value = UrlConstants.API + "group/{groupId:\\d+}/user", method = RequestMethod.DELETE)
|
|
|
|
|
+ public UserVO deleteMyselfFromGroup(@PathVariable("groupId") long groupId){
|
|
|
|
|
+ Long userId = ((User)SecurityUtils.getSubject().getSession().getAttribute("User")).getId();
|
|
|
|
|
+ return groupLogic.deleteUserFromGroup(userId,groupId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@RequestMapping(value = UrlConstants.API_WORKER + "group/{id:\\d+}", method = RequestMethod.GET)
|
|
@RequestMapping(value = UrlConstants.API_WORKER + "group/{id:\\d+}", method = RequestMethod.GET)
|
|
|
public GroupVO getGroupByWorkerId(HttpServletRequest request, @PathVariable("id")long id){
|
|
public GroupVO getGroupByWorkerId(HttpServletRequest request, @PathVariable("id")long id){
|
|
|
long workerId = RequestUtils.getWorkerId(request);
|
|
long workerId = RequestUtils.getWorkerId(request);
|