mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Enforece that part lot owner matches storage location owner, if option is selected
This commit is contained in:
parent
a7ff690891
commit
1acceae81e
2 changed files with 25 additions and 2 deletions
|
@ -34,6 +34,7 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This entity describes a lot where parts can be stored.
|
* This entity describes a lot where parts can be stored.
|
||||||
|
@ -332,10 +333,26 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Assert\Callback
|
||||||
|
*/
|
||||||
|
public function validate(ExecutionContextInterface $context, $payload)
|
||||||
|
{
|
||||||
|
//When the storage location sets the owner must match, the part lot owner must match the storage location owner
|
||||||
|
if ($this->getStorageLocation() && $this->getStorageLocation()->isPartOwnerMustMatch()
|
||||||
|
&& $this->getStorageLocation()->getOwner() && $this->getOwner()) {
|
||||||
|
if ($this->getOwner() !== $this->getStorageLocation()->getOwner()
|
||||||
|
&& $this->owner->getID() !== $this->getStorageLocation()->getOwner()->getID()) {
|
||||||
|
$context->buildViolation('validator.part_lot.owner_must_match_storage_location_owner')
|
||||||
|
->setParameter('%owner_name%', $this->getStorageLocation()->getOwner()->getFullName(true))
|
||||||
|
->atPath('owner')
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,5 +305,11 @@
|
||||||
<target>Set a value here, or upload a file to automatically use its filename as name for the attachment.</target>
|
<target>Set a value here, or upload a file to automatically use its filename as name for the attachment.</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="nwGaNBW" name="validator.part_lot.owner_must_match_storage_location_owner">
|
||||||
|
<segment>
|
||||||
|
<source>validator.part_lot.owner_must_match_storage_location_owner</source>
|
||||||
|
<target>The owner of this lot must match the owner of the selected storage location (%owner_name%)!</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue