Commit a4fb3285 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Fixed issue on permission removal

parent a57c7823
......@@ -34,7 +34,7 @@ public class PermissionsController {
@Autowired
private PermissionsManager permissionsManager;
@GetMapping(value = "/permissions", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@GetMapping(value = "/permissions", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PaginatedData<UserPermission>> getPermissionsTab(TabRequest request) {
GroupEntity group = groupsManager.getGroupById(request.getGroupId());
......@@ -44,14 +44,14 @@ public class PermissionsController {
return ResponseEntity.ok(permissionsPanel);
}
@GetMapping(value = "/permission", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@GetMapping(value = "/permission", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Permission>> getUserPermission(@RequestParam("groupId") String groupId, @RequestParam("userId") String userId) {
GroupEntity group = groupsManager.getGroupById(groupId);
Permission permission = permissionsManager.getUserPermission(group, userId);
Permission permission = permissionsManager.getDirectUserPermission(group, userId);
if (permission == null) {
return ResponseEntity.notFound().build();
return ResponseEntity.noContent().build();
} else {
Map<String, Permission> response = new HashMap<>();
response.put("permission", permission);
......@@ -59,7 +59,7 @@ public class PermissionsController {
}
}
@PostMapping(value = "/permission", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@PostMapping(value = "/permission", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PaginatedData<UserPermission>> addPermission(@Valid @RequestBody AddPermissionRequest request) {
GroupEntity group = groupsManager.getGroupById(request.getGroupId());
......@@ -68,7 +68,7 @@ public class PermissionsController {
return new ResponseEntity<>(getPermissionsPanel(group, request), HttpStatus.CREATED);
}
@DeleteMapping(value = "/permission", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@DeleteMapping(value = "/permission", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PaginatedData<UserPermission>> deletePermission(@Valid MemberRequest request) {
GroupEntity group = groupsManager.getGroupById(request.getGroupId());
......
......@@ -61,6 +61,17 @@ public class PermissionsManager extends UserAwareComponent {
return result;
}
public Permission getDirectUserPermission(GroupEntity group, String userId) {
verifyUserCanManagePermissions(group);
List<PermissionEntity> permissions = permissionsService.findUserPermissions(group, getCurrentUserId());
for (PermissionEntity permission : permissions) {
if (permission.getGroupId().equals(group.getId())) {
return permission.getPermission();
}
}
return null;
}
public Permission getUserPermission(GroupEntity group, String userId) {
verifyUserCanManagePermissions(group);
List<PermissionEntity> permissions = permissionsService.findUserPermissions(group, getCurrentUserId());
......
......@@ -59,10 +59,10 @@ public class PermissionsControllerTest {
@Test
public void testGetPermission() throws Exception {
when(permissionsManager.getUserPermission(eq(group), eq("user_id"))).thenReturn(Permission.MANAGE_MEMBERS);
when(permissionsManager.getDirectUserPermission(eq(group), eq("user_id"))).thenReturn(Permission.MANAGE_MEMBERS);
mockMvc.perform(get("/permission?groupId=group_id&userId=user_id")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.permission", is("MANAGE_MEMBERS")));
}
......@@ -71,8 +71,8 @@ public class PermissionsControllerTest {
public void testGetInexistentPermission() throws Exception {
mockMvc.perform(get("/permission?groupId=group_id&userId=user_id")
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isNotFound());
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent());
}
@Test
......@@ -87,7 +87,7 @@ public class PermissionsControllerTest {
mockMvc.perform(post("/permission")
.content(mapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON_UTF8))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.currentPage", is(1)));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment