Skip to content

Commit

Permalink
Js magic for deleted shares
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Jun 20, 2018
1 parent a5231e5 commit 0861a86
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 19 deletions.
3 changes: 3 additions & 0 deletions apps/files/css/files.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions apps/files/img/unshare.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions apps/files_sharing/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ function() {
);

$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');
Expand All @@ -59,6 +62,19 @@ function() {
'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 () {
Expand Down
59 changes: 59 additions & 0 deletions apps/files_sharing/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -110,6 +134,12 @@ OCA.Sharing.App = {
}
},

removeSharingDeleted: function() {
if (this._deletedFileList) {
this._deletedFileList.$fileList.empty();
}
},

/**
* Destroy the app
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
});
});
48 changes: 34 additions & 14 deletions apps/files_sharing/js/sharedfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
_sharedWithUser: false,
_linksOnly: false,
_showDeleted: false,
_clientSideSort: true,
_allowSelection: false,

Expand All @@ -56,6 +57,9 @@
if (options && options.linksOnly) {
this._linksOnly = true;
}
if (options && options.showDeleted) {
this._showDeleted = true;
}
},

_renderRow: function() {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
66 changes: 62 additions & 4 deletions apps/files_sharing/lib/Controller/DeletedShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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;
Expand All @@ -24,25 +26,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;

}

/**
Expand Down
1 change: 0 additions & 1 deletion apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n
$node = $recipientNode;
} else {
$nodes = $userFolder->getById($share->getNodeId());

if (empty($nodes)) {
// fallback to guessing the path
$node = $userFolder->get($share->getTarget());
Expand Down

0 comments on commit 0861a86

Please sign in to comment.