diff --git a/src/main/java/io/hexlet/typoreporter/controller/WorkspaceSettingsController.java b/src/main/java/io/hexlet/typoreporter/controller/WorkspaceSettingsController.java index 1802aadb..b7b95b0a 100644 --- a/src/main/java/io/hexlet/typoreporter/controller/WorkspaceSettingsController.java +++ b/src/main/java/io/hexlet/typoreporter/controller/WorkspaceSettingsController.java @@ -167,7 +167,9 @@ public String deleteAllowedUrl(Model model, @GetMapping("/integration") @PreAuthorize(IS_USER_RELATED_TO_WKS) public String getWorkspaceIntegrationPage(Model model, @PathVariable Long wksId, HttpServletRequest req) { - if (!workspaceService.existsWorkspaceById(wksId)) { + var wksOptional = workspaceService.getWorkspaceInfoById(wksId).orElse(null); + + if (wksOptional == null) { //TODO send to error page log.error("Workspace with id {} not found", wksId); return "redirect:/workspaces"; @@ -175,6 +177,9 @@ public String getWorkspaceIntegrationPage(Model model, @PathVariable Long wksId, addTokenAndUrlToModel(model, wksId, req); + model.addAttribute("wksInfo", wksOptional); + model.addAttribute("wksName", wksOptional.name()); + getStatisticDataToModel(model, wksId); getLastTypoDataToModel(model, wksId); diff --git a/src/test/java/io/hexlet/typoreporter/web/WorkspaceSettingsControllerIT.java b/src/test/java/io/hexlet/typoreporter/web/WorkspaceSettingsControllerIT.java index 61de04be..5a84838c 100644 --- a/src/test/java/io/hexlet/typoreporter/web/WorkspaceSettingsControllerIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/WorkspaceSettingsControllerIT.java @@ -83,18 +83,25 @@ static void datasourceProperties(DynamicPropertyRegistry registry) { @ParameterizedTest @MethodSource("io.hexlet.typoreporter.test.factory.EntitiesFactory#getWorkspacesAndUsersRelated") void getWorkspaceIntegrationPageIsSuccessful(final Long wksId, final String email) throws Exception { - final var apiAccessToken = workspaceSettingsRepository.getWorkspaceSettingsByWorkspaceId(wksId) + final var workspaces = workspaceSettingsRepository.getWorkspaceSettingsByWorkspaceId(wksId); + final var apiAccessToken = workspaces .map(s -> s.getId() + ":" + s.getApiAccessToken()) .map(String::getBytes) .map(Base64.getEncoder()::encodeToString) .orElse(null); + final var wksName = workspaces + .map(m -> m.getWorkspace().getName()) + .orElse(null); + MockHttpServletResponse response = mockMvc.perform(get("/workspace/{wksId}/integration", wksId.toString()) .with(user(email))) - .andExpect(model().attributeExists("wksBasicToken")) + .andExpect(model().attributeExists("wksBasicToken", "wksName")) .andReturn().getResponse(); assertThat(response.getContentAsString()).contains(apiAccessToken); + assertThat(response.getContentAsString()).contains(wksName); + } @ParameterizedTest @@ -213,4 +220,5 @@ void delAllowedUrlFromWorkspace() throws Exception { WORKSPACE_101_ID); assertThat(deletedAllowedUrlOptional).isEmpty(); } + }