Skip to content

Commit 2373644

Browse files
authored
Merge pull request #223 from Arne1303/fix-unauthorized-columns
fix: unauthorized columns being displayed by the builder
2 parents 88c5f71 + 895f46c commit 2373644

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Html/Options/HasColumns.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ public function columns(array $columns): static
9292

9393
$this->collection->push(new Column($attributes));
9494
} else {
95-
$this->collection->push($value);
95+
96+
// Only add the column if it is authorized, otherwise ignore it.
97+
if ($value->isAuthorized()) {
98+
$this->collection->push($value);
99+
}
96100
}
97101
}
98102

tests/BuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,19 @@ public function it_has_editors()
287287
]);
288288
$this->assertCount(2, $builder->getEditors());
289289
}
290+
291+
#[Test]
292+
public function it_ignores_unauthorized_columns(): void
293+
{
294+
$builder = $this->getHtmlBuilder();
295+
296+
$builder->columns([
297+
Column::makeIf(false)
298+
->title('unauthorized_column'),
299+
300+
Column::make('authorized_column'),
301+
]);
302+
303+
$this->assertCount(1, $builder->getColumns());
304+
}
290305
}

0 commit comments

Comments
 (0)