[BUGFIX] Access module preselects owner/group when changed via AJAX 27/54527/3
authorMarkus Klein <markus.klein@typo3.org>
Mon, 30 Oct 2017 20:42:05 +0000 (21:42 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 2 Nov 2017 08:39:25 +0000 (09:39 +0100)
Resolves: #79915
Releases: master, 8.7, 7.6
Change-Id: Ie3b573857ff011295be198633a0f6868b1ff55b6
Reviewed-on: https://review.typo3.org/54527
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/beuser/Classes/Controller/PermissionAjaxController.php
typo3/sysext/beuser/Resources/Private/Partials/Permission/Groupname.html
typo3/sysext/beuser/Resources/Private/Templates/PermissionAjax/ChangeGroup.html
typo3/sysext/beuser/Resources/Private/Templates/PermissionAjax/ChangeOwner.html
typo3/sysext/beuser/Resources/Public/JavaScript/Permissions.js

index bac3c7a..804c9bb 100644 (file)
@@ -81,94 +81,95 @@ class PermissionAjaxController
         $view->setPartialRootPaths(['default' => ExtensionManagementUtility::extPath('beuser') . 'Resources/Private/Partials']);
         $view->assign('pageId', $this->conf['page']);
 
-        $content = '';
-        // Basic test for required value
-        if ($this->conf['page'] > 0) {
-            // Init TCE for execution of update
-            /** @var $tce DataHandler */
-            $tce = GeneralUtility::makeInstance(DataHandler::class);
-            $tce->stripslashes_values = false;
-            // Determine the scripts to execute
-            switch ($this->conf['action']) {
-                case 'show_change_owner_selector':
-                    $content = $this->renderUserSelector($this->conf['page'], $this->conf['ownerUid'], $this->conf['username']);
-                    break;
-                case 'change_owner':
-                    $userId = $this->conf['new_owner_uid'];
-                    if (is_int($userId)) {
-                        // Prepare data to change
-                        $data = [];
-                        $data['pages'][$this->conf['page']]['perms_userid'] = $userId;
-                        // Execute TCE Update
-                        $tce->start($data, []);
-                        $tce->process_datamap();
+        $response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');
 
-                        $view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangeOwner.html');
-                        $view->assign('userId', $userId);
-                        $usernameArray = BackendUtility::getUserNames('username', ' AND uid = ' . $userId);
-                        $view->assign('username', $usernameArray[$userId]['username']);
-                        $content = $view->render();
-                    } else {
-                        $response->getBody()->write('An error occurred: No page owner uid specified');
-                        $response = $response->withStatus(500);
-                    }
-                    break;
-                case 'show_change_group_selector':
-                    $content = $this->renderGroupSelector($this->conf['page'], $this->conf['groupUid'], $this->conf['groupname']);
-                    break;
-                case 'change_group':
-                    $groupId = $this->conf['new_group_uid'];
-                    if (is_int($groupId)) {
-                        // Prepare data to change
-                        $data = [];
-                        $data['pages'][$this->conf['page']]['perms_groupid'] = $groupId;
-                        // Execute TCE Update
-                        $tce->start($data, []);
-                        $tce->process_datamap();
+        // Basic test for required value
+        if ($this->conf['page'] <= 0) {
+            $response->getBody()->write('This script cannot be called directly');
+            $response = $response->withStatus(500);
+            return $response;
+        }
 
-                        $view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangeGroup.html');
-                        $view->assign('groupId', $groupId);
-                        $groupnameArray = BackendUtility::getGroupNames('title', ' AND uid = ' . $groupId);
-                        $view->assign('groupname', $groupnameArray[$groupId]['title']);
-                        $content = $view->render();
-                    } else {
-                        $response->getBody()->write('An error occurred: No page group uid specified');
-                        $response = $response->withStatus(500);
-                    }
-                    break;
-                case 'toggle_edit_lock':
+        $content = '';
+        // Init TCE for execution of update
+        /** @var $tce DataHandler */
+        $tce = GeneralUtility::makeInstance(DataHandler::class);
+        $tce->stripslashes_values = false;// Determine the scripts to execute
+        switch ($this->conf['action']) {
+            case 'show_change_owner_selector':
+                $content = $this->renderUserSelector($this->conf['page'], $this->conf['ownerUid'], $this->conf['username']);
+                break;
+            case 'change_owner':
+                $userId = $this->conf['new_owner_uid'];
+                if (is_int($userId)) {
                     // Prepare data to change
                     $data = [];
-                    $data['pages'][$this->conf['page']]['editlock'] = $this->conf['editLockState'] === 1 ? 0 : 1;
+                    $data['pages'][$this->conf['page']]['perms_userid'] = $userId;
                     // Execute TCE Update
                     $tce->start($data, []);
                     $tce->process_datamap();
-                    $content = $this->renderToggleEditLock($this->conf['page'], $data['pages'][$this->conf['page']]['editlock']);
-                    break;
-                default:
-                    if ($this->conf['mode'] === 'delete') {
-                        $this->conf['permissions'] = (int)($this->conf['permissions'] - $this->conf['bits']);
-                    } else {
-                        $this->conf['permissions'] = (int)($this->conf['permissions'] + $this->conf['bits']);
-                    }
+
+                    $view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangeOwner.html');
+                    $view->assign('userId', $userId);
+                    $usernameArray = BackendUtility::getUserNames('username', ' AND uid = ' . $userId);
+                    $view->assign('username', $usernameArray[$userId]['username']);
+                    $content = $view->render();
+                } else {
+                    $response->getBody()->write('An error occurred: No page owner uid specified');
+                    $response = $response->withStatus(500);
+                }
+                break;
+            case 'show_change_group_selector':
+                $content = $this->renderGroupSelector($this->conf['page'], $this->conf['groupUid'], $this->conf['groupname']);
+                break;
+            case 'change_group':
+                $groupId = $this->conf['new_group_uid'];
+                if (is_int($groupId)) {
                     // Prepare data to change
                     $data = [];
-                    $data['pages'][$this->conf['page']]['perms_' . $this->conf['who']] = $this->conf['permissions'];
+                    $data['pages'][$this->conf['page']]['perms_groupid'] = $groupId;
                     // Execute TCE Update
                     $tce->start($data, []);
                     $tce->process_datamap();
 
-                    $view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangePermission.html');
-                    $view->assign('permission', $this->conf['permissions']);
-                    $view->assign('scope', $this->conf['who']);
+                    $view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangeGroup.html');
+                    $view->assign('groupId', $groupId);
+                    $groupnameArray = BackendUtility::getGroupNames('title', ' AND uid = ' . $groupId);
+                    $view->assign('groupname', $groupnameArray[$groupId]['title']);
                     $content = $view->render();
-            }
-        } else {
-            $response->getBody()->write('This script cannot be called directly');
-            $response = $response->withStatus(500);
+                } else {
+                    $response->getBody()->write('An error occurred: No page group uid specified');
+                    $response = $response->withStatus(500);
+                }
+                break;
+            case 'toggle_edit_lock':
+                // Prepare data to change
+                $data = [];
+                $data['pages'][$this->conf['page']]['editlock'] = $this->conf['editLockState'] === 1 ? 0 : 1;
+                // Execute TCE Update
+                $tce->start($data, []);
+                $tce->process_datamap();
+                $content = $this->renderToggleEditLock($this->conf['page'], $data['pages'][$this->conf['page']]['editlock']);
+                break;
+            default:
+                if ($this->conf['mode'] === 'delete') {
+                    $this->conf['permissions'] = (int)($this->conf['permissions'] - $this->conf['bits']);
+                } else {
+                    $this->conf['permissions'] = (int)($this->conf['permissions'] + $this->conf['bits']);
+                }
+                // Prepare data to change
+                $data = [];
+                $data['pages'][$this->conf['page']]['perms_' . $this->conf['who']] = $this->conf['permissions'];
+                // Execute TCE Update
+                $tce->start($data, []);
+                $tce->process_datamap();
+
+                $view->setTemplatePathAndFilename($extPath . 'Resources/Private/Templates/PermissionAjax/ChangePermission.html');
+                $view->assign('permission', $this->conf['permissions']);
+                $view->assign('scope', $this->conf['who']);
+                $content = $view->render();
         }
         $response->getBody()->write($content);
-        $response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');
         return $response;
     }
 
@@ -197,8 +198,16 @@ class PermissionAjaxController
         $elementId = 'o_' . $page;
         $options = '<option value="0"></option>' . $options;
         $selector = '<select name="new_page_owner" id="new_page_owner">' . $options . '</select>';
-        $saveButton = '<a class="saveowner btn btn-default" data-page="' . $page . '" data-owner="' . $ownerUid . '" data-element-id="' . $elementId . '" title="Change owner">' . $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)->render() . '</a>';
-        $cancelButton = '<a class="restoreowner btn btn-default" data-page="' . $page . '"  data-owner="' . $ownerUid . '" data-element-id="' . $elementId . '"' . (!empty($username) ? ' data-username="' . htmlspecialchars($username) . '"' : '') . ' title="Cancel">' . $this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)->render() . '</a>';
+        $saveButton = '<a class="saveowner btn btn-default" data-page="' . $page . '" data-owner="' . $ownerUid
+                      . '" data-element-id="' . $elementId . '" title="Change owner">'
+                      . $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)->render()
+                      . '</a>';
+        $cancelButton = '<a class="restoreowner btn btn-default" data-page="' . $page . '"  data-owner="' . $ownerUid
+                        . '" data-element-id="' . $elementId . '"'
+                        . (!empty($username) ? ' data-username="' . htmlspecialchars($username) . '"' : '')
+                        . ' title="Cancel">'
+                        . $this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)->render()
+                        . '</a>';
         return '<span id="' . $elementId . '">'
             . $selector
             . '<span class="btn-group">'
@@ -246,8 +255,16 @@ class PermissionAjaxController
         $elementId = 'g_' . $page;
         $options = '<option value="0"></option>' . $options;
         $selector = '<select name="new_page_group" id="new_page_group">' . $options . '</select>';
-        $saveButton = '<a class="savegroup btn btn-default" data-page="' . $page . '" data-group="' . $groupUid . '" data-element-id="' . $elementId . '" title="Change group">' . $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)->render() . '</a>';
-        $cancelButton = '<a class="restoregroup btn btn-default" data-page="' . $page . '" data-group="' . $groupUid . '" data-element-id="' . $elementId . '"' . (!empty($groupname) ? ' data-groupname="' . htmlspecialchars($groupname) . '"' : '') . ' title="Cancel">' . $this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)->render() . '</a>';
+        $saveButton = '<a class="savegroup btn btn-default" data-page="' . $page . '" data-group-id="' . $groupUid
+                      . '" data-element-id="' . $elementId . '" title="Change group">'
+                      . $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)->render()
+                      . '</a>';
+        $cancelButton = '<a class="restoregroup btn btn-default" data-page="' . $page . '" data-group-id="' . $groupUid
+                        . '" data-element-id="' . $elementId . '"'
+                        . (!empty($groupname) ? ' data-groupname="' . htmlspecialchars($groupname) . '"' : '')
+                        . ' title="Cancel">'
+                        . $this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)->render()
+                        . '</a>';
         return '<span id="' . $elementId . '">'
             . $selector
             . '<span class="btn-group">'
@@ -302,9 +319,13 @@ class PermissionAjaxController
     {
         $page = (int)$page;
         if ($editLockState === 1) {
-            $ret = '<span id="el_' . $page . '"><a class="editlock btn btn-default" data-page="' . $page . '" data-lockstate="1" title="The page and all content is locked for editing by all non-Admin users.">' . $this->iconFactory->getIcon('actions-lock', Icon::SIZE_SMALL)->render() . '</a></span>';
+            $ret = '<span id="el_' . $page . '"><a class="editlock btn btn-default" data-page="' . $page
+                   . '" data-lockstate="1" title="The page and all content is locked for editing by all non-Admin users.">'
+                   . $this->iconFactory->getIcon('actions-lock', Icon::SIZE_SMALL)->render() . '</a></span>';
         } else {
-            $ret = '<span id="el_' . $page . '"><a class="editlock btn btn-default" data-page="' . $page . '" data-lockstate="0" title="Enable the &raquo;Admin-only&laquo; edit lock for this page">' . $this->iconFactory->getIcon('actions-unlock', Icon::SIZE_SMALL)->render() . '</a></span>';
+            $ret = '<span id="el_' . $page . '"><a class="editlock btn btn-default" data-page="' . $page .
+                   '" data-lockstate="0" title="Enable the &raquo;Admin-only&laquo; edit lock for this page">'
+                   . $this->iconFactory->getIcon('actions-unlock', Icon::SIZE_SMALL)->render() . '</a></span>';
         }
         return $ret;
     }
index 9842cbd..0e19034 100644 (file)
@@ -2,8 +2,8 @@
        <a
                class="ug_selector changegroup"
                data-page="{pageId}"
-               data-owner="{groupId}"
-               data-username="{groupname}"
+               data-group-id="{groupId}"
+               data-groupname="{groupname}"
        >
                <f:if condition="{groupId} == 0">
                        <f:then>
index 6165036..036de1e 100644 (file)
@@ -1,8 +1 @@
-<f:render
-       partial="Permission/Groupname"
-       arguments="{
-               pageId: '{pageId}',
-               groupId: '{groupId}',
-               groupname: '{groupname}'
-       }"
-/>
+<f:render partial="Permission/Groupname" arguments="{pageId: pageId, groupId: groupId, groupname: groupname}" />
index 1a3b6b1..9a1c477 100644 (file)
@@ -1,8 +1 @@
-<f:render
-       partial="Permission/Ownername"
-       arguments="{
-               pageId: '{pageId}',
-               userId: '{userId}',
-               username: '{username}'
-       }"
-/>
+<f:render partial="Permission/Ownername" arguments="{pageId: pageId, userId: userId, username: username}" />
index ad68902..cb49991 100644 (file)
@@ -164,7 +164,7 @@ define(['jquery'], function($) {
                        data: {
                                'action': 'show_change_owner_selector',
                                'page': page,
-                               'ownerUid': $element.data('ownerUid'),
+                               'ownerUid': $element.data('owner'),
                                'username': $element.data('username')
                        }
                }).done(function(data) {
@@ -223,7 +223,7 @@ define(['jquery'], function($) {
                        data: {
                                'action': 'change_group',
                                'page': page,
-                               'groupUid': $element.data('group'),
+                               'groupUid': $element.data('groupId'),
                                'newGroupUid': $('#new_page_group').val()
                        }
                }).done(function(data) {
@@ -248,7 +248,7 @@ define(['jquery'], function($) {
                        data: {
                                'action': 'show_change_group_selector',
                                'page': page,
-                               'groupUid': $element.data('lockstate'),
+                               'groupUid': $element.data('groupId'),
                                'groupname': $element.data('groupname')
                        }
                }).done(function(data) {
@@ -280,7 +280,7 @@ define(['jquery'], function($) {
                var aSelector = $('<a/>', {
                        'class': 'ug_selector changegroup',
                        'data-page': page,
-                       'data-group': $element.data('group'),
+                       'data-group': $element.data('groupId'),
                        'data-groupname': groupnameHtml,
                        'text': groupname
                });