[TASK] Allow to create admins as system maintainers in Install Tool 98/54898/7
authorJonathan IROULIN <joniroutypo3@gmail.com>
Fri, 1 Dec 2017 15:35:35 +0000 (16:35 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Sat, 9 Dec 2017 22:23:34 +0000 (23:23 +0100)
This patch add a checkbox to add the new administrator as system
maintainer.

Resolves: #83178
Releases: master
Change-Id: I814ed693ef8e57f2ae58e417727684a701b1fcfd
Reviewed-on: https://review.typo3.org/54898
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/install/Classes/Controller/MaintenanceController.php
typo3/sysext/install/Resources/Private/Partials/Maintenance/CreateAdmin.html
typo3/sysext/install/Resources/Public/JavaScript/Modules/CreateAdmin.js

index c4ef8d5..7fc7919 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Install\Controller;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Configuration\ConfigurationManager;
 use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Core\ClassLoadingInformation;
 use TYPO3\CMS\Core\Database\ConnectionPool;
@@ -407,7 +408,10 @@ class MaintenanceController extends AbstractController
         $username = preg_replace('/\\s/i', '', $request->getParsedBody()['install']['userName']);
         $password = $request->getParsedBody()['install']['userPassword'];
         $passwordCheck = $request->getParsedBody()['install']['userPasswordCheck'];
+        $isSystemMaintainer = ((bool)$request->getParsedBody()['install']['userSystemMaintainer'] == '1') ? true : false;
+
         $messages = new FlashMessageQueue('install');
+
         if (strlen($username) < 1) {
             $messages->enqueue(new FlashMessage(
                 'No valid username given.',
@@ -451,6 +455,26 @@ class MaintenanceController extends AbstractController
                     'crdate' => $GLOBALS['EXEC_TIME']
                 ];
                 $connectionPool->getConnectionForTable('be_users')->insert('be_users', $adminUserFields);
+
+                if ($isSystemMaintainer) {
+
+                    // Get the new admin user uid juste created
+                    $newAdminUserUid = (int)$connectionPool->getConnectionForTable('be_users')->lastInsertId('be_users');
+
+                    // Get the list of the existing systemMaintainer
+                    $existingSystemMaintainersList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemMaintainers'] ?? [];
+
+                    // Add the new admin user to the existing systemMaintainer list
+                    $newSystemMaintainersList = $existingSystemMaintainersList;
+                    $newSystemMaintainersList[] = $newAdminUserUid;
+
+                    // Update the LocalConfiguration.php file with the new list
+                    $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
+                    $configurationManager->setLocalConfigurationValuesByPathValuePairs(
+                        [ 'SYS/systemMaintainers' => $newSystemMaintainersList ]
+                    );
+                }
+
                 $messages->enqueue(new FlashMessage(
                     '',
                     'Administrator created with username "' . $username . '".'
index a32477f..f4b043e 100644 (file)
                        />
                </div>
        </div>
+    <div class="form-group">
+        <label for="add-as-sytem-maintainer" class="col-sm-3 control-label">Add as system maintainer:</label>
+        <div class="col-md-9">
+            <div class="checkbox">
+                <label>
+                    <input
+                            class="t3-install-form-input-checkbox t3js-createAdmin-system-maintainer form-control"
+                            type="checkbox"
+                            id="add-as-sytem-maintainer"
+                    />
+                </label>
+            </div>
+        </div>
+    </div>
 </div>
 
 <div class="t3js-createAdmin-output"></div>
index 479b284..311942b 100644 (file)
@@ -56,7 +56,8 @@ define([
                                                'token': $(self.selectorCreateToken).text(),
                                                'userName': $('.t3js-createAdmin-user').val(),
                                                'userPassword': $('.t3js-createAdmin-password').val(),
-                                               'userPasswordCheck': $('.t3js-createAdmin-password-check').val()
+                                               'userPasswordCheck': $('.t3js-createAdmin-password-check').val(),
+                                               'userSystemMaintainer': ($('.t3js-createAdmin-system-maintainer').is(':checked'))? 1 : 0
                                        }
                                },
                                cache: false,