Skip to content

Commit

Permalink
use auth guard, fix edge case for guest
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgehrmann committed Mar 26, 2021
1 parent 5a913e1 commit 721e6bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion resources/views/Widgets/FeedbackOrderWidget.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
:item-images="{{ Twig.print("data.itemImages | json_encode") }}"
:options="{{ options | json_encode }}"
:split-item-bundles="{{ Twig.print("splitItemBundle | json_encode") }}"
access-key="{{ Twig.print("feedbackServices.feedback.getOrderAccessKey(data.order.id)") }}"
access-key="{{ Twig.print(Twig.call("feedbackServices.feedback.getOrderAccessKey", [Twig.var("data.order.id")])) }}"
order-id="{{ Twig.print("data.order.id | json_encode") }}">
</feedback-order-container>
</div>
Expand Down
12 changes: 10 additions & 2 deletions src/Services/FeedbackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function () use ($accountService) {

$allowGuestFeedbacks = $this->coreHelper->configValueAsBool(FeedbackCoreHelper::KEY_ALLOW_GUEST_FEEDBACKS);

if (!$allowGuestFeedbacks && $creatorContactId == 0) {
if (!$allowGuestFeedbacks && $creatorContactId == 0 && $order == null) {
return 'Guests are not allowed to write feedbacks';
}

Expand Down Expand Up @@ -485,7 +485,15 @@ public function getAuthenticatedUser($itemId, $variationId)
public function getOrderAccessKey($orderId)
{
$orderRepository = pluginApp(OrderRepositoryContract::class);
return $orderRepository->generateAccessKey($orderId);
$authHelper = pluginApp(AuthHelper::class);

$accessKey = $authHelper->processUnguarded(
function () use ($orderRepository, $orderId) {
return $orderRepository->generateAccessKey($orderId);
}
);

return $accessKey;
}

/**
Expand Down

0 comments on commit 721e6bb

Please sign in to comment.