From 08d173f24af4fcf51bde399e2dac820b580636db Mon Sep 17 00:00:00 2001 From: Jake Bentvelzen Date: Thu, 19 May 2016 13:22:24 +1000 Subject: [PATCH] fix(Reorder): Fix bug where 'Content Authors' can no longer re-order form fields due to how GridFieldOrderableRows checks canEdit() permissions. fix(Reorder): Fix EditableFormField to fallback to current page editing permissions when reordering with GridFieldOrderableRows component. fix(Reorder): Check if record exists before calling 'hasExtension' check. --- .../editableformfields/EditableFormField.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/code/model/editableformfields/EditableFormField.php b/code/model/editableformfields/EditableFormField.php index cee82c1..91977d7 100755 --- a/code/model/editableformfields/EditableFormField.php +++ b/code/model/editableformfields/EditableFormField.php @@ -365,6 +365,22 @@ class EditableFormField extends DataObject { $parent = $this->Parent(); if($parent && $parent->exists()) { return $parent->canEdit($member) && !$this->isReadonly(); + } else if ($this->ID == 0) { + // This is for GridFieldOrderableRows support as it checks edit permissions on + // singleton of the class. Allows editing of User Defined Form pages by + // 'Content Authors' and those with permission to edit the UDF page. (ie. CanEditType/EditorGroups) + // This is to restore User Forms 2.x backwards compatibility. + $controller = Controller::curr(); + if ($controller && $controller instanceof CMSPageEditController) + { + $parent = $controller->getRecord($controller->currentPageID()); + // Only allow this behaviour on pages using UserFormFieldEditorExtension, such + // as UserDefinedForm page type. + if ($parent && $parent->hasExtension('UserFormFieldEditorExtension')) + { + return $parent->canEdit($member); + } + } } // Fallback to secure admin permissions