Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 01b1ab7

Browse files
committed
Merge branch '0384_ShareDupe_yuzheng'
* 0384_ShareDupe_yuzheng: BUG: refs #0384. Fix Folder::getItemsFiltered() to display shared items BUG: Refs #0384. Fixed a logic error in sharing item. check if the destination folder is the souce folder first, then share item. BUG: Refs #0384. Fixed the error in UploadDownloadControllerTest. BUG: Refs #0384. fixed the styling issue. BUG: Refs #0384. Change item name convention to avoid same named items in the same folder. ENH: Refs #0384. Fixed style errors. ENH: Refs #0384. Support both share and duplicate actions for items.
2 parents 89f3841 + 1b940a9 commit 01b1ab7

File tree

11 files changed

+416
-143
lines changed

11 files changed

+416
-143
lines changed

core/controllers/BrowseController.php

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@ public function indexAction()
5858
/** move or copy selected element*/
5959
public function movecopyAction()
6060
{
61-
$copySubmit = $this->_getParam('copyElement');
61+
$shareSubmit = $this->_getParam('shareElement');
62+
$duplicateSubmit = $this->_getParam('duplicateElement');
6263
$moveSubmit = $this->_getParam('moveElement');
64+
6365
$select = $this->_getParam('selectElement');
64-
if(isset($copySubmit) || isset($moveSubmit))
66+
$share = $this->_getParam('share');
67+
$duplicate = $this->_getParam('duplicate');
68+
69+
// used for drag-and-drop actions
70+
if(isset($moveSubmit) || isset($shareSubmit) || isset($duplicateSubmit))
6571
{
6672
$elements = explode(';', $this->_getParam('elements'));
6773
$destination = $this->_getParam('destination');
@@ -70,41 +76,58 @@ public function movecopyAction()
7076
$itemIds = explode('-', $elements[1]);
7177
$folders = $this->Folder->load($folderIds);
7278
$items = $this->Item->load($itemIds);
73-
$destination = $this->Folder->load($destination);
79+
$destinationFolder = $this->Folder->load($destination);
7480
if(empty($folders) && empty ($items))
7581
{
7682
throw new Zend_Exception("No element selected");
7783
}
78-
if($destination == false)
84+
if($destinationFolder == false)
7985
{
8086
throw new Zend_Exception("Unable to load destination");
8187
}
8288

8389
foreach($folders as $folder)
8490
{
85-
if(!isset($copySubmit))
91+
if(isset($moveSubmit))
8692
{
87-
$this->Folder->move($folder, $destination);
93+
$this->Folder->move($folder, $destinationFolder);
8894
}
8995
}
9096

97+
$sourceFolderIds = array();
9198
foreach($items as $item)
9299
{
93-
if(isset($copySubmit))
100+
if(isset($shareSubmit))
94101
{
95-
$this->Folder->addItem($destination, $item);
96-
$this->Item->copyParentPolicies($item, $destination);
102+
foreach($item->getFolders() as $parentFolder)
103+
{
104+
$folderId = $parentFolder->getKey();
105+
array_push($sourceFolderIds, $folderId);
106+
}
107+
if(in_array($destinationFolder->getKey(), $sourceFolderIds))
108+
{
109+
$this->_redirect('/item/'.$item->getKey());
110+
}
111+
else
112+
{
113+
$this->Folder->addItem($destinationFolder, $item);
114+
$this->Item->addReadonlyPolicy($item, $destinationFolder);
115+
}
97116
}
98-
else
117+
elseif(isset($duplicateSubmit))
118+
{
119+
$this->Item->duplicateItem($item, $this->userSession->Dao, $destinationFolder);
120+
}
121+
else //moveSubmit
99122
{
100123
$from = $this->_getParam('from');
101124
$from = $this->Folder->load($from);
102-
if($destination == false)
125+
if($destinationFolder == false)
103126
{
104127
throw new Zend_Exception("Unable to load destination");
105128
}
106-
$this->Folder->addItem($destination, $item);
107-
$this->Item->copyParentPolicies($item, $destination);
129+
$this->Folder->addItem($destinationFolder, $item);
130+
$this->Item->copyParentPolicies($item, $destinationFolder);
108131
$this->Folder->removeItem($from, $item);
109132
}
110133
}
@@ -115,24 +138,19 @@ public function movecopyAction()
115138
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
116139
return;
117140
}
118-
$this->_redirect('/folder/'.$destination->getKey());
141+
$this->_redirect('/folder/'.$destinationFolder->getKey());
119142
}
120143

144+
// Used for movecopy dialog
121145
$this->requireAjaxRequest();
122146
$this->_helper->layout->disableLayout();
123147

124-
if(!isset($select))
148+
if(isset($share) || isset($duplicate))
125149
{
126150
$folderIds = $this->_getParam('folders');
127151
$itemIds = $this->_getParam('items');
128-
$move = $this->_getParam('move');
129152
$this->view->folderIds = $folderIds;
130153
$this->view->itemIds = $itemIds;
131-
$this->view->moveEnabled = true;
132-
if(isset($move))
133-
{
134-
$this->view->moveEnabled = false;
135-
}
136154
$folderIds = explode('-', $folderIds);
137155
$itemIds = explode('-', $itemIds);
138156
$folders = $this->Folder->load($folderIds);
@@ -147,9 +165,19 @@ public function movecopyAction()
147165
}
148166
$this->view->folders = $folders;
149167
$this->view->items = $items;
168+
if(isset($share))
169+
{
170+
$this->view->shareEnabled = true;
171+
$this->view->duplicateEnabled = false;
172+
}
173+
else
174+
{
175+
$this->view->duplicateEnabled = true;
176+
$this->view->shareEnabled = false;
177+
}
150178
$this->view->selectEnabled = false;
151179
}
152-
else
180+
else //isset($select)
153181
{
154182
$this->view->selectEnabled = true;
155183
}
@@ -225,7 +253,6 @@ public function selectfolderAction()
225253
/** get getfolders content (ajax function for the treetable) */
226254
public function getfolderscontentAction()
227255
{
228-
$this->requireAjaxRequest();
229256
$this->_helper->layout->disableLayout();
230257
$this->_helper->viewRenderer->setNoRender();
231258
$folderIds = $this->_getParam('folders');

core/controllers/ItemController.php

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ class ItemController extends AppController
2626
public $_components = array('Date', 'Utility', 'Sortdao');
2727
public $_forms = array('Item');
2828

29-
/** Init Controller */
29+
/**
30+
* Init Controller
31+
*
32+
* @method init()
33+
*/
3034
function init()
3135
{
3236
$this->view->activemenu = ''; // set the active menu
@@ -38,7 +42,13 @@ function init()
3842
} // end init()
3943

4044

41-
/** create/edit metadata*/
45+
46+
/**
47+
* create/edit metadata
48+
*
49+
* @method editmetadataAction()
50+
* @throws Zend_Exception on non-logged user, invalid itemId and incorrect access permission
51+
*/
4252
function editmetadataAction()
4353
{
4454
$this->disableLayout();
@@ -77,7 +87,12 @@ function editmetadataAction()
7787
$this->view->jsonMetadataType = JsonComponent::encode($this->view->metadataType);
7888
}
7989

80-
/** view a community*/
90+
/**
91+
* View a Item
92+
*
93+
* @method viewAction()
94+
* @throws Zend_Exception on invalid itemId and incorrect access permission
95+
*/
8196
function viewAction()
8297
{
8398
$this->view->header = $this->t("Item");
@@ -261,12 +276,19 @@ function viewAction()
261276

262277
$this->view->json['item'] = $itemDao->toArray();
263278
$this->view->json['item']['message']['delete'] = $this->t('Delete');
279+
$this->view->json['item']['message']['sharedItem'] = $this->t('This item is currrently shared by other folders and/or communities. Deletion will make it disappear in all these folders and/or communitites. ');
264280
$this->view->json['item']['message']['deleteMessage'] = $this->t('Do you really want to delete this item? It cannot be undone.');
265281
$this->view->json['item']['message']['deleteMetadataMessage'] = $this->t('Do you really want to delete this metadata? It cannot be undone.');
266-
$this->view->json['item']['message']['movecopy'] = $this->t('Copy Item.');
282+
$this->view->json['item']['message']['share'] = $this->t('Share Item (Display the same item in the destination folder)');
283+
$this->view->json['item']['message']['duplicate'] = $this->t('Duplicate Item (Create a new item in the destination folder)');
267284
}//end index
268285

269-
/** Edit (ajax) */
286+
/**
287+
* Edit an item
288+
*
289+
* @method editAction()
290+
* @throws Zend_Exception on invalid itemId and incorrect access permission
291+
*/
270292
function editAction()
271293
{
272294
$this->disableLayout();
@@ -308,7 +330,12 @@ function editAction()
308330
$this->view->form = $formArray;
309331
}
310332

311-
/** Delete an item */
333+
/**
334+
* Delete an item
335+
*
336+
* @method deleteAction()
337+
* @throws Zend_Exception on invalid itemId and incorrect access permission
338+
*/
312339
function deleteAction()
313340
{
314341
$this->disableLayout();
@@ -331,7 +358,12 @@ function deleteAction()
331358
}//end delete
332359

333360

334-
/** Merge items*/
361+
/**
362+
* Merge items
363+
*
364+
* @method mergeAction()
365+
* @throws Zend_Exception on invalid item name and incorrect access permission
366+
*/
335367
function mergeAction()
336368
{
337369
$this->_helper->layout->disableLayout();
@@ -383,6 +415,34 @@ function mergeAction()
383415
$this->Item->save($mainItem);
384416

385417
$this->_redirect('/browse/uploaded');
386-
}//end delete
418+
}//end merge
419+
420+
/**
421+
* Check if an item is shared
422+
*
423+
* ajax function which checks if an item is shared in other folder/community
424+
*
425+
* @method checksharedAction()
426+
* @throws Zend_Exception on non-ajax call
427+
*/
428+
public function checksharedAction()
429+
{
430+
if(!$this->getRequest()->isXmlHttpRequest())
431+
{
432+
throw new Zend_Exception("Why are you here ? Should be ajax.");
433+
}
434+
$this->disableLayout();
435+
$this->disableView();
436+
$itemId = $this->_getParam("itemId");
437+
$itemDao = $this->Item->load($itemId);
438+
$shareCount = count($itemDao->getFolders());
439+
$ifShared = false;
440+
if($shareCount > 1)
441+
{
442+
$ifShared = true;
443+
}
444+
445+
echo JsonComponent::encode($ifShared);
446+
} // end checkshared
387447

388448
}//end class

core/controllers/components/UploadComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function createLinkItem($userDao, $name, $url, $parent = null)
139139

140140
Zend_Loader::loadClass('ItemDao', BASE_PATH.'/core/models/dao');
141141
$item = new ItemDao;
142-
$item->setName($name);
142+
$item->setName($itemModel->updateItemName($name, $parent));
143143
$item->setDescription('');
144144
$item->setType(0);
145145
$item->setThumbnail('');

0 commit comments

Comments
 (0)