diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index 02b9a6ab4..67ffce4d8 100755 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -383,6 +383,7 @@ private function setIntegrationConfig(array $values): array { } } $this->clearUserInfo($userUID); + $this->clearUserInfoForOIDCBasedAuth($userUID); }); } diff --git a/lib/Controller/OpenProjectAPIController.php b/lib/Controller/OpenProjectAPIController.php index 99f777873..8b2ceb1c2 100644 --- a/lib/Controller/OpenProjectAPIController.php +++ b/lib/Controller/OpenProjectAPIController.php @@ -126,11 +126,16 @@ public function getOpenProjectAvatar(string $userId = '', string $userName = '') * @return DataResponse */ public function getNotifications(): DataResponse { - if ($this->accessToken === '') { - return new DataResponse('', Http::STATUS_UNAUTHORIZED); - } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { - return new DataResponse('', Http::STATUS_BAD_REQUEST); - } + $user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user'); + if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' && + $user_value === '0' + ) { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { + return new DataResponse('', Http::STATUS_BAD_REQUEST); + } $result = $this->openprojectAPIService->getNotifications($this->userId); if (!isset($result['error'])) { $response = new DataResponse($result); @@ -237,11 +242,16 @@ public function linkWorkPackageToFile(array $values): DataResponse { * @return DataResponse */ public function markNotificationAsRead(int $workpackageId) { - if ($this->accessToken === '') { - return new DataResponse('', Http::STATUS_UNAUTHORIZED); - } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { - return new DataResponse('', Http::STATUS_BAD_REQUEST); - } + $user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user'); + if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' && + $user_value === '0' + ) { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { + return new DataResponse('', Http::STATUS_BAD_REQUEST); + } try { $result = $this->openprojectAPIService->markAllNotificationsOfWorkPackageAsRead( $workpackageId, @@ -334,11 +344,16 @@ public function deleteFileLink(int $id): DataResponse { * @return DataResponse */ public function getOpenProjectWorkPackageStatus(string $id): DataResponse { - if ($this->accessToken === '') { - return new DataResponse('', Http::STATUS_UNAUTHORIZED); - } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { - return new DataResponse('', Http::STATUS_BAD_REQUEST); - } + $user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user'); + if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' && + $user_value === '0' + ) { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { + return new DataResponse('', Http::STATUS_BAD_REQUEST); + } $result = $this->openprojectAPIService->getOpenProjectWorkPackageStatus( $this->userId, $id @@ -361,11 +376,16 @@ public function getOpenProjectWorkPackageStatus(string $id): DataResponse { * @return DataResponse */ public function getOpenProjectWorkPackageType(string $id): DataResponse { - if ($this->accessToken === '') { - return new DataResponse('', Http::STATUS_UNAUTHORIZED); - } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { - return new DataResponse('', Http::STATUS_BAD_REQUEST); - } + $user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user'); + if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' && + $user_value === '0' + ) { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { + return new DataResponse('', Http::STATUS_BAD_REQUEST); + } $result = $this->openprojectAPIService->getOpenProjectWorkPackageType( $this->userId, $id @@ -384,11 +404,16 @@ public function getOpenProjectWorkPackageType(string $id): DataResponse { * @return DataResponse */ public function getAvailableOpenProjectProjects(?string $searchQuery = null): DataResponse { - if ($this->accessToken === '') { - return new DataResponse('', Http::STATUS_UNAUTHORIZED); - } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { - return new DataResponse('', Http::STATUS_BAD_REQUEST); - } + $user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user'); + if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' && + $user_value === '0' + ) { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { + return new DataResponse('', Http::STATUS_BAD_REQUEST); + } try { $result = $this->openprojectAPIService->getAvailableOpenProjectProjects($this->userId, $searchQuery); } catch (OpenprojectErrorException $e) { @@ -436,11 +461,16 @@ public function getAvailableOpenProjectProjects(?string $searchQuery = null): Da * @return DataResponse */ public function getOpenProjectWorkPackageForm(string $projectId, array $body): DataResponse { - if ($this->accessToken === '') { - return new DataResponse('', Http::STATUS_UNAUTHORIZED); - } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { - return new DataResponse('', Http::STATUS_BAD_REQUEST); - } + $user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user'); + if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' && + $user_value === '0' + ) { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { + return new DataResponse('', Http::STATUS_BAD_REQUEST); + } try { $result = $this->openprojectAPIService->getOpenProjectWorkPackageForm($this->userId, $projectId, $body); } catch (OpenprojectErrorException $e) { @@ -458,11 +488,16 @@ public function getOpenProjectWorkPackageForm(string $projectId, array $body): D * @return DataResponse */ public function getAvailableAssigneesOfAProject(string $projectId): DataResponse { - if ($this->accessToken === '') { - return new DataResponse('', Http::STATUS_UNAUTHORIZED); - } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { - return new DataResponse('', Http::STATUS_BAD_REQUEST); - } + $user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user'); + if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' && + $user_value === '0' + ) { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { + return new DataResponse('', Http::STATUS_BAD_REQUEST); + } try { $result = $this->openprojectAPIService->getAvailableAssigneesOfAProject($this->userId, $projectId); } catch (OpenprojectErrorException $e) { @@ -507,11 +542,16 @@ public function getAvailableAssigneesOfAProject(string $projectId): DataResponse * @return DataResponse */ public function createWorkPackage(array $body): DataResponse { - if ($this->accessToken === '') { - return new DataResponse('', Http::STATUS_UNAUTHORIZED); - } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { - return new DataResponse('', Http::STATUS_BAD_REQUEST); - } + $user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user'); + if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' && + $user_value === '0' + ) { + return new DataResponse('', Http::STATUS_UNAUTHORIZED); + } elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) { + return new DataResponse('', Http::STATUS_BAD_REQUEST); + } // we don't want to check if all the data in the body is set or not because // that calculation will be done by the openproject api itself // we don't want to duplicate the logic diff --git a/lib/Dashboard/OpenProjectWidget.php b/lib/Dashboard/OpenProjectWidget.php index 04bd475d7..7f9ee9176 100644 --- a/lib/Dashboard/OpenProjectWidget.php +++ b/lib/Dashboard/OpenProjectWidget.php @@ -123,6 +123,10 @@ public function load(): void { $this->config->deleteUserValue( $this->user->getUID(), Application::APP_ID, 'oauth_connection_result' ); + $adminConfigStatusOIDC = OpenProjectAPIService::isAdminConfigOkForOIDCAuth($this->config); + $this->initialStateService->provideInitialState('admin-config-status-oidc', $adminConfigStatusOIDC); + $authenticationMethodActive = $this->config->getAppValue(Application::APP_ID, 'authentication_method', ''); + $this->initialStateService->provideInitialState('auth_method', $authenticationMethodActive); $this->initialStateService->provideInitialState( 'oauth-connection-result', $oauthConnectionResult ); diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index b6fe9f791..9a12ea9e3 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -831,7 +831,6 @@ export default { }, methods: { init() { - console.log(this.state) if (this.state) { if (this.state.all_terms_of_services_signed === false) { this.isAllTermsOfServiceSignedForUserOpenProject = false diff --git a/src/components/OAuthConnectButton.vue b/src/components/OAuthConnectButton.vue index 0cd009de9..50f1cd714 100644 --- a/src/components/OAuthConnectButton.vue +++ b/src/components/OAuthConnectButton.vue @@ -76,7 +76,6 @@ export default { }, async onOAuthClick() { if (this.isAuthMethod === 'oidc') { - console.log('Handle connect button for the oidc authentication flow!') const url = generateUrl('/apps/integration_openproject/config') const req = { values: { @@ -85,7 +84,6 @@ export default { } const response = await axios.put(url, req) if (response.status === 200) { - console.log('Yes its 200') window.location.reload() } diff --git a/src/components/PersonalSettings.vue b/src/components/PersonalSettings.vue index 4e464475c..7a9b209ee 100644 --- a/src/components/PersonalSettings.vue +++ b/src/components/PersonalSettings.vue @@ -94,9 +94,6 @@ export default { }) }, }, - created() { - console.log(this.state) - }, mounted() { checkOauthConnectionResult(this.oauthConnectionResult, this.oauthConnectionErrorMessage) diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index 0f71b5b3f..5e124eae3 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -9,8 +9,9 @@ + :is-admin-config-ok="isAdminConfigOk || isAdminConfigOkOIDC" /> @@ -47,6 +48,8 @@ export default { oauthConnectionErrorMessage: loadState('integration_openproject', 'oauth-connection-error-message'), oauthConnectionResult: loadState('integration_openproject', 'oauth-connection-result'), isAdminConfigOk: loadState('integration_openproject', 'admin-config-status'), + isAdminConfigOkOIDC: loadState('integration_openproject', 'admin-config-status-oidc'), + authMethod: loadState('integration_openproject', 'auth_method'), settingsUrl: generateUrl('/settings/user/openproject'), themingColor: OCA.Theming ? OCA.Theming.color.replace('#', '') : '0082C9', windowVisibility: true, @@ -128,7 +131,11 @@ export default { clearInterval(this.loop) }, async launchLoop() { - if (!this.isAdminConfigOk) { + if (this.authMethod === 'oidc' && !this.isAdminConfigOkOIDC) { + this.state = STATE.ERROR + return + } + if (this.authMethod === 'oauth2' && !this.isAdminConfigOk) { this.state = STATE.ERROR return } diff --git a/src/views/LinkMultipleFilesModal.vue b/src/views/LinkMultipleFilesModal.vue index 3f5ebe4c4..8db4f3ed0 100644 --- a/src/views/LinkMultipleFilesModal.vue +++ b/src/views/LinkMultipleFilesModal.vue @@ -48,7 +48,7 @@

{{ t('integration-openproject', 'Link to work package') }}

- + :is-admin-config-ok="isAdminConfigOk || isAdminConfigOkOIDC" /> @@ -106,6 +107,8 @@ export default { fileInfos: [], alreadyLinkedWorkPackage: [], isAdminConfigOk: loadState('integration_openproject', 'admin-config-status'), + isAdminConfigOkOIDC: loadState('integration_openproject', 'admin-config-status-oidc'), + authMethod: loadState('integration_openproject', 'auth_method'), oauthConnectionErrorMessage: loadState('integration_openproject', 'oauth-connection-error-message'), oauthConnectionResult: loadState('integration_openproject', 'oauth-connection-result'), searchOrigin: WORKPACKAGES_SEARCH_ORIGIN.LINK_MULTIPLE_FILES_MODAL, @@ -170,7 +173,7 @@ export default { }, async setFileInfos(fileInfos) { this.fileInfos = fileInfos - if (this.isAdminConfigOk) { + if (this.isAdminConfigOk || this.isAdminConfigOkOIDC) { await this.fetchWorkpackagesForSingleFileSelected(this.fileInfos[0].id) } else { this.state = STATE.ERROR diff --git a/src/views/ProjectsTab.vue b/src/views/ProjectsTab.vue index 4d2487347..27737cfd5 100644 --- a/src/views/ProjectsTab.vue +++ b/src/views/ProjectsTab.vue @@ -23,7 +23,7 @@