partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 380d11814b002b6ecdb470dc3641855c1974843d
parent a474c07c31d01fbfae46f10181355a1186df4b5b
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed, 25 Nov 2015 21:26:31 +0100

Implemented authentification provider selection and optional user creation, fixes #498 and #485

Diffstat:
Asrc/PartKeepr/SetupBundle/Controller/ExistingUserSetupController.php | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/PartKeepr/SetupBundle/Controller/SetupController.php | 3+++
Msrc/PartKeepr/SetupBundle/Resources/config/routing.yml | 4++++
Mweb/setup/index.html | 3++-
Mweb/setup/js/Cards/AdminUserCard.js | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Dweb/setup/js/Cards/DatabaseConnectivityTestCard.js | 19-------------------
Mweb/setup/js/Cards/DatabaseSetupCard.js | 5++---
Aweb/setup/js/Cards/UserSetupCard.js | 19+++++++++++++++++++
Mweb/setup/js/PartKeeprSetup.js | 4+++-
Mweb/setup/js/SetupSteps/AdminUserSetup.js | 2+-
Mweb/setup/js/SetupTests/AbstractTest.js | 7++++++-
Mweb/setup/js/SetupTests/ExistingConfigurationTest.js | 4----
Aweb/setup/js/SetupTests/ExistingUserTest.js | 23+++++++++++++++++++++++
Mweb/setup/js/SetupWizard.js | 4++--
Mweb/setup/js/TestResultPanel.js | 3+--
15 files changed, 206 insertions(+), 59 deletions(-)

diff --git a/src/PartKeepr/SetupBundle/Controller/ExistingUserSetupController.php b/src/PartKeepr/SetupBundle/Controller/ExistingUserSetupController.php @@ -0,0 +1,53 @@ +<?php +namespace PartKeepr\SetupBundle\Controller; + +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +class ExistingUserSetupController extends SetupController +{ + /** + * Checks if there are existing userds in the database + * @Route("/setup/testExistingUsers") + */ + public function testExistingUsersAction(Request $request) + { + $this->dumpConfig($request); + + $response = $this->handleRequest($request, "/setup/_int_test_existing_users"); + + return new Response($response->getContent()); + } + + /** + * @Route("/setup/_int_test_existing_users") + */ + public function intTestExistingUsersAction() + { + $repository = $this->getDoctrine()->getRepository("PartKeeprAuthBundle:User"); + + $legacyUsersDQL = "SELECT COUNT(u) FROM PartKeepr\AuthBundle\Entity\User u WHERE u.legacy = 1"; + + $legacyUsersQuery = $this->get("doctrine.orm.default_entity_manager")->createQuery($legacyUsersDQL); + + $totalUsersDQL = "SELECT COUNT(u) FROM PartKeepr\AuthBundle\Entity\User u"; + + $totalUsersQuery = $this->get("doctrine.orm.default_entity_manager")->createQuery($totalUsersDQL); + + $response = array( + "success" => true, + "legacyUsers" => (int)$legacyUsersQuery->getSingleScalarResult(), + "totalUsers" => (int)$totalUsersQuery->getSingleScalarResult(), + "errors" => [], + "message" => "No existing users found", + ); + + if ($totalUsersQuery->getSingleScalarResult() > 0) { + $response["message"] = "Existing users found"; + } + + return new JsonResponse($response); + } +} diff --git a/src/PartKeepr/SetupBundle/Controller/SetupController.php b/src/PartKeepr/SetupBundle/Controller/SetupController.php @@ -13,6 +13,9 @@ use Symfony\Component\Routing\Annotation\Route; class SetupController extends Controller { + /** + * The authentification key length + */ const KEY_LENGTH = 32; /** diff --git a/src/PartKeepr/SetupBundle/Resources/config/routing.yml b/src/PartKeepr/SetupBundle/Resources/config/routing.yml @@ -41,3 +41,7 @@ _setup_manufacturers: _setup_parseconfig: resource: "@PartKeeprSetupBundle/Controller/ExistingConfigParserController.php" type: annotation + +_setup_existingusers: + resource: "@PartKeeprSetupBundle/Controller/ExistingUserSetupController.php" + type: annotation diff --git a/web/setup/index.html b/web/setup/index.html @@ -27,10 +27,10 @@ <script type="text/javascript" src="js/Cards/DatabaseParametersCard.js"></script> <script type="text/javascript" src="js/Cards/DatabaseParametersCard.MySQL.js"></script> <script type="text/javascript" src="js/Cards/DatabaseParametersCard.PostgreSQL.js"></script> - <script type="text/javascript" src="js/Cards/DatabaseConnectivityTestCard.js"></script> <script type="text/javascript" src="js/Cards/DatabaseSetupCard.js"></script> <script type="text/javascript" src="js/Cards/AuthKeyCard.js"></script> <script type="text/javascript" src="js/Cards/ExistingConfigParserCard.js"></script> + <script type="text/javascript" src="js/Cards/UserSetupCard.js"></script> <script type="text/javascript" src="js/SetupTests/AbstractTest.js"></script> <script type="text/javascript" src="js/SetupTests/GenerateAuthKey.js"></script> @@ -40,6 +40,7 @@ <script type="text/javascript" src="js/SetupTests/DatabaseConnectivityTest.js"></script> <script type="text/javascript" src="js/SetupTests/PHPSettingsTest.js"></script> <script type="text/javascript" src="js/SetupTests/ExistingConfigurationTest.js"></script> + <script type="text/javascript" src="js/SetupTests/ExistingUserTest.js"></script> <script type="text/javascript" src="js/SetupSteps/ConfigSetup.js"></script> <script type="text/javascript" src="js/SetupSteps/WarmupCacheSetup.js"></script> diff --git a/web/setup/js/Cards/AdminUserCard.js b/web/setup/js/Cards/AdminUserCard.js @@ -12,10 +12,14 @@ Ext.define('PartKeeprSetup.AdminUserCard', { bodyStyle: 'background: none;', autoScroll: true, - breadCrumbTitle: 'Admin User', - layout: 'card', + breadCrumbTitle: 'User Data', + layout: { + type: 'vbox', + pack: 'start', + align: 'stretch' + }, defaults: { - labelWidth: 120 + labelWidth: 150 }, /** @@ -54,11 +58,42 @@ Ext.define('PartKeeprSetup.AdminUserCard', { this.email.on("change", this.onUpdateParameters, this); - this.items = [ - { - bodyStyle: 'background:none;padding-bottom: 10px;', - border: false, - items: [{ + this.createNewUserRadioGroup = Ext.create("Ext.form.RadioGroup", { + columns: 1, + items: [ + { + boxLabel: 'Leave existing users untouched', name: 'create', inputValue: false, columnWidth: .4 + }, + { + boxLabel: 'Create new user', name: 'create', inputValue: true + } + ] + }); + + this.createNewUserRadioGroup.on("change", this.onUserModeChanged, this); + + this.authenticationMethodRadioGroup = Ext.create("Ext.form.RadioGroup", { + labelAlign: 'top', + height: 75, + fieldLabel: 'Authentication Method', + columns: 1, + items: [ + { + boxLabel: 'HTTP Basic', name: 'authentication_provider', inputValue: 'PartKeepr.Auth.HTTPBasicAuthenticationProvider' + }, + { + boxLabel: 'WSSE', name: 'authentication_provider', inputValue: 'PartKeepr.Auth.WSSEAuthenticationProvider' + } + ] + }); + + //this.authenticationMethodRadioGroup.on("change", this.onAuthenticationMethodChanged, this); + + this.userInputForm = Ext.create("Ext.Panel", { + bodyStyle: 'background:none;padding-bottom: 10px;', + border: false, + items: [ + { border: false, bodyStyle: 'background:none;padding-bottom: 10px;', html: 'Please enter the user which will become the administrator:' @@ -66,39 +101,66 @@ Ext.define('PartKeeprSetup.AdminUserCard', { this.username, this.password, this.email - ] - }, { - border: false, - bodyStyle: 'background:none;padding-bottom: 10px;', - html: 'An existing installation has been detected, no new user will be created. Click Next to continue.' - } - + ], + flex: 1 + }); + this.items = [ + this.createNewUserRadioGroup, + this.userInputForm, + this.authenticationMethodRadioGroup, + { + xtype: 'fieldcontainer', + hideEmptyLabel: true, + height: 20, + border: false, + bodyStyle: 'background: none;', + html: '<a href="https://wiki.partkeepr.org/wiki/KB00006:Authentication_Provider" target="_blank">Help me decide</a>' + } ]; this.callParent(); this.on("activate", this.onActivate, this); }, + onAuthenticationMethodChanged: function () { + var values = this.authenticationMethodRadioGroup.getValue(); + + console.log(values); + PartKeeprSetup.getApplication().getSetupConfig().values.authentication_provider = values.authentication_provider; + }, + onUserModeChanged: function () + { + var values = this.createNewUserRadioGroup.getValue(); + + if (values.create === true) { + Ext.ComponentQuery.query('#nextBtn')[0].disable(); + this.userInputForm.show(); + } else { + Ext.ComponentQuery.query('#nextBtn')[0].enable(); + this.userInputForm.hide(); + } + + PartKeeprSetup.getApplication().getSetupConfig().createUser = values.create; + }, /** * Gets called when the card is activated */ onActivate: function () { - if (PartKeeprSetup.getApplication().getSetupConfig().existingConfig === true) { - this.layout.setActiveItem(1); + if (PartKeeprSetup.getApplication().getSetupConfig().createUser === false) { + this.createNewUserRadioGroup.setValue({ create: false}); } else { - this.layout.setActiveItem(0); - // Disable the "next" button, this needs to get enabled by the admin user form - Ext.ComponentQuery.query('#nextBtn')[0].disable(); + this.createNewUserRadioGroup.setValue({ create: true}); } - this.onUpdateParameters(); + this.authenticationMethodRadioGroup.setValue({ authentication_provider: PartKeeprSetup.getApplication().getSetupConfig().values.authentication_provider}); + + if (PartKeeprSetup.getApplication().getSetupConfig().existingUsers === 0) { + this.createNewUserRadioGroup.hide(); + Ext.ComponentQuery.query('#nextBtn')[0].disable(); + } }, onUpdateParameters: function () { - if (PartKeeprSetup.getApplication().getSetupConfig().existingConfig === true) { - return; - } - if (this.username.isValid() && this.password.isValid() && this.email.isValid()) { var config = PartKeeprSetup.getApplication().getSetupConfig(); diff --git a/web/setup/js/Cards/DatabaseConnectivityTestCard.js b/web/setup/js/Cards/DatabaseConnectivityTestCard.js @@ -1,19 +0,0 @@ -/** - * This card tests the database connectivity for the MySQL database. - * - * Basically this submits all connection settings to a special PHP script, - * which then attempts to establish the database connection. - */ -Ext.define('PartKeeprSetup.DatabaseConnectivityTestCard', { - extend: 'PartKeeprSetup.AbstractTestCard', - - cardMessage: "Setup tests if the database is reachable. Please note that this may take a minute or two to display a status if your database is not reachable.", - breadCrumbTitle: 'Database Connectivity', - /** - * Sets up the tests - */ - setupTests: function () - { - this.tests.push(new PartKeeprSetup.DatabaseConnectivityTest()); - } -}); diff --git a/web/setup/js/Cards/DatabaseSetupCard.js b/web/setup/js/Cards/DatabaseSetupCard.js @@ -15,15 +15,14 @@ Ext.define('PartKeeprSetup.DatabaseSetupCard', { */ setupTests: function () { + this.tests.push(new PartKeeprSetup.DatabaseConnectivityTest()); this.tests.push(new PartKeeprSetup.SchemaSetup()); this.tests.push(new PartKeeprSetup.SchemaMigration()); - this.tests.push(new PartKeeprSetup.AdminUserSetup()); this.tests.push(new PartKeeprSetup.PartUnitSetup()); this.tests.push(new PartKeeprSetup.FootprintSetup()); this.tests.push(new PartKeeprSetup.SiPrefixSetup()); this.tests.push(new PartKeeprSetup.UnitSetup()); this.tests.push(new PartKeeprSetup.ManufacturerSetup()); - this.tests.push(new PartKeeprSetup.ConfigSetup()); - this.tests.push(new PartKeeprSetup.WarmupCacheSetup()); + this.tests.push(new PartKeeprSetup.ExistingUserTest()); } }); diff --git a/web/setup/js/Cards/UserSetupCard.js b/web/setup/js/Cards/UserSetupCard.js @@ -0,0 +1,19 @@ +/** + * This card creates the user + */ +Ext.define('PartKeeprSetup.UserSetupCard', { + extend: 'PartKeeprSetup.AbstractTestCard', + + cardMessage: "Admin user is being created", + breadCrumbTitle: 'User Setup', + rerunTestText: "Re-run setup", + /** + * Sets up the tests + */ + setupTests: function () + { + this.tests.push(new PartKeeprSetup.AdminUserSetup()); + this.tests.push(new PartKeeprSetup.ConfigSetup()); + this.tests.push(new PartKeeprSetup.WarmupCacheSetup()); + } +}); diff --git a/web/setup/js/PartKeeprSetup.js b/web/setup/js/PartKeeprSetup.js @@ -27,8 +27,10 @@ Ext.application({ password: "", email: "" }, - existingConfig: false, + createUser: false, legacyAuth: false, + existingUsers: 0, + legacyUsers: 0, authKey: "" }; diff --git a/web/setup/js/SetupSteps/AdminUserSetup.js b/web/setup/js/SetupSteps/AdminUserSetup.js @@ -10,7 +10,7 @@ Ext.define('PartKeeprSetup.AdminUserSetup', { onBeforeRunTest: function () { this.callParent(arguments); - if (PartKeeprSetup.getApplication().getSetupConfig().existingConfig === true) { + if (PartKeeprSetup.getApplication().getSetupConfig().createUser === false) { this.skip = true; } } diff --git a/web/setup/js/SetupTests/AbstractTest.js b/web/setup/js/SetupTests/AbstractTest.js @@ -72,8 +72,13 @@ Ext.define('PartKeeprSetup.AbstractTest', { { this.onBeforeRunTest(); + this.callback.outputTestMessage(this); + if (this.skip === true) { this.fireEvent("complete", this); + this.success = true; + this.resultMessage = "Skipped"; + this.callback.appendTestResult(this); return; } var url = this.url; @@ -82,7 +87,7 @@ Ext.define('PartKeeprSetup.AbstractTest', { url = url + this.action; } - this.callback.outputTestMessage(this); + Ext.Ajax.request({ url: url, success: this.onSuccess, diff --git a/web/setup/js/SetupTests/ExistingConfigurationTest.js b/web/setup/js/SetupTests/ExistingConfigurationTest.js @@ -13,9 +13,5 @@ Ext.define('PartKeeprSetup.ExistingConfigurationTest', { Ext.merge(config.values, data.config); } - - if (data.existingConfig) { - config.existingConfig = data.existingConfig; - } } }); diff --git a/web/setup/js/SetupTests/ExistingUserTest.js b/web/setup/js/SetupTests/ExistingUserTest.js @@ -0,0 +1,23 @@ +/** + * Tests if an user already exists + */ +Ext.define('PartKeeprSetup.ExistingUserTest', { + extend: 'PartKeeprSetup.AbstractTest', + action: 'testExistingUsers', + name: "Database", + message: "Checking for existing users", + + onAfterRunTest: function (data) + { + var config = PartKeeprSetup.getApplication().getSetupConfig(); + + config.existingUsers = data.totalUsers; + config.legacyUsers = data.legacyUsers; + + if (config.existingUsers > 0) { + config.createUser = false; + } else { + config.createUser = true; + } + } +}); diff --git a/web/setup/js/SetupWizard.js b/web/setup/js/SetupWizard.js @@ -74,9 +74,9 @@ Ext.define('PartKeeprSetup.SetupWizard', { "PartKeeprSetup.AuthKeyCard", "PartKeeprSetup.ExistingConfigParserCard", "PartKeeprSetup.DatabaseParametersCard", - "PartKeeprSetup.DatabaseConnectivityTestCard", - "PartKeeprSetup.AdminUserCard", "PartKeeprSetup.DatabaseSetupCard", + "PartKeeprSetup.AdminUserCard", + "PartKeeprSetup.UserSetupCard", ]; for (var card = 0; card < cardNames.length; card++) { diff --git a/web/setup/js/TestResultPanel.js b/web/setup/js/TestResultPanel.js @@ -106,10 +106,9 @@ Ext.define('PartKeeprSetup.TestResultPanel', { rec.set("message", test.resultMessage); rec.set("errors", test.errors.join("<br/>")); rec.set("waiting", false); + rec.commit(); } - rec.commit(); - if (!test.success) { this.fireEvent("test-error"); }