Skip to content

Commit

Permalink
Connection dashboard and op fetch api
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar <sagargurung1001@gmail.com>
  • Loading branch information
SagarGi committed Nov 21, 2024
1 parent d1f12d3 commit 10c298a
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 53 deletions.
1 change: 1 addition & 0 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ private function setIntegrationConfig(array $values): array {
}
}
$this->clearUserInfo($userUID);
$this->clearUserInfoForOIDCBasedAuth($userUID);
});
}

Expand Down
120 changes: 80 additions & 40 deletions lib/Controller/OpenProjectAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ public function getOpenProjectAvatar(string $userId = '', string $userName = '')
* @return DataResponse
*/
public function getNotifications(): DataResponse {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user');
if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' &&
$user_value === '0'
) {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$result = $this->openprojectAPIService->getNotifications($this->userId);
if (!isset($result['error'])) {
$response = new DataResponse($result);
Expand Down Expand Up @@ -237,11 +242,16 @@ public function linkWorkPackageToFile(array $values): DataResponse {
* @return DataResponse
*/
public function markNotificationAsRead(int $workpackageId) {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user');
if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' &&
$user_value === '0'
) {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
try {
$result = $this->openprojectAPIService->markAllNotificationsOfWorkPackageAsRead(
$workpackageId,
Expand Down Expand Up @@ -334,11 +344,16 @@ public function deleteFileLink(int $id): DataResponse {
* @return DataResponse
*/
public function getOpenProjectWorkPackageStatus(string $id): DataResponse {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user');
if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' &&
$user_value === '0'
) {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}

$result = $this->openprojectAPIService->getOpenProjectWorkPackageStatus(
$this->userId, $id
Expand All @@ -361,11 +376,16 @@ public function getOpenProjectWorkPackageStatus(string $id): DataResponse {
* @return DataResponse
*/
public function getOpenProjectWorkPackageType(string $id): DataResponse {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user');
if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' &&
$user_value === '0'
) {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}

$result = $this->openprojectAPIService->getOpenProjectWorkPackageType(
$this->userId, $id
Expand All @@ -384,11 +404,16 @@ public function getOpenProjectWorkPackageType(string $id): DataResponse {
* @return DataResponse
*/
public function getAvailableOpenProjectProjects(?string $searchQuery = null): DataResponse {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user');
if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' &&
$user_value === '0'
) {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
try {
$result = $this->openprojectAPIService->getAvailableOpenProjectProjects($this->userId, $searchQuery);
} catch (OpenprojectErrorException $e) {
Expand Down Expand Up @@ -436,11 +461,16 @@ public function getAvailableOpenProjectProjects(?string $searchQuery = null): Da
* @return DataResponse
*/
public function getOpenProjectWorkPackageForm(string $projectId, array $body): DataResponse {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user');
if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' &&
$user_value === '0'
) {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
try {
$result = $this->openprojectAPIService->getOpenProjectWorkPackageForm($this->userId, $projectId, $body);
} catch (OpenprojectErrorException $e) {
Expand All @@ -458,11 +488,16 @@ public function getOpenProjectWorkPackageForm(string $projectId, array $body): D
* @return DataResponse
*/
public function getAvailableAssigneesOfAProject(string $projectId): DataResponse {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user');
if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' &&
$user_value === '0'
) {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
try {
$result = $this->openprojectAPIService->getAvailableAssigneesOfAProject($this->userId, $projectId);
} catch (OpenprojectErrorException $e) {
Expand Down Expand Up @@ -507,11 +542,16 @@ public function getAvailableAssigneesOfAProject(string $projectId): DataResponse
* @return DataResponse
*/
public function createWorkPackage(array $body): DataResponse {
if ($this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
$user_value = $this->config->getUserValue($this->userId, Application::APP_ID, 'token_active_for_user');
if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oauth2' && $this->accessToken === '') {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} else if ($this->config->getAppValue(Application::APP_ID, 'authentication_method', '') === 'oidc' &&
$user_value === '0'
) {
return new DataResponse('', Http::STATUS_UNAUTHORIZED);
} elseif (!OpenProjectAPIService::validateURL($this->openprojectUrl)) {
return new DataResponse('', Http::STATUS_BAD_REQUEST);
}
// we don't want to check if all the data in the body is set or not because
// that calculation will be done by the openproject api itself
// we don't want to duplicate the logic
Expand Down
4 changes: 4 additions & 0 deletions lib/Dashboard/OpenProjectWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public function load(): void {
$this->config->deleteUserValue(
$this->user->getUID(), Application::APP_ID, 'oauth_connection_result'
);
$adminConfigStatusOIDC = OpenProjectAPIService::isAdminConfigOkForOIDCAuth($this->config);
$this->initialStateService->provideInitialState('admin-config-status-oidc', $adminConfigStatusOIDC);
$authenticationMethodActive = $this->config->getAppValue(Application::APP_ID, 'authentication_method', '');
$this->initialStateService->provideInitialState('auth_method', $authenticationMethodActive);
$this->initialStateService->provideInitialState(
'oauth-connection-result', $oauthConnectionResult
);
Expand Down
1 change: 0 additions & 1 deletion src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,6 @@ export default {
},
methods: {
init() {
console.log(this.state)
if (this.state) {
if (this.state.all_terms_of_services_signed === false) {
this.isAllTermsOfServiceSignedForUserOpenProject = false
Expand Down
2 changes: 0 additions & 2 deletions src/components/OAuthConnectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default {
},
async onOAuthClick() {
if (this.isAuthMethod === 'oidc') {
console.log('Handle connect button for the oidc authentication flow!')
const url = generateUrl('/apps/integration_openproject/config')
const req = {
values: {
Expand All @@ -85,7 +84,6 @@ export default {
}
const response = await axios.put(url, req)
if (response.status === 200) {
console.log('Yes its 200')
window.location.reload()
}
Expand Down
3 changes: 0 additions & 3 deletions src/components/PersonalSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ export default {
})
},
},
created() {
console.log(this.state)
},
mounted() {
checkOauthConnectionResult(this.oauthConnectionResult, this.oauthConnectionErrorMessage)
Expand Down
11 changes: 9 additions & 2 deletions src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<EmptyContent v-if="emptyContentMessage"
id="openproject-empty-content"
:state="state"
:is-auth-method="authMethod"
:dashboard="true"
:is-admin-config-ok="isAdminConfigOk" />
:is-admin-config-ok="isAdminConfigOk || isAdminConfigOkOIDC" />
</template>
</NcDashboardWidget>
</template>
Expand Down Expand Up @@ -47,6 +48,8 @@ export default {
oauthConnectionErrorMessage: loadState('integration_openproject', 'oauth-connection-error-message'),
oauthConnectionResult: loadState('integration_openproject', 'oauth-connection-result'),
isAdminConfigOk: loadState('integration_openproject', 'admin-config-status'),
isAdminConfigOkOIDC: loadState('integration_openproject', 'admin-config-status-oidc'),
authMethod: loadState('integration_openproject', 'auth_method'),
settingsUrl: generateUrl('/settings/user/openproject'),
themingColor: OCA.Theming ? OCA.Theming.color.replace('#', '') : '0082C9',
windowVisibility: true,
Expand Down Expand Up @@ -128,7 +131,11 @@ export default {
clearInterval(this.loop)
},
async launchLoop() {
if (!this.isAdminConfigOk) {
if (this.authMethod === 'oidc' && !this.isAdminConfigOkOIDC) {
this.state = STATE.ERROR
return
}
if (this.authMethod === 'oauth2' && !this.isAdminConfigOk) {
this.state = STATE.ERROR
return
}
Expand Down
9 changes: 6 additions & 3 deletions src/views/LinkMultipleFilesModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<h2>
{{ t('integration-openproject', 'Link to work package') }}
</h2>
<SearchInput v-if="!!isAdminConfigOk && !!isStateOk"
<SearchInput v-if="(!!isAdminConfigOk || !!isAdminConfigOkOIDC) && !!isStateOk"
:linked-work-packages="alreadyLinkedWorkPackage"
:file-info="fileInfos"
:search-origin="searchOrigin"
Expand All @@ -57,8 +57,9 @@
<EmptyContent
id="openproject-empty-content"
:state="state"
:is-auth-method="authMethod"
:is-multiple-workpackage-linking="true"
:is-admin-config-ok="isAdminConfigOk" />
:is-admin-config-ok="isAdminConfigOk || isAdminConfigOkOIDC" />
</div>
</div>
</NcModal>
Expand Down Expand Up @@ -106,6 +107,8 @@ export default {
fileInfos: [],
alreadyLinkedWorkPackage: [],
isAdminConfigOk: loadState('integration_openproject', 'admin-config-status'),
isAdminConfigOkOIDC: loadState('integration_openproject', 'admin-config-status-oidc'),
authMethod: loadState('integration_openproject', 'auth_method'),
oauthConnectionErrorMessage: loadState('integration_openproject', 'oauth-connection-error-message'),
oauthConnectionResult: loadState('integration_openproject', 'oauth-connection-result'),
searchOrigin: WORKPACKAGES_SEARCH_ORIGIN.LINK_MULTIPLE_FILES_MODAL,
Expand Down Expand Up @@ -170,7 +173,7 @@ export default {
},
async setFileInfos(fileInfos) {
this.fileInfos = fileInfos
if (this.isAdminConfigOk) {
if (this.isAdminConfigOk || this.isAdminConfigOkOIDC) {
await this.fetchWorkpackagesForSingleFileSelected(this.fileInfos[0].id)
} else {
this.state = STATE.ERROR
Expand Down
3 changes: 1 addition & 2 deletions src/views/ProjectsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<template>
<div class="projects"
:class="{'projects--empty': filterWorkpackagesByFileId.length === 0}">
<SearchInput v-if="!!isAdminConfigOkOIDC && !!isStateOk"
<SearchInput v-if="(!!isAdminConfigOk || !!isAdminConfigOkOIDC) && !!isStateOk"
:file-info="fileInfo"
:linked-work-packages="filterWorkpackagesByFileId"
:search-origin="searchOrigin"
Expand Down Expand Up @@ -239,7 +239,6 @@ export default {
const req = {}
const url = generateUrl('/apps/integration_openproject/work-packages?fileId=' + fileId)
try {
console.log('helllllll')
const response = await axios.get(url, req)
if (!Array.isArray(response.data)) {
this.state = STATE.FAILED_FETCHING_WORKPACKAGES
Expand Down

0 comments on commit 10c298a

Please sign in to comment.