Skip to content

Commit

Permalink
[Backport] support nextcloud30 and remove safe (#653)
Browse files Browse the repository at this point in the history
* add support for integration_app in nextcloud master

Signed-off-by: nabim777 <nabinalemagar019@gmail.com>

* remove safe as there is removed of thecodingmachine module

Signed-off-by: nabim777 <nabinalemagar019@gmail.com>

* make return JSON_EXCEPTION for json_decode and json_encode

Signed-off-by: nabim777 <nabinalemagar019@gmail.com>

---------

Signed-off-by: nabim777 <nabinalemagar019@gmail.com>
  • Loading branch information
nabim777 authored Jun 11, 2024
1 parent 3e004d3 commit 4b7b465
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 33 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/shared_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -161,7 +163,7 @@ jobs:
name: API tests
strategy:
matrix:
nextcloudVersion: [ stable26, stable27, stable28, stable29 ]
nextcloudVersion: [ stable26, stable27, stable28, stable29, master ]
phpVersionMajor: [ 8 ]
phpVersionMinor: [ 2 ]
database: [pgsql, mysql]
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ For more information on how to set up and use the OpenProject application, pleas
<screenshot>https://github.com/nextcloud/integration_openproject/raw/master/img/screenshot1.png</screenshot>
<screenshot>https://github.com/nextcloud/integration_openproject/raw/master/img/screenshot2.png</screenshot>
<dependencies>
<nextcloud min-version="26" max-version="29" />
<nextcloud min-version="26" max-version="30" />
</dependencies>
<background-jobs>
<job>OCA\OpenProject\BackgroundJob\RemoveExpiredDirectUploadTokens</job>
Expand Down
8 changes: 5 additions & 3 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -407,7 +409,7 @@ public function oauthRedirect(string $code = '', string $state = ''): RedirectRe
);

try {
$oauthJourneyStartingPageDecoded = \Safe\json_decode($oauthJourneyStartingPage);
$oauthJourneyStartingPageDecoded = json_decode($oauthJourneyStartingPage, false, 512, JSON_THROW_ON_ERROR);

if ($oauthJourneyStartingPageDecoded->page === 'dashboard') {
$newUrl = $this->urlGenerator->linkToRoute('dashboard.dashboard.index');
Expand Down Expand Up @@ -438,12 +440,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) {
Expand Down
40 changes: 19 additions & 21 deletions lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
use OCP\Security\ISecureRandom;
use OCP\Server;
use Psr\Log\LoggerInterface;
use Safe\Exceptions\JsonException;

define('CACHE_TTL', 3600);

Expand Down Expand Up @@ -180,6 +179,7 @@ public function now(): string {
/**
* @param string $userId
* @return array<mixed>
* @throws \JsonException
*/
public function getNotifications(string $userId): array {
$filters[] = [
Expand All @@ -189,7 +189,7 @@ public function getNotifications(string $userId): array {

$params = [
'pageSize' => -1,
'filters' => \Safe\json_encode($filters)
'filters' => json_encode($filters, JSON_THROW_ON_ERROR)
];
$result = $this->request($userId, 'notifications', $params);
if (isset($result['error'])) {
Expand Down Expand Up @@ -222,7 +222,6 @@ public function getBaseUrl(): string {
* @param bool $onlyLinkableWorkPackages
* @return array<mixed>
* @throws \OCP\PreConditionNotMetException
* @throws \Safe\Exceptions\JsonException
*/
public function searchWorkPackage(
string $userId,
Expand Down Expand Up @@ -260,8 +259,7 @@ public function searchWorkPackage(
* @param array<mixed> $filters
* @param bool $onlyLinkableWorkPackages
* @return array<mixed>
* @throws \OCP\PreConditionNotMetException
* @throws \Safe\Exceptions\JsonException
* @throws \OCP\PreConditionNotMetException|\JsonException
*/
private function searchRequest(string $userId, array $filters, bool $onlyLinkableWorkPackages = true): array {
$resultsById = [];
Expand All @@ -274,8 +272,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, JSON_THROW_ON_ERROR),
'sortBy' => json_encode($sortBy, JSON_THROW_ON_ERROR),
];
$searchResult = $this->request($userId, 'work_packages', $params);

Expand Down Expand Up @@ -700,10 +698,10 @@ public function getNode($userId, $fileId) {
/**
*
* @param array<mixed> $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<int>
Expand All @@ -715,6 +713,7 @@ public function getNode($userId, $fileId) {
* @throws OpenprojectResponseException
* @throws InvalidArgumentException
* @throws InvalidPathException
* @throws \JsonException
*
*/
public function linkWorkPackageToFile(
Expand Down Expand Up @@ -772,7 +771,7 @@ public function linkWorkPackageToFile(
]
];

$params['body'] = \Safe\json_encode($body);
$params['body'] = json_encode($body, JSON_THROW_ON_ERROR);
$result = $this->request(
$userId, 'work_packages/' . $values["workpackageId"] . '/file_links', $params, 'POST'
);
Expand Down Expand Up @@ -804,7 +803,6 @@ public function linkWorkPackageToFile(
/**
* @throws OpenprojectErrorException
* @throws PreConditionNotMetException
* @throws JsonException
* @throws Exception
* @return array<mixed>
*/
Expand All @@ -816,7 +814,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, JSON_THROW_ON_ERROR));

$result = $this->request(
$userId, $fullUrl, $params, 'POST'
Expand Down Expand Up @@ -1370,7 +1368,7 @@ public function getLinkToOpenProject(array $entry, string $url): string {
* @return array<mixed>
*
* @throws OpenprojectErrorException
* @throws OpenprojectResponseException|PreConditionNotMetException
* @throws OpenprojectResponseException|PreConditionNotMetException|\JsonException
*/
public function getAvailableOpenProjectProjects(string $userId): array {
$resultsById = [];
Expand All @@ -1381,7 +1379,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, JSON_THROW_ON_ERROR)
];
$result = $this->request($userId, 'work_packages/available_projects', $params);
if (isset($result['error'])) {
Expand All @@ -1405,10 +1403,10 @@ public function getAvailableOpenProjectProjects(string $userId): array {
* @param array<mixed> $body
*
* @return array<string,mixed>
* @throws OpenprojectResponseException|PreConditionNotMetException|JsonException|OpenprojectErrorException
* @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException|\JsonException
*/
public function getOpenProjectWorkPackageForm(string $userId, string $projectId, array $body): array {
$params['body'] = \Safe\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']);
Expand Down Expand Up @@ -1453,10 +1451,10 @@ public function getAvailableAssigneesOfAProject(string $userId, string $projectI
* @param array<mixed> $body
*
* @return array<mixed>
* @throws OpenprojectResponseException|PreConditionNotMetException|JsonException|OpenprojectErrorException
* @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException|\JsonException
*/
public function createWorkPackage(string $userId, array $body): array {
$params['body'] = \Safe\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']);
Expand All @@ -1477,7 +1475,7 @@ public function createWorkPackage(string $userId, array $body): array {
*
* @return array<mixed>
* @throws OpenprojectErrorException
* @throws OpenprojectResponseException
* @throws OpenprojectResponseException|PreConditionNotMetException
*/
public function getOpenProjectConfiguration(string $userId): array {
$result = $this->request(
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Controller/DirectUploadControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -974,16 +974,17 @@ public function testSearchWorkPackageRequestProblem() {

/**
* @return void
* @throws \JsonException
*/
public function testGetNotificationsRequest() {
$consumerRequest = new ConsumerRequest();
$consumerRequest
->setMethod('GET')
->setPath($this->notificationsPath)
->setQuery("pageSize=-1&filters=" . \Safe\json_encode([[
->setQuery("pageSize=-1&filters=" . json_encode([[
'readIAN' =>
['operator' => '=', 'values' => ['f']]
]]))
]], JSON_THROW_ON_ERROR))
->setHeaders(["Authorization" => "Bearer 1234567890"]);

$providerResponse = new ProviderResponse();
Expand Down Expand Up @@ -1587,6 +1588,7 @@ public function testGetNode($nodeClassName) {

/**
* @return void
* @throws \JsonException
*/
public function testLinkWorkPackageToFileRequest(): void {
$service = $this->getServiceMock(['request', 'getNode']);
Expand All @@ -1600,7 +1602,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, JSON_THROW_ON_ERROR)]
);
$values = $this->singleFileInformation;
$result = $service->linkWorkPackageToFile(
Expand Down Expand Up @@ -1845,6 +1847,7 @@ public function testLinkWorkPackageToFileFileNotFound(): void {

/**
* @return void
* @throws \JsonException
*/
public function testLinkWorkPackageToMultipleFileRequest(): void {
$service = $this->getServiceMock(['request', 'getNode']);
Expand All @@ -1858,7 +1861,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, JSON_THROW_ON_ERROR)]
);
$values = $this->multipleFileInformation;
$result = $service->linkWorkPackageToFile(
Expand Down

0 comments on commit 4b7b465

Please sign in to comment.