From 0e424821a8ff96b0ebdb215608c641f8d9cf36b8 Mon Sep 17 00:00:00 2001 From: John Milmine Date: Thu, 8 May 2014 14:13:17 +1200 Subject: [PATCH 1/3] Update GridFieldOrderableRows.php If it's a many many relationship, then it should be based on View not edit, as the sort field will be on the relationship using many_many_extraFields. Plus the view permission allows the user to create a many relationship, so it should allow editing of the relationship. --- code/GridFieldOrderableRows.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/GridFieldOrderableRows.php b/code/GridFieldOrderableRows.php index fdf75fe..3ce2538 100755 --- a/code/GridFieldOrderableRows.php +++ b/code/GridFieldOrderableRows.php @@ -138,7 +138,9 @@ class GridFieldOrderableRows extends RequestHandler implements * Handles requests to reorder a set of IDs in a specific order. */ public function handleReorder($grid, $request) { - if(!singleton($grid->getModelClass())->canEdit()) { + if (is_a($grid->getList(), 'ManyManyList') && !singleton($grid->getModelClass())->canView()) { + $this->httpError(403); + } else if(!is_a($grid->getList(), 'ManyManyList') && !singleton($grid->getModelClass())->canEdit()) { $this->httpError(403); } From d983768165a2c3cb15c92a561b79c4386c38dc6a Mon Sep 17 00:00:00 2001 From: John Milmine Date: Mon, 26 May 2014 16:13:19 +1200 Subject: [PATCH 2/3] fixed many many ordering so that other many many lists with the same relation aren't affected --- code/GridFieldOrderableRows.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/GridFieldOrderableRows.php b/code/GridFieldOrderableRows.php index fdf75fe..da5bb78 100755 --- a/code/GridFieldOrderableRows.php +++ b/code/GridFieldOrderableRows.php @@ -278,9 +278,11 @@ class GridFieldOrderableRows extends RequestHandler implements if($list instanceof ManyManyList) { $extra = $list->getExtraFields(); $key = $list->getLocalKey(); + $foreignKey = $list->getForeignKey(); + $foreignID = '= ' . (int) $list->getForeignID(); if(array_key_exists($this->getSortField(), $extra)) { - return sprintf('"%s" %s', $key, $value); + return sprintf('"%s" %s AND "%s" %s', $key, $value, $foreignKey, $foreignID); } } From 5af8f1086923a606c138503f503fffcfe0e3f6c8 Mon Sep 17 00:00:00 2001 From: John Milmine Date: Thu, 29 Jan 2015 16:18:24 +1300 Subject: [PATCH 3/3] refactored to make code cleaner --- code/GridFieldOrderableRows.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/GridFieldOrderableRows.php b/code/GridFieldOrderableRows.php index d996152..5923cd5 100755 --- a/code/GridFieldOrderableRows.php +++ b/code/GridFieldOrderableRows.php @@ -138,14 +138,15 @@ class GridFieldOrderableRows extends RequestHandler implements * Handles requests to reorder a set of IDs in a specific order. */ public function handleReorder($grid, $request) { - if (is_a($grid->getList(), 'ManyManyList') && !singleton($grid->getModelClass())->canView()) { + $list = $grid->getList(); + $modelClass = $grid->getModelClass(); + if ($list instanceof ManyManyList && !singleton($modelClass)->canView()) { $this->httpError(403); - } else if(!is_a($grid->getList(), 'ManyManyList') && !singleton($grid->getModelClass())->canEdit()) { + } else if(!($list instanceof ManyManyList) && !singleton($modelClass)->canEdit()) { $this->httpError(403); } $ids = $request->postVar('order'); - $list = $grid->getList(); $field = $this->getSortField(); if(!is_array($ids)) {