Js magic for deleted shares
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
6a0552224d
commit
3b835d8076
|
@ -105,6 +105,9 @@
|
||||||
.nav-icon-trashbin {
|
.nav-icon-trashbin {
|
||||||
background-image: url('../img/delete.svg?v=1');
|
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 {
|
#app-navigation .nav-files a.nav-icon-files {
|
||||||
width: auto;
|
width: auto;
|
||||||
|
|
|
@ -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 |
|
@ -48,6 +48,9 @@ $eventDispatcher->addListener(
|
||||||
);
|
);
|
||||||
|
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
|
$shareManager = \OC::$server->getShareManager();
|
||||||
|
$userSession = \OC::$server->getUserSession();
|
||||||
|
|
||||||
if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
|
if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
|
||||||
\OCA\Files\App::getNavigationManager()->add(function () {
|
\OCA\Files\App::getNavigationManager()->add(function () {
|
||||||
$l = \OC::$server->getL10N('files_sharing');
|
$l = \OC::$server->getL10N('files_sharing');
|
||||||
|
@ -59,6 +62,19 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
|
||||||
'name' => $l->t('Shared with you'),
|
'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) {
|
if (\OCP\Util::isSharingDisabledForUser() === false) {
|
||||||
\OCA\Files\App::getNavigationManager()->add(function () {
|
\OCA\Files\App::getNavigationManager()->add(function () {
|
||||||
|
|
|
@ -92,6 +92,30 @@ OCA.Sharing.App = {
|
||||||
return this._linkFileList;
|
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() {
|
removeSharingIn: function() {
|
||||||
if (this._inFileList) {
|
if (this._inFileList) {
|
||||||
this._inFileList.$fileList.empty();
|
this._inFileList.$fileList.empty();
|
||||||
|
@ -110,6 +134,12 @@ OCA.Sharing.App = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeSharingDeleted: function() {
|
||||||
|
if (this._deletedFileList) {
|
||||||
|
this._deletedFileList.$fileList.empty();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the app
|
* Destroy the app
|
||||||
*/
|
*/
|
||||||
|
@ -151,6 +181,29 @@ OCA.Sharing.App = {
|
||||||
return fileActions;
|
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) {
|
_onActionsUpdated: function(ev) {
|
||||||
_.each([this._inFileList, this._outFileList, this._linkFileList], function(list) {
|
_.each([this._inFileList, this._outFileList, this._linkFileList], function(list) {
|
||||||
if (!list) {
|
if (!list) {
|
||||||
|
@ -193,4 +246,10 @@ $(document).ready(function() {
|
||||||
$('#app-content-sharinglinks').on('hide', function() {
|
$('#app-content-sharinglinks').on('hide', function() {
|
||||||
OCA.Sharing.App.removeSharingLinks();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
*/
|
*/
|
||||||
_sharedWithUser: false,
|
_sharedWithUser: false,
|
||||||
_linksOnly: false,
|
_linksOnly: false,
|
||||||
|
_showDeleted: false,
|
||||||
_clientSideSort: true,
|
_clientSideSort: true,
|
||||||
_allowSelection: false,
|
_allowSelection: false,
|
||||||
|
|
||||||
|
@ -56,6 +57,9 @@
|
||||||
if (options && options.linksOnly) {
|
if (options && options.linksOnly) {
|
||||||
this._linksOnly = true;
|
this._linksOnly = true;
|
||||||
}
|
}
|
||||||
|
if (options && options.showDeleted) {
|
||||||
|
this._showDeleted = true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_renderRow: function() {
|
_renderRow: function() {
|
||||||
|
@ -183,7 +187,21 @@
|
||||||
// there is only root
|
// there is only root
|
||||||
this._setCurrentDir('/', false);
|
this._setCurrentDir('/', false);
|
||||||
|
|
||||||
var promises = [];
|
|
||||||
|
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({
|
var shares = $.ajax({
|
||||||
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
|
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
|
||||||
/* jshint camelcase: false */
|
/* jshint camelcase: false */
|
||||||
|
@ -197,6 +215,8 @@
|
||||||
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
|
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
var promises = [];
|
||||||
promises.push(shares);
|
promises.push(shares);
|
||||||
|
|
||||||
if (!!this._sharedWithUser) {
|
if (!!this._sharedWithUser) {
|
||||||
|
|
|
@ -30,6 +30,8 @@ use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
use OCP\AppFramework\OCS\OCSException;
|
||||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||||
use OCP\AppFramework\OCSController;
|
use OCP\AppFramework\OCSController;
|
||||||
|
use OCP\Files\IRootFolder;
|
||||||
|
use OCP\IGroupManager;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\Share\Exceptions\GenericShareException;
|
use OCP\Share\Exceptions\GenericShareException;
|
||||||
|
@ -48,25 +50,81 @@ class DeletedShareAPIController extends OCSController {
|
||||||
/** @var IUserManager */
|
/** @var IUserManager */
|
||||||
private $userManager;
|
private $userManager;
|
||||||
|
|
||||||
|
/** @var IGroupManager */
|
||||||
|
private $groupManager;
|
||||||
|
|
||||||
|
/** @var IRootFolder */
|
||||||
|
private $rootFolder;
|
||||||
|
|
||||||
public function __construct(string $appName,
|
public function __construct(string $appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
ShareManager $shareManager,
|
ShareManager $shareManager,
|
||||||
string $UserId,
|
string $UserId,
|
||||||
IUserManager $userManager) {
|
IUserManager $userManager,
|
||||||
|
IGroupManager $groupManager,
|
||||||
|
IRootFolder $rootFolder) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
|
|
||||||
$this->shareManager = $shareManager;
|
$this->shareManager = $shareManager;
|
||||||
$this->userId = $UserId;
|
$this->userId = $UserId;
|
||||||
$this->userManager = $userManager;
|
$this->userManager = $userManager;
|
||||||
|
$this->groupManager = $groupManager;
|
||||||
|
$this->rootFolder = $rootFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formatShare(IShare $share): array {
|
private function formatShare(IShare $share): array {
|
||||||
return [
|
|
||||||
|
$result = [
|
||||||
'id' => $share->getFullId(),
|
'id' => $share->getFullId(),
|
||||||
'uid_owner' => $share->getShareOwner(),
|
'share_type' => $share->getShareType(),
|
||||||
'displayname_owner' => $this->userManager->get($share->getShareOwner())->getDisplayName(),
|
'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(),
|
'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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -151,7 +151,6 @@ class ShareAPIController extends OCSController {
|
||||||
$node = $recipientNode;
|
$node = $recipientNode;
|
||||||
} else {
|
} else {
|
||||||
$nodes = $userFolder->getById($share->getNodeId());
|
$nodes = $userFolder->getById($share->getNodeId());
|
||||||
|
|
||||||
if (empty($nodes)) {
|
if (empty($nodes)) {
|
||||||
// fallback to guessing the path
|
// fallback to guessing the path
|
||||||
$node = $userFolder->get($share->getTarget());
|
$node = $userFolder->get($share->getTarget());
|
||||||
|
|
Loading…
Reference in New Issue