@Test public void testDelete() throws Exception { String id = "{}"; mockMvc.perform(delete("/sys/user/1" + id) .header(HttpHeaders.AUTHORIZATION, String.join(" ", accessToken.getTokenType(), accessToken.getValue())) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); }
@Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除用户") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") public Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) { return super.delete(id); }
UserController extends LeftTreeRightTableControllerImpl<Department, User> { @Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除用户") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") public Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) { return super.delete(id); } }
UserController extends LeftTreeRightTableControllerImpl<Department, User> { @Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除用户") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") public Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) { return super.delete(id); }  }
UserController extends LeftTreeRightTableControllerImpl<Department, User> { @Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除用户") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") public Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) { return super.delete(id); }  @Autowired void setUserService(UserService userService); @Override @GetMapping("/dict") @ApiOperation("获取用户的数据字典") @PreAuthorize("hasAnyAuthority('" + LIST_PERM + "')") Result<TableInfo> getTableInfo(); @Override @PostMapping @ApiOperation("保存用户") @PreAuthorize("hasAnyAuthority('" + ADD_PERM + "')") Result<User> save(@Valid @RequestBody User model); @Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除用户") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) {; @Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新用户") // @PreAuthorize("hasAnyAuthority('sys:user:edit') or principal.id.equals(#id)") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") Result<User> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, /*@Valid*/@RequestBody User model) {; @Override @GetMapping("/{page:[0-9]+}/{size:[0-9]+}") @ApiOperation("分页查询用户列表") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<QueryResult<User>> query(@ApiParam(value = "页码", required = true) @PathVariable("page") int page, @ApiParam(value = "每页数据条数", required = true) @PathVariable("size") int size, User model) {; @Override @GetMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("根据ID查询用户") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<User> findById(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) {; @PostMapping("/register") @ApiOperation("用户注册") Result<User> register(@Valid @RequestBody User model); @GetMapping("/me") @ApiOperation("我的信息") @PreAuthorize("isAuthenticated()") UserDetails getCurrentUser(); @Override @PostMapping("/batch") @ApiOperation("批量操作数据") @PreAuthorize("hasAuthority('" + ADD_PERM +"') and hasAuthority('" + EDIT_PERM +"') and hasAuthority('" + DELETE_PERM +"')") Result batch(@RequestBody BatchModel<User> batch); @PostMapping(value = "/setRoles/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("分配角色") @PreAuthorize("hasAnyRole('ADMIN')") Result<User> setRoles(@ApiParam("用户id") @PathVariable String id, @ApiParam("角色id数组") @RequestBody String[] roles) {; @PostMapping(value = "/hasPermissions") @ApiOperation("判断是否有权限") @PreAuthorize("isAuthenticated()") Result<String> hasPermissions(@ApiParam("权限编码数组") @RequestBody String[] permissions) {; @Override @PostMapping("/import") @ApiOperation("从文件导入用户") @PreAuthorize("hasAnyAuthority('" + IMPORT_PERM + "')") Result<List<User>> importData(MultipartFile file); @Override @GetMapping("/export") @ApiOperation("导出用户到文件") @PreAuthorize("permitAll()") void exportData(@RequestBody(required = false) List<String> ids, HttpServletResponse response); @Override @GetMapping("/leftTree") @ApiOperation("获取左树数据") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<List<Department>> leftTreeData(); }
UserController extends LeftTreeRightTableControllerImpl<Department, User> { @Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除用户") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") public Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) { return super.delete(id); }  @Autowired void setUserService(UserService userService); @Override @GetMapping("/dict") @ApiOperation("获取用户的数据字典") @PreAuthorize("hasAnyAuthority('" + LIST_PERM + "')") Result<TableInfo> getTableInfo(); @Override @PostMapping @ApiOperation("保存用户") @PreAuthorize("hasAnyAuthority('" + ADD_PERM + "')") Result<User> save(@Valid @RequestBody User model); @Override @DeleteMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("删除用户") @PreAuthorize("hasAnyAuthority('" + DELETE_PERM + "')") Result<Void> delete(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) {; @Override @PutMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("更新用户") // @PreAuthorize("hasAnyAuthority('sys:user:edit') or principal.id.equals(#id)") @PreAuthorize("hasAnyAuthority('" + EDIT_PERM + "')") Result<User> update(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id, /*@Valid*/@RequestBody User model) {; @Override @GetMapping("/{page:[0-9]+}/{size:[0-9]+}") @ApiOperation("分页查询用户列表") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<QueryResult<User>> query(@ApiParam(value = "页码", required = true) @PathVariable("page") int page, @ApiParam(value = "每页数据条数", required = true) @PathVariable("size") int size, User model) {; @Override @GetMapping("/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("根据ID查询用户") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<User> findById(@ApiParam(value = "主键id", required = true) @PathVariable("id") String id) {; @PostMapping("/register") @ApiOperation("用户注册") Result<User> register(@Valid @RequestBody User model); @GetMapping("/me") @ApiOperation("我的信息") @PreAuthorize("isAuthenticated()") UserDetails getCurrentUser(); @Override @PostMapping("/batch") @ApiOperation("批量操作数据") @PreAuthorize("hasAuthority('" + ADD_PERM +"') and hasAuthority('" + EDIT_PERM +"') and hasAuthority('" + DELETE_PERM +"')") Result batch(@RequestBody BatchModel<User> batch); @PostMapping(value = "/setRoles/{id:^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$}") @ApiOperation("分配角色") @PreAuthorize("hasAnyRole('ADMIN')") Result<User> setRoles(@ApiParam("用户id") @PathVariable String id, @ApiParam("角色id数组") @RequestBody String[] roles) {; @PostMapping(value = "/hasPermissions") @ApiOperation("判断是否有权限") @PreAuthorize("isAuthenticated()") Result<String> hasPermissions(@ApiParam("权限编码数组") @RequestBody String[] permissions) {; @Override @PostMapping("/import") @ApiOperation("从文件导入用户") @PreAuthorize("hasAnyAuthority('" + IMPORT_PERM + "')") Result<List<User>> importData(MultipartFile file); @Override @GetMapping("/export") @ApiOperation("导出用户到文件") @PreAuthorize("permitAll()") void exportData(@RequestBody(required = false) List<String> ids, HttpServletResponse response); @Override @GetMapping("/leftTree") @ApiOperation("获取左树数据") @PreAuthorize("hasAnyAuthority('" + QUERY_PERM + "')") Result<List<Department>> leftTreeData();  }