Skip to content

Commit 7863d4e

Browse files
committed
review: check if rolesDiagram is not empty before injecting flowchart scripts
1 parent c79dd55 commit 7863d4e

File tree

5 files changed

+6
-8
lines changed

5 files changed

+6
-8
lines changed

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ CHANGELOG
33

44
7.4
55
---
6-
76
* Add role hierarchy graph to the profiler security panel
87
* Add `debug:security:role-hierarchy` command to dump role hierarchy graphs in the Mermaid.js flowchart format
9-
* Add `Security::getAccessDecision()` and `getAccessDecisionForUser()` helpers
8+
* Add `Security::getAccessDecision()` and `getAccessDecisionForUser()` helpers
109
* Add options to configure a cache pool and storage service for login throttling rate limiters
1110
* Register alias for argument for password hasher when its key is not a class name:
1211

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
9494
$impersonatorUser = $originalToken->getUserIdentifier();
9595
}
9696

97-
if (null !== $this->roleHierarchy) {
97+
if ($this->roleHierarchy) {
9898
foreach ($this->roleHierarchy->getReachableRoleNames($assignedRoles) as $role) {
9999
if (!\in_array($role, $assignedRoles, true)) {
100100
$inheritedRoles[] = $role;
@@ -223,7 +223,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
223223
$response->headers->clearCookie($authCookieName);
224224
}
225225
}
226-
if (null !== $this->roleHierarchy) {
226+
if ($this->roleHierarchy) {
227227
$this->data['roles_diagram'] = $this->mermaidDumper->dump($this->roleHierarchy);
228228
}
229229
}

src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
</td>
247247
</tr>
248248

249-
{% if collector.supportsRoleHierarchy %}
249+
{% if collector.supportsRoleHierarchy and collector.rolesDiagram is not empty %}
250250
<script>
251251
{{ source('@WebProfiler/Script/Mermaid/mermaid-flowchart-v2.min.js') }}
252252
const isDarkMode = document.querySelector('body').classList.contains('theme-dark');

src/Symfony/Component/Security/Core/Dumper/MermaidDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function dump(RoleHierarchyInterface $roleHierarchy, MermaidDirection $di
3232
$hierarchy = $this->extractHierarchy($roleHierarchy);
3333

3434
if (!$hierarchy) {
35-
return "graph {$direction->value}\n classDef default fill:#e1f5fe;";
35+
return "";
3636
}
3737

3838
$output = ["graph {$direction->value}"];

src/Symfony/Component/Security/Core/Tests/Dumper/MermaidDumperTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public function testDumpEmptyHierarchy()
5757
$dumper = new MermaidDumper();
5858
$output = $dumper->dump($roleHierarchy);
5959

60-
$this->assertStringContainsString('graph TB', $output);
61-
$this->assertStringContainsString('classDef default fill:#e1f5fe;', $output);
60+
$this->assertEmpty($output);
6261
}
6362

6463
public function testDumpComplexHierarchy()

0 commit comments

Comments
 (0)