Skip to content

Commit

Permalink
Merge branch 'feature/user-context' of github.com:justbetter/magento2…
Browse files Browse the repository at this point in the history
…-sentry into feature/user-context
  • Loading branch information
indykoning committed Mar 28, 2024
2 parents ce3ff95 + fc8879b commit f88644f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Model/SentryInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

// phpcs:disable Magento2.Functions.DiscouragedFunction

use function Sentry\captureException;
use function Sentry\configureScope;
use function Sentry\init;
use Magento\Authorization\Model\UserContextInterface;
use Magento\Backend\Model\Auth\Session as AdminSession;
use Magento\Customer\Model\Session as CustomerSession;
Expand All @@ -17,12 +14,17 @@
use Magento\Framework\Exception\LocalizedException;
use Sentry\State\Scope;

use function Sentry\captureException;
use function Sentry\configureScope;
use function Sentry\init;

class SentryInteraction
{
public function __construct(
private UserContextInterface $userContext,
private State $appState
) { }
) {
}

public function initialize($config)
{
Expand All @@ -49,7 +51,7 @@ private function getSessionUserData()
if ($this->appState->getAreaCode() === Area::AREA_ADMINHTML) {
$adminSession = $objectManager->get(AdminSession::class);

if($adminSession->isLoggedIn()) {
if ($adminSession->isLoggedIn()) {
return [
'id' => $adminSession->getUser()->getId(),
'email' => $adminSession->getUser()->getEmail(),
Expand All @@ -61,7 +63,7 @@ private function getSessionUserData()
if ($this->appState->getAreaCode() === Area::AREA_FRONTEND) {
$customerSession = $objectManager->get(CustomerSession::class);

if($customerSession->loggedIn()) {
if ($customerSession->loggedIn()) {
return [
'id' => $customerSession->getCustomer()->getId(),
'email' => $customerSession->getCustomer()->getEmail(),
Expand All @@ -80,6 +82,7 @@ public function addUserContext()
$userId = null;
$userType = null;
$userData = [];

try {
$userId = $this->userContext->getUserId();
if ($userId) {
Expand All @@ -100,7 +103,7 @@ public function addUserContext()
$scope->setUser([
'id' => $userId,
...$userData,
'user_type' => match($userType) {
'user_type' => match ($userType) {
UserContextInterface::USER_TYPE_INTEGRATION => 'integration',
UserContextInterface::USER_TYPE_ADMIN => 'admin',
UserContextInterface::USER_TYPE_CUSTOMER => 'customer',
Expand Down

0 comments on commit f88644f

Please sign in to comment.