Skip to content

Commit 9a2c517

Browse files
committed
Merge pull request #22253 from owncloud/notifications-for-remote-shares
Notifications for remote shares
2 parents a8d9eb5 + fa89376 commit 9a2c517

6 files changed

Lines changed: 30 additions & 17 deletions

File tree

apps/files_sharing/api/remote.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function acceptShare($params) {
6363
\OC_User::getUser()
6464
);
6565

66-
if ($externalManager->acceptShare($params['id'])) {
66+
if ($externalManager->acceptShare((int) $params['id'])) {
6767
return new \OC_OCS_Result();
6868
}
6969

@@ -86,7 +86,7 @@ public static function declineShare($params) {
8686
\OC_User::getUser()
8787
);
8888

89-
if ($externalManager->declineShare($params['id'])) {
89+
if ($externalManager->declineShare((int) $params['id'])) {
9090
return new \OC_OCS_Result();
9191
}
9292

apps/files_sharing/api/server2server.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,35 @@ public function createShare($params) {
8181

8282
try {
8383
$externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
84+
$shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');
8485

8586
$user = $owner . '@' . $this->cleanupRemote($remote);
8687

8788
\OC::$server->getActivityManager()->publishActivity(
8889
Activity::FILES_SHARING_APP, Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user, trim($name, '/')), '', array(),
8990
'', '', $shareWith, Activity::TYPE_REMOTE_SHARE, Activity::PRIORITY_LOW);
9091

91-
/**
92-
* FIXME
9392
$urlGenerator = \OC::$server->getURLGenerator();
9493

9594
$notificationManager = \OC::$server->getNotificationManager();
9695
$notification = $notificationManager->createNotification();
9796
$notification->setApp('files_sharing')
9897
->setUser($shareWith)
99-
->setTimestamp(time())
100-
->setObject('remote_share', $remoteId)
98+
->setDateTime(new \DateTime())
99+
->setObject('remote_share', $shareId)
101100
->setSubject('remote_share', [$user, trim($name, '/')]);
102101

103102
$declineAction = $notification->createAction();
104103
$declineAction->setLabel('decline')
105-
->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'DELETE');
104+
->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId), 'DELETE');
106105
$notification->addAction($declineAction);
107106

108107
$acceptAction = $notification->createAction();
109108
$acceptAction->setLabel('accept')
110-
->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/' . $remoteId), 'POST');
109+
->setLink($urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId), 'POST');
111110
$notification->addAction($acceptAction);
112111

113112
$notificationManager->notify($notification);
114-
*/
115113

116114
return new \OC_OCS_Result();
117115
} catch (\Exception $e) {

apps/files_sharing/appinfo/app.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ function() {
114114
}
115115
}
116116

117-
/**
118-
* FIXME
119117
$manager = \OC::$server->getNotificationManager();
120118
$manager->registerNotifier(function() {
121119
return new \OCA\Files_Sharing\Notifier(
122120
\OC::$server->getL10NFactory()
123121
);
122+
}, function() use ($l) {
123+
return [
124+
'id' => 'files_sharing',
125+
'name' => $l->t('Federated sharing'),
126+
];
124127
});
125-
*/

apps/files_sharing/js/external.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,21 @@
6969
filesApp: null,
7070

7171
attach: function(filesApp) {
72+
var self = this;
7273
this.filesApp = filesApp;
7374
this.processIncomingShareFromUrl();
74-
this.processSharesToConfirm();
75+
76+
if (!$('#header').find('div.notifications').length) {
77+
// No notification app, display the modal
78+
this.processSharesToConfirm();
79+
}
80+
81+
$('body').on('OCA.Notification.Action', function(e) {
82+
if (e.notification.app === 'files_sharing' && e.notification.object_type === 'remote_share' && e.action.type === 'POST') {
83+
// User accepted a remote share reload
84+
self.filesApp.fileList.reload();
85+
}
86+
});
7587
},
7688

7789
/**

apps/files_sharing/lib/external/manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function acceptShare($id) {
194194

195195
\OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $share['remote']]);
196196

197-
//FIXME $this->scrapNotification($share['remote_id']);
197+
$this->scrapNotification($id);
198198
return true;
199199
}
200200

@@ -217,7 +217,7 @@ public function declineShare($id) {
217217
$removeShare->execute(array($id, $this->uid));
218218
$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline');
219219

220-
//FIXME $this->scrapNotification($share['remote_id']);
220+
$this->scrapNotification($id);
221221
return true;
222222
}
223223

apps/files_sharing/lib/notifier.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function prepare(INotification $notification, $languageCode) {
5555
case 'remote_share':
5656
$params = $notification->getSubjectParameters();
5757
$notification->setParsedSubject(
58-
(string) $l->t('You received %2$s as a remote share from %1$s', $params)
58+
(string) $l->t('You received "/%2$s" as a remote share from %1$s', $params)
5959
);
6060

6161
// Deal with the actions for a known subject
@@ -64,7 +64,8 @@ public function prepare(INotification $notification, $languageCode) {
6464
case 'accept':
6565
$action->setParsedLabel(
6666
(string) $l->t('Accept')
67-
);
67+
)
68+
->setPrimary(true);
6869
break;
6970

7071
case 'decline':

0 commit comments

Comments
 (0)