Skip to content
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

DDST-382: Handle errors while deleting orphaned embargo #41

Merged
merged 7 commits into from
Aug 5, 2024
13 changes: 9 additions & 4 deletions src/Entity/Embargo.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ public function getCacheMaxAge() {
* {@inheritdoc}
*/
public function getCacheTags() {
$tags = Cache::mergeTags(parent::getCacheTags(), $this->getEmbargoedNode()->getCacheTags());
$tags = parent::getCacheTags();
if ($node = $this->getEmbargoedNode()) {
$tags = Cache::mergeTags($tags, $node->getCacheTags());
}

if ($this->getExemptIps()) {
$tags = Cache::mergeTags($tags, $this->getExemptIps()->getCacheTags());
Expand All @@ -411,9 +414,11 @@ public function getCacheTags() {
public function getCacheContexts() {
$contexts = Cache::mergeContexts(
parent::getCacheContexts(),
$this->getEmbargoedNode()->getCacheContexts(),
['user.embargo__has_exemption'],
);
if ($node = $this->getEmbargoedNode()) {
$contexts = Cache::mergeContexts($contexts, $node->getCacheContexts());
}

if ($this->getExemptIps()) {
$contexts = Cache::mergeContexts($contexts, $this->getExemptIps()->getCacheContexts());
Expand All @@ -439,8 +444,8 @@ public function isUserExempt(AccountInterface $user): bool {
$exempt_users = $this->getExemptUsers();
$has_permission = $user->hasPermission('bypass embargo access');
return $has_permission || in_array($user->id(), array_map(function (UserInterface $user) {
return $user->id();
}, $exempt_users));
return $user->id();
}, $exempt_users));
adam-vessey marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Loading