Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
fb717f25
Commit
fb717f25
authored
Sep 10, 2015
by
Lukas Reschke
Browse files
Merge pull request #18699 from owncloud/notification-manager
Notification manager
parents
89cd9295
38001d82
Changes
24
Hide whitespace changes
Inline
Side-by-side
apps/files_sharing/ajax/external.php
View file @
fb717f25
...
...
@@ -52,6 +52,7 @@ $externalManager = new \OCA\Files_Sharing\External\Manager(
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
getHTTPHelper
(),
\
OC
::
$server
->
getNotificationManager
(),
\
OC
::
$server
->
getUserSession
()
->
getUser
()
->
getUID
()
);
...
...
apps/files_sharing/api/remote.php
View file @
fb717f25
...
...
@@ -38,6 +38,7 @@ class Remote {
Filesystem
::
getMountManager
(),
Filesystem
::
getLoader
(),
\
OC
::
$server
->
getHTTPHelper
(),
\
OC
::
$server
->
getNotificationManager
(),
\
OC_User
::
getUser
()
);
...
...
@@ -56,6 +57,7 @@ class Remote {
Filesystem
::
getMountManager
(),
Filesystem
::
getLoader
(),
\
OC
::
$server
->
getHTTPHelper
(),
\
OC
::
$server
->
getNotificationManager
(),
\
OC_User
::
getUser
()
);
...
...
@@ -78,6 +80,7 @@ class Remote {
Filesystem
::
getMountManager
(),
Filesystem
::
getLoader
(),
\
OC
::
$server
->
getHTTPHelper
(),
\
OC
::
$server
->
getNotificationManager
(),
\
OC_User
::
getUser
()
);
...
...
@@ -87,5 +90,4 @@ class Remote {
return
new
\
OC_OCS_Result
(
null
,
404
,
"wrong share ID, share doesn't exist."
);
}
}
apps/files_sharing/api/server2server.php
View file @
fb717f25
...
...
@@ -70,6 +70,7 @@ class Server2Server {
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
getHTTPHelper
(),
\
OC
::
$server
->
getNotificationManager
(),
$shareWith
);
...
...
@@ -82,6 +83,28 @@ class Server2Server {
Activity
::
FILES_SHARING_APP
,
Activity
::
SUBJECT_REMOTE_SHARE_RECEIVED
,
array
(
$user
,
trim
(
$name
,
'/'
)),
''
,
array
(),
''
,
''
,
$shareWith
,
Activity
::
TYPE_REMOTE_SHARE
,
Activity
::
PRIORITY_LOW
);
$urlGenerator
=
\
OC
::
$server
->
getURLGenerator
();
$notificationManager
=
\
OC
::
$server
->
getNotificationManager
();
$notification
=
$notificationManager
->
createNotification
();
$notification
->
setApp
(
'files_sharing'
)
->
setUser
(
$shareWith
)
->
setTimestamp
(
time
())
->
setObject
(
'remote_share'
,
$remoteId
)
->
setSubject
(
'remote_share'
,
[
$user
,
trim
(
$name
,
'/'
)]);
$acceptAction
=
$notification
->
createAction
();
$acceptAction
->
setLabel
(
'accept'
)
->
setLink
(
$urlGenerator
->
getAbsoluteURL
(
'/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/'
.
$remoteId
),
'POST'
);
$declineAction
=
$notification
->
createAction
();
$declineAction
->
setLabel
(
'decline'
)
->
setLink
(
$urlGenerator
->
getAbsoluteURL
(
'/ocs/v1.php/apps/files_sharing/api/v1/remote_shares/'
.
$remoteId
),
'DELETE'
);
$notification
->
addAction
(
$acceptAction
)
->
addAction
(
$declineAction
);
$notificationManager
->
notify
(
$notification
);
return
new
\
OC_OCS_Result
();
}
catch
(
\
Exception
$e
)
{
\
OCP\Util
::
writeLog
(
'files_sharing'
,
'server can not add remote share, '
.
$e
->
getMessage
(),
\
OCP\Util
::
ERROR
);
...
...
apps/files_sharing/appinfo/app.php
View file @
fb717f25
...
...
@@ -103,3 +103,10 @@ if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
}
}
}
$manager
=
\
OC
::
$server
->
getNotificationManager
();
$manager
->
registerNotifier
(
function
()
{
return
new
\
OCA\Files_Sharing\Notifier
(
\
OC
::
$server
->
getL10NFactory
()
);
});
apps/files_sharing/appinfo/application.php
View file @
fb717f25
...
...
@@ -93,6 +93,7 @@ class Application extends App {
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
$server
->
getHTTPHelper
(),
$server
->
getNotificationManager
(),
$uid
);
});
...
...
apps/files_sharing/lib/external/manager.php
View file @
fb717f25
...
...
@@ -28,6 +28,7 @@ namespace OCA\Files_Sharing\External;
use
OC\Files\Filesystem
;
use
OCP\Files
;
use
OC\Notification\IManager
;
class
Manager
{
const
STORAGE
=
'\OCA\Files_Sharing\External\Storage'
;
...
...
@@ -57,20 +58,27 @@ class Manager {
*/
private
$httpHelper
;
/**
* @var IManager
*/
private
$notificationManager
;
/**
* @param \OCP\IDBConnection $connection
* @param \OC\Files\Mount\Manager $mountManager
* @param \OCP\Files\Storage\IStorageFactory $storageLoader
* @param \OC\HTTPHelper $httpHelper
* @param IManager $notificationManager
* @param string $uid
*/
public
function
__construct
(
\
OCP\IDBConnection
$connection
,
\
OC\Files\Mount\Manager
$mountManager
,
\
OCP\Files\Storage\IStorageFactory
$storageLoader
,
\
OC\HTTPHelper
$httpHelper
,
$uid
)
{
\
OCP\Files\Storage\IStorageFactory
$storageLoader
,
\
OC\HTTPHelper
$httpHelper
,
IManager
$notificationManager
,
$uid
)
{
$this
->
connection
=
$connection
;
$this
->
mountManager
=
$mountManager
;
$this
->
storageLoader
=
$storageLoader
;
$this
->
httpHelper
=
$httpHelper
;
$this
->
uid
=
$uid
;
$this
->
notificationManager
=
$notificationManager
;
}
/**
...
...
@@ -206,6 +214,7 @@ class Manager {
$acceptShare
->
execute
(
array
(
1
,
$mountPoint
,
$hash
,
$id
,
$this
->
uid
));
$this
->
sendFeedbackToRemote
(
$share
[
'remote'
],
$share
[
'share_token'
],
$share
[
'remote_id'
],
'accept'
);
$this
->
scrapNotification
(
$share
[
'remote_id'
]);
return
true
;
}
...
...
@@ -228,12 +237,24 @@ class Manager {
$removeShare
->
execute
(
array
(
$id
,
$this
->
uid
));
$this
->
sendFeedbackToRemote
(
$share
[
'remote'
],
$share
[
'share_token'
],
$share
[
'remote_id'
],
'decline'
);
$this
->
scrapNotification
(
$share
[
'remote_id'
]);
return
true
;
}
return
false
;
}
/**
* @param int $remoteShare
*/
protected
function
scrapNotification
(
$remoteShare
)
{
$filter
=
$this
->
notificationManager
->
createNotification
();
$filter
->
setApp
(
'files_sharing'
)
->
setUser
(
$this
->
uid
)
->
setObject
(
'remote_share'
,
(
int
)
$remoteShare
);
$this
->
notificationManager
->
markProcessed
(
$filter
);
}
/**
* inform remote server whether server-to-server share was accepted/declined
*
...
...
@@ -265,6 +286,7 @@ class Manager {
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
getHTTPHelper
(),
\
OC
::
$server
->
getNotificationManager
(),
$params
[
'user'
]
);
...
...
apps/files_sharing/lib/hooks.php
View file @
fb717f25
...
...
@@ -33,6 +33,7 @@ class Hooks {
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
getHTTPHelper
(),
\
OC
::
$server
->
getNotificationManager
(),
$params
[
'uid'
]);
$manager
->
removeUserShares
(
$params
[
'uid'
]);
...
...
apps/files_sharing/lib/notifier.php
0 → 100644
View file @
fb717f25
<?php
/**
* @author Joas Schilling <nickvergessen@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace
OCA\Files_Sharing
;
use
OC\Notification\INotification
;
use
OC\Notification\INotifier
;
class
Notifier
implements
INotifier
{
/** @var \OCP\L10N\IFactory */
protected
$factory
;
/**
* @param \OCP\L10N\IFactory $factory
*/
public
function
__construct
(
\
OCP\L10N\IFactory
$factory
)
{
$this
->
factory
=
$factory
;
}
/**
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
*/
public
function
prepare
(
INotification
$notification
,
$languageCode
)
{
if
(
$notification
->
getApp
()
!==
'files_sharing'
)
{
// Not my app => throw
throw
new
\
InvalidArgumentException
();
}
// Read the language from the notification
$l
=
$this
->
factory
->
get
(
'files_sharing'
,
$languageCode
);
switch
(
$notification
->
getSubject
())
{
// Deal with known subjects
case
'remote_share'
:
$params
=
$notification
->
getSubjectParameters
();
$notification
->
setParsedSubject
(
(
string
)
$l
->
t
(
'You received %s as a remote share from %s'
,
$params
)
);
// Deal with the actions for a known subject
foreach
(
$notification
->
getActions
()
as
$action
)
{
switch
(
$action
->
getLabel
())
{
case
'accept'
:
$action
->
setParsedLabel
(
(
string
)
$l
->
t
(
'Accept'
)
);
break
;
case
'decline'
:
$action
->
setParsedLabel
(
(
string
)
$l
->
t
(
'Decline'
)
);
break
;
}
$notification
->
addParsedAction
(
$action
);
}
return
$notification
;
default
:
// Unknown subject => Unknown notification => throw
throw
new
\
InvalidArgumentException
();
}
}
}
apps/files_sharing/tests/external/managertest.php
View file @
fb717f25
...
...
@@ -50,6 +50,7 @@ class ManagerTest extends TestCase {
$this
->
mountManager
,
new
StorageFactory
(),
$httpHelper
,
\
OC
::
$server
->
getNotificationManager
(),
$this
->
uid
);
}
...
...
apps/files_sharing/tests/server2server.php
View file @
fb717f25
...
...
@@ -154,6 +154,7 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
getHTTPHelper
(),
\
OC
::
$server
->
getNotificationManager
(),
$toDelete
);
...
...
lib/private/notification/action.php
0 → 100644
View file @
fb717f25
<?php
/**
* @author Joas Schilling <nickvergessen@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace
OC\Notification
;
class
Action
implements
IAction
{
/** @var string */
protected
$label
;
/** @var string */
protected
$labelParsed
;
/** @var string */
protected
$link
;
/** @var string */
protected
$requestType
;
/** @var string */
protected
$icon
;
/**
* Constructor
*/
public
function
__construct
()
{
$this
->
label
=
''
;
$this
->
labelParsed
=
''
;
$this
->
link
=
''
;
$this
->
requestType
=
''
;
$this
->
icon
=
''
;
}
/**
* @param string $label
* @return $this
* @throws \InvalidArgumentException if the label is invalid
* @since 8.2.0
*/
public
function
setLabel
(
$label
)
{
if
(
!
is_string
(
$label
)
||
$label
===
''
||
isset
(
$label
[
32
]))
{
throw
new
\
InvalidArgumentException
(
'The given label is invalid'
);
}
$this
->
label
=
$label
;
return
$this
;
}
/**
* @return string
* @since 8.2.0
*/
public
function
getLabel
()
{
return
$this
->
label
;
}
/**
* @param string $label
* @return $this
* @throws \InvalidArgumentException if the label is invalid
* @since 8.2.0
*/
public
function
setParsedLabel
(
$label
)
{
if
(
!
is_string
(
$label
)
||
$label
===
''
)
{
throw
new
\
InvalidArgumentException
(
'The given parsed label is invalid'
);
}
$this
->
labelParsed
=
$label
;
return
$this
;
}
/**
* @return string
* @since 8.2.0
*/
public
function
getParsedLabel
()
{
return
$this
->
labelParsed
;
}
/**
* @param string $link
* @param string $requestType
* @return $this
* @throws \InvalidArgumentException if the link is invalid
* @since 8.2.0
*/
public
function
setLink
(
$link
,
$requestType
)
{
if
(
!
is_string
(
$link
)
||
$link
===
''
||
isset
(
$link
[
256
]))
{
throw
new
\
InvalidArgumentException
(
'The given link is invalid'
);
}
if
(
!
in_array
(
$requestType
,
[
'GET'
,
'POST'
,
'PUT'
,
'DELETE'
],
true
))
{
throw
new
\
InvalidArgumentException
(
'The given request type is invalid'
);
}
$this
->
link
=
$link
;
$this
->
requestType
=
$requestType
;
return
$this
;
}
/**
* @return string
* @since 8.2.0
*/
public
function
getLink
()
{
return
$this
->
link
;
}
/**
* @return string
* @since 8.2.0
*/
public
function
getRequestType
()
{
return
$this
->
requestType
;
}
/**
* @param string $icon
* @return $this
* @throws \InvalidArgumentException if the icon is invalid
* @since 8.2.0
*/
public
function
setIcon
(
$icon
)
{
if
(
!
is_string
(
$icon
)
||
$icon
===
''
||
isset
(
$icon
[
64
]))
{
throw
new
\
InvalidArgumentException
(
'The given icon is invalid'
);
}
$this
->
icon
=
$icon
;
return
$this
;
}
/**
* @return string
* @since 8.2.0
*/
public
function
getIcon
()
{
return
$this
->
icon
;
}
/**
* @return bool
*/
public
function
isValid
()
{
return
$this
->
label
!==
''
&&
$this
->
link
!==
''
;
}
/**
* @return bool
*/
public
function
isValidParsed
()
{
return
$this
->
labelParsed
!==
''
&&
$this
->
link
!==
''
;
}
}
lib/private/notification/iaction.php
0 → 100644
View file @
fb717f25
<?php
/**
* @author Joas Schilling <nickvergessen@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace
OC\Notification
;
/**
* Interface IAction
*
* @package OC\Notification
* @since 8.2.0
*
* DEVELOPER NOTE:
* The notification api is experimental only in 8.2.0! Do not start using it,
* if you can not prepare an update for the next version afterwards.
*/
interface
IAction
{
/**
* @param string $label
* @return $this
* @throws \InvalidArgumentException if the label is invalid
* @since 8.2.0
*/
public
function
setLabel
(
$label
);
/**
* @return string
* @since 8.2.0
*/
public
function
getLabel
();
/**
* @param string $label
* @return $this
* @throws \InvalidArgumentException if the label is invalid
* @since 8.2.0
*/
public
function
setParsedLabel
(
$label
);
/**
* @return string
* @since 8.2.0
*/
public
function
getParsedLabel
();
/**
* @param string $link
* @param string $requestType
* @return $this
* @throws \InvalidArgumentException if the link is invalid
* @since 8.2.0
*/
public
function
setLink
(
$link
,
$requestType
);
/**
* @return string
* @since 8.2.0
*/
public
function
getLink
();
/**
* @return string
* @since 8.2.0
*/
public
function
getRequestType
();
/**
* @param string $icon
* @return $this
* @throws \InvalidArgumentException if the icon is invalid
* @since 8.2.0
*/
public
function
setIcon
(
$icon
);
/**
* @return string
* @since 8.2.0
*/
public
function
getIcon
();
/**
* @return bool
* @since 8.2.0
*/
public
function
isValid
();
/**
* @return bool
* @since 8.2.0
*/
public
function
isValidParsed
();
}
lib/private/notification/iapp.php
0 → 100644
View file @
fb717f25
<?php
/**
* @author Joas Schilling <nickvergessen@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace
OC\Notification
;
/**
* Interface IApp
*
* @package OC\Notification
* @since 8.2.0
*
* DEVELOPER NOTE:
* The notification api is experimental only in 8.2.0! Do not start using it,
* if you can not prepare an update for the next version afterwards.
*/
interface
IApp
{
/**
* @param INotification $notification
* @return null
* @throws \InvalidArgumentException When the notification is not valid
* @since 8.2.0
*/
public
function
notify
(
INotification
$notification
);
/**
* @param INotification $notification
* @return null
* @since 8.2.0
*/
public
function
markProcessed
(
INotification
$notification
);
/**
* @param INotification $notification
* @return int
* @since 8.2.0
*/
public
function
getCount
(
INotification
$notification
);
}