Skip to content

Commit

Permalink
hide partially
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar <sagargurung1001@gmail.com>
  • Loading branch information
SagarGi committed Nov 27, 2024
1 parent 0be9b87 commit 480a02a
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 11 deletions.
21 changes: 18 additions & 3 deletions lib/Dashboard/OpenProjectWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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', ''
Expand All @@ -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
);
Expand Down
24 changes: 24 additions & 0 deletions lib/Listener/LoadAdditionalScriptsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,40 @@
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;

/**
* @template-implements IEventListener<Event>
*/
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;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Listener/LoadSidebarScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 12 additions & 1 deletion lib/Listener/OpenProjectReferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/PersonalSettings.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div class="openproject-prefs section">
<SettingsTitle is-setting="personal" />
<div v-if="state.auth_method === 'oidc' && !connectedViaOidc" class="demo-error-oidc">
The authorization is OIDC based and there is no valid token for OpenProject Integration :/
</div>
<div v-if="connected || connectedViaOidc" class="openproject-prefs--connected">
<label>
<CheckIcon :size="20" />
Expand Down Expand Up @@ -169,5 +172,9 @@ export default {
text-align: left;
padding: 0;
}
.demo-error-oidc {
color: red;
margin-top: 20px;
}
}
</style>
5 changes: 4 additions & 1 deletion src/components/tab/EmptyContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
</div>
</div>
<div v-if="showConnectButton" class="empty-content--connect-button">
<OAuthConnectButton :is-auth-method="isAuthMethod" :is-admin-config-ok="isAdminConfigOk" :file-info="fileInfo" />
<OAuthConnectButton v-if="isAuthMethod === 'oauth2'"
:is-auth-method="isAuthMethod"
:is-admin-config-ok="isAdminConfigOk"
:file-info="fileInfo" />
</div>
</div>
</div>
Expand Down
34 changes: 28 additions & 6 deletions src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
:loading="isLoading"
@markAsRead="onMarkAsRead">
<template #empty-content>
<EmptyContent v-if="emptyContentMessage"
id="openproject-empty-content"
:state="state"
:is-auth-method="authMethod"
:dashboard="true"
:is-admin-config-ok="isAdminConfigOk || isAdminConfigOkOIDC" />
<div v-if="authMethod === 'oidc' && connectedViaOidc === false" class="demo-error-oidc">
The authorization is OIDC based and there is no valid token for OpenProject Integration :/
</div>
<div v-else>
<EmptyContent v-if="emptyContentMessage"
id="openproject-empty-content"
:state="state"
:is-auth-method="authMethod"
:dashboard="true"
:is-admin-config-ok="isAdminConfigOk || isAdminConfigOkOIDC" />
</div>
</template>
</NcDashboardWidget>
</template>
Expand Down Expand Up @@ -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',
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -286,4 +304,8 @@ export default {
:deep(.connect-button) {
margin-top: 10px;
}
.demo-error-oidc {
color: red;
margin-top: 20px;
}
</style>

0 comments on commit 480a02a

Please sign in to comment.