Skip to content

Commit 13c2138

Browse files
authored
Merge pull request #167 from UIUCLibrary/issue_158_rebase
Issue 158 rebase
2 parents 2ae929a + dcde73e commit 13c2138

28 files changed

+1456
-480
lines changed

Module.php

Lines changed: 128 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ public function upgrade($oldVersion, $newVersion, ServiceLocatorInterface $servi
180180
$conn = $serviceLocator->get('Omeka\Connection');
181181
$conn->exec('ALTER TABLE team_user MODIFY id INT NOT NULL AUTO_INCREMENT');
182182
}
183+
if (version_compare($oldVersion,'4.1.0', '<')) {
184+
//add global admin to the list of settings for bypass team users
185+
$globalSettings = $serviceLocator->get('Omeka\Settings');
186+
$globalSettings->set('teams_filter_bypass_roles', ["global_admin"]);
187+
}
183188
}
184189

185190
public function updateAllUserSites()
@@ -882,8 +887,6 @@ public function filterByTeam(Event $event)
882887
if ($this->getUser() === null) {
883888
return;
884889
}
885-
//TODO: if is set (search_everywhere) and ACL check passes as global admin, bypass the join
886-
//for times when the admin needs to turn off the filter by teams (e.g. when adding resources to a new team)
887890

888891
$globalSettings = $this->getServiceLocator()->get('Omeka\Settings');
889892
$bypass_teams_filter_roles = $globalSettings->get('teams_filter_bypass_roles');
@@ -900,7 +903,6 @@ public function filterByTeam(Event $event)
900903
if (isset($query['bypass_team_filter']) && $this->getServiceLocator()->get('Omeka\Status')->isSiteRequest()) {
901904
return;
902905
}
903-
904906
if (isset($query['resource_class_id']) && $this->getServiceLocator()->get('Omeka\Status')->isSiteRequest()) {
905907
return;
906908
}
@@ -1894,8 +1896,27 @@ public function itemUpdate(Event $event)
18941896
$operation = $request->getOperation();
18951897
$logger = $this->getServiceLocator()->get('Omeka\Logger');
18961898
$teamAuth = new TeamAuth($em, $logger);
1897-
18981899
if ($operation == 'update') {
1900+
1901+
if(array_key_exists('remove_team', $request->getContent())) {
1902+
if (!is_array($request->getContent()['remove_team'])) {
1903+
$remove = array($request->getContent()['remove_team']);
1904+
} else {
1905+
$remove = $request->getContent()['remove_team'];
1906+
}
1907+
} else {
1908+
$remove = [];
1909+
}
1910+
1911+
if(array_key_exists('add_team', $request->getContent())) {
1912+
if (!is_array($request->getContent()['add_team'])) {
1913+
$add = array($request->getContent()['add_team']);
1914+
} else {
1915+
$add = $request->getContent()['add_team'];
1916+
}
1917+
} else {
1918+
$add = [];
1919+
}
18991920
if (array_key_exists('remove_team', $request->getContent()) ||
19001921
array_key_exists('add_team', $request->getContent())) {
19011922

@@ -1906,7 +1927,8 @@ public function itemUpdate(Event $event)
19061927
$resource_ids[$media->getId()] = true;
19071928
}
19081929

1909-
foreach ($request->getContent()['add_team'] as $team_id) {
1930+
1931+
foreach ($add as $team_id) {
19101932
//if the user is authorized to add items to that team
19111933
if ($teamAuth->teamAuthorized($this->getUser(),'add', 'resource', $team_id)) {
19121934
$team = $em->getRepository('Teams\Entity\Team')->findOneBy(['id' => $team_id]);
@@ -1923,7 +1945,7 @@ public function itemUpdate(Event $event)
19231945
}
19241946
$em->flush();
19251947

1926-
foreach ($request->getContent()['remove_team'] as $team_id) {
1948+
foreach ($remove as $team_id) {
19271949
if ($teamAuth->teamAuthorized($this->getUser(),'delete', 'resource', $team_id)) {
19281950
foreach (array_keys($resource_ids) as $resource_id) {
19291951
$team_resource = $em->getRepository('Teams\Entity\TeamResource')
@@ -2487,6 +2509,93 @@ public function siteSettingsRemoveAutoAssign(Event $event)
24872509
->setOption('info', 'The Teams Module manages how items become associated with sites, so this has been disabled.');
24882510
}
24892511

2512+
//Add Team options to Batch Edit
2513+
2514+
/**
2515+
* Add "Add Team" and "Remove Team" select elements to the batch edit forme
2516+
* @param Event $event
2517+
* @return void
2518+
*/
2519+
public function addTeamToBatchEditForm(Event $event) {
2520+
$form = $event->getTarget();
2521+
2522+
$groups = $form->getOption('element_groups');
2523+
$groups['teams'] = 'Teams'; // @translate
2524+
$form->setOption('element_groups', $groups);
2525+
$form->add([
2526+
'type' => TeamSelect::class,
2527+
'name' => 'add_team',
2528+
'options' => [
2529+
'element_group' => 'teams',
2530+
'label' => 'Add resource to Teams', // @translate
2531+
'empty_option' => 'Select a team',
2532+
'chosen' => true,
2533+
],
2534+
'attributes' => [
2535+
'multiple' => true,
2536+
]
2537+
2538+
]);
2539+
$form->add([
2540+
'type' => TeamSelect::class,
2541+
'name' => 'remove_team',
2542+
'options' => [
2543+
'element_group' => 'teams',
2544+
'label' => 'Remove resources from teams', // @translate
2545+
'chosen' => true
2546+
],
2547+
'attributes' => [
2548+
'multiple' => true,
2549+
]
2550+
]);
2551+
$inputFilter = $form->getInputFilter();
2552+
$inputFilter->add([
2553+
'name' => 'remove_team',
2554+
'required' => false
2555+
]);
2556+
$inputFilter->add([
2557+
'name' => 'add_team',
2558+
'required' => false
2559+
]);
2560+
}
2561+
2562+
public function processTeamBatchEditData (Event $event) {
2563+
$data = $event->getParam('data');
2564+
$rawData = $event->getParam('request')->getContent();
2565+
2566+
//add first then remove
2567+
$targets = ['add_team', 'remove_team'];
2568+
2569+
foreach ($targets as $teamData) {
2570+
if (isset($rawData[$teamData])) {
2571+
$data[$teamData] = $rawData[$teamData];
2572+
}
2573+
}
2574+
2575+
$event->setParam('data', $data);
2576+
}
2577+
2578+
2579+
// public function batchAddRemoveTeam (Event $event) {
2580+
// $data = $event->getParam('request')->getContent();
2581+
// $item = $event->getParam('response')->getContent();
2582+
//
2583+
// if (!(isset($data['add_team']) && $data['add_team'])) {
2584+
// return;
2585+
// }
2586+
//
2587+
// $services = $this->getServiceLocator();
2588+
// $entityManager = $services->get('Omeka\EntityManager');
2589+
//
2590+
// $dql = 'DELETE FROM Mapping\Entity\MappingFeature m WHERE m.item = :item_id';
2591+
// $entityManager->createQuery($dql)
2592+
// ->setParameter('item_id', $item->getId())
2593+
// ->execute();
2594+
//
2595+
//
2596+
// }
2597+
2598+
24902599
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
24912600
{
24922601
$services = $this->getServiceLocator();
@@ -3001,6 +3110,19 @@ public function attachListeners(SharedEventManagerInterface $sharedEventManager)
30013110
'form.add_elements',
30023111
[$this, 'addSiteFormElement']
30033112
);
3113+
3114+
// Add teams to batch update
3115+
$sharedEventManager->attach(
3116+
'Omeka\Form\ResourceBatchUpdateForm',
3117+
'form.add_elements',
3118+
[$this, 'addTeamToBatchEditForm']
3119+
);
3120+
3121+
$sharedEventManager->attach(
3122+
'Omeka\Api\Adapter\ItemAdapter',
3123+
'api.preprocess_batch_update',
3124+
[$this, 'processTeamBatchEditData']
3125+
);
30043126
}
30053127

30063128
/**

asset/js/item-set-removal.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
$(window).on('load', function() {
2+
// $("#o-modules-team-remove-item-sets").parent().parent().css('visibility', 'hidden');
3+
// $("#o-modules-team-remove-resource-templates").parent().parent().css('visibility', 'hidden');
4+
5+
//not ideal, but for some reason the chosen option from chosen-options.js are getting unset, so settin them here
6+
$("#o-modules-team-item-sets").chosen({
7+
allow_single_deselect: true,
8+
disable_search_threshold: 10,
9+
width: '100%',
10+
include_group_label_in_selected: true,
11+
}).change( function(event, params) {
12+
let $values = $("#o-modules-team-remove-item-sets").val();
13+
if (params.deselected){
14+
let $label = $("#o-modules-team-item-sets option[value='"+params.deselected+"']").text();
15+
$("#o-modules-team-remove-item-sets").append('<option value='+params.deselected+'>'+$label+'</option>').trigger("chosen:updated");
16+
$values.push(params.deselected);
17+
console.log($values);
18+
}
19+
if (params.selected) {
20+
$values.splice($.inArray(params.selected, $values), 1);
21+
}
22+
$("#o-modules-team-remove-item-sets").val($values).trigger("chosen:updated");
23+
});
24+
25+
$("#o-modules-team-resource-templates").chosen({
26+
allow_single_deselect: true,
27+
disable_search_threshold: 10,
28+
width: '100%',
29+
include_group_label_in_selected: true,
30+
}).change( function(event, params) {
31+
let $values = $("#o-modules-team-remove-resource-templates").val();
32+
if (params.deselected){
33+
let $label = $("#o-modules-team-resource-templates option[value='"+params.deselected+"']").text();
34+
$("#o-modules-team-remove-resource-templates").append('<option value='+params.deselected+'>'+$label+'</option>').trigger("chosen:updated");
35+
$values.push(params.deselected);
36+
console.log($values);
37+
}
38+
if (params.selected) {
39+
$values.splice($.inArray(params.selected, $values), 1);
40+
}
41+
$("#o-modules-team-remove-resource-templates").val($values).trigger("chosen:updated");
42+
});
43+
});

config/module.config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@
9494
Form\Element\AllSiteSelect::class => Service\Form\Element\AllSiteSelectFactory::class,
9595
Form\Element\AllSiteSelectOrdered::class => Service\Form\Element\AllSiteSelectOrderedFactory::class,
9696
Form\ConfigForm::class => Service\Form\ConfigFormFactory::class,
97+
Form\SecondaryResourcesForm::class => Service\Form\SecondaryResourceFormFactory::class,
9798
Form\Element\TeamName::class => Service\Form\Element\TeamNameFactory::class,
9899
Form\Element\RoleName::class => Service\Form\Element\RoleNameFactory::class,
99-
100+
Form\Element\ItemSetTeamSelect::class => Service\Form\Element\ItemSetTeamSelectFactory::class,
101+
Form\Element\ResourceTemplateTeamsSelect::class => Service\Form\Element\ResourceTemplateTeamsSelectFactory::class,
100102
],
101103
],
102104
'view_helpers' =>[

config/module.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[info]
22
name = "Teams"
3-
version = "4.0.1"
3+
version = "4.1.0"
44
author = "Alex Dryden"
55
configurable = true
66
description = "Assigns items and itemsets to teams so that only approved team mates see them"

0 commit comments

Comments
 (0)