-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Training] fixes organization filter for data source
- Loading branch information
Showing
7 changed files
with
80 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Claroline Connect package. | ||
* | ||
* (c) Claroline Consortium <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Claroline\CursusBundle\Listener\DataSource; | ||
|
||
use Claroline\AppBundle\API\FinderProvider; | ||
|
@@ -51,17 +42,8 @@ public function getData(GetDataEvent $event) | |
$options = $event->getOptions(); | ||
$options['hiddenFilters']['hidden'] = false; | ||
|
||
if (!$this->authorization->isGranted('ROLE_ADMIN')) { | ||
$user = $this->tokenStorage->getToken()->getUser(); | ||
if ($user instanceof User) { | ||
$organizations = $user->getOrganizations(); | ||
} else { | ||
$organizations = $this->om->getRepository(Organization::class)->findBy(['default' => true]); | ||
} | ||
|
||
$options['hiddenFilters']['organizations'] = array_map(function (Organization $organization) { | ||
return $organization->getUuid(); | ||
}, $organizations); | ||
if (!$this->authorization->isGranted('ROLE_ADMIN') && (empty($options['filters']) || empty($options['filters']['organizations']))) { | ||
$options['hiddenFilters']['organizations'] = $this->getOrganizations(); | ||
} | ||
|
||
$event->setData( | ||
|
@@ -70,4 +52,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 []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Claroline Connect package. | ||
* | ||
* (c) Claroline Consortium <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Claroline\CursusBundle\Listener\DataSource; | ||
|
||
use Claroline\AppBundle\API\FinderProvider; | ||
|
@@ -59,20 +50,8 @@ public function getData(GetDataEvent $event) | |
$options['hiddenFilters']['session'] = array_map(function (Session $session) { | ||
return $session->getUuid(); | ||
}, $this->sessionRepo->findByWorkspace($event->getWorkspace())); | ||
} else { | ||
// filter by organization for desktop | ||
if (!$this->authorization->isGranted('ROLE_ADMIN')) { | ||
$user = $this->tokenStorage->getToken()->getUser(); | ||
if ($user instanceof User) { | ||
$organizations = $user->getOrganizations(); | ||
} else { | ||
$organizations = $this->om->getRepository(Organization::class)->findBy(['default' => true]); | ||
} | ||
|
||
$options['hiddenFilters']['organizations'] = array_map(function (Organization $organization) { | ||
return $organization->getUuid(); | ||
}, $organizations); | ||
} | ||
} elseif (!$this->authorization->isGranted('ROLE_ADMIN') && (empty($options['filters']) || empty($options['filters']['organizations']))) { | ||
$options['hiddenFilters']['organizations'] = $this->getOrganizations(); | ||
} | ||
|
||
$event->setData( | ||
|
@@ -81,4 +60,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 []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Claroline Connect package. | ||
* | ||
* (c) Claroline Consortium <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Claroline\CursusBundle\Listener\DataSource; | ||
|
||
use Claroline\AppBundle\API\FinderProvider; | ||
|
@@ -53,26 +44,8 @@ public function getData(GetDataEvent $event) | |
|
||
if (DataSource::CONTEXT_WORKSPACE === $event->getContext() && (empty($options['filters'] || empty($options['filters']['workspace'])))) { | ||
$options['hiddenFilters']['workspace'] = $event->getWorkspace()->getUuid(); | ||
} elseif (DataSource::CONTEXT_HOME === $event->getContext()) { | ||
// only display sessions of the default organization on home | ||
$organizations = $this->om->getRepository(Organization::class)->findBy(['default' => true]); | ||
$options['hiddenFilters']['organizations'] = array_map(function (Organization $organization) { | ||
return $organization->getUuid(); | ||
}, $organizations); | ||
} else { | ||
// filter by organization for desktop | ||
if (!$this->authorization->isGranted('ROLE_ADMIN')) { | ||
$user = $this->tokenStorage->getToken()->getUser(); | ||
if ($user instanceof User) { | ||
$organizations = $user->getOrganizations(); | ||
} else { | ||
$organizations = $this->om->getRepository(Organization::class)->findBy(['default' => true]); | ||
} | ||
|
||
$options['hiddenFilters']['organizations'] = array_map(function (Organization $organization) { | ||
return $organization->getUuid(); | ||
}, $organizations); | ||
} | ||
} elseif (!$this->authorization->isGranted('ROLE_ADMIN') && (empty($options['filters']) || empty($options['filters']['organizations']))) { | ||
$options['hiddenFilters']['organizations'] = $this->getOrganizations(); | ||
} | ||
|
||
$event->setData( | ||
|
@@ -81,4 +54,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 []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters