Skip to content

Commit

Permalink
[shopsys] Role ROLE_ALL_API sees all company complaints (#3534)
Browse files Browse the repository at this point in the history
Co-authored-by: Michal Vanek <[email protected]>
  • Loading branch information
AmpMVn and Michal Vanek authored Nov 2, 2024
1 parent a3cec58 commit e38a8be
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/Migrations/Version20241023142037.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Shopsys\FrameworkBundle\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;

final class Version20241023142037 extends AbstractMigration
{
/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema): void
{
$this->sql('ALTER TABLE complaints ADD customer_id INT DEFAULT NULL');
$this->sql('UPDATE complaints c SET customer_id = cu.customer_id FROM customer_users cu WHERE cu.id = c.customer_user_id');
$this->sql(
'
ALTER TABLE
complaints
ADD
CONSTRAINT FK_A05AAF3A9395C3F3 FOREIGN KEY (customer_id) REFERENCES customers (id) ON DELETE
SET
NULL NOT DEFERRABLE INITIALLY IMMEDIATE',
);
$this->sql('CREATE INDEX IDX_A05AAF3A9395C3F3 ON complaints (customer_id)');
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema): void
{
}
}
26 changes: 25 additions & 1 deletion src/Model/Complaint/Complaint.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ class Complaint
*/
protected $items;

/**
* @var \Shopsys\FrameworkBundle\Model\Customer\Customer|null
* @ORM\ManyToOne(targetEntity="Shopsys\FrameworkBundle\Model\Customer\Customer")
* @ORM\JoinColumn(nullable=true, name="customer_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected $customer;

/**
* @param \Shopsys\FrameworkBundle\Model\Complaint\ComplaintData $complaintData
* @param \Shopsys\FrameworkBundle\Model\Complaint\ComplaintItem[] $complaintItems
Expand All @@ -139,7 +146,7 @@ public function __construct(ComplaintData $complaintData, array $complaintItems)
$this->number = $complaintData->number;
$this->domainId = $complaintData->domainId;
$this->order = $complaintData->order;
$this->customerUser = $complaintData->customerUser;
$this->setCustomerUser($complaintData->customerUser);

$this->setData($complaintData);

Expand Down Expand Up @@ -317,4 +324,21 @@ protected function setItems($items): void
$item->setComplaint($this);
}
}

/**
* @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser|null $customerUser
*/
protected function setCustomerUser($customerUser): void
{
$this->customerUser = $customerUser;
$this->customer = $customerUser?->getCustomer();
}

/**
* @return \Shopsys\FrameworkBundle\Model\Customer\Customer|null
*/
public function getCustomer()
{
return $this->customer;
}
}

0 comments on commit e38a8be

Please sign in to comment.