Skip to content

Commit

Permalink
enh: add password confirmation in admin settings, minor fixes (#342)
Browse files Browse the repository at this point in the history
Minor improvements to the Admin settings.

Signed-off-by: Andrey Borysenko <[email protected]>
  • Loading branch information
andrey18106 authored Aug 2, 2024
1 parent 65003cd commit 938a820
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 57 deletions.
13 changes: 4 additions & 9 deletions lib/Controller/DaemonConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use OCA\AppAPI\Service\ExAppService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
Expand All @@ -37,15 +37,14 @@ public function __construct(
parent::__construct(Application::APP_ID, $request);
}

#[NoCSRFRequired]
public function getAllDaemonConfigs(): Response {
return new JSONResponse([
'daemons' => $this->daemonConfigService->getDaemonConfigsWithAppsCount(),
'default_daemon_config' => $this->config->getAppValue(Application::APP_ID, 'default_daemon_config'),
]);
}

#[NoCSRFRequired]
#[PasswordConfirmationRequired]
public function registerDaemonConfig(array $daemonConfigParams, bool $defaultDaemon = false): Response {
$daemonConfig = $this->daemonConfigService->registerDaemonConfig($daemonConfigParams);
if ($daemonConfig !== null && $defaultDaemon) {
Expand All @@ -57,7 +56,7 @@ public function registerDaemonConfig(array $daemonConfigParams, bool $defaultDae
]);
}

#[NoCSRFRequired]
#[PasswordConfirmationRequired]
public function updateDaemonConfig(string $name, array $daemonConfigParams): Response {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($name);
$updatedDaemonConfig = new DaemonConfig($daemonConfigParams);
Expand All @@ -69,7 +68,7 @@ public function updateDaemonConfig(string $name, array $daemonConfigParams): Res
]);
}

#[NoCSRFRequired]
#[PasswordConfirmationRequired]
public function unregisterDaemonConfig(string $name): Response {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($name);
$defaultDaemonConfig = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', '');
Expand All @@ -84,7 +83,6 @@ public function unregisterDaemonConfig(string $name): Response {
]);
}

#[NoCSRFRequired]
public function verifyDaemonConnection(string $name): Response {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($name);
if ($daemonConfig->getAcceptsDeployId() !== $this->dockerActions->getAcceptsDeployId()) {
Expand All @@ -99,7 +97,6 @@ public function verifyDaemonConnection(string $name): Response {
]);
}

#[NoCSRFRequired]
public function checkDaemonConnection(array $daemonParams): Response {
$daemonConfig = new DaemonConfig([
'name' => $daemonParams['name'],
Expand All @@ -121,7 +118,6 @@ public function checkDaemonConnection(array $daemonParams): Response {
]);
}

#[NoCSRFRequired]
public function startTestDeploy(string $name): Response {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($name);
if (!$daemonConfig) {
Expand Down Expand Up @@ -151,7 +147,6 @@ public function startTestDeploy(string $name): Response {
]);
}

#[NoCSRFRequired]
public function stopTestDeploy(string $name): Response {
$exApp = $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID);
if ($exApp !== null) {
Expand Down
33 changes: 20 additions & 13 deletions src/components/DaemonConfig/DaemonConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import { confirmPassword } from '@nextcloud/password-confirmation'
import NcListItem from '@nextcloud/vue/dist/Components/NcListItem.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
Expand Down Expand Up @@ -163,19 +164,25 @@ export default {
},
_deleteDaemonConfig(daemon) {
this.deleting = true
return axios.delete(generateUrl(`/apps/app_api/daemons/${daemon.name}?removeExApps=${this.removeExAppsOnDaemonDelete}`))
.then(res => {
if (res.data.success) {
this.getAllDaemons()
}
this.deleting = false
this.showDetailsModal = false
})
.catch(err => {
console.debug(err)
this.deleting = false
this.showDetailsModal = false
})
return confirmPassword().then(() => {
return axios.delete(generateUrl(`/apps/app_api/daemons/${daemon.name}?removeExApps=${this.removeExAppsOnDaemonDelete}`))
.then(res => {
if (res.data.success) {
this.getAllDaemons()
}
this.deleting = false
this.showDetailsModal = false
})
.catch(err => {
console.debug(err)
this.deleting = false
this.showDetailsModal = false
})
}).catch(() => {
this.deleting = false
this.showDeleteDialog = false
showError(t('app_api', 'Password confirmation failed'))
})
},
showTestDeployModal() {
this.showTestDeployDialog = true
Expand Down
81 changes: 46 additions & 35 deletions src/components/DaemonConfig/ManageDaemonConfigModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
import axios from '@nextcloud/axios'
import { showSuccess, showError } from '@nextcloud/dialogs'
import { generateUrl } from '@nextcloud/router'
import { confirmPassword } from '@nextcloud/password-confirmation'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import NcInputField from '@nextcloud/vue/dist/Components/NcInputField.js'
Expand Down Expand Up @@ -444,25 +445,30 @@ export default {
registerDaemon() {
this.registeringDaemon = true
axios.post(generateUrl('/apps/app_api/daemons'), {
daemonConfigParams: this._buildDaemonParams(),
defaultDaemon: this.acceptsDeployId === 'docker-install' ? this.defaultDaemon : false,
})
.then(res => {
this.registeringDaemon = false
if (res.data.success) {
showSuccess(t('app_api', 'DaemonConfig successfully registered'))
this.closeModal()
this.getAllDaemons()
} else {
showError(t('app_api', 'Failed to register DaemonConfig. Check the logs'))
}
})
.catch(err => {
this.registeringDaemon = false
console.debug(err)
showError(t('app_api', 'Failed to register DaemonConfig. Check the logs'))
confirmPassword().then(() => {
axios.post(generateUrl('/apps/app_api/daemons'), {
daemonConfigParams: this._buildDaemonParams(),
defaultDaemon: this.acceptsDeployId === 'docker-install' ? this.defaultDaemon : false,
})
.then(res => {
this.registeringDaemon = false
if (res.data.success) {
showSuccess(t('app_api', 'DaemonConfig successfully registered'))
this.closeModal()
this.getAllDaemons()
} else {
showError(t('app_api', 'Failed to register DaemonConfig. Check the logs'))
}
})
.catch(err => {
this.registeringDaemon = false
console.debug(err)
showError(t('app_api', 'Failed to register DaemonConfig. Check the logs'))
})
}).catch(() => {
this.registeringDaemon = false
showError(t('app_api', 'Password confirmation failed'))
})
},
updateDaemon() {
if (this.isEdit) {
Expand All @@ -471,24 +477,29 @@ export default {
this.registeringDaemon = true
axios.put(generateUrl(`/apps/app_api/daemons/${this.daemon.name}`), {
daemonConfigParams: this._buildDaemonParams(),
})
.then(res => {
this.registeringDaemon = false
if (res.data.success) {
showSuccess(t('app_api', 'DaemonConfig successfully updated'))
this.closeModal()
this.getAllDaemons()
} else {
showError(t('app_api', 'Failed to update DaemonConfig. Check the logs'))
}
})
.catch(err => {
this.registeringDaemon = false
console.debug(err)
showError(t('app_api', 'Failed to update DaemonConfig. Check the logs'))
confirmPassword().then(() => {
axios.put(generateUrl(`/apps/app_api/daemons/${this.daemon.name}`), {
daemonConfigParams: this._buildDaemonParams(),
})
.then(res => {
this.registeringDaemon = false
if (res.data.success) {
showSuccess(t('app_api', 'DaemonConfig successfully updated'))
this.closeModal()
this.getAllDaemons()
} else {
showError(t('app_api', 'Failed to update DaemonConfig. Check the logs'))
}
})
.catch(err => {
this.registeringDaemon = false
console.debug(err)
showError(t('app_api', 'Failed to update DaemonConfig. Check the logs'))
})
}).catch(() => {
this.registeringDaemon = false
showError(t('app_api', 'Password confirmation failed'))
})
},
verifyDaemonConnection() {
this.verifyingDaemonConnection = true
Expand Down

0 comments on commit 938a820

Please sign in to comment.