Skip to content

Commit

Permalink
Donot save app password and setup group folder in database
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Apr 12, 2023
1 parent 58c37ac commit 762bf88
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 44 deletions.
5 changes: 4 additions & 1 deletion lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private function setIntegrationConfig(array $values): array {
// this condition applies only when user and group with along with app password is created
// code to for updating the app password token
$groupFolderID = $this->config->getAppValue(Application::APP_ID, 'openproject_groupfolder_id', '');
if(key_exists('reset_app_password', $values) && $values['reset_app_password'] && $groupFolderID !== '') {
if(key_exists('reset_app_password', $values) && $values['reset_app_password']) {
$app_password = $this->openprojectAPIService->replaceAppPasswordToken();
}

Expand All @@ -232,6 +232,9 @@ private function setIntegrationConfig(array $values): array {
);

foreach ($values as $key => $value) {
if($key === 'setup_group_folder' || $key === 'reset_app_password') {
continue;
}
$this->config->setAppValue(Application::APP_ID, $key, trim($value));
}
// if the OpenProject OAuth URL has changed
Expand Down
3 changes: 0 additions & 3 deletions lib/Controller/OpenProjectAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,6 @@ private function base64UrlEncode(string $plainText): string {
* @NoAdminRequired
* @NoCSRFRequired
*
*
* @param string $url
*
* @return DataResponse
*/
public function getGroupFolderSetUpStatus(): DataResponse {
Expand Down
4 changes: 2 additions & 2 deletions lib/Migration/Version2400Date20230406144300.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public function __construct(IConfig $config) {
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$this->config->setAppValue(
Application::APP_ID, 'default_managed_folders', true
Application::APP_ID, 'default_managed_folders', '1'
);
$this->config->setAppValue(
Application::APP_ID, 'managed_folder_state', false
Application::APP_ID, 'managed_folder_state', '0'
);
return null;
}
Expand Down
11 changes: 7 additions & 4 deletions lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,11 @@ public function revokeUserOAuthToken(
* @throws OpenprojectGroupfolderSetupConflictException
*/
public function isSystemReadyForGroupFolderSetUp(): bool {
if($this->userManager->userExists(Application::OPEN_PROJECT_ENTITIES_NAME) && $this->groupManager->groupExists(Application::OPEN_PROJECT_ENTITIES_NAME)) {
if(!$this->isGroupfoldersAppEnabled()) {
throw new \Exception('The group folder app is not installed');
}
}
if ($this->userManager->userExists(Application::OPEN_PROJECT_ENTITIES_NAME)) {
throw new OpenprojectGroupfolderSetupConflictException('The user '. Application::OPEN_PROJECT_ENTITIES_NAME .' already exists');
} elseif ($this->groupManager->groupExists(Application::OPEN_PROJECT_ENTITIES_NAME)) {
Expand Down Expand Up @@ -939,11 +944,9 @@ public function isGroupFolderSetup(): bool {
}

/**
* returns true if the group-folder setup is completed
*
* @return array
* @return array<mixed>
*/
public function isGroupFolderSetupInformation(): array {
public function getGroupFolderSetupInformation(): array {
$status = $this->isGroupFolderSetup();
$errorMessage = null;
if(!$status) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getForm(): TemplateResponse {
}
// We only need a single app password for user OpenProject
$appPasswordCount = sizeof($this->tokenProvider->getTokenByUser(Application::OPEN_PROJECT_ENTITIES_NAME));
$groupFolderStatusInformation = $this->openProjectAPIService-> isGroupFolderSetupInformation();
$groupFolderStatusInformation = $this->openProjectAPIService-> getGroupFolderSetupInformation();
$adminConfig = [
'openproject_client_id' => $clientID,
'openproject_client_secret' => $clientSecret,
Expand Down
48 changes: 15 additions & 33 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
t('integration_openproject', 'The app will never delete files or folders, even if you deactivate this later')
}}
</p>
<ManagedFolderError v-if="groupFolderSetUpError !== null" :group-folder-set-up-error-message-description="groupFolderSetUpErrorMessageDescription(this.groupFolderSetUpError)" :group-folder-set-up-error="groupFolderSetUpError" />
<ManagedFolderError v-if="groupFolderSetUpError !== null" :group-folder-set-up-error-message-description="groupFolderSetUpErrorMessageDescription(groupFolderSetUpError)" :group-folder-set-up-error="groupFolderSetUpError" />
<div class="form-actions">
<NcButton v-if="groupFolderSetUpError === null"
type="primary"
Expand Down Expand Up @@ -241,8 +241,8 @@
</div>
<ManagedFolderError
v-if="state.app_password_set && !isGroupFolderSetupCorrect"
:group-folder-set-up-error-message-description="groupFolderSetUpErrorMessageDescription(this.state.group_folder_status.errorMessage)"
:group-folder-set-up-error="this.state.group_folder_status.errorMessage" />
:group-folder-set-up-error-message-description="groupFolderSetUpErrorMessageDescription(state.group_folder_status.errorMessage)"
:group-folder-set-up-error="state.group_folder_status.errorMessage" />
<div class="form-actions">
<NcButton
data-test-id="reset-server-host-btn"
Expand Down Expand Up @@ -518,8 +518,6 @@ export default {
init() {
if (this.state) {
this.isGroupFolderSetupCorrect = this.state.group_folder_status.status
console.log(this.state)
console.log(this.isGroupFolderSetupCorrect)
if (this.state.openproject_instance_url) {
this.formMode.server = F_MODES.VIEW
this.isFormCompleted.server = true
Expand Down Expand Up @@ -563,16 +561,16 @@ export default {
},
groupFolderSetUpErrorMessageDescription(errorKey) {
switch (errorKey) {
case 'The group folder name OpenProject integration already exists' :
return t('integration_openproject', 'Please make sure to rename the group folder or completely delete the previous one or deactivate the automatically managed folders.')
case 'The group folder app is not installed' :
return t('integration_openproject', 'Please install the group folder to be able to use automatic managed folders or deactivate the automatically managed folders.')
case 'The user OpenProject already exists' :
return t('integration_openproject', 'Please make sure to completely delete the previous user or deactivate the automatically managed folders.')
case 'The group OpenProject already exists' :
return t('integration_openproject', 'Please make sure to completely delete the previous group or deactivate the automatically managed folders.')
default:
return t('integration_openproject', 'Something went wrong during groupfolder setup. Deactivate the automatically managed folders.')
case 'The group folder name OpenProject integration already exists' :
return t('integration_openproject', 'Please make sure to rename the group folder or completely delete the previous one or deactivate the automatically managed folders.')
case 'The group folder app is not installed' :
return t('integration_openproject', 'Please install the group folder to be able to use automatic managed folders or deactivate the automatically managed folders.')
case 'The user OpenProject already exists' :
return t('integration_openproject', 'Please make sure to completely delete the previous user or deactivate the automatically managed folders.')
case 'The group OpenProject already exists' :
return t('integration_openproject', 'Please make sure to completely delete the previous group or deactivate the automatically managed folders.')
default:
return t('integration_openproject', 'Something went wrong during groupfolder setup. Deactivate the automatically managed folders.')
}
},
setServerHostFormToViewMode() {
Expand Down Expand Up @@ -607,27 +605,19 @@ export default {
},
async setManagedGroupFolderSetupToViewMode() {
this.groupFolderStatus = await this.checkIfGroupFolderIsAlreadyReadyForSetup()
console.log("Status ====" + this.groupFolderStatus)
if (this.groupFolderStatus) {
console.log("Entered here")
// TODO remove this comment and make it short
// it means all the thing is already set up so we donot need to do anything
// but we can have a case where app password is not there and we need to reset the app password in case we shift from inactive to active managed folder
if (this.state.app_password_set === false) {
console.log("Yes no app password")
// we will get the app password this api request
const success = await this.saveOPOptions()
if (success) {
this.formMode.opSystemPassword = F_MODES.EDIT
console.log("Direct here !!")
this.state.managed_folder_state = true
this.iskeepCurrentCompleteIntegration = 'Keep Current Change'
this.isFormCompleted.managedGroupFolderSetUp = true
this.isGroupFolderSetupCorrect = true
this.formMode.managedGroupFolderSetUp = F_MODES.VIEW
}
} else {
console.log("Direct here !!")
this.state.managed_folder_state = true
this.iskeepCurrentCompleteIntegration = 'Keep Current Change'
this.isFormCompleted.managedGroupFolderSetUp = true
Expand All @@ -636,7 +626,6 @@ export default {
}
} else {
// we will check for the error making the setup_group_folder === true
console.log("Should hit here !!")
const success = await this.saveOPOptions()
if (success) {
this.state.managed_folder_state = true
Expand Down Expand Up @@ -685,7 +674,7 @@ export default {
this.loadingSetUpGroupFolder = true
await this.setManagedGroupFolderSetupToViewMode()
this.loadingSetUpGroupFolder = false
if(this.formMode.managedGroupFolderSetUp === F_MODES.VIEW) {
if (this.formMode.managedGroupFolderSetUp === F_MODES.VIEW) {
this.groupFolderSetUpError = null
}
},
Expand Down Expand Up @@ -899,31 +888,24 @@ export default {
},
setUpGroupFolder() {
if (this.formMode.server === F_MODES.EDIT || !this.isFormCompleted.opOauth || !this.isFormCompleted.ncOauth) {
console.log("hit 1")
return false
}
if (this.state.managed_folder_state === true && this.isGroupfolderSetupAutomaticallyReady === true && !this.state.app_password_set) {
console.log("hit 2")
return true
}
if (this.formMode.opSystemPassword === F_MODES.EDIT) {
console.log("hit 3")
return false
}
if (this.groupFolderStatus === true) {
console.log("hit 4")
return false
}
if (this.state.managed_folder_state === true && this.isGroupfolderSetupAutomaticallyReady === true) {
console.log("hit 5")
return true
}
if (this.state.managed_folder_state === false && this.isGroupfolderSetupAutomaticallyReady === true) {
console.log("hit 6")
return true
}
console.log("hit 7")
return false
},
async saveOPOptions() {
Expand Down Expand Up @@ -1048,7 +1030,7 @@ export default {
}
// we want to show the error only when managed group folder is in edit mode
if(this.formMode.managedGroupFolderSetUp === F_MODES.VIEW) {
if (this.formMode.managedGroupFolderSetUp === F_MODES.VIEW) {
this.groupFolderSetUpError = null
}
},
Expand Down

0 comments on commit 762bf88

Please sign in to comment.