From cc8b72263a3fdd5d6d62021875fd2cb43b7a76fe Mon Sep 17 00:00:00 2001 From: nabim777 Date: Thu, 6 Jun 2024 12:45:10 +0545 Subject: [PATCH 1/3] add support for integration_app in nextcloud master Signed-off-by: nabim777 --- .github/workflows/shared_workflow.yml | 8 ++++++-- appinfo/info.xml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/shared_workflow.yml b/.github/workflows/shared_workflow.yml index a6ba36f75..260e70c1b 100644 --- a/.github/workflows/shared_workflow.yml +++ b/.github/workflows/shared_workflow.yml @@ -11,13 +11,15 @@ jobs: name: unit tests and linting strategy: matrix: - nextcloudVersion: [ stable26, stable27, stable28, stable29 ] + nextcloudVersion: [ stable26, stable27, stable28, stable29, master ] phpVersion: [ 8.0, 8.1, 8.2, 8.3] exclude: - nextcloudVersion: stable26 phpVersion: 8.3 - nextcloudVersion: stable27 phpVersion: 8.3 + - nextcloudVersion: master + phpVersion: 8.0 runs-on: ubuntu-20.04 steps: - name: Checkout for nightly CI @@ -161,7 +163,7 @@ jobs: name: API tests strategy: matrix: - nextcloudVersion: [ stable26, stable27, stable28, stable29 ] + nextcloudVersion: [ stable26, stable27, stable28, stable29, master ] phpVersionMajor: [ 8 ] phpVersionMinor: [ 0, 1, 2, 3 ] database: [pgsql, mysql] @@ -172,6 +174,8 @@ jobs: phpVersionMinor: 3 - nextcloudVersion: stable27 phpVersionMinor: 3 + - nextcloudVersion: master + phpVersionMinor: 0 - isScheduledEventNightly: false phpVersionMinor: 0 - isScheduledEventNightly: false diff --git a/appinfo/info.xml b/appinfo/info.xml index fec6a43d6..db09aff8b 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -41,7 +41,7 @@ For more information on how to set up and use the OpenProject application, pleas https://github.com/nextcloud/integration_openproject/raw/master/img/screenshot1.png https://github.com/nextcloud/integration_openproject/raw/master/img/screenshot2.png - + OCA\OpenProject\BackgroundJob\RemoveExpiredDirectUploadTokens From a86283d74b8871d357dd8196bbbf21e43426e56b Mon Sep 17 00:00:00 2001 From: nabim777 Date: Thu, 6 Jun 2024 17:18:09 +0545 Subject: [PATCH 2/3] remove safe as there is removed of thecodingmachine module Signed-off-by: nabim777 --- lib/Controller/ConfigController.php | 6 ++--- lib/Service/OpenProjectAPIService.php | 24 ++++++++----------- .../Controller/DirectUploadControllerTest.php | 4 ++-- .../lib/Service/OpenProjectAPIServiceTest.php | 6 ++--- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index 724d1c72e..477aeebb7 100755 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -407,7 +407,7 @@ public function oauthRedirect(string $code = '', string $state = ''): RedirectRe ); try { - $oauthJourneyStartingPageDecoded = \Safe\json_decode($oauthJourneyStartingPage); + $oauthJourneyStartingPageDecoded = json_decode($oauthJourneyStartingPage); if ($oauthJourneyStartingPageDecoded->page === 'dashboard') { $newUrl = $this->urlGenerator->linkToRoute('dashboard.dashboard.index'); @@ -438,12 +438,12 @@ public function oauthRedirect(string $code = '', string $state = ''): RedirectRe $validCodeVerifier = false; if (is_string($codeVerifier)) { - $validCodeVerifier = (\Safe\preg_match('/^[A-Za-z0-9\-._~]{43,128}$/', $codeVerifier) === 1); + $validCodeVerifier = (preg_match('/^[A-Za-z0-9\-._~]{43,128}$/', $codeVerifier) === 1); } $validClientSecret = false; if (is_string($clientSecret)) { - $validClientSecret = (\Safe\preg_match('/^.{10,}$/', $clientSecret) === 1); + $validClientSecret = (preg_match('/^.{10,}$/', $clientSecret) === 1); } if ($clientID && $validClientSecret && $validCodeVerifier && $configState !== '' && $configState === $state) { diff --git a/lib/Service/OpenProjectAPIService.php b/lib/Service/OpenProjectAPIService.php index 0fd5e7fde..7a1fb40be 100644 --- a/lib/Service/OpenProjectAPIService.php +++ b/lib/Service/OpenProjectAPIService.php @@ -53,7 +53,6 @@ use OCP\Security\ISecureRandom; use OCP\Server; use Psr\Log\LoggerInterface; -use Safe\Exceptions\JsonException; define('CACHE_TTL', 3600); @@ -189,7 +188,7 @@ public function getNotifications(string $userId): array { $params = [ 'pageSize' => -1, - 'filters' => \Safe\json_encode($filters) + 'filters' => json_encode($filters) ]; $result = $this->request($userId, 'notifications', $params); if (isset($result['error'])) { @@ -222,7 +221,6 @@ public function getBaseUrl(): string { * @param bool $onlyLinkableWorkPackages * @return array * @throws \OCP\PreConditionNotMetException - * @throws \Safe\Exceptions\JsonException */ public function searchWorkPackage( string $userId, @@ -261,7 +259,6 @@ public function searchWorkPackage( * @param bool $onlyLinkableWorkPackages * @return array * @throws \OCP\PreConditionNotMetException - * @throws \Safe\Exceptions\JsonException */ private function searchRequest(string $userId, array $filters, bool $onlyLinkableWorkPackages = true): array { $resultsById = []; @@ -274,8 +271,8 @@ private function searchRequest(string $userId, array $filters, bool $onlyLinkabl } $params = [ - 'filters' => \Safe\json_encode($filters), - 'sortBy' => \Safe\json_encode($sortBy), + 'filters' => json_encode($filters), + 'sortBy' => json_encode($sortBy), ]; $searchResult = $this->request($userId, 'work_packages', $params); @@ -772,7 +769,7 @@ public function linkWorkPackageToFile( ] ]; - $params['body'] = \Safe\json_encode($body); + $params['body'] = json_encode($body); $result = $this->request( $userId, 'work_packages/' . $values["workpackageId"] . '/file_links', $params, 'POST' ); @@ -804,7 +801,6 @@ public function linkWorkPackageToFile( /** * @throws OpenprojectErrorException * @throws PreConditionNotMetException - * @throws JsonException * @throws Exception * @return array */ @@ -816,7 +812,7 @@ public function markAllNotificationsOfWorkPackageAsRead( ['operator' => '=', 'values' => [(string)$workpackageId]] ]; $params['body'] = ''; - $fullUrl = 'notifications/read_ian?filters=' . urlencode(\Safe\json_encode($filters)); + $fullUrl = 'notifications/read_ian?filters=' . urlencode(json_encode($filters)); $result = $this->request( $userId, $fullUrl, $params, 'POST' @@ -1358,7 +1354,7 @@ public function getAvailableOpenProjectProjects(string $userId): array { ['operator' => '&=', 'values' => ["file_links/manage", "work_packages/create"]] ]; $params = [ - 'filters' => \Safe\json_encode($filters) + 'filters' => json_encode($filters) ]; $result = $this->request($userId, 'work_packages/available_projects', $params); if (isset($result['error'])) { @@ -1382,10 +1378,10 @@ public function getAvailableOpenProjectProjects(string $userId): array { * @param array $body * * @return array - * @throws OpenprojectResponseException|PreConditionNotMetException|JsonException|OpenprojectErrorException + * @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException */ public function getOpenProjectWorkPackageForm(string $userId, string $projectId, array $body): array { - $params['body'] = \Safe\json_encode($body); + $params['body'] = json_encode($body); $result = $this->request($userId, 'projects/'.$projectId.'/work_packages/form', $params, 'POST'); if (isset($result['error'])) { throw new OpenprojectErrorException($result['error'], $result['statusCode']); @@ -1430,10 +1426,10 @@ public function getAvailableAssigneesOfAProject(string $userId, string $projectI * @param array $body * * @return array - * @throws OpenprojectResponseException|PreConditionNotMetException|JsonException|OpenprojectErrorException + * @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException */ public function createWorkPackage(string $userId, array $body): array { - $params['body'] = \Safe\json_encode($body); + $params['body'] = json_encode($body); $result = $this->request($userId, 'work_packages', $params, 'POST'); if (isset($result['error'])) { throw new OpenprojectErrorException($result['error'], $result['statusCode']); diff --git a/tests/lib/Controller/DirectUploadControllerTest.php b/tests/lib/Controller/DirectUploadControllerTest.php index 409a8d339..d1c9976f5 100644 --- a/tests/lib/Controller/DirectUploadControllerTest.php +++ b/tests/lib/Controller/DirectUploadControllerTest.php @@ -197,7 +197,7 @@ public function testDirectUploadException( ):void { $nodeMock = $this->getNodeMock('folder'); $tmpFileName = '/tmp/integration_openproject_unit_test'; - \Safe\touch($tmpFileName); + touch($tmpFileName); $nodeMock[0]->method('newFile')->will($this->throwException($exception)); $userFolderMock = $this->getMockBuilder('\OCP\Files\Folder')->getMock(); $userFolderMock->method('getById')->willReturn($nodeMock); @@ -219,7 +219,7 @@ public function testNegativeFreeSpace(): void { $fileMock->method('getId')->willReturn(123); $nodeMock = $this->getNodeMock('folder'); $tmpFileName = '/tmp/integration_openproject_unit_test'; - \Safe\touch($tmpFileName); + touch($tmpFileName); $nodeMock[0]->method('getFreeSpace')->willReturn(-3); $nodeMock[0]->method('newFile')->willReturn($fileMock); $userFolderMock = $this->getMockBuilder('\OCP\Files\Folder')->getMock(); diff --git a/tests/lib/Service/OpenProjectAPIServiceTest.php b/tests/lib/Service/OpenProjectAPIServiceTest.php index ef39df837..f954d4378 100644 --- a/tests/lib/Service/OpenProjectAPIServiceTest.php +++ b/tests/lib/Service/OpenProjectAPIServiceTest.php @@ -976,7 +976,7 @@ public function testGetNotificationsRequest() { $consumerRequest ->setMethod('GET') ->setPath($this->notificationsPath) - ->setQuery("pageSize=-1&filters=" . \Safe\json_encode([[ + ->setQuery("pageSize=-1&filters=" . json_encode([[ 'readIAN' => ['operator' => '=', 'values' => ['f']] ]])) @@ -1594,7 +1594,7 @@ public function testLinkWorkPackageToFileRequest(): void { ->method('request') ->with( 'user', 'work_packages/123/file_links', - ['body' => \Safe\json_encode($this->validFileLinkRequestBody)] + ['body' => json_encode($this->validFileLinkRequestBody)] ); $values = $this->singleFileInformation; $result = $service->linkWorkPackageToFile( @@ -1852,7 +1852,7 @@ public function testLinkWorkPackageToMultipleFileRequest(): void { ->method('request') ->with( 'user', 'work_packages/123/file_links', - ['body' => \Safe\json_encode($this->validFileLinkRequestBodyForMultipleFiles)] + ['body' => json_encode($this->validFileLinkRequestBodyForMultipleFiles)] ); $values = $this->multipleFileInformation; $result = $service->linkWorkPackageToFile( From df767f11186ac6abd8846b8d6b54bdbf0156f32b Mon Sep 17 00:00:00 2001 From: nabim777 Date: Fri, 7 Jun 2024 17:34:24 +0545 Subject: [PATCH 3/3] make return JSON_EXCEPTION for json_decode and json_encode Signed-off-by: nabim777 --- CHANGELOG.md | 2 ++ lib/Controller/ConfigController.php | 4 ++- lib/Service/OpenProjectAPIService.php | 36 ++++++++++--------- .../lib/Service/OpenProjectAPIServiceTest.php | 9 +++-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a44b2e4f9..d05c23f0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed +- Add application's support for Nextcloud 30 ## 2.6.3 - 2024-04-17 ### Changed diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index 477aeebb7..e24b209e3 100755 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -388,12 +388,14 @@ public function setAdminConfig(array $values): DataResponse { /** * receive oauth code and get oauth access token + * * @NoAdminRequired * @NoCSRFRequired * * @param string $code * @param string $state * @return RedirectResponse + * @throws PreConditionNotMetException */ public function oauthRedirect(string $code = '', string $state = ''): RedirectResponse { $configState = $this->config->getUserValue($this->userId, Application::APP_ID, 'oauth_state'); @@ -407,7 +409,7 @@ public function oauthRedirect(string $code = '', string $state = ''): RedirectRe ); try { - $oauthJourneyStartingPageDecoded = json_decode($oauthJourneyStartingPage); + $oauthJourneyStartingPageDecoded = json_decode($oauthJourneyStartingPage, false, 512, JSON_THROW_ON_ERROR); if ($oauthJourneyStartingPageDecoded->page === 'dashboard') { $newUrl = $this->urlGenerator->linkToRoute('dashboard.dashboard.index'); diff --git a/lib/Service/OpenProjectAPIService.php b/lib/Service/OpenProjectAPIService.php index 7a1fb40be..64dfc0f5d 100644 --- a/lib/Service/OpenProjectAPIService.php +++ b/lib/Service/OpenProjectAPIService.php @@ -179,6 +179,7 @@ public function now(): string { /** * @param string $userId * @return array + * @throws \JsonException */ public function getNotifications(string $userId): array { $filters[] = [ @@ -188,7 +189,7 @@ public function getNotifications(string $userId): array { $params = [ 'pageSize' => -1, - 'filters' => json_encode($filters) + 'filters' => json_encode($filters, JSON_THROW_ON_ERROR) ]; $result = $this->request($userId, 'notifications', $params); if (isset($result['error'])) { @@ -258,7 +259,7 @@ public function searchWorkPackage( * @param array $filters * @param bool $onlyLinkableWorkPackages * @return array - * @throws \OCP\PreConditionNotMetException + * @throws \OCP\PreConditionNotMetException|\JsonException */ private function searchRequest(string $userId, array $filters, bool $onlyLinkableWorkPackages = true): array { $resultsById = []; @@ -271,8 +272,8 @@ private function searchRequest(string $userId, array $filters, bool $onlyLinkabl } $params = [ - 'filters' => json_encode($filters), - 'sortBy' => json_encode($sortBy), + 'filters' => json_encode($filters, JSON_THROW_ON_ERROR), + 'sortBy' => json_encode($sortBy, JSON_THROW_ON_ERROR), ]; $searchResult = $this->request($userId, 'work_packages', $params); @@ -697,10 +698,10 @@ public function getNode($userId, $fileId) { /** * * @param array $values An array containing the following keys: - * - "workpackageId" (int): The ID of the work package. - * - "fileinfo" (array): An array of file information with the following keys: - * - "id" (int): File id of the file - * - "name" (string): Name of the file + * - "workpackageId" (int): The ID of the work package. + * - "fileinfo" (array): An array of file information with the following keys: + * - "id" (int): File id of the file + * - "name" (string): Name of the file * @param string $userId * * @return array @@ -712,6 +713,7 @@ public function getNode($userId, $fileId) { * @throws OpenprojectResponseException * @throws InvalidArgumentException * @throws InvalidPathException + * @throws \JsonException * */ public function linkWorkPackageToFile( @@ -769,7 +771,7 @@ public function linkWorkPackageToFile( ] ]; - $params['body'] = json_encode($body); + $params['body'] = json_encode($body, JSON_THROW_ON_ERROR); $result = $this->request( $userId, 'work_packages/' . $values["workpackageId"] . '/file_links', $params, 'POST' ); @@ -812,7 +814,7 @@ public function markAllNotificationsOfWorkPackageAsRead( ['operator' => '=', 'values' => [(string)$workpackageId]] ]; $params['body'] = ''; - $fullUrl = 'notifications/read_ian?filters=' . urlencode(json_encode($filters)); + $fullUrl = 'notifications/read_ian?filters=' . urlencode(json_encode($filters, JSON_THROW_ON_ERROR)); $result = $this->request( $userId, $fullUrl, $params, 'POST' @@ -1343,7 +1345,7 @@ public function getLinkToOpenProject(array $entry, string $url): string { * @return array * * @throws OpenprojectErrorException - * @throws OpenprojectResponseException|PreConditionNotMetException + * @throws OpenprojectResponseException|PreConditionNotMetException|\JsonException */ public function getAvailableOpenProjectProjects(string $userId): array { $resultsById = []; @@ -1354,7 +1356,7 @@ public function getAvailableOpenProjectProjects(string $userId): array { ['operator' => '&=', 'values' => ["file_links/manage", "work_packages/create"]] ]; $params = [ - 'filters' => json_encode($filters) + 'filters' => json_encode($filters, JSON_THROW_ON_ERROR) ]; $result = $this->request($userId, 'work_packages/available_projects', $params); if (isset($result['error'])) { @@ -1378,10 +1380,10 @@ public function getAvailableOpenProjectProjects(string $userId): array { * @param array $body * * @return array - * @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException + * @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException|\JsonException */ public function getOpenProjectWorkPackageForm(string $userId, string $projectId, array $body): array { - $params['body'] = json_encode($body); + $params['body'] = json_encode($body, JSON_THROW_ON_ERROR); $result = $this->request($userId, 'projects/'.$projectId.'/work_packages/form', $params, 'POST'); if (isset($result['error'])) { throw new OpenprojectErrorException($result['error'], $result['statusCode']); @@ -1426,10 +1428,10 @@ public function getAvailableAssigneesOfAProject(string $userId, string $projectI * @param array $body * * @return array - * @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException + * @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException|\JsonException */ public function createWorkPackage(string $userId, array $body): array { - $params['body'] = json_encode($body); + $params['body'] = json_encode($body, JSON_THROW_ON_ERROR); $result = $this->request($userId, 'work_packages', $params, 'POST'); if (isset($result['error'])) { throw new OpenprojectErrorException($result['error'], $result['statusCode']); @@ -1450,7 +1452,7 @@ public function createWorkPackage(string $userId, array $body): array { * * @return array * @throws OpenprojectErrorException - * @throws OpenprojectResponseException + * @throws OpenprojectResponseException|PreConditionNotMetException */ public function getOpenProjectConfiguration(string $userId): array { $result = $this->request( diff --git a/tests/lib/Service/OpenProjectAPIServiceTest.php b/tests/lib/Service/OpenProjectAPIServiceTest.php index f954d4378..108815a18 100644 --- a/tests/lib/Service/OpenProjectAPIServiceTest.php +++ b/tests/lib/Service/OpenProjectAPIServiceTest.php @@ -970,6 +970,7 @@ public function testSearchWorkPackageRequestProblem() { /** * @return void + * @throws \JsonException */ public function testGetNotificationsRequest() { $consumerRequest = new ConsumerRequest(); @@ -979,7 +980,7 @@ public function testGetNotificationsRequest() { ->setQuery("pageSize=-1&filters=" . json_encode([[ 'readIAN' => ['operator' => '=', 'values' => ['f']] - ]])) + ]], JSON_THROW_ON_ERROR)) ->setHeaders(["Authorization" => "Bearer 1234567890"]); $providerResponse = new ProviderResponse(); @@ -1581,6 +1582,7 @@ public function testGetNode($nodeClassName) { /** * @return void + * @throws \JsonException */ public function testLinkWorkPackageToFileRequest(): void { $service = $this->getServiceMock(['request', 'getNode']); @@ -1594,7 +1596,7 @@ public function testLinkWorkPackageToFileRequest(): void { ->method('request') ->with( 'user', 'work_packages/123/file_links', - ['body' => json_encode($this->validFileLinkRequestBody)] + ['body' => json_encode($this->validFileLinkRequestBody, JSON_THROW_ON_ERROR)] ); $values = $this->singleFileInformation; $result = $service->linkWorkPackageToFile( @@ -1839,6 +1841,7 @@ public function testLinkWorkPackageToFileFileNotFound(): void { /** * @return void + * @throws \JsonException */ public function testLinkWorkPackageToMultipleFileRequest(): void { $service = $this->getServiceMock(['request', 'getNode']); @@ -1852,7 +1855,7 @@ public function testLinkWorkPackageToMultipleFileRequest(): void { ->method('request') ->with( 'user', 'work_packages/123/file_links', - ['body' => json_encode($this->validFileLinkRequestBodyForMultipleFiles)] + ['body' => json_encode($this->validFileLinkRequestBodyForMultipleFiles, JSON_THROW_ON_ERROR)] ); $values = $this->multipleFileInformation; $result = $service->linkWorkPackageToFile(