Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

FLPATH-556:return pending requests #505

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions workflow-service/generated/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,65 @@
"tags" : [ "Project" ]
}
},
"/api/v1/projects/access/pending" : {
"get" : {
"operationId" : "getPendingProjectAccessRequests",
"responses" : {
"200" : {
"content" : {
"application/json" : {
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ProjectAccessRequestDTO"
}
}
}
},
"description" : "Succeeded"
},
"400" : {
"content" : {
"*/*" : {
"schema" : {
"$ref" : "#/components/schemas/ErrorMessageDTO"
}
}
},
"description" : "Bad Request"
},
"401" : {
"description" : "Unauthorized"
},
"404" : {
"content" : { },
"description" : "Not found"
},
"409" : {
"content" : {
"*/*" : {
"schema" : {
"$ref" : "#/components/schemas/ErrorMessageDTO"
}
}
},
"description" : "Conflict"
},
"500" : {
"content" : {
"*/*" : {
"schema" : {
"$ref" : "#/components/schemas/ErrorMessageDTO"
}
}
},
"description" : "Internal Server Error"
}
},
"summary" : "Return all pending project access requests",
"tags" : [ "Project Access" ]
}
},
"/api/v1/projects/access/{id}/status" : {
"get" : {
"operationId" : "getProjectAccessStatus",
Expand Down Expand Up @@ -1610,6 +1669,42 @@
}
}
},
"ProjectAccessRequestDTO" : {
"type" : "object",
"properties" : {
"accessRequestId" : {
"type" : "string",
"format" : "uuid"
},
"comment" : {
"type" : "string"
},
"createDate" : {
"type" : "string",
"format" : "date-time"
},
"firstname" : {
"type" : "string"
},
"lastname" : {
"type" : "string"
},
"projectId" : {
"type" : "string",
"format" : "uuid"
},
"role" : {
"type" : "string"
},
"status" : {
"type" : "string",
"enum" : [ "APPROVED", "PENDING", "REJECTED" ]
},
"username" : {
"type" : "string"
}
}
},
"ProjectDTO" : {
"type" : "object",
"properties" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
*/
package com.redhat.parodos.project.controller;

import java.util.List;
import java.util.UUID;

import com.redhat.parodos.project.dto.request.AccessStatusRequestDTO;
import com.redhat.parodos.project.dto.response.AccessStatusResponseDTO;
import com.redhat.parodos.project.dto.response.ProjectAccessRequestDTO;
import com.redhat.parodos.project.service.ProjectAccessServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -79,4 +82,18 @@ public ResponseEntity<String> updateProjectAccessStatus(@PathVariable UUID id,
return ResponseEntity.noContent().build();
}

@Operation(summary = "Return all pending project access requests")
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "Succeeded",
content = { @Content(mediaType = "application/json",
array = @ArraySchema(
schema = @Schema(implementation = ProjectAccessRequestDTO.class))) }),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content),
@ApiResponse(responseCode = "404", description = "Not found", content = @Content) })
@GetMapping("/pending")
public ResponseEntity<List<ProjectAccessRequestDTO>> getPendingProjectAccessRequests() {
return ResponseEntity.ok(projectAccessService.getPendingProjectAccessRequests());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.redhat.parodos.project.dto.response;

import java.util.Date;
import java.util.UUID;

import com.redhat.parodos.project.enums.ProjectAccessStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProjectAccessRequestDTO {
RichardW98 marked this conversation as resolved.
Show resolved Hide resolved

private UUID accessRequestId;

private UUID projectId;

private String role;

private String username;

private String firstname;

private String lastname;

private ProjectAccessStatus status;

private String comment;

private Date createDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/
package com.redhat.parodos.project.service;

import java.util.List;
import java.util.UUID;

import com.redhat.parodos.project.dto.request.AccessStatusRequestDTO;
import com.redhat.parodos.project.dto.response.AccessStatusResponseDTO;
import com.redhat.parodos.project.dto.response.ProjectAccessRequestDTO;

/**
* Project access service
Expand All @@ -32,4 +34,6 @@ public interface ProjectAccessService {

void updateProjectAccessStatusById(UUID id, AccessStatusRequestDTO accessStatusRequestDTO);

List<ProjectAccessRequestDTO> getPendingProjectAccessRequests();

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.redhat.parodos.project.dto.request.AccessStatusRequestDTO;
import com.redhat.parodos.project.dto.request.UserRoleRequestDTO;
import com.redhat.parodos.project.dto.response.AccessStatusResponseDTO;
import com.redhat.parodos.project.dto.response.ProjectAccessRequestDTO;
import com.redhat.parodos.project.entity.ProjectAccessRequest;
import com.redhat.parodos.project.entity.ProjectUserRole;
import com.redhat.parodos.project.enums.ProjectAccessStatus;
Expand Down Expand Up @@ -104,6 +105,22 @@ public void updateProjectAccessStatusById(UUID id, AccessStatusRequestDTO access
}
}

@Override
public List<ProjectAccessRequestDTO> getPendingProjectAccessRequests() {
return projectAccessRequestRepository.findAll().stream()
.filter(projectAccessRequest -> ProjectAccessStatus.PENDING == projectAccessRequest.getStatus())
.map(projectAccessRequest -> ProjectAccessRequestDTO.builder()
.accessRequestId(projectAccessRequest.getId())
.projectId(projectAccessRequest.getProject().getId())
.role(projectAccessRequest.getRole().getName())
.username(projectAccessRequest.getUser().getUsername())
.firstname(projectAccessRequest.getUser().getFirstName())
.lastname(projectAccessRequest.getUser().getLastName())
.createDate(projectAccessRequest.getCreatedDate()).comment(projectAccessRequest.getComment())
.status(projectAccessRequest.getStatus()).build())
.toList();
}

private Boolean canUserUpdateProjectAccessStatus(UUID projectId, UUID userId) {
List<ProjectUserRole> projectUserRoleList = projectUserRoleRepository.findByProjectIdAndUserId(projectId,
userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.redhat.parodos.project.controller;

import java.util.List;
import java.util.UUID;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.parodos.ControllerMockClient;
import com.redhat.parodos.common.exceptions.ResourceNotFoundException;
import com.redhat.parodos.project.dto.request.AccessStatusRequestDTO;
import com.redhat.parodos.project.dto.response.AccessStatusResponseDTO;
import com.redhat.parodos.project.dto.response.ProjectAccessRequestDTO;
import com.redhat.parodos.project.enums.ProjectAccessStatus;
import com.redhat.parodos.project.service.ProjectAccessServiceImpl;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -154,4 +156,24 @@ public void testUpdateProjectAccessStatusWithInvalidCredentials() throws Excepti
verify(projectAccessService, never()).updateProjectAccessStatusById(eq(TEST_ACCESS_REQUEST_ID), any());
}

@Test
void testGetPendingProjectAccessRequests() throws Exception {
UUID projectId = UUID.randomUUID();
UUID id = UUID.randomUUID();
String username = "test-user";
// given
List<ProjectAccessRequestDTO> projectAccessRequestDTOList = List.of(
ProjectAccessRequestDTO.builder().projectId(projectId).username(username).accessRequestId(id).build());

when(projectAccessService.getPendingProjectAccessRequests()).thenReturn(projectAccessRequestDTOList);

// When
mockMvc.perform(this.getRequestWithValidCredentials("/api/v1/projects/access/pending"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].accessRequestId",
Matchers.is(projectAccessRequestDTOList.get(0).getAccessRequestId().toString())));
// Then
verify(projectAccessService, times(1)).getPendingProjectAccessRequests();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import com.redhat.parodos.common.exceptions.OperationDeniedException;
import com.redhat.parodos.common.exceptions.ResourceNotFoundException;
import com.redhat.parodos.project.dto.request.AccessStatusRequestDTO;
import com.redhat.parodos.project.dto.response.AccessStatusResponseDTO;
import com.redhat.parodos.project.dto.response.ProjectAccessRequestDTO;
import com.redhat.parodos.project.entity.Project;
import com.redhat.parodos.project.entity.ProjectAccessRequest;
import com.redhat.parodos.project.entity.ProjectUserRole;
Expand All @@ -29,6 +31,7 @@
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -187,6 +190,29 @@ void updateProjectAccessStatusByIdWhenUserIsNotAdminOrOwner() {
});
}

@Test
@WithMockUser(username = TEST_USERNAME)
void getPendingAccessRequests() {
// given
Project project = getProject(TEST_PROJECT_NAME, TEST_PROJECT_DESCRIPTION);
User user = getUser(TEST_USER_DEVELOPER_ID, TEST_USERNAME_DEVELOPER);
Role role = getRole(TEST_ROLE_DEVELOPER_NAME);
ProjectAccessRequest projectAccessRequest = getProjectAccessRequest(TEST_ACCESS_REQUEST_ID, project, user,
role);

// when
when(projectAccessRequestRepository.findAll()).thenReturn(List.of(projectAccessRequest));

// then
List<ProjectAccessRequestDTO> projectAccessRequestDTOList = projectAccessService
.getPendingProjectAccessRequests();

assertThat(projectAccessRequestDTOList).hasSize(1).satisfies(projectAccessRequestDTO -> {
assertEquals(TEST_USERNAME_DEVELOPER, projectAccessRequestDTO.get(0).getUsername());
assertEquals(project.getId(), projectAccessRequestDTO.get(0).getProjectId());
});
}

private Project getProject(String name, String description) {
Project project = Project.builder().name(name).description(description).build();
project.setId(UUID.randomUUID());
Expand Down
Loading