Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
92fa0c7d
Unverified
Commit
92fa0c7d
authored
8 years ago
by
Björn Schießle
Browse files
Options
Downloads
Patches
Plain Diff
fall back to old re-sharing behaviour in case the remote server doesn't support flat-reshares
parent
2dc26aad
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/federatedfilesharing/lib/FederatedShareProvider.php
+63
-35
63 additions, 35 deletions
apps/federatedfilesharing/lib/FederatedShareProvider.php
apps/federatedfilesharing/lib/Notifications.php
+7
-0
7 additions, 0 deletions
apps/federatedfilesharing/lib/Notifications.php
with
70 additions
and
35 deletions
apps/federatedfilesharing/lib/FederatedShareProvider.php
+
63
−
35
View file @
92fa0c7d
...
...
@@ -133,7 +133,6 @@ class FederatedShareProvider implements IShareProvider {
$shareWith
=
$share
->
getSharedWith
();
$itemSource
=
$share
->
getNodeId
();
$itemType
=
$share
->
getNodeType
();
$uidOwner
=
$share
->
getShareOwner
();
$permissions
=
$share
->
getPermissions
();
$sharedBy
=
$share
->
getSharedBy
();
...
...
@@ -160,7 +159,7 @@ class FederatedShareProvider implements IShareProvider {
throw
new
\Exception
(
$message_t
);
}
$shareWith
=
$user
.
'@'
.
$remote
;
$share
->
setShared
With
(
$user
.
'@'
.
$remote
)
;
try
{
$remoteShare
=
$this
->
getShareFromExternalShareTable
(
$share
);
...
...
@@ -169,39 +168,33 @@ class FederatedShareProvider implements IShareProvider {
}
if
(
$remoteShare
)
{
$uidOwner
=
$remoteShare
[
'owner'
]
.
'@'
.
$remoteShare
[
'remote'
];
$shareId
=
$this
->
addShareToDB
(
$itemSource
,
$itemType
,
$shareWith
,
$sharedBy
,
$uidOwner
,
$permissions
,
'tmp_token_'
.
time
());
list
(
$token
,
$remoteId
)
=
$this
->
askOwnerToReShare
(
$shareWith
,
$share
,
$shareId
);
// remote share was create successfully if we get a valid token as return
$send
=
is_string
(
$token
)
&&
$token
!==
''
;
if
(
$send
)
{
$this
->
updateSuccessfulReshare
(
$shareId
,
$token
);
$this
->
storeRemoteId
(
$shareId
,
$remoteId
);
try
{
$uidOwner
=
$remoteShare
[
'owner'
]
.
'@'
.
$remoteShare
[
'remote'
];
$shareId
=
$this
->
addShareToDB
(
$itemSource
,
$itemType
,
$shareWith
,
$sharedBy
,
$uidOwner
,
$permissions
,
'tmp_token_'
.
time
());
list
(
$token
,
$remoteId
)
=
$this
->
askOwnerToReShare
(
$shareWith
,
$share
,
$shareId
);
// remote share was create successfully if we get a valid token as return
$send
=
is_string
(
$token
)
&&
$token
!==
''
;
if
(
$send
)
{
$this
->
updateSuccessfulReshare
(
$shareId
,
$token
);
$this
->
storeRemoteId
(
$shareId
,
$remoteId
);
}
}
catch
(
\Exception
$e
)
{
// fall back to old re-share behavior if the remote server
// doesn't support flat re-shares (was introduced with ownCloud 9.1)
$data
=
$this
->
getRawShare
(
$shareId
);
$brokenShare
=
$this
->
createShareObject
(
$data
);
$this
->
removeShareFromTable
(
$brokenShare
);
list
(
$shareId
,
$send
)
=
$this
->
createFederatedShare
(
$share
);
}
}
else
{
$token
=
$this
->
tokenHandler
->
generateToken
();
$shareId
=
$this
->
addShareToDB
(
$itemSource
,
$itemType
,
$shareWith
,
$sharedBy
,
$uidOwner
,
$permissions
,
$token
);
$sharedByFederatedId
=
$share
->
getSharedBy
();
if
(
$this
->
userManager
->
userExists
(
$sharedByFederatedId
))
{
$sharedByFederatedId
=
$sharedByFederatedId
.
'@'
.
$this
->
addressHandler
->
generateRemoteURL
();
}
$send
=
$this
->
notifications
->
sendRemoteShare
(
$token
,
$shareWith
,
$share
->
getNode
()
->
getName
(),
$shareId
,
$share
->
getShareOwner
(),
$share
->
getShareOwner
()
.
'@'
.
$this
->
addressHandler
->
generateRemoteURL
(),
$share
->
getSharedBy
(),
$sharedByFederatedId
);
list
(
$shareId
,
$send
)
=
$this
->
createFederatedShare
(
$share
);
}
$data
=
$this
->
getRawShare
(
$shareId
);
$share
=
$this
->
createShare
(
$data
);
$share
=
$this
->
createShare
Object
(
$data
);
if
(
$send
===
false
)
{
$this
->
delet
e
(
$share
);
$this
->
removeShareFromTabl
e
(
$share
);
$message_t
=
$this
->
l
->
t
(
'Sharing %s failed, could not find %s, maybe the server is currently unreachable.'
,
[
$share
->
getNode
()
->
getName
(),
$shareWith
]);
throw
new
\Exception
(
$message_t
);
...
...
@@ -210,6 +203,41 @@ class FederatedShareProvider implements IShareProvider {
return
$share
;
}
/**
* create federated share and inform the recipient
*
* @param IShare $share
* @return array
*/
protected
function
createFederatedShare
(
IShare
$share
)
{
$token
=
$this
->
tokenHandler
->
generateToken
();
$shareId
=
$this
->
addShareToDB
(
$share
->
getNodeId
(),
$share
->
getNodeType
(),
$share
->
getSharedWith
(),
$share
->
getSharedBy
(),
$share
->
getShareOwner
(),
$share
->
getPermissions
(),
$token
);
$sharedByFederatedId
=
$share
->
getSharedBy
();
if
(
$this
->
userManager
->
userExists
(
$sharedByFederatedId
))
{
$sharedByFederatedId
=
$sharedByFederatedId
.
'@'
.
$this
->
addressHandler
->
generateRemoteURL
();
}
$send
=
$this
->
notifications
->
sendRemoteShare
(
$token
,
$share
->
getSharedWith
(),
$share
->
getNode
()
->
getName
(),
$shareId
,
$share
->
getShareOwner
(),
$share
->
getShareOwner
()
.
'@'
.
$this
->
addressHandler
->
generateRemoteURL
(),
$share
->
getSharedBy
(),
$sharedByFederatedId
);
return
[
$shareId
,
$send
];
}
/**
* @param string $shareWith
* @param IShare $share
...
...
@@ -421,7 +449,7 @@ class FederatedShareProvider implements IShareProvider {
$cursor
=
$qb
->
execute
();
while
(
$data
=
$cursor
->
fetch
())
{
$children
[]
=
$this
->
createShare
(
$data
);
$children
[]
=
$this
->
createShare
Object
(
$data
);
}
$cursor
->
closeCursor
();
...
...
@@ -562,7 +590,7 @@ class FederatedShareProvider implements IShareProvider {
$cursor
=
$qb
->
execute
();
$shares
=
[];
while
(
$data
=
$cursor
->
fetch
())
{
$shares
[]
=
$this
->
createShare
(
$data
);
$shares
[]
=
$this
->
createShare
Object
(
$data
);
}
$cursor
->
closeCursor
();
...
...
@@ -589,7 +617,7 @@ class FederatedShareProvider implements IShareProvider {
}
try
{
$share
=
$this
->
createShare
(
$data
);
$share
=
$this
->
createShare
Object
(
$data
);
}
catch
(
InvalidShare
$e
)
{
throw
new
ShareNotFound
();
}
...
...
@@ -614,7 +642,7 @@ class FederatedShareProvider implements IShareProvider {
$shares
=
[];
while
(
$data
=
$cursor
->
fetch
())
{
$shares
[]
=
$this
->
createShare
(
$data
);
$shares
[]
=
$this
->
createShare
Object
(
$data
);
}
$cursor
->
closeCursor
();
...
...
@@ -653,7 +681,7 @@ class FederatedShareProvider implements IShareProvider {
$cursor
=
$qb
->
execute
();
while
(
$data
=
$cursor
->
fetch
())
{
$shares
[]
=
$this
->
createShare
(
$data
);
$shares
[]
=
$this
->
createShare
Object
(
$data
);
}
$cursor
->
closeCursor
();
...
...
@@ -684,7 +712,7 @@ class FederatedShareProvider implements IShareProvider {
}
try
{
$share
=
$this
->
createShare
(
$data
);
$share
=
$this
->
createShare
Object
(
$data
);
}
catch
(
InvalidShare
$e
)
{
throw
new
ShareNotFound
();
}
...
...
@@ -726,7 +754,7 @@ class FederatedShareProvider implements IShareProvider {
* @throws InvalidShare
* @throws ShareNotFound
*/
private
function
createShare
(
$data
)
{
private
function
createShare
Object
(
$data
)
{
$share
=
new
Share
(
$this
->
rootFolder
,
$this
->
userManager
);
$share
->
setId
((
int
)
$data
[
'id'
])
...
...
This diff is collapsed.
Click to expand it.
apps/federatedfilesharing/lib/Notifications.php
+
7
−
0
View file @
92fa0c7d
...
...
@@ -23,6 +23,7 @@
namespace
OCA\FederatedFileSharing
;
use
OCP\AppFramework\Http
;
use
OCP\BackgroundJob\IJobList
;
use
OCP\Http\Client\IClientService
;
...
...
@@ -291,6 +292,12 @@ class Notifications {
$result
[
'success'
]
=
true
;
break
;
}
catch
(
\Exception
$e
)
{
// if flat re-sharing is not supported by the remote server
// we re-throw the exception and fall back to the old behaviour.
// (flat re-shares has been introduced in ownCloud 9.1)
if
(
$e
->
getCode
()
===
Http
::
STATUS_INTERNAL_SERVER_ERROR
)
{
throw
$e
;
}
$try
++
;
$protocol
=
'http://'
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment