Skip to content

Commit

Permalink
Merge pull request #3136 from bolt/fix/api-access-public
Browse files Browse the repository at this point in the history
Don't break `/bolt/api/` if it's set to public and it's accessed in a browser
  • Loading branch information
bobdenotter authored Mar 24, 2022
2 parents 8b5b77d + 920a457 commit e69cdd9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
formats:
jsonld: ['application/ld+json']
json: ['application/json']
jsonld: ['application/ld+json']
jsonapi: ['application/vnd.api+json']
html: ['text/html']
# html: ['text/html']
defaults:
pagination:
client_items_per_page: true
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* @ApiResource(
* normalizationContext={"groups"={"get_content","get_definition"}},
* normalizationContext={"groups"={"get_content"}},
* denormalizationContext={"groups"={"api_write"},"enable_max_depth"=true},
* collectionOperations={
* "get"={"security"="is_granted('api:get')"},
Expand Down
9 changes: 7 additions & 2 deletions src/Menu/BackendMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ public function buildAdminMenu(): array

$locale = $this->requestStack->getCurrentRequest()->getLocale();

/** @var User $user */
/** @var User|null $user */
$user = $this->security->getUser();
$username = $user->getUsername();

if ($user instanceof User) {
$username = $user->getUsername();
} else {
$username = '';
}

$cacheKey = 'bolt.backendMenu_' . $locale . '_' . $username;

Expand Down
7 changes: 5 additions & 2 deletions templates/_base/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
<!-- Admin Toolbar -->
<nav class="admin__toolbar" id="toolbar">
{% set user_display_name = app.user.displayName|default('Unknown user') %}
{% set user_avatar = app.user.avatar|thumbnail(25, 25, 'crop')|default(null) %}

{% if user_avatar ends with 'placeholder.png' %}
{% if app.user.avatar is defined %}
{% set user_avatar = app.user.avatar|thumbnail(25, 25, 'crop')|default(null) %}
{% endif %}

{% if app.user.avatar is not defined or user_avatar ends with 'placeholder.png' %}
{% set user_avatar = null %}
{% endif %}

Expand Down

0 comments on commit e69cdd9

Please sign in to comment.