Skip to content

Commit 2ae929a

Browse files
authored
Merge pull request #159 from UIUCLibrary/issue_157
fixes issue 157
2 parents 82ef497 + 95333b1 commit 2ae929a

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

Module.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use Laminas\ServiceManager\ServiceLocatorInterface;
3838
use Laminas\View\Renderer\PhpRenderer;
3939
use Teams\Mvc\Controller\Plugin\TeamAuth;
40+
use function Symfony\Component\String\b;
4041

4142
class Module extends AbstractModule
4243
{
@@ -200,6 +201,8 @@ public function handleConfigForm(AbstractController $controller)
200201
$globalSettings->set('teams_site_admin_make_site', $params['teams_site_admin_make_site']);
201202
$globalSettings->set('teams_editor_make_site', $params['teams_editor_make_site']);
202203
$globalSettings->set('teams_site_admin_make_user', $params['teams_site_admin_make_user']);
204+
$globalSettings->set('teams_filter_bypass_roles', $params['teams_filter_bypass_roles']);
205+
203206
}
204207

205208
public function getConfigForm(PhpRenderer $renderer)
@@ -736,8 +739,15 @@ public function teamSelectorNav(Event $event)
736739

737740
public function bypassTeamsSortSelector(Event $event)
738741
{
742+
$globalSettings = $this->getServiceLocator()->get('Omeka\Settings');
743+
$roles = $globalSettings->get('teams_filter_bypass_roles');
744+
745+
if (!is_array($roles)) {
746+
$roles[] = $roles;
747+
}
748+
739749
$user = $this->getUser();
740-
if ($user && $user->getRole() == 'global_admin'){
750+
if ($user && in_array($user->getRole(),$roles) ){
741751
$view = $event->getTarget();
742752
$params = $view->params();
743753
$bypassTeams = $params->fromQuery('bypass_team_filter');
@@ -875,9 +885,15 @@ public function filterByTeam(Event $event)
875885
//TODO: if is set (search_everywhere) and ACL check passes as global admin, bypass the join
876886
//for times when the admin needs to turn off the filter by teams (e.g. when adding resources to a new team)
877887

888+
$globalSettings = $this->getServiceLocator()->get('Omeka\Settings');
889+
$bypass_teams_filter_roles = $globalSettings->get('teams_filter_bypass_roles');
890+
891+
if (!is_array($bypass_teams_filter_roles)) {
892+
$bypass_teams_filter_roles[] = $bypass_teams_filter_roles;
893+
}
878894
if (isset($query['bypass_team_filter'])
879895
&& $query['bypass_team_filter']
880-
&& $this->getUser()->getRole() == 'global_admin'
896+
&& in_array($this->getUser()->getRole(), $bypass_teams_filter_roles)
881897
) {
882898
return;
883899
}

src/Form/ConfigForm.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
namespace Teams\Form;
55

6+
use Omeka\Permissions\Acl;
67
use Laminas\Form\Form;
78

89
class ConfigForm extends Form
910
{
11+
/**
12+
* @var Acl
13+
*/
14+
protected $acl;
1015
protected $globalSettings;
1116

1217
public function init()
@@ -46,9 +51,44 @@ public function init()
4651
'id' => 'teams_site_admin_make_user',
4752
],
4853
]);
54+
$roles = $this->getAcl()->getRoleLabels(false);
55+
56+
$this->add([
57+
'name' => 'teams_filter_bypass_roles',
58+
'type' => 'select',
59+
'options' => [
60+
'label' => 'Grant "Bypass Teams Filter" ability', // @translate
61+
'info' =>'List of core Omeka S roles that can bypass the Teams filter on admin search interfaces',
62+
'value_options' => $roles,
63+
64+
],
65+
'attributes' => [
66+
'id' => 'role',
67+
'class' => 'chosen-select',
68+
'multiple' => true,
69+
'value' => $this->globalSettings->get('teams_filter_bypass_roles'),
70+
],
71+
]);
72+
4973
}
5074
public function setGlobalSettings($globalSettings)
5175
{
5276
$this->globalSettings = $globalSettings;
5377
}
78+
79+
/**
80+
* @param Acl $acl
81+
*/
82+
public function setAcl(Acl $acl)
83+
{
84+
$this->acl = $acl;
85+
}
86+
87+
/**
88+
* @return Acl
89+
*/
90+
public function getAcl()
91+
{
92+
return $this->acl;
93+
}
5494
}

src/Form/TeamCompactForm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public function init()
8989
if ($this->getOption('include_role')) {
9090
$excludeAdminRoles = !$this->getOption('include_admin_roles');
9191
$roles = $this->getAcl()->getRoleLabels($excludeAdminRoles);
92-
$this->get('user-information')->add([
92+
$this->get('user-information')
93+
->add([
9394
'name' => 'o:role',
9495
'type' => 'select',
9596
'options' => [

src/Service/Form/ConfigFormFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ConfigFormFactory implements FactoryInterface
1111
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
1212
{
1313
$form = new ConfigForm();
14+
$form->setAcl($container->get('Omeka\Acl'));
1415
$globalSettings = $container->get('Omeka\Settings');
1516
$form->setGlobalSettings($globalSettings);
1617

0 commit comments

Comments
 (0)