diff --git a/build.gradle b/build.gradle index ce65f7b916..f447d9c3ec 100644 --- a/build.gradle +++ b/build.gradle @@ -76,7 +76,7 @@ dependencies { } else { implementation 'com.github.reportportal:commons-dao:b1599ca' implementation 'com.github.reportportal:commons:2b470a3' - implementation 'com.github.reportportal:plugin-api:c2a742a' + implementation 'com.github.reportportal:plugin-api:d96f33f' } implementation 'org.springframework.boot:spring-boot-starter-aop' diff --git a/reportportal-common-api b/reportportal-common-api index f65907e678..2c642596fa 160000 --- a/reportportal-common-api +++ b/reportportal-common-api @@ -1 +1 @@ -Subproject commit f65907e6780701e5cc99602c6f16364ff5c5ebf8 +Subproject commit 2c642596fa85cd5e95833818232da821350712dd diff --git a/src/main/java/com/epam/ta/reportportal/core/user/GetUserHandler.java b/src/main/java/com/epam/ta/reportportal/core/user/GetUserHandler.java index de377c309f..560fb6451d 100644 --- a/src/main/java/com/epam/ta/reportportal/core/user/GetUserHandler.java +++ b/src/main/java/com/epam/ta/reportportal/core/user/GetUserHandler.java @@ -24,7 +24,6 @@ import com.epam.ta.reportportal.entity.jasper.ReportFormat; import com.epam.ta.reportportal.entity.organization.MembershipDetails; import com.epam.ta.reportportal.model.YesNoRS; -import com.epam.ta.reportportal.model.user.UserBidRS; import com.epam.ta.reportportal.model.user.UserResource; import java.io.OutputStream; import java.util.Map; @@ -62,14 +61,6 @@ public interface GetUserHandler { InstanceUser getCurrentUser(ReportPortalUser currentUser); - /** - * Get information about user registration bid - * - * @param uuid UUID - * @return {@link UserBidRS} - */ - UserBidRS getBidInformation(String uuid); - /** * Validate existence of username or email * diff --git a/src/main/java/com/epam/ta/reportportal/core/user/UserInvitationHandler.java b/src/main/java/com/epam/ta/reportportal/core/user/UserInvitationHandler.java index fdb5c1f7ec..fa1bfdbf28 100644 --- a/src/main/java/com/epam/ta/reportportal/core/user/UserInvitationHandler.java +++ b/src/main/java/com/epam/ta/reportportal/core/user/UserInvitationHandler.java @@ -34,4 +34,12 @@ public interface UserInvitationHandler { Invitation createUserInvitation(InvitationRequest request, ReportPortalUser username, String userRegURL); + /** + * Retrieve an invitation by its ID. + * + * @param invitationId the ID of the invitation to retrieve + * @param baseUrl the base url of the webservice + * @return the invitation corresponding to the given ID + */ + Invitation getInvitation(String invitationId, String baseUrl); } diff --git a/src/main/java/com/epam/ta/reportportal/core/user/impl/GetUserHandlerImpl.java b/src/main/java/com/epam/ta/reportportal/core/user/impl/GetUserHandlerImpl.java index 3143b2683a..86d9b568b5 100644 --- a/src/main/java/com/epam/ta/reportportal/core/user/impl/GetUserHandlerImpl.java +++ b/src/main/java/com/epam/ta/reportportal/core/user/impl/GetUserHandlerImpl.java @@ -21,7 +21,6 @@ import static com.epam.ta.reportportal.commons.querygen.constant.UserCriteriaConstant.CRITERIA_EMAIL; import static com.epam.ta.reportportal.commons.querygen.constant.UserCriteriaConstant.CRITERIA_EXPIRED; import static com.epam.ta.reportportal.commons.querygen.constant.UserCriteriaConstant.CRITERIA_USER; -import static com.epam.ta.reportportal.core.user.impl.CreateUserHandlerImpl.INTERNAL_BID_TYPE; import static com.epam.ta.reportportal.util.OffsetUtils.responseWithPageParameters; import static com.epam.ta.reportportal.ws.converter.converters.UserConverter.TO_INSTANCE_USER; import static java.util.Optional.ofNullable; @@ -48,9 +47,7 @@ import com.epam.ta.reportportal.entity.project.ProjectUtils; import com.epam.ta.reportportal.entity.user.ProjectUser; import com.epam.ta.reportportal.entity.user.User; -import com.epam.ta.reportportal.entity.user.UserCreationBid; import com.epam.ta.reportportal.model.YesNoRS; -import com.epam.ta.reportportal.model.user.UserBidRS; import com.epam.ta.reportportal.model.user.UserResource; import com.epam.ta.reportportal.util.PersonalProjectService; import com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler; @@ -146,22 +143,6 @@ public Iterable getUsers(Filter filter, Pageable pageable, .apply(userRepository.findByFilterExcluding(filter, pageable, "email")); } - @Override - public UserBidRS getBidInformation(String uuid) { - Optional bid = userCreationBidRepository.findByUuidAndType(uuid, - INTERNAL_BID_TYPE); - return bid.map(b -> { - UserBidRS rs = new UserBidRS(); - rs.setIsActive(true); - rs.setEmail(b.getEmail()); - rs.setUuid(b.getUuid()); - return rs; - }).orElseGet(() -> { - UserBidRS rs = new UserBidRS(); - rs.setIsActive(false); - return rs; - }); - } @Override public YesNoRS validateInfo(String username, String email) { diff --git a/src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandlerImpl.java b/src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandlerImpl.java index c30d2ef893..463c312026 100644 --- a/src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandlerImpl.java +++ b/src/main/java/com/epam/ta/reportportal/core/user/impl/UserInvitationHandlerImpl.java @@ -41,6 +41,7 @@ import com.epam.ta.reportportal.entity.user.UserCreationBid; import com.epam.ta.reportportal.util.UserUtils; import com.epam.ta.reportportal.util.email.MailServiceFactory; +import com.epam.ta.reportportal.ws.converter.converters.InvitationConverter; import com.google.common.collect.Maps; import java.net.URI; import java.time.Instant; @@ -116,22 +117,22 @@ public Invitation createUserInvitation(InvitationRequest request, ReportPortalUs userBid.setInvitingUser(user); userBid.setMetadata(getUserCreationBidMetadata(request.getOrganizations())); + UserCreationBid storedUserBid; try { - userCreationBidRepository.save(userBid); + storedUserBid = userCreationBidRepository.save(userBid); } catch (Exception e) { throw new ReportPortalException("Error while user creation bid registering.", e); } - StringBuilder emailLink = new StringBuilder(baseUrl) - .append("/ui/#registration?uuid=") - .append(userBid.getUuid()); - var response = new Invitation(); - response.setCreatedAt(now); - response.setExpiresAt(now.plus(1, ChronoUnit.DAYS)); + response.setCreatedAt(storedUserBid.getLastModified()); + response.setExpiresAt(storedUserBid.getLastModified().plus(1, ChronoUnit.DAYS)); response.setId(UUID.fromString(userBid.getUuid())); - response.setLink(URI.create(emailLink.toString())); + response.setLink(getEmailLink(baseUrl, userBid.getUuid())); + response.setEmail(request.getEmail()); response.setStatus(PENDING); + response.setUserId(user.getId()); + response.setFullName(user.getFullName()); /* emailExecutorService.execute(() -> emailServiceFactory.getEmailService(integration, false) @@ -145,6 +146,14 @@ public Invitation createUserInvitation(InvitationRequest request, ReportPortalUs return response; } + @Override + public Invitation getInvitation(String invitationId, String baseUrl) { + var bid = userCreationBidRepository.getById(invitationId); + var invitation = InvitationConverter.TO_INVITATION.apply(bid); + invitation.setLink(getEmailLink(baseUrl, bid.getUuid())); + return invitation; + } + private void validateInvitationRequest(InvitationRequest request) { expect(UserUtils.isEmailValid(request.getEmail().trim()), equalTo(true)) .verify(BAD_REQUEST_ERROR, formattedSupplier("email='{}'", request.getEmail())); @@ -193,4 +202,8 @@ private boolean isSsoEnabled() { return settingsRepository.findByKey(SERVER_USERS_SSO).map(ServerSettings::getValue) .map(Boolean::parseBoolean).orElse(false); } + + private URI getEmailLink(String baseUrl, String invitationId) { + return URI.create(baseUrl + "/ui/#registration?uuid=" + invitationId); + } } diff --git a/src/main/java/com/epam/ta/reportportal/ws/controller/InvitationController.java b/src/main/java/com/epam/ta/reportportal/ws/controller/InvitationController.java index 5ec49105ae..97979e1827 100644 --- a/src/main/java/com/epam/ta/reportportal/ws/controller/InvitationController.java +++ b/src/main/java/com/epam/ta/reportportal/ws/controller/InvitationController.java @@ -18,6 +18,7 @@ import static com.epam.ta.reportportal.auth.permissions.Permissions.INVITATION_ALLOWED; import static com.epam.ta.reportportal.core.launch.util.LinkGenerator.composeBaseUrl; +import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.OK; import com.epam.reportportal.api.InvitationApi; @@ -25,9 +26,9 @@ import com.epam.reportportal.api.model.InvitationRequest; import com.epam.ta.reportportal.core.user.UserInvitationHandler; import javax.servlet.http.HttpServletRequest; -import javax.transaction.Transactional; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RestController; @RestController @@ -54,8 +55,18 @@ public ResponseEntity postInvitations(InvitationRequest invitationRe composeBaseUrl(httpServletRequest)); return ResponseEntity - .status(OK) + .status(CREATED) .body(response); } + + @Override + public ResponseEntity getInvitationsId(String invitationId) { + return ResponseEntity + .status(OK) + .body( + userInvitationHandler.getInvitation(invitationId, composeBaseUrl(httpServletRequest))); + + } + } diff --git a/src/main/java/com/epam/ta/reportportal/ws/controller/UserControllerOld.java b/src/main/java/com/epam/ta/reportportal/ws/controller/UserControllerOld.java index 2400c26c6b..0a278b7b8b 100644 --- a/src/main/java/com/epam/ta/reportportal/ws/controller/UserControllerOld.java +++ b/src/main/java/com/epam/ta/reportportal/ws/controller/UserControllerOld.java @@ -51,7 +51,6 @@ import com.epam.ta.reportportal.model.user.EditUserRQ; import com.epam.ta.reportportal.model.user.ResetPasswordRQ; import com.epam.ta.reportportal.model.user.RestorePasswordRQ; -import com.epam.ta.reportportal.model.user.UserBidRS; import com.epam.ta.reportportal.model.user.UserResource; import com.epam.ta.reportportal.ws.reporting.OperationCompletionRS; import com.epam.ta.reportportal.ws.resolver.ActiveRole; @@ -137,11 +136,6 @@ public CreateUserRS createUser(@RequestBody @Validated CreateUserRQConfirm reque return createUserMessageHandler.createUser(request, uuid); } - @Transactional(readOnly = true) - @GetMapping(value = "/registration") - public UserBidRS getUserBidInfo(@RequestParam(value = "uuid") String uuid) { - return getUserHandler.getBidInformation(uuid); - } @DeleteMapping(value = "/{id}") @Operation(summary = "Delete specified user") diff --git a/src/main/java/com/epam/ta/reportportal/ws/converter/converters/InvitationConverter.java b/src/main/java/com/epam/ta/reportportal/ws/converter/converters/InvitationConverter.java new file mode 100644 index 0000000000..af69b199b0 --- /dev/null +++ b/src/main/java/com/epam/ta/reportportal/ws/converter/converters/InvitationConverter.java @@ -0,0 +1,44 @@ +/* + * Copyright 2024 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.epam.ta.reportportal.ws.converter.converters; + +import com.epam.reportportal.api.model.Invitation; +import com.epam.reportportal.api.model.InvitationStatus; +import com.epam.ta.reportportal.entity.user.UserCreationBid; +import java.time.temporal.ChronoUnit; +import java.util.UUID; +import java.util.function.Function; + +public class InvitationConverter { + + private InvitationConverter() { + } + + public static final Function TO_INVITATION = bid -> { + var invitation = new Invitation(); + + invitation.setId(UUID.fromString(bid.getUuid())); + invitation.setEmail(bid.getEmail()); + invitation.setStatus(InvitationStatus.PENDING); + invitation.setCreatedAt(bid.getLastModified()); + invitation.setExpiresAt(bid.getLastModified().plus(1, ChronoUnit.DAYS)); + invitation.setUserId(bid.getInvitingUser().getId()); + invitation.setFullName(bid.getInvitingUser().getFullName()); + + return invitation; + }; +} diff --git a/src/test/java/com/epam/ta/reportportal/core/user/impl/GetUserHandlerImplTest.java b/src/test/java/com/epam/ta/reportportal/core/user/impl/GetUserHandlerImplTest.java index 5b6270cf32..9a9c5a5f2e 100644 --- a/src/test/java/com/epam/ta/reportportal/core/user/impl/GetUserHandlerImplTest.java +++ b/src/test/java/com/epam/ta/reportportal/core/user/impl/GetUserHandlerImplTest.java @@ -17,23 +17,20 @@ package com.epam.ta.reportportal.core.user.impl; import static com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser; -import static com.epam.ta.reportportal.core.user.impl.CreateUserHandlerImpl.INTERNAL_BID_TYPE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; +import com.epam.reportportal.rules.exception.ReportPortalException; import com.epam.ta.reportportal.dao.UserCreationBidRepository; import com.epam.ta.reportportal.dao.UserRepository; import com.epam.ta.reportportal.entity.organization.OrganizationRole; import com.epam.ta.reportportal.entity.project.ProjectRole; import com.epam.ta.reportportal.entity.user.User; import com.epam.ta.reportportal.entity.user.UserRole; -import com.epam.reportportal.rules.exception.ReportPortalException; import com.epam.ta.reportportal.model.YesNoRS; -import com.epam.ta.reportportal.model.user.UserBidRS; import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -78,18 +75,6 @@ void getNotExistedUserByLoggedInUser() { assertEquals("User 'not_exist' not found.", exception.getMessage()); } - @Test - void getEmptyBidInfo() { - String uuid = "uuid"; - - when(userCreationBidRepository.findByUuidAndType(uuid, INTERNAL_BID_TYPE)).thenReturn( - Optional.empty()); - - UserBidRS bidInformation = handler.getBidInformation(uuid); - assertFalse(bidInformation.getIsActive()); - assertNull(bidInformation.getEmail()); - assertNull(bidInformation.getUuid()); - } @Test void validateInfoByNotExistUsername() { diff --git a/src/test/java/com/epam/ta/reportportal/ws/controller/InvitationControllerTest.java b/src/test/java/com/epam/ta/reportportal/ws/controller/InvitationControllerTest.java index 4345dd68ab..6977e87628 100644 --- a/src/test/java/com/epam/ta/reportportal/ws/controller/InvitationControllerTest.java +++ b/src/test/java/com/epam/ta/reportportal/ws/controller/InvitationControllerTest.java @@ -19,6 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.epam.reportportal.api.model.Invitation; @@ -34,7 +36,6 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; class InvitationControllerTest extends BaseMvcTest { @@ -65,11 +66,11 @@ void createInvitationByAdmin() throws Exception { rq.setEmail("invitation@example.com"); rq.setOrganizations(organizations); - var result = mockMvc.perform(MockMvcRequestBuilders.post(INVITATIONS_ENDPOINT) + var result = mockMvc.perform(post(INVITATIONS_ENDPOINT) .content(objectMapper.writeValueAsBytes(rq)) .contentType(APPLICATION_JSON) .with(token(oAuthHelper.getSuperadminToken()))) - .andExpect(status().isOk()) + .andExpect(status().isCreated()) .andReturn() .getResponse().getContentAsString(); @@ -79,6 +80,17 @@ void createInvitationByAdmin() throws Exception { assertEquals(InvitationStatus.PENDING, invitation.getStatus()); + var storedInvitationString = mockMvc.perform(get(INVITATIONS_ENDPOINT + "/" + invitation.getId()) + .content(objectMapper.writeValueAsBytes(rq)) + .contentType(APPLICATION_JSON) + .with(token(oAuthHelper.getSuperadminToken()))) + .andExpect(status().isOk()) + .andReturn() + .getResponse().getContentAsString(); + var storedInvitation = objectMapper.readValue(storedInvitationString, Invitation.class); + + assertEquals(storedInvitation, invitation); + } @@ -104,7 +116,7 @@ void createInvitationNotEnoughPermissions() throws Exception { rq.setEmail("invitation@example.com"); rq.setOrganizations(organizations); - mockMvc.perform(MockMvcRequestBuilders.post(INVITATIONS_ENDPOINT) + mockMvc.perform(post(INVITATIONS_ENDPOINT) .content(objectMapper.writeValueAsBytes(rq)) .contentType(APPLICATION_JSON) .with(token(oAuthHelper.getDefaultToken()))) diff --git a/src/test/java/com/epam/ta/reportportal/ws/controller/UserControllerTest.java b/src/test/java/com/epam/ta/reportportal/ws/controller/UserControllerTest.java index 63b8b32ac5..6f910b45b9 100644 --- a/src/test/java/com/epam/ta/reportportal/ws/controller/UserControllerTest.java +++ b/src/test/java/com/epam/ta/reportportal/ws/controller/UserControllerTest.java @@ -219,11 +219,6 @@ void createUserPositive() throws Exception { assertTrue(userRepository.findById(createUserRS.getId()).isPresent()); } - @Test - void getUserBidInfoPositive() throws Exception { - mockMvc.perform(get(USERS_URL + "/registration?uuid=e5f98deb-8966-4b2d-ba2f-35bc69d30c06")) - .andExpect(status().isOk()); - } @Test void deleteUserNegative() throws Exception {