Skip to content

Commit

Permalink
[Badge] fixes organization filter for data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Mar 1, 2023
1 parent 040f776 commit 74e411f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/plugin/open-badge/Listener/DataSource/BadgesSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,8 @@ public function getData(GetDataEvent $event)

if (DataSource::CONTEXT_WORKSPACE === $event->getContext()) {
$options['hiddenFilters']['workspace'] = $event->getWorkspace()->getUuid();
} elseif (!$this->authorization->isGranted('ROLE_ADMIN')) {
// only display badges for the current user organization
$options['hiddenFilters']['organizations'] = [];

$user = $this->tokenStorage->getToken()->getUser();
if ($user instanceof User) {
$options['hiddenFilters']['organizations'] = array_map(function (Organization $organization) {
return $organization->getUuid();
}, $user->getOrganizations());
}
} elseif (!$this->authorization->isGranted('ROLE_ADMIN') && (empty($options['filters']) || empty($options['filters']['organizations']))) {
$options['hiddenFilters']['organizations'] = $this->getOrganizations();
}

$event->setData(
Expand All @@ -55,4 +47,16 @@ public function getData(GetDataEvent $event)

$event->stopPropagation();
}

private function getOrganizations(): array
{
$user = $this->tokenStorage->getToken()->getUser();
if ($user instanceof User) {
return array_map(function (Organization $organization) {
return $organization->getUuid();
}, $user->getOrganizations());
}

return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ export default {
options: {
objectClass: 'Claroline\\OpenBadgeBundle\\Entity\\BadgeClass'
}
}, {
name: 'organizations',
type: 'organizations',
label: trans('organizations'),
displayable: false,
displayed: false,
sortable: false,
filterable: true
}
],
card: BadgeCard
Expand Down

0 comments on commit 74e411f

Please sign in to comment.