Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show error if connection cannot be made to OpenProject #756

Merged
merged 7 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"helmich/phpunit-json-assert": "^3.4",
"vimeo/psalm": "5.23.1",
"guzzlehttp/guzzle": "^7.9",
"behat/gherkin": "v4.9.0"
"behat/gherkin": "v4.9.0",
"php-mock/php-mock-phpunit": "^2.10"
},
"scripts": {
"cs:fix": "php-cs-fixer fix",
Expand Down
211 changes: 209 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCA\TermsOfService\Db\Mapper\TermsMapper;
use OCA\UserOIDC\Db\ProviderMapper;
use OCA\UserOIDC\Exception\TokenExchangeFailedException;
use OCA\UserOIDC\User\Backend as OIDCBackend;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\Encryption\IManager;
Expand All @@ -55,7 +56,9 @@
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Log\ILogFactory;
use OCP\PreConditionNotMetException;
use OCP\Security\ISecureRandom;
Expand Down Expand Up @@ -128,6 +131,11 @@ class OpenProjectAPIService {
private ILogFactory $logFactory;
private IManager $encryptionManager;

/**
* @var IUserSession
*/
private $userSession;


/**
* Service to make requests to OpenProject v3 (JSON) API
Expand Down Expand Up @@ -161,6 +169,7 @@ public function __construct(
ILogFactory $logFactory,
IManager $encryptionManager,
ExchangedTokenRequestedEventHelper $exchangedTokenRequestedEventHelper,
IUserSession $userSession,
) {
$this->appName = $appName;
$this->avatarManager = $avatarManager;
Expand All @@ -182,6 +191,7 @@ public function __construct(
$this->logFactory = $logFactory;
$this->encryptionManager = $encryptionManager;
$this->exchangedTokenRequestedEventHelper = $exchangedTokenRequestedEventHelper;
$this->userSession = $userSession;
}

/**
Expand Down Expand Up @@ -1647,7 +1657,6 @@ public function getOIDCToken(): ?string {
return $token->getAccessToken();
}


/**
* @param string $userId
* @return void
Expand Down Expand Up @@ -1682,4 +1691,19 @@ class_exists('\OCA\UserOIDC\Exception\TokenExchangeFailedException') &&
)
);
}

/**
* @return bool
*/
public function isOIDCUser(): bool {
if (!class_exists(OIDCBackend::class)) {
return false;
}

$user = $this->userSession->getUser();
if ($user instanceof IUser && $user->getBackend() instanceof OIDCBackend) {
return true;
}
return false;
}
}
11 changes: 5 additions & 6 deletions lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use OCA\OpenProject\Service\OpenProjectAPIService;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;

use OCP\IConfig;
use OCP\Settings\ISettings;

Expand Down Expand Up @@ -35,7 +34,8 @@ public function __construct(
IConfig $config,
IInitialState $initialStateService,
OpenProjectAPIService $openProjectAPIService,
?string $userId) {
?string $userId,
) {
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->userId = $userId;
Expand Down Expand Up @@ -78,10 +78,10 @@ public function getForm(): TemplateResponse {
'search_enabled' => ($searchEnabled === '1'),
'navigation_enabled' => ($navigationEnabled === '1'),
'user_name' => $userName,
'admin_config_ok' => OpenProjectAPIService::isAdminConfigOk($this->config),
'authorization_method' => $authorizationMethod,
'oidc_user' => $this->openProjectAPIService->isOIDCUser(),
];

$userConfig['admin_config_ok'] = OpenProjectAPIService::isAdminConfigOk($this->config);
$userConfig['authorization_method'] = $authorizationMethod;
$this->initialStateService->provideInitialState('user-config', $userConfig);

$oauthConnectionResult = $this->config->getUserValue(
Expand All @@ -103,7 +103,6 @@ public function getForm(): TemplateResponse {
'oauth-connection-error-message', $oauthConnectionErrorMessage
);


return new TemplateResponse(Application::APP_ID, 'personalSettings');
}

Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<referencedClass name="OCA\UserOIDC\Model\Token" />
<referencedClass name="OCA\UserOIDC\Event\ExchangedTokenRequestedEvent" />
<referencedClass name="OCA\UserOIDC\Exception\TokenExchangeFailedException" />
<referencedClass name="OCA\UserOIDC\User\Backend" />
<!-- these classes belong to the activity app, which isn't compulsory, so might not exist while running psalm -->
<referencedClass name="OCA\Activity\UserSettings" />
<referencedClass name="OCA\Activity\GroupHelperDisabled" />
Expand Down Expand Up @@ -91,6 +92,7 @@
<!-- these classes belong to the user_oidc app, which isn't compulsory, so might not exist while running psalm -->
<referencedClass name="OCA\UserOIDC\Model\Token" />
<referencedClass name="OCA\UserOIDC\Event\ExchangedTokenRequestedEvent" />
<referencedClass name="OCA\UserOIDC\User\Backend" />
<!-- these are classes form activity app, which isn't cloned while doing static code analysis -->
<referencedClass name="OCA\Activity\UserSettings" />
<referencedClass name="OCA\Activity\GroupHelperDisabled" />
Expand Down
23 changes: 23 additions & 0 deletions src/components/ErrorLabel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<p class="error">
{{ error }}
</p>
</template>

<script>
export default {
name: 'ErrorLabel',
props: {
error: {
type: String,
required: true,
},
},
}
</script>

<style scoped lang="scss">
.error {
color: var(--color-error);
}
</style>
Loading
Loading