Skip to content

Commit

Permalink
Move legacy code of canAccessIssue to subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed May 5, 2020
1 parent ed5611e commit 9435b2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
10 changes: 1 addition & 9 deletions lib/eventum/class.workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -992,15 +992,7 @@ public static function canAccessIssue($prj_id, $issue_id, $usr_id)
$event = new GenericEvent(null, $arguments);
EventManager::dispatch(SystemEvents::ACCESS_ISSUE, $event);

if ($event->isPropagationStopped()) {
return false;
}

if (!$backend = self::getBackend($prj_id)) {
return null;
}

return $backend->canAccessIssue($prj_id, $issue_id, $usr_id);
return $event->isPropagationStopped() ? false : true;
}

/**
Expand Down
21 changes: 20 additions & 1 deletion src/Extension/Legacy/WorkflowLegacyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

namespace Eventum\Extension\Legacy;

use Eventum\Event\SystemEvents;
use Eventum\Extension\Provider;
use Symfony\Component\EventDispatcher\GenericEvent;
use Workflow;

/**
* Extension that adds integration of legacy workflow classes to Extension events
Expand All @@ -23,7 +26,23 @@ class WorkflowLegacyExtension implements Provider\SubscriberProvider
public function getSubscribers(): array
{
return [

/** @see WorkflowLegacyExtension::canAccessIssue */
SystemEvents::ACCESS_ISSUE => ['canAccessIssue'],
];
}

/**
* @see Workflow::canAccessIssue
*/
public function canAccessIssue(GenericEvent $event): void
{
if (!$backend = Workflow::getBackend($event['prj_id'])) {
return;
}

$canAccess = $backend->canAccessIssue($event['prj_id'], $event['issue_id'], $event['usr_id']);
if ($canAccess === false) {
$event->stopPropagation();
}
}
}

0 comments on commit 9435b2c

Please sign in to comment.