Skip to content

Commit

Permalink
Fix link previewd
Browse files Browse the repository at this point in the history
Signed-off-by: Swikriti Tripathi <swikriti808@gmail.com>
  • Loading branch information
SwikritiT committed Aug 18, 2023
1 parent 8492120 commit 2ee0086
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ private function setIntegrationConfig(array $values): array {
}
$appPassword = null;

if ($values['openproject_instance_url']) {
$values['openproject_instance_url'] = rtrim($values['openproject_instance_url'], '/');
}

if (key_exists('setup_project_folder', $values) && $values['setup_project_folder'] === true) {
$isSystemReady = $this->openprojectAPIService->isSystemReadyForProjectFolderSetUp();
if ($isSystemReady) {
Expand Down
13 changes: 9 additions & 4 deletions lib/Reference/WorkPackageReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,19 @@ public function getIconUrl(): string {
* @return int|null
*/
private function getWorkPackageIdFromUrl(string $referenceText): ?int {
$patterns = array('\/projects\/[^\/\?]+\/work_packages(?:\/details)?\/([0-9]+)/',
'\/wp\/([0-9]+)/',
'\/(?:work_packages|notifications)\/[^\/\?]+\/([0-9]+)/',);
// example links
// https://community.openproject.org/projects/nextcloud-integration/work_packages/40070
$openProjectUrl = $this->config->getAppValue(Application::APP_ID, 'openproject_instance_url');
preg_match('/^' . preg_quote($openProjectUrl, '/') . '\/projects\/[^\/\?]+\/work_packages\/([0-9]+)/', $referenceText, $matches);
if (count($matches) > 1) {
return (int) $matches[1];
foreach ($patterns as $pattern) {
$string ='/^' . preg_quote($openProjectUrl, '/') . $pattern;
preg_match($string, $referenceText, $patternMatches);
if (count($patternMatches) > 1) {
return (int) $patternMatches[1];
}
}

return null;
}

Expand Down

0 comments on commit 2ee0086

Please sign in to comment.