Skip to content

Commit

Permalink
remove CSP listener
Browse files Browse the repository at this point in the history
Signed-off-by: Swikriti Tripathi <swikriti808@gmail.com>
  • Loading branch information
SwikritiT committed Oct 9, 2023
1 parent ccc4c76 commit b93fe67
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 82 deletions.
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
['name' => 'openProjectAPI#getOpenProjectOauthURLWithStateAndPKCE', 'url' => '/op-oauth-url', 'verb' => 'GET'],
['name' => 'openProjectAPI#getProjectFolderSetupStatus', 'url' => '/project-folder-status', 'verb' => 'GET'],
['name' => 'openProjectAPI#getAvailableOpenProjectProjects', 'url' => '/projects','verb' => 'GET'],
['name' => 'openProjectAPI#getOpenProjectWorkPackageForm', 'url' => '/projects/{id}/work-packages/form','verb' => 'POST'],
['name' => 'openProjectAPI#getAvailableAssignees', 'url' => '/projects/{id}/available-assignees','verb' => 'GET'],
['name' => 'openProjectAPI#getOpenProjectWorkPackageForm', 'url' => '/projects/{projectId}/work-packages/form','verb' => 'POST'],
['name' => 'openProjectAPI#getAvailableAssigneesOfAProject', 'url' => '/projects/{projectId}/available-assignees','verb' => 'GET'],
['name' => 'openProjectAPI#createWorkPackages', 'url' => '/create/work-packages','verb' => 'POST'],
],
'ocs' => [
Expand Down
13 changes: 7 additions & 6 deletions lib/Controller/OpenProjectAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,18 @@ public function getAvailableOpenProjectProjects(): DataResponse {
/**
* @NoAdminRequired
*
* @param string $id
* @param string $projectId
* @param array<mixed> $body body is same in the format that openproject api expects the body to be
* @return DataResponse
*/
public function getOpenProjectWorkPackageForm(string $id, array $body): 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);
}
try {
$result = $this->openprojectAPIService->getOpenProjectWorkPackageForm($this->userId, $id, $body);
$result = $this->openprojectAPIService->getOpenProjectWorkPackageForm($this->userId, $projectId, $body);
} catch (OpenprojectErrorException $e) {
return new DataResponse($e->getMessage(), $e->getcode());
} catch (\Exception $e) {
Expand All @@ -403,19 +403,20 @@ public function getOpenProjectWorkPackageForm(string $id, array $body): DataResp
}

/**
* @NoCSRFRequired
* @NoAdminRequired
*
* @param string $id
* @param string $projectId
* @return DataResponse
*/
public function getAvailableAssignees(string $id): 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);
}
try {
$result = $this->openprojectAPIService->getAvailableAssignees($this->userId, $id);
$result = $this->openprojectAPIService->getAvailableAssigneesOfAProject($this->userId, $projectId);
} catch (OpenprojectErrorException $e) {
return new DataResponse($e->getMessage(), $e->getcode());
} catch (\Exception $e) {
Expand Down
73 changes: 0 additions & 73 deletions lib/Listener/AddContentSecurityPolicyListener.php

This file was deleted.

2 changes: 1 addition & 1 deletion lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ public function getOpenProjectWorkPackageForm(string $userId, string $projectId,
* @return array<mixed>
* @throws OpenprojectResponseException|PreConditionNotMetException|OpenprojectErrorException
*/
public function getAvailableAssignees(string $userId, string $projectId): array {
public function getAvailableAssigneesOfAProject(string $userId, string $projectId): array {
$result = $this->request($userId, 'projects/'.$projectId.'/available_assignees');
if (isset($result['error'])) {
throw new OpenprojectErrorException($result['error'], $result['statusCode']);
Expand Down
112 changes: 112 additions & 0 deletions tests/lib/Controller/OpenProjectAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1479,4 +1479,116 @@ public function testGetOpenProjectWorkPackageForm(): void {
$this->assertSame(Http::STATUS_OK, $response->getStatus());
$this->assertSame($result, $response->getData());
}

/**
* @param \Exception $exception
* @param int $expectedHttpStatusCode
* @param string $expectedError
* @dataProvider exceptionDataProvider
*
*@return void
*/
public function testGetOpenProjectWorkPackageFormException(Exception $exception, int $expectedHttpStatusCode, string $expectedError) {
$this->getUserValueMock();
$service = $this->getMockBuilder(OpenProjectAPIService::class)
->disableOriginalConstructor()
->getMock();
$service
->method('getOpenProjectWorkPackageForm')
->willThrowException($exception);
$controller = new OpenProjectAPIController(
'integration_openproject',
$this->requestMock,
$this->configMock,
$service,
$this->urlGeneratorMock,
$this->loggerMock,
'test'
);
$response = $controller->getOpenProjectWorkPackageForm(6, ["_links" => [

Check failure on line 1508 in tests/lib/Controller/OpenProjectAPIControllerTest.php

View workflow job for this annotation

GitHub Actions / unit tests and linting (stable25, 8.1)

Parameter #1 $projectId of method OCA\OpenProject\Controller\OpenProjectAPIController::getOpenProjectWorkPackageForm() expects string, int given.

Check failure on line 1508 in tests/lib/Controller/OpenProjectAPIControllerTest.php

View workflow job for this annotation

GitHub Actions / unit tests and linting (stable26, 8)

Parameter #1 $projectId of method OCA\OpenProject\Controller\OpenProjectAPIController::getOpenProjectWorkPackageForm() expects string, int given.
"type" => [
"href" => "/api/v3/types/2",
"title" => "Milestone"
]]]);
$this->assertSame($expectedHttpStatusCode, $response->getStatus());
$this->assertSame($expectedError, $response->getData());
}

public function testGetAvailableAssigneesOfAProject() {

Check failure on line 1517 in tests/lib/Controller/OpenProjectAPIControllerTest.php

View workflow job for this annotation

GitHub Actions / unit tests and linting (stable25, 8.1)

Method OCA\OpenProject\Controller\OpenProjectAPIControllerTest::testGetAvailableAssigneesOfAProject() has no return type specified.

Check failure on line 1517 in tests/lib/Controller/OpenProjectAPIControllerTest.php

View workflow job for this annotation

GitHub Actions / unit tests and linting (stable26, 8)

Method OCA\OpenProject\Controller\OpenProjectAPIControllerTest::testGetAvailableAssigneesOfAProject() has no return type specified.
$this->getUserValueMock();
$result = [ 0 => [
"_type" => "User",
"id" => 10,
"name" => "openproject admin",
"_links" => [
"self" => [
"href" => "/api/v3/users/10",
"title" => "openproject admin"
]
]
],
1 => [
"_type" => "User",
"id" => 11,
"name" => "openproject member",
"_links" => [
"self" => [
"href" => "/api/v3/users/11",
"title" => "openproject member"
]
]
]
];
$service = $this->getMockBuilder(OpenProjectAPIService::class)
->disableOriginalConstructor()
->onlyMethods(['getAvailableAssigneesOfAProject'])
->getMock();
$service->expects($this->once())
->method('getAvailableAssigneesOfAProject')
->with('test', 6)
->willReturn($result);
$controller = new OpenProjectAPIController(
'integration_openproject',
$this->requestMock,
$this->configMock,
$service,
$this->urlGeneratorMock,
$this->loggerMock,
'test'
);
$response = $controller->getAvailableAssigneesOfAProject(6);

Check failure on line 1559 in tests/lib/Controller/OpenProjectAPIControllerTest.php

View workflow job for this annotation

GitHub Actions / unit tests and linting (stable25, 8.1)

Parameter #1 $projectId of method OCA\OpenProject\Controller\OpenProjectAPIController::getAvailableAssigneesOfAProject() expects string, int given.

Check failure on line 1559 in tests/lib/Controller/OpenProjectAPIControllerTest.php

View workflow job for this annotation

GitHub Actions / unit tests and linting (stable26, 8)

Parameter #1 $projectId of method OCA\OpenProject\Controller\OpenProjectAPIController::getAvailableAssigneesOfAProject() expects string, int given.
$this->assertSame(Http::STATUS_OK, $response->getStatus());
$this->assertSame(
$result, $response->getData());
}

/**
* @param \Exception $exception
* @param int $expectedHttpStatusCode
* @param string $expectedError
* @dataProvider exceptionDataProvider
*
*@return void
*/
public function testGetAvailableAssigneesOfAProjectException(Exception $exception, int $expectedHttpStatusCode, string $expectedError) {
$this->getUserValueMock();
$service = $this->getMockBuilder(OpenProjectAPIService::class)
->disableOriginalConstructor()
->getMock();
$service
->method('getAvailableAssigneesOfAProject')
->willThrowException($exception);
$controller = new OpenProjectAPIController(
'integration_openproject',
$this->requestMock,
$this->configMock,
$service,
$this->urlGeneratorMock,
$this->loggerMock,
'test'
);
$response = $controller->getAvailableAssigneesOfAProject(6);

Check failure on line 1590 in tests/lib/Controller/OpenProjectAPIControllerTest.php

View workflow job for this annotation

GitHub Actions / unit tests and linting (stable25, 8.1)

Parameter #1 $projectId of method OCA\OpenProject\Controller\OpenProjectAPIController::getAvailableAssigneesOfAProject() expects string, int given.

Check failure on line 1590 in tests/lib/Controller/OpenProjectAPIControllerTest.php

View workflow job for this annotation

GitHub Actions / unit tests and linting (stable26, 8)

Parameter #1 $projectId of method OCA\OpenProject\Controller\OpenProjectAPIController::getAvailableAssigneesOfAProject() expects string, int given.
$this->assertSame($expectedHttpStatusCode, $response->getStatus());
$this->assertSame($expectedError, $response->getData());
}
}

0 comments on commit b93fe67

Please sign in to comment.