From 480a02a4ae678ba9fab18d4438f4e355b7a85d92 Mon Sep 17 00:00:00 2001 From: Sagar Date: Tue, 26 Nov 2024 17:06:23 +0545 Subject: [PATCH] hide partially Signed-off-by: Sagar --- lib/Dashboard/OpenProjectWidget.php | 21 ++++++++++-- .../LoadAdditionalScriptsListener.php | 24 +++++++++++++ lib/Listener/LoadSidebarScript.php | 5 +++ lib/Listener/OpenProjectReferenceListener.php | 13 ++++++- src/components/PersonalSettings.vue | 7 ++++ src/components/tab/EmptyContent.vue | 5 ++- src/views/Dashboard.vue | 34 +++++++++++++++---- 7 files changed, 98 insertions(+), 11 deletions(-) diff --git a/lib/Dashboard/OpenProjectWidget.php b/lib/Dashboard/OpenProjectWidget.php index 7f9ee9176..b88862599 100644 --- a/lib/Dashboard/OpenProjectWidget.php +++ b/lib/Dashboard/OpenProjectWidget.php @@ -59,18 +59,26 @@ class OpenProjectWidget implements IWidget { */ private $user; - public function __construct( + /** + * @var OpenProjectAPIService + */ + private OpenProjectAPIService $openProjectAPIService; + + + public function __construct( IL10N $l10n, IInitialState $initialStateService, IURLGenerator $url, IConfig $config, - IUserSession $userSession + IUserSession $userSession, + OpenProjectAPIService $openProjectAPIService ) { $this->initialStateService = $initialStateService; $this->l10n = $l10n; $this->url = $url; $this->config = $config; $this->user = $userSession->getUser(); + $this->openProjectAPIService = $openProjectAPIService; } /** @@ -115,7 +123,7 @@ public function load(): void { Util::addScript(Application::APP_ID, Application::APP_ID . '-dashboard'); Util::addStyle(Application::APP_ID, 'dashboard'); - $this->initialStateService->provideInitialState('admin-config-status', OpenProjectAPIService::isAdminConfigOk($this->config)); + $this->initialStateService->provideInitialState('admin-config-status', $this->openProjectAPIService->isAdminConfigOk($this->config)); $oauthConnectionResult = $this->config->getUserValue( $this->user->getUID(), Application::APP_ID, 'oauth_connection_result', '' @@ -136,6 +144,13 @@ public function load(): void { $this->config->deleteUserValue( $this->user->getUID(), Application::APP_ID, 'oauth_connection_error_message' ); + $token = $this->openProjectAPIService->getOIDCBasedTokenForTheTargetedAudienceClient('openproject'); + $isOIDCBasedAuthOk = OpenProjectAPIService::isAdminConfigOkForOIDCAuth($this->config); + $userConfig = [ + 'token' => $token, + 'admin_config_ok_for_oidc_auth' => $isOIDCBasedAuthOk + ]; + $this->initialStateService->provideInitialState('user-config', $userConfig); $this->initialStateService->provideInitialState( 'oauth-connection-error-message', $oauthConnectionErrorMessage ); diff --git a/lib/Listener/LoadAdditionalScriptsListener.php b/lib/Listener/LoadAdditionalScriptsListener.php index d8c90d3fb..65f213f52 100644 --- a/lib/Listener/LoadAdditionalScriptsListener.php +++ b/lib/Listener/LoadAdditionalScriptsListener.php @@ -5,8 +5,10 @@ use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\OpenProject\AppInfo\Application; use OCA\OpenProject\ServerVersionHelper; +use OCA\OpenProject\Service\OpenProjectAPIService; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\IConfig; use OCP\Util; /** @@ -14,7 +16,29 @@ */ class LoadAdditionalScriptsListener implements IEventListener { + /** + * @var OpenProjectAPIService + */ + private $openProjectAPIService; + /** + * @var IConfig + */ + private $config; + + public function __construct( + IConfig $config, + OpenProjectAPIService $openProjectAPIService, + ) { + $this->config = $config; + $this->openProjectAPIService = $openProjectAPIService; + } + public function handle(Event $event): void { + $token = $this->openProjectAPIService->getOIDCBasedTokenForTheTargetedAudienceClient('openproject'); + $authenticationMethodActive = $this->config->getAppValue(Application::APP_ID, 'authentication_method', ''); + if ($authenticationMethodActive === 'oidc' && $token === null) { + return; + } if (!$event instanceof LoadAdditionalScriptsEvent) { return; } diff --git a/lib/Listener/LoadSidebarScript.php b/lib/Listener/LoadSidebarScript.php index c4a3db1c9..8a4c42b8b 100644 --- a/lib/Listener/LoadSidebarScript.php +++ b/lib/Listener/LoadSidebarScript.php @@ -107,6 +107,11 @@ public function __construct( } public function handle(Event $event): void { + $token = $this->openProjectAPIService->getOIDCBasedTokenForTheTargetedAudienceClient('openproject'); + $authenticationMethodActive = $this->config->getAppValue(Application::APP_ID, 'authentication_method', ''); + if ($authenticationMethodActive === 'oidc' && $token === null) { + return; + } if (!($event instanceof LoadSidebar)) { return; } diff --git a/lib/Listener/OpenProjectReferenceListener.php b/lib/Listener/OpenProjectReferenceListener.php index a8cc62903..05d17f64e 100644 --- a/lib/Listener/OpenProjectReferenceListener.php +++ b/lib/Listener/OpenProjectReferenceListener.php @@ -45,15 +45,26 @@ class OpenProjectReferenceListener implements IEventListener { * @var IConfig */ private $config; + /** + * @var OpenProjectAPIService + */ + private $openProjectAPIService; public function __construct( IInitialState $initialStateService, - IConfig $config + IConfig $config, + OpenProjectAPIService $openProjectAPIService, ) { $this->initialStateService = $initialStateService; $this->config = $config; + $this->openProjectAPIService = $openProjectAPIService; } public function handle(Event $event): void { + $token = $this->openProjectAPIService->getOIDCBasedTokenForTheTargetedAudienceClient('openproject'); + $authenticationMethodActive = $this->config->getAppValue(Application::APP_ID, 'authentication_method', ''); + if ($authenticationMethodActive === 'oidc' && $token === null) { + return; + } if (!$event instanceof RenderReferenceEvent) { return; } diff --git a/src/components/PersonalSettings.vue b/src/components/PersonalSettings.vue index cb08e0245..3300e6a8f 100644 --- a/src/components/PersonalSettings.vue +++ b/src/components/PersonalSettings.vue @@ -1,6 +1,9 @@ @@ -49,6 +54,7 @@ export default { oauthConnectionResult: loadState('integration_openproject', 'oauth-connection-result'), isAdminConfigOk: loadState('integration_openproject', 'admin-config-status'), isAdminConfigOkOIDC: loadState('integration_openproject', 'admin-config-status-oidc'), + userState: loadState('integration_openproject', 'user-config'), authMethod: loadState('integration_openproject', 'auth_method'), settingsUrl: generateUrl('/settings/user/openproject'), themingColor: OCA.Theming ? OCA.Theming.color.replace('#', '') : '0082C9', @@ -71,6 +77,15 @@ export default { showMoreUrl() { return this.openprojectUrl + '/notifications' }, + connectedViaOidc() { + if (!this.userState.admin_config_ok_for_oidc_auth) { + return false + } + if (!this.userState.token) { + return false + } + return true + }, items() { const notifications = [] for (const key in this.notifications) { @@ -88,6 +103,9 @@ export default { return notifications }, emptyContentMessage() { + if (this.authMethod === 'oidc' && this.connectedViaOidc === false) { + return + } if (this.state === STATE.NO_TOKEN) { return t('integration_openproject', 'No connection with OpenProject') } else if (this.state === STATE.CONNECTION_ERROR) { @@ -286,4 +304,8 @@ export default { :deep(.connect-button) { margin-top: 10px; } +.demo-error-oidc { + color: red; + margin-top: 20px; +}