Js magic for deleted shares

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-06-20 19:14:50 +02:00
parent 6a0552224d
commit 3b835d8076
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
7 changed files with 175 additions and 19 deletions

View File

@ -105,6 +105,9 @@
.nav-icon-trashbin {
background-image: url('../img/delete.svg?v=1');
}
.nav-icon-deletedshares {
background-image: url('../img/unshare.svg?v=1');
}
#app-navigation .nav-files a.nav-icon-files {
width: auto;

View File

@ -0,0 +1 @@
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="m12.5 1a2.5 2.5 0 0 0-2.5 2.5 2.5 2.5 0 0 0 0.003906 0.12891l-4.9023 2.4512a2.5 2.5 0 0 0-1.6016-0.58008 2.5 2.5 0 0 0-2.5 2.5 2.5 2.5 0 0 0 2.5 2.5 2.5 2.5 0 0 0 0.30469-0.021484l3.4395-1.7246-1.25-0.625a2.5 2.5 0 0 0 0.0058594-0.12891 2.5 2.5 0 0 0-0.0039062-0.12891l4.9023-2.4512a2.5 2.5 0 0 0 1.6016 0.58008 2.5 2.5 0 0 0 0.26562-0.013672l1.5625-0.7832a2.5 2.5 0 0 0 0.67188-1.7031 2.5 2.5 0 0 0-2.5-2.5zm0.25391 9.0156-3.7246 1.8672 0.97656 0.48828a2.5 2.5 0 0 0-0.005859 0.12891 2.5 2.5 0 0 0 2.5 2.5 2.5 2.5 0 0 0 2.5-2.5 2.5 2.5 0 0 0-2.2461-2.4844z"/><rect transform="rotate(-26.63)" x="-1.0586" y="11.891" width="11.687" height="2.0029" ry="0" style="paint-order:normal"/></svg>

After

Width:  |  Height:  |  Size: 795 B

View File

@ -48,6 +48,9 @@ $eventDispatcher->addListener(
);
$config = \OC::$server->getConfig();
$shareManager = \OC::$server->getShareManager();
$userSession = \OC::$server->getUserSession();
if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
@ -59,6 +62,19 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
'name' => $l->t('Shared with you'),
];
});
$deletedShares = $shareManager->getDeletedSharedWith($userSession->getUser()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
if (count($deletedShares) > 0) {
\OCA\Files\App::getNavigationManager()->add(function () {
$l = \OC::$server->getL10N('files_sharing');
return [
'id' => 'deletedshares',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 18,
'name' => $l->t('Deleted shares'),
];
});
}
if (\OCP\Util::isSharingDisabledForUser() === false) {
\OCA\Files\App::getNavigationManager()->add(function () {

View File

@ -92,6 +92,30 @@ OCA.Sharing.App = {
return this._linkFileList;
},
initSharingDeleted: function($el) {
if (this._deletedFileList) {
return this._deletedFileList;
}
this._deletedFileList = new OCA.Sharing.FileList(
$el,
{
id: 'shares.deleted',
scrollContainer: $('#app-content'),
showDeleted: true,
sharedWithUser: true,
fileActions: this._restoreShareAction(),
config: OCA.Files.App.getFilesConfig()
}
);
this._extendFileList(this._deletedFileList);
this._deletedFileList.appName = t('files_sharing', 'Deleted shares');
this._deletedFileList.$el.find('#emptycontent').html('<div class="icon-share"></div>' +
'<h2>' + t('files_sharing', 'No deleted shares') + '</h2>' +
'<p>' + t('files_sharing', 'Shares you deleted will show up here') + '</p>');
return this._deletedFileList;
},
removeSharingIn: function() {
if (this._inFileList) {
this._inFileList.$fileList.empty();
@ -110,6 +134,12 @@ OCA.Sharing.App = {
}
},
removeSharingDeleted: function() {
if (this._deletedFileList) {
this._deletedFileList.$fileList.empty();
}
},
/**
* Destroy the app
*/
@ -151,6 +181,29 @@ OCA.Sharing.App = {
return fileActions;
},
_restoreShareAction: function() {
var fileActions = new OCA.Files.FileActions();
fileActions.registerAction({
name: 'Restore',
displayName: '',
altText: t('files_sharing', 'Restore share'),
mime: 'all',
permissions: OC.PERMISSION_ALL,
iconClass: 'icon-history',
type: OCA.Files.FileActions.TYPE_INLINE,
actionHandler: function(fileName, context) {
var shareId = context.$file.data('shareId');
$.post(OC.linkToOCS('apps/files_sharing/api/v1/deletedshares', 2) + shareId)
.success(function(result) {
context.fileList.remove(context.fileInfoModel.attributes.name);
}).fail(function() {
OC.Notification.showTemporary(t('files_sharing', 'Something happened. Unable to restore the share.'));
});
}
});
return fileActions;
},
_onActionsUpdated: function(ev) {
_.each([this._inFileList, this._outFileList, this._linkFileList], function(list) {
if (!list) {
@ -193,4 +246,10 @@ $(document).ready(function() {
$('#app-content-sharinglinks').on('hide', function() {
OCA.Sharing.App.removeSharingLinks();
});
$('#app-content-deletedshares').on('show', function(e) {
OCA.Sharing.App.initSharingDeleted($(e.target));
});
$('#app-content-deletedshares').on('hide', function() {
OCA.Sharing.App.removeSharingDeleted();
});
});

View File

@ -37,6 +37,7 @@
*/
_sharedWithUser: false,
_linksOnly: false,
_showDeleted: false,
_clientSideSort: true,
_allowSelection: false,
@ -56,6 +57,9 @@
if (options && options.linksOnly) {
this._linksOnly = true;
}
if (options && options.showDeleted) {
this._showDeleted = true;
}
},
_renderRow: function() {
@ -78,7 +82,7 @@
var permission = parseInt($tr.attr('data-permissions')) | OC.PERMISSION_DELETE;
$tr.attr('data-permissions', permission);
}
// add row with expiration date for link only shares - influenced by _createRow of filelist
if (this._linksOnly) {
var expirationTimestamp = 0;
@ -183,20 +187,36 @@
// there is only root
this._setCurrentDir('/', false);
if (this._showDeleted) {
var shares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
} else {
var shares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: !!this._sharedWithUser,
include_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
}
var promises = [];
var shares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: !!this._sharedWithUser,
include_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
promises.push(shares);
if (!!this._sharedWithUser) {

View File

@ -30,6 +30,8 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\Files\IRootFolder;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Share\Exceptions\GenericShareException;
@ -48,25 +50,81 @@ class DeletedShareAPIController extends OCSController {
/** @var IUserManager */
private $userManager;
/** @var IGroupManager */
private $groupManager;
/** @var IRootFolder */
private $rootFolder;
public function __construct(string $appName,
IRequest $request,
ShareManager $shareManager,
string $UserId,
IUserManager $userManager) {
IUserManager $userManager,
IGroupManager $groupManager,
IRootFolder $rootFolder) {
parent::__construct($appName, $request);
$this->shareManager = $shareManager;
$this->userId = $UserId;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->rootFolder = $rootFolder;
}
private function formatShare(IShare $share): array {
return [
$result = [
'id' => $share->getFullId(),
'uid_owner' => $share->getShareOwner(),
'displayname_owner' => $this->userManager->get($share->getShareOwner())->getDisplayName(),
'share_type' => $share->getShareType(),
'uid_owner' => $share->getSharedBy(),
'displayname_owner' => $this->userManager->get($share->getSharedBy())->getDisplayName(),
'permissions' => $share->getPermissions(),
'stime' => $share->getShareTime()->getTimestamp(),
'parent' => null,
'expiration' => null,
'token' => null,
'uid_file_owner' => $share->getShareOwner(),
'displayname_file_owner' => $this->userManager->get($share->getShareOwner())->getDisplayName(),
'path' => $share->getTarget(),
];
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
$nodes = $userFolder->getById($share->getNodeId());
if (empty($nodes)) {
// fallback to guessing the path
$node = $userFolder->get($share->getTarget());
if ($node === null || $share->getTarget() === '') {
throw new NotFoundException();
}
} else {
$node = $nodes[0];
}
$result['path'] = $userFolder->getRelativePath($node->getPath());
if ($node instanceOf \OCP\Files\Folder) {
$result['item_type'] = 'folder';
} else {
$result['item_type'] = 'file';
}
$result['mimetype'] = $node->getMimetype();
$result['storage_id'] = $node->getStorage()->getId();
$result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
$result['item_source'] = $node->getId();
$result['file_source'] = $node->getId();
$result['file_parent'] = $node->getParent()->getId();
$result['file_target'] = $share->getTarget();
$expiration = $share->getExpirationDate();
if ($expiration !== null) {
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
}
$group = $this->groupManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
return $result;
}
/**

View File

@ -151,7 +151,6 @@ class ShareAPIController extends OCSController {
$node = $recipientNode;
} else {
$nodes = $userFolder->getById($share->getNodeId());
if (empty($nodes)) {
// fallback to guessing the path
$node = $userFolder->get($share->getTarget());