Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
make return JSON_EXCEPTION for json_decode and json_encode
Signed-off-by: nabim777 <[email protected]>
  • Loading branch information
nabim777 committed Jun 10, 2024
commit df767f11186ac6abd8846b8d6b54bdbf0156f32b
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
4 changes: 3 additions & 1 deletion 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 = 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
36 changes: 19 additions & 17 deletions lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function now(): string {
/**
* @param string $userId
* @return array<mixed>
* @throws \JsonException
*/
public function getNotifications(string $userId): array {
$filters[] = [
Expand All @@ -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'])) {
Expand Down Expand Up @@ -258,7 +259,7 @@ public function searchWorkPackage(
* @param array<mixed> $filters
* @param bool $onlyLinkableWorkPackages
* @return array<mixed>
* @throws \OCP\PreConditionNotMetException
* @throws \OCP\PreConditionNotMetException|\JsonException
*/
private function searchRequest(string $userId, array $filters, bool $onlyLinkableWorkPackages = true): array {
$resultsById = [];
Expand All @@ -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);

Expand Down Expand Up @@ -697,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 @@ -712,6 +713,7 @@ public function getNode($userId, $fileId) {
* @throws OpenprojectResponseException
* @throws InvalidArgumentException
* @throws InvalidPathException
* @throws \JsonException
*
*/
public function linkWorkPackageToFile(
Expand Down Expand Up @@ -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'
);
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -1343,7 +1345,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 @@ -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'])) {
Expand All @@ -1378,10 +1380,10 @@ public function getAvailableOpenProjectProjects(string $userId): array {
* @param array<mixed> $body
*
* @return array<string,mixed>
* @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']);
Expand Down Expand Up @@ -1426,10 +1428,10 @@ public function getAvailableAssigneesOfAProject(string $userId, string $projectI
* @param array<mixed> $body
*
* @return array<mixed>
* @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']);
Expand All @@ -1450,7 +1452,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
9 changes: 6 additions & 3 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ public function testSearchWorkPackageRequestProblem() {

/**
* @return void
* @throws \JsonException
*/
public function testGetNotificationsRequest() {
$consumerRequest = new ConsumerRequest();
Expand All @@ -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();
Expand Down Expand Up @@ -1581,6 +1582,7 @@ public function testGetNode($nodeClassName) {

/**
* @return void
* @throws \JsonException
*/
public function testLinkWorkPackageToFileRequest(): void {
$service = $this->getServiceMock(['request', 'getNode']);
Expand All @@ -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(
Expand Down Expand Up @@ -1839,6 +1841,7 @@ public function testLinkWorkPackageToFileFileNotFound(): void {

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