-
Notifications
You must be signed in to change notification settings - Fork 6
Change in crud return management 2le/crudit#591 #540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a263bc
Change in crud return management 2le/crudit#591
valentin-helies c9101db
Fix PHPCS
valentin-helies 2a18232
Merge branch 'main' into feature/upgrade-redirect-system
valentin-helies 9b126ee
Finalisation of referrer management
valentin-helies 0f8e8a5
Remove unused template
valentin-helies 72c94de
Remove useless use
valentin-helies 3c4c033
Disable listener when stateless request
valentin-helies 164eb68
Remove duplicated code
valentin-helies 33e1b2a
Fix role on ShowAction
valentin-helies 6f3fa2c
Fix role on ShowAction
valentin-helies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <?php | ||
|
|
||
| namespace Lle\CruditBundle\EventListener; | ||
|
|
||
| use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
| use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
|
|
||
| // This listener allows you to manage your browsing history. | ||
| class KernelRequestListener | ||
| { | ||
| public function __construct( | ||
| protected ParameterBagInterface $parameterBag, | ||
| ) { | ||
| } | ||
|
|
||
| public function onKernelRequest(RequestEvent $event): void | ||
SpaghettiBolognaise marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| // Ignore AJAX calls and referrers not related to documents | ||
| if ( | ||
| $event->getRequest()->isXmlHttpRequest() | ||
| || $event->getRequest()->attributes->get('_stateless') === true | ||
| || $event->getRequest()->headers->get('sec-fetch-dest') !== 'document' | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| $referer = $event->getRequest()->headers->get('referer'); | ||
| $requestUri = $event->getRequest()->getUri(); | ||
| $requestMethod = $event->getRequest()->getMethod(); | ||
|
|
||
| // Ignore routes defined in the configuration | ||
| /** @var array $ignoredRoutes */ | ||
| $ignoredRoutes = $this->parameterBag->get('lle_crudit.ignore_referer_routes'); | ||
| if (array_any($ignoredRoutes, fn($ignoredRoute) => preg_match($ignoredRoute, $referer))) { | ||
| return; | ||
| } | ||
|
|
||
| $session = $event->getRequest()->getSession(); | ||
| $cruditReferer = json_decode($session->get('lle_crudit_referers'), true); | ||
|
|
||
| // Remove the last referer if it's the current one | ||
| if ($cruditReferer && end($cruditReferer) === $requestUri) { | ||
| array_pop($cruditReferer); | ||
|
|
||
| $session->set('lle_crudit_referers', json_encode($cruditReferer)); | ||
| } elseif ( | ||
| $requestMethod !== 'POST' | ||
| && (!$cruditReferer || end($cruditReferer) !== $referer) | ||
| && $referer !== $requestUri | ||
| ) { | ||
| $cruditReferer[] = $referer; | ||
|
|
||
| // Keep only the last 20 referers | ||
| while (count($cruditReferer) > 20) { | ||
| array_shift($cruditReferer); | ||
| } | ||
|
|
||
| $session->set('lle_crudit_referers', json_encode($cruditReferer)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| {% block list_action %} | ||
| {% set cruditReferers = app.session.get('lle_crudit_referers')|json_decode %} | ||
| {% if not cruditReferers|length %} | ||
| {% set disabled = disabled or not | ||
| ((action.path.role is null or is_granted(action.path.role, view.data.resource)) | ||
| and (action.role is null or is_granted(action.role, view.data.resource))) | ||
| %} | ||
| {% endif %} | ||
|
|
||
| <a | ||
| {% block attributes %} | ||
| rel="noreferrer" | ||
| class=" | ||
| {{ action.cssClass ?? 'btn btn-sm btn-primary mt-2 ms-1 mt-md-0 crudit-action' }} | ||
| {% if disabled %} disabled{% endif %} | ||
| " | ||
| {% if action.modal %} | ||
| data-bs-toggle="modal" | ||
| data-bs-target="#modal_{{ action.id }}" | ||
| {% elseif action.confirmModal %} | ||
| data-bs-toggle="modal" | ||
| data-bs-target="#modal-confirm" | ||
| data-confirm-link="{{ path(action.path.route, params) }}" | ||
| data-confirm-text="{{ ('modal.confirm.' ~ action.label)|trans(domain=view.config.translation_domain) }}" | ||
| {% elseif not disabled %} | ||
| {% if cruditReferers|length %} | ||
| href="{{ cruditReferers|last }}" | ||
| {% else %} | ||
| href="{{ action.url ?? path(action.path.route, params) }}" | ||
| {% endif %} | ||
| {% endif %} | ||
|
|
||
| {% if action.target is defined and action.target %} | ||
| target="{{ action.target }}" | ||
| {% endif %} | ||
| {% endblock %} | ||
| > | ||
| {% if action.icon %} | ||
| {% block icon %}<i class="{{ action.icon.cssClass }}"></i>{% endblock %} | ||
| {% endif %} | ||
| {% if not action.hideLabel %} | ||
| {% block label %}{{ action.label|trans(domain=view.config.translation_domain) }}{% endblock %} | ||
| {% endif %} | ||
| </a> | ||
| {% endblock %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.