Fix reading ACL values in non-Ajax form builder forms (#4060)
authorMatthias Schmidt <gravatronics@live.com>
Tue, 9 Mar 2021 15:21:04 +0000 (16:21 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Mar 2021 15:21:04 +0000 (16:21 +0100)
The wrong data source was used in `AclFormField` (the whole `$_POST` array instead of the dedicated entry) and the data was always stored in `aclValues` instead of a dedicated entry per form field.

com.woltlab.wcf/templates/__aclFormField.tpl
com.woltlab.wcf/templates/aclPermissionJavaScript.tpl
wcfsetup/install/files/acp/templates/__aclFormField.tpl
wcfsetup/install/files/acp/templates/aclPermissionJavaScript.tpl
wcfsetup/install/files/js/WCF.ACL.js
wcfsetup/install/files/lib/system/form/builder/field/acl/AclFormField.class.php

index 1b16c1c51dc75a37e956f37a7a004a297685fe21..9fbd05189346bbdd7e25ad7ae9a3ccc8bdab1942 100644 (file)
@@ -2,4 +2,4 @@
        {include file='aclPermissions'}
 {/if}
 
-{include file='aclPermissionJavaScript' containerID=$field->getPrefixedId()|concat:'Container' categoryName=$field->getCategoryName() objectID=$field->getObjectID() objectTypeID=$field->getObjectType()->objectTypeID aclFormBuilderMode=true}
+{include file='aclPermissionJavaScript' containerID=$field->getPrefixedId()|concat:'Container' categoryName=$field->getCategoryName() objectID=$field->getObjectID() objectTypeID=$field->getObjectType()->objectTypeID aclFormBuilderMode=true aclValuesFieldName=$field->getPrefixedId()}
index 830c86576229355c336b9cfa579ec610c8b9b05e..6151e37d01709f25068b010006ac0ffe470d9098 100644 (file)
                        {/if}
                {/if}
                
-               var aclList = new {if $aclListClassName|isset}{@$aclListClassName}{else}WCF.ACL.List{/if}($('#{@$containerID}'), {@$objectTypeID}, {if $categoryName|isset}'{@$categoryName}'{else}null{/if}, {if $objectID|isset}{@$objectID}{else}0{/if}, {if !$includeUserGroups|isset || $includeUserGroups}true{else}false{/if}{if $aclValues[$objectTypeID]|isset}, initialPermissions{/if});
+               var aclList = new {if $aclListClassName|isset}{@$aclListClassName}{else}WCF.ACL.List{/if}(
+                       $('#{@$containerID}'),
+                       {@$objectTypeID},
+                       {if $categoryName|isset}'{@$categoryName}'{else}null{/if},
+                       {if $objectID|isset}{@$objectID}{else}0{/if},
+                       {if !$includeUserGroups|isset || $includeUserGroups}true{else}false{/if},
+                       {if $aclValues[$objectTypeID]|isset}initialPermissions{else}undefined{/if},
+                       {if $aclValuesFieldName|isset}'{@$aclValuesFieldName}'{else}undefined{/if}
+               );
                
                {if !$aclFormBuilderMode|empty}
                        require(['WoltLabSuite/Core/Form/Builder/Manager'], function(FormBuilderManager) {
index 1b16c1c51dc75a37e956f37a7a004a297685fe21..9fbd05189346bbdd7e25ad7ae9a3ccc8bdab1942 100644 (file)
@@ -2,4 +2,4 @@
        {include file='aclPermissions'}
 {/if}
 
-{include file='aclPermissionJavaScript' containerID=$field->getPrefixedId()|concat:'Container' categoryName=$field->getCategoryName() objectID=$field->getObjectID() objectTypeID=$field->getObjectType()->objectTypeID aclFormBuilderMode=true}
+{include file='aclPermissionJavaScript' containerID=$field->getPrefixedId()|concat:'Container' categoryName=$field->getCategoryName() objectID=$field->getObjectID() objectTypeID=$field->getObjectType()->objectTypeID aclFormBuilderMode=true aclValuesFieldName=$field->getPrefixedId()}
index 830c86576229355c336b9cfa579ec610c8b9b05e..6151e37d01709f25068b010006ac0ffe470d9098 100644 (file)
                        {/if}
                {/if}
                
-               var aclList = new {if $aclListClassName|isset}{@$aclListClassName}{else}WCF.ACL.List{/if}($('#{@$containerID}'), {@$objectTypeID}, {if $categoryName|isset}'{@$categoryName}'{else}null{/if}, {if $objectID|isset}{@$objectID}{else}0{/if}, {if !$includeUserGroups|isset || $includeUserGroups}true{else}false{/if}{if $aclValues[$objectTypeID]|isset}, initialPermissions{/if});
+               var aclList = new {if $aclListClassName|isset}{@$aclListClassName}{else}WCF.ACL.List{/if}(
+                       $('#{@$containerID}'),
+                       {@$objectTypeID},
+                       {if $categoryName|isset}'{@$categoryName}'{else}null{/if},
+                       {if $objectID|isset}{@$objectID}{else}0{/if},
+                       {if !$includeUserGroups|isset || $includeUserGroups}true{else}false{/if},
+                       {if $aclValues[$objectTypeID]|isset}initialPermissions{else}undefined{/if},
+                       {if $aclValuesFieldName|isset}'{@$aclValuesFieldName}'{else}undefined{/if}
+               );
                
                {if !$aclFormBuilderMode|empty}
                        require(['WoltLabSuite/Core/Form/Builder/Manager'], function(FormBuilderManager) {
index fd4c2e9f96fd91c9fb7b689177b38422be72c94b..8caba67a2e521d6cd2798a44079d3b18da46e72e 100644 (file)
@@ -79,8 +79,9 @@ if (COMPILER_TARGET_DEFAULT) {
                 * @param        string                categoryName
                 * @param        integer                objectID
                 * @param        boolean                includeUserGroups
+                * @param        string|undefined       aclValuesFieldName
                 */
-               init: function (containerSelector, objectTypeID, categoryName, objectID, includeUserGroups, initialPermissions) {
+               init: function (containerSelector, objectTypeID, categoryName, objectID, includeUserGroups, initialPermissions, aclValuesFieldName) {
                        this._objectID = objectID || 0;
                        this._objectTypeID = objectTypeID;
                        this._categoryName = categoryName;
@@ -91,6 +92,7 @@ if (COMPILER_TARGET_DEFAULT) {
                                group: {},
                                user: {}
                        };
+                       this._aclValuesFieldName = aclValuesFieldName || 'aclValues';
                        
                        this._proxy = new WCF.Action.Proxy({
                                showLoadingOverlay: false,
@@ -595,7 +597,7 @@ if (COMPILER_TARGET_DEFAULT) {
                                        var $object = this._values[$type][$objectID];
                                        
                                        for (var $optionID in $object) {
-                                               $('<input type="hidden" name="aclValues[' + $type + '][' + $objectID + '][' + $optionID + ']" value="' + $object[$optionID] + '" />').appendTo($form);
+                                               $('<input type="hidden" name="' + this._aclValuesFieldName + '[' + $type + '][' + $objectID + '][' + $optionID + ']" value="' + $object[$optionID] + '" />').appendTo($form);
                                        }
                                }
                        }
index 3bdae00ca858786f20620aa42ef35abc33e298d4..317f9a8033d0bda313180fa66d5e5343140fce5a 100644 (file)
@@ -150,7 +150,7 @@ class AclFormField extends AbstractFormField implements IObjectTypeFormNode {
         * @inheritDoc
         */
        public function readValue() {
-               $valueSource = $_POST;
+               $valueSource = $_POST[$this->getPrefixedId()] ?? [];
                if ($this->getDocument()->isAjax()) {
                        $valueSource = [];
                        if (