Skip to content

Commit

Permalink
[OP-40679] Feature search workpackages (#43)
Browse files Browse the repository at this point in the history
* Implement searchbar feature to list workpackages

Signed-off-by: Swikriti Tripathi <swikriti808@gmail.com>
  • Loading branch information
SwikritiT committed Feb 17, 2022
1 parent 7d87ff3 commit 439ce0a
Show file tree
Hide file tree
Showing 15 changed files with 978 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ coverage/
example/
log/
vendor/
.php-cs-fixer.cache

3 changes: 3 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
['name' => 'openProjectAPI#getNotifications', 'url' => '/notifications', 'verb' => 'GET'],
['name' => 'openProjectAPI#getOpenProjectUrl', 'url' => '/url', 'verb' => 'GET'],
['name' => 'openProjectAPI#getOpenProjectAvatar', 'url' => '/avatar', 'verb' => 'GET'],
['name' => 'openProjectAPI#getSearchedWorkPackages', 'url' => '/work_packages', 'verb' => 'GET'],
['name' => 'openProjectAPI#getOpenProjectWorkPackageStatus', 'url' => '/statuses/{id}', 'verb' => 'GET'],
['name' => 'openProjectAPI#getOpenProjectWorkPackageType', 'url' => '/types/{id}', 'verb' => 'GET'],
]
];
6 changes: 4 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = {
collectCoverage: true,
collectCoverageFrom: ['./src/**'],
coverageDirectory: '<rootDir>/coverage/jest/',
coverageReporters: ['lcov', 'html', 'text']

coverageReporters: ['lcov', 'html', 'text'],
transformIgnorePatterns: [
"node_modules/(?!vue-material-design-icons)"
],
}
71 changes: 71 additions & 0 deletions lib/Controller/OpenProjectAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,75 @@ public function getNotifications(?string $since = null): DataResponse {
}
return $response;
}
/**
* get searched work packages
*
* @NoAdminRequired
*
* @param ?string $searchQuery
*
* @return DataResponse
*/
public function getSearchedWorkPackages(?string $searchQuery = null): DataResponse {
if ($this->accessToken === '' || !OpenProjectAPIService::validateOpenProjectURL($this->openprojectUrl)) {
return new DataResponse('', 400);
}
$result = $this->openprojectAPIService->searchWorkPackage(
$this->openprojectUrl, $this->accessToken, 'oauth', $this->refreshToken, $this->clientID, $this->clientSecret, $this->userId, $searchQuery
);
if (!isset($result['error'])) {
$response = new DataResponse($result);
} else {
$response = new DataResponse($result, 401);
}
return $response;
}

/**
* get status of work packages
*
* @NoAdminRequired
*
* @param string $id
*
* @return DataResponse
*/
public function getOpenProjectWorkPackageStatus(string $id): DataResponse {
if ($this->accessToken === '' || !OpenProjectAPIService::validateOpenProjectURL($this->openprojectUrl)) {
return new DataResponse('', 400);
}
$result = $this->openprojectAPIService->getOpenProjectWorkPackageStatus(
$this->openprojectUrl, $this->accessToken, 'oauth', $this->refreshToken, $this->clientID, $this->clientSecret, $this->userId, $id
);
if (!isset($result['error'])) {
$response = new DataResponse($result);
} else {
$response = new DataResponse($result, 401);
}
return $response;
}

/**
* get type work packages
*
* @NoAdminRequired
*
* @param string $id
*
* @return DataResponse
*/
public function getOpenProjectWorkPackageType(string $id): DataResponse {
if ($this->accessToken === '' || !OpenProjectAPIService::validateOpenProjectURL($this->openprojectUrl)) {
return new DataResponse('', 400);
}
$result = $this->openprojectAPIService->getOpenProjectWorkPackageType(
$this->openprojectUrl, $this->accessToken, 'oauth', $this->refreshToken, $this->clientID, $this->clientSecret, $this->userId, $id
);
if (!isset($result['error'])) {
$response = new DataResponse($result);
} else {
$response = new DataResponse($result, 401);
}
return $response;
}
}
62 changes: 62 additions & 0 deletions lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,66 @@ public static function validateOpenProjectURL(string $openprojectUrl): bool {
return filter_var($openprojectUrl, FILTER_VALIDATE_URL) &&
preg_match('/^https?/', $openprojectUrl);
}

/**
* authenticated request to get status of a work package
*
* @param string $url
* @param string $accessToken
* @param string $authType
* @param string $refreshToken
* @param string $clientID
* @param string $clientSecret
* @param string $userId
* @param string $statusId
* @return string[]
*/
public function getOpenProjectWorkPackageStatus(
string $url,
string $accessToken,
string $authType,
string $refreshToken,
string $clientID,
string $clientSecret,
string $userId,
string $statusId): array {
$result = $this->request(
$url, $accessToken, $authType, $refreshToken, $clientID, $clientSecret, $userId, 'statuses/' . $statusId);
if (!isset($result['id'])) {
return ['error' => 'Malformed response'];
}
return $result;
}

/**
* authenticated request to get status of a work package
*
* @param string $url
* @param string $accessToken
* @param string $authType
* @param string $refreshToken
* @param string $clientID
* @param string $clientSecret
* @param string $userId
* @param string $typeId
* @return string[]
*/
public function getOpenProjectWorkPackageType(
string $url,
string $accessToken,
string $authType,
string $refreshToken,
string $clientID,
string $clientSecret,
string $userId,
string $typeId
): array {
$result = $this->request(
$url, $accessToken, $authType, $refreshToken, $clientID, $clientSecret, $userId, 'types/' . $typeId);
if (!isset($result['id'])) {
return ['error' => 'Malformed response'];
}

return $result;
}
}
2 changes: 1 addition & 1 deletion src/components/tab/EmptyContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default {
} else if (this.state === 'error') {
return t('integration_openproject', 'Error connecting to OpenProject')
} else if (this.state === 'ok') {
return t('integration_openproject', 'No workspaces linked yet')
return t('integration_openproject', 'No workspaces linked yet, search for workpackage to add!')
}
return 'invalid state'
},
Expand Down
Loading

0 comments on commit 439ce0a

Please sign in to comment.