Skip to content

Commit

Permalink
Merge pull request #27751 from nextcloud/enh/23769/accept-decline-fed…
Browse files Browse the repository at this point in the history
…-sharing-ui
  • Loading branch information
juliushaertl authored Jul 28, 2021
2 parents 640f339 + f6f2f63 commit a71294e
Show file tree
Hide file tree
Showing 14 changed files with 816 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
use OCP\Share\IManager;
use OCP\Share\IShare;
use OCP\Util;
use Psr\Log\LoggerInterface;

class CloudFederationProviderFiles implements ICloudFederationProvider {

Expand Down Expand Up @@ -250,7 +251,8 @@ public function shareReceived(ICloudFederationShare $share) {
\OC::$server->getGroupManager(),
\OC::$server->getUserManager(),
$shareWith,
\OC::$server->query(IEventDispatcher::class)
\OC::$server->query(IEventDispatcher::class),
\OC::$server->get(LoggerInterface::class)
);

try {
Expand Down
8 changes: 8 additions & 0 deletions apps/files/js/fileactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@
if (_.isFunction(action.render)) {
actionSpec.render = action.render;
}
if (_.isFunction(action.shouldRender)) {
actionSpec.shouldRender = action.shouldRender;
}
if (!this.actions[mime]) {
this.actions[mime] = {};
}
Expand Down Expand Up @@ -397,6 +400,11 @@
* @param {OCA.Files.FileActionContext} context rendering context
*/
_renderInlineAction: function(actionSpec, isDefault, context) {
if (actionSpec.shouldRender) {
if (!actionSpec.shouldRender(context)) {
return;
}
}
var renderFunc = actionSpec.render || _.bind(this._defaultRenderAction, this);
var $actionEl = renderFunc(actionSpec, isDefault, context);
if (!$actionEl || !$actionEl.length) {
Expand Down
5 changes: 5 additions & 0 deletions apps/files/js/gotoplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
if (this.disallowedLists.indexOf(fileList.id) !== -1) {
return;
}
// lists where the "Open" default action is disabled should
// also have the goto action disabled
if (fileList._defaultFileActionsDisabled) {
return
}
var fileActions = fileList.fileActions;

fileActions.registerAction({
Expand Down
23 changes: 21 additions & 2 deletions apps/files_sharing/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ OCA.Sharing.App = {
{
id: 'shares.pending',
showPending: true,
detailsViewEnabled: false,
defaultFileActionsDisabled: true,
sharedWithUser: true,
fileActions: this._acceptShareAction(),
config: OCA.Files.App.getFilesConfig(),
Expand Down Expand Up @@ -296,7 +298,11 @@ OCA.Sharing.App = {
type: OCA.Files.FileActions.TYPE_INLINE,
actionHandler(fileName, context) {
const shareId = context.$file.data('shareId')
$.post(OC.linkToOCS('apps/files_sharing/api/v1/shares/pending/{shareId}', { shareId }))
let shareBase = 'shares/pending'
if (context.$file.attr('data-remote-id')) {
shareBase = 'remote_shares/pending'
}
$.post(OC.linkToOCS('apps/files_sharing/api/v1/' + shareBase + '/{shareId}', { shareId }))
.success(function(result) {
context.fileList.remove(context.fileInfoModel.attributes.name)
}).fail(function() {
Expand All @@ -311,10 +317,23 @@ OCA.Sharing.App = {
permissions: OC.PERMISSION_ALL,
iconClass: 'icon-close',
type: OCA.Files.FileActions.TYPE_INLINE,
shouldRender(context) {
// disable rejecting group shares from the pending list because they anyway
// land back into that same list
if (context.$file.attr('data-remote-id') && parseInt(context.$file.attr('data-share-type'), 10) === OC.Share.SHARE_TYPE_REMOTE_GROUP) {
return false
}
return true
},
actionHandler(fileName, context) {
const shareId = context.$file.data('shareId')
let shareBase = 'shares'
if (context.$file.attr('data-remote-id')) {
shareBase = 'remote_shares/pending'
}

$.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1/shares/{shareId}', { shareId }),
url: OC.linkToOCS('apps/files_sharing/api/v1/' + shareBase + '/{shareId}', { shareId }),
type: 'DELETE',
}).success(function(result) {
context.fileList.remove(context.fileInfoModel.attributes.name)
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/additionalScripts.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/additionalScripts.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing.js.map

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion apps/files_sharing/js/sharedfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@
$tr.attr('data-share-permissions', permission)
}

if (fileData.remoteId) {
$tr.attr('data-remote-id', fileData.remoteId)
}

if (fileData.shareType) {
$tr.attr('data-share-type', fileData.shareType)
}

// add row with expiration date for link only shares - influenced by _createRow of filelist
if (this._linksOnly) {
var expirationTimestamp = 0
Expand Down Expand Up @@ -212,6 +220,18 @@
}
}

var pendingRemoteShares = {
url: OC.linkToOCS('apps/files_sharing/api/v1/remote_shares/pending'),
/* jshint camelcase: false */
data: {
format: 'json'
},
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true')
}
}

var shares = {
url: OC.linkToOCS('apps/files_sharing/api/v1/shares'),
/* jshint camelcase: false */
Expand Down Expand Up @@ -245,6 +265,7 @@
promises.push($.ajax(deletedShares))
} else if (this._showPending) {
promises.push($.ajax(pendingShares))
promises.push($.ajax(pendingRemoteShares))
} else {
promises.push($.ajax(shares))

Expand Down Expand Up @@ -292,7 +313,12 @@
}

if (additionalShares && additionalShares.ocs && additionalShares.ocs.data) {
files = files.concat(this._makeFilesFromShares(additionalShares.ocs.data, !this._sharedWithUser))
if (this._showPending) {
// in this case the second callback is about pending remote shares
files = files.concat(this._makeFilesFromRemoteShares(additionalShares.ocs.data))
} else {
files = files.concat(this._makeFilesFromShares(additionalShares.ocs.data, !this._sharedWithUser))
}
}

this.setFiles(files)
Expand All @@ -311,12 +337,29 @@
mtime: share.mtime * 1000,
mimetype: share.mimetype,
type: share.type,
// remote share types are different and need to be mapped
shareType: (parseInt(share.share_type, 10) === 1) ? OC.Share.SHARE_TYPE_REMOTE_GROUP : OC.Share.SHARE_TYPE_REMOTE,
id: share.file_id,
path: OC.dirname(share.mountpoint),
permissions: share.permissions,
tags: share.tags || []
}

if (share.remote_id) {
// remote share
if (share.accepted !== '1') {
file.name = OC.basename(share.name)
file.path = '/'
}
file.remoteId = share.remote_id
file.shareOwnerId = share.owner
}

if (!file.mimetype) {
// pending shares usually have no type, so default to showing a directory icon
file.mimetype = 'dir-shared'
}

file.shares = [{
id: share.id,
type: OC.Share.SHARE_TYPE_REMOTE
Expand Down
4 changes: 3 additions & 1 deletion apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OCP\Share\IManager;
use OCP\Util;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

Expand Down Expand Up @@ -98,7 +99,8 @@ public function __construct(array $urlParams = []) {
$server->getGroupManager(),
$server->getUserManager(),
$uid,
$server->query(IEventDispatcher::class)
$server->query(IEventDispatcher::class),
$server->get(LoggerInterface::class)
);
});

Expand Down
Loading

0 comments on commit a71294e

Please sign in to comment.