@Test public void editRole() throws IOException { when(userStore.getRole("role")).thenReturn( new Role("role", EnumSet.of(Permission.EDIT_BRANCH, Permission.EDIT_PAGE))); String view = roleController.editRole("role", model); assertEquals("/user/role/edit", view); verify(model).addAttribute(eq("roleForm"), argRoleForm( "role", Sets.newHashSet(Permission.EDIT_BRANCH.name(), Permission.EDIT_PAGE.name()))); }
@RequestMapping(value="/edit/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") public String editRole(@PathVariable String roleName, Model model) throws IOException { Role role = userStore.getRole(roleName); Set<String> permissions = Sets.newHashSet(); for (Permission permission : role.getPermissions()) { permissions.add(permission.name()); } RoleForm form = new RoleForm(role.getName(), role.getName(), permissions); model.addAttribute("roleForm", form); return "/user/role/edit"; }
RoleController { @RequestMapping(value="/edit/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") public String editRole(@PathVariable String roleName, Model model) throws IOException { Role role = userStore.getRole(roleName); Set<String> permissions = Sets.newHashSet(); for (Permission permission : role.getPermissions()) { permissions.add(permission.name()); } RoleForm form = new RoleForm(role.getName(), role.getName(), permissions); model.addAttribute("roleForm", form); return "/user/role/edit"; } }
RoleController { @RequestMapping(value="/edit/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") public String editRole(@PathVariable String roleName, Model model) throws IOException { Role role = userStore.getRole(roleName); Set<String> permissions = Sets.newHashSet(); for (Permission permission : role.getPermissions()) { permissions.add(permission.name()); } RoleForm form = new RoleForm(role.getName(), role.getName(), permissions); model.addAttribute("roleForm", form); return "/user/role/edit"; }  }
RoleController { @RequestMapping(value="/edit/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") public String editRole(@PathVariable String roleName, Model model) throws IOException { Role role = userStore.getRole(roleName); Set<String> permissions = Sets.newHashSet(); for (Permission permission : role.getPermissions()) { permissions.add(permission.name()); } RoleForm form = new RoleForm(role.getName(), role.getName(), permissions); model.addAttribute("roleForm", form); return "/user/role/edit"; }  @RequestMapping(value="/add", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String addRole(Model model); @RequestMapping(value="/edit/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String editRole(@PathVariable String roleName, Model model); @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") String saveRole(@ModelAttribute @Valid RoleForm form, BindingResult bindingResult,
			Authentication authentication); @RequestMapping(value="/delete/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN) and !isLastAdminRole(#roleName)") String deleteRole(@PathVariable String roleName, Authentication authentication); @ModelAttribute RoleForm createRoleForm(@RequestParam(required=false) String name,
			@RequestParam(required=false) String originalName,
			@RequestParam(required=false) Set<String> permissions); }
RoleController { @RequestMapping(value="/edit/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") public String editRole(@PathVariable String roleName, Model model) throws IOException { Role role = userStore.getRole(roleName); Set<String> permissions = Sets.newHashSet(); for (Permission permission : role.getPermissions()) { permissions.add(permission.name()); } RoleForm form = new RoleForm(role.getName(), role.getName(), permissions); model.addAttribute("roleForm", form); return "/user/role/edit"; }  @RequestMapping(value="/add", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String addRole(Model model); @RequestMapping(value="/edit/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN)") String editRole(@PathVariable String roleName, Model model); @RequestMapping(value="/save", method=RequestMethod.POST) @PreAuthorize("hasApplicationPermission(ADMIN)") String saveRole(@ModelAttribute @Valid RoleForm form, BindingResult bindingResult,
			Authentication authentication); @RequestMapping(value="/delete/{roleName:" + DocumentrConstants.ROLE_NAME_PATTERN + "}", method=RequestMethod.GET) @PreAuthorize("hasApplicationPermission(ADMIN) and !isLastAdminRole(#roleName)") String deleteRole(@PathVariable String roleName, Authentication authentication); @ModelAttribute RoleForm createRoleForm(@RequestParam(required=false) String name,
			@RequestParam(required=false) String originalName,
			@RequestParam(required=false) Set<String> permissions);  }