mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #10759 from creative-commoners/pulls/4.12/gridfieldprint-canview
Check canView before printing from GridField
This commit is contained in:
commit
961499f640
@ -228,6 +228,7 @@ class GridFieldPrintButton extends AbstractGridFieldComponent implements GridFie
|
|||||||
|
|
||||||
/** @var DataObject $item */
|
/** @var DataObject $item */
|
||||||
foreach ($items->limit(null) as $item) {
|
foreach ($items->limit(null) as $item) {
|
||||||
|
if (!$item->hasMethod('canView') || $item->canView()) {
|
||||||
$itemRow = new ArrayList();
|
$itemRow = new ArrayList();
|
||||||
|
|
||||||
foreach ($printColumns as $field => $label) {
|
foreach ($printColumns as $field => $label) {
|
||||||
@ -243,6 +244,7 @@ class GridFieldPrintButton extends AbstractGridFieldComponent implements GridFie
|
|||||||
$itemRows->push(new ArrayData([
|
$itemRows->push(new ArrayData([
|
||||||
"ItemRow" => $itemRow
|
"ItemRow" => $itemRow
|
||||||
]));
|
]));
|
||||||
|
}
|
||||||
if ($item->hasMethod('destroy')) {
|
if ($item->hasMethod('destroy')) {
|
||||||
$item->destroy();
|
$item->destroy();
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,19 @@ class GridFieldPrintButtonTest extends SapphireTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testLimit()
|
public function testLimit()
|
||||||
|
{
|
||||||
|
$this->assertEquals(42, $this->getTestableRows()->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanViewIsRespected()
|
||||||
|
{
|
||||||
|
$orig = TestObject::$canView;
|
||||||
|
TestObject::$canView = false;
|
||||||
|
$this->assertEquals(0, $this->getTestableRows()->count());
|
||||||
|
TestObject::$canView = $orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTestableRows()
|
||||||
{
|
{
|
||||||
$list = TestObject::get();
|
$list = TestObject::get();
|
||||||
|
|
||||||
@ -48,7 +61,6 @@ class GridFieldPrintButtonTest extends SapphireTest
|
|||||||
|
|
||||||
// Printed data should ignore pagination limit
|
// Printed data should ignore pagination limit
|
||||||
$printData = $button->generatePrintData($gridField);
|
$printData = $button->generatePrintData($gridField);
|
||||||
$rows = $printData->ItemRows;
|
return $printData->ItemRows;
|
||||||
$this->assertEquals(42, $rows->count());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,11 @@ class TestObject extends DataObject implements TestOnly
|
|||||||
private static $db = [
|
private static $db = [
|
||||||
'Name' => 'Varchar'
|
'Name' => 'Varchar'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static bool $canView = true;
|
||||||
|
|
||||||
|
public function canView($member = null)
|
||||||
|
{
|
||||||
|
return static::$canView;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user