Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
f0f2d939
Commit
f0f2d939
authored
12 years ago
by
Michael Gapczynski
Browse files
Options
Downloads
Patches
Plain Diff
Restructure generateTarget for the post_addToGroup hook
parent
a77c1637
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
lib/public/share.php
+44
-20
44 additions, 20 deletions
lib/public/share.php
tests/lib/share/share.php
+13
-12
13 additions, 12 deletions
tests/lib/share/share.php
with
57 additions
and
32 deletions
lib/public/share.php
+
44
−
20
View file @
f0f2d939
...
@@ -823,14 +823,17 @@ class Share {
...
@@ -823,14 +823,17 @@ class Share {
}
else
{
}
else
{
$groupFileTarget
=
null
;
$groupFileTarget
=
null
;
}
}
$query
->
execute
(
array
(
$itemType
,
$itemSource
,
$groupItemTarget
,
$parent
,
$shareType
,
$shareWith
[
'group'
],
$uidOwner
,
$permissions
,
time
(),
$fileSource
,
$groupFileTarget
));
// Save this id, any extra rows for this group share will need to reference it
$parent
=
\OC_DB
::
insertid
(
'*PREFIX*share'
);
$uniqueTargets
=
array
();
$uniqueTargets
=
array
();
// Loop through all users of this group in case we need to add an extra row
// Loop through all users of this group in case we need to add an extra row
foreach
(
$shareWith
[
'users'
]
as
$uid
)
{
foreach
(
$shareWith
[
'users'
]
as
$uid
)
{
$itemTarget
=
self
::
generateTarget
(
$itemType
,
$itemSource
,
self
::
SHARE_TYPE_USER
,
$uid
,
$uidOwner
);
$itemTarget
=
self
::
generateTarget
(
$itemType
,
$itemSource
,
self
::
SHARE_TYPE_USER
,
$uid
,
$uidOwner
,
$suggestedItemTarget
,
$parent
);
if
(
isset
(
$fileSource
))
{
if
(
isset
(
$fileSource
))
{
if
(
$parentFolder
)
{
if
(
$parentFolder
)
{
if
(
$parentFolder
===
true
)
{
if
(
$parentFolder
===
true
)
{
$fileTarget
=
self
::
generateTarget
(
'file'
,
$filePath
,
self
::
SHARE_TYPE_USER
,
$uid
,
$uidOwner
);
$fileTarget
=
self
::
generateTarget
(
'file'
,
$filePath
,
self
::
SHARE_TYPE_USER
,
$uid
,
$uidOwner
,
$suggestedFileTarget
,
$parent
);
if
(
$fileTarget
!=
$groupFileTarget
)
{
if
(
$fileTarget
!=
$groupFileTarget
)
{
$parentFolders
[
$uid
][
'folder'
]
=
$fileTarget
;
$parentFolders
[
$uid
][
'folder'
]
=
$fileTarget
;
}
}
...
@@ -839,24 +842,14 @@ class Share {
...
@@ -839,24 +842,14 @@ class Share {
$parent
=
$parentFolder
[
$uid
][
'id'
];
$parent
=
$parentFolder
[
$uid
][
'id'
];
}
}
}
else
{
}
else
{
$fileTarget
=
self
::
generateTarget
(
'file'
,
$filePath
,
self
::
SHARE_TYPE_USER
,
$uid
,
$uidOwner
);
$fileTarget
=
self
::
generateTarget
(
'file'
,
$filePath
,
self
::
SHARE_TYPE_USER
,
$uid
,
$uidOwner
,
$suggestedFileTarget
,
$parent
);
}
}
}
else
{
}
else
{
$fileTarget
=
null
;
$fileTarget
=
null
;
}
}
// Insert an extra row for the group share if the item or file target is unique for this user
// Insert an extra row for the group share if the item or file target is unique for this user
if
(
$itemTarget
!=
$groupItemTarget
||
(
isset
(
$fileSource
)
&&
$fileTarget
!=
$groupFileTarget
))
{
if
(
$itemTarget
!=
$groupItemTarget
||
(
isset
(
$fileSource
)
&&
$fileTarget
!=
$groupFileTarget
))
{
$uniqueTargets
[]
=
array
(
'uid'
=>
$uid
,
'item_target'
=>
$itemTarget
,
'file_target'
=>
$fileTarget
);
$query
->
execute
(
array
(
$itemType
,
$itemSource
,
$itemTarget
,
$parent
,
self
::
$shareTypeGroupUserUnique
,
$uid
,
$uidOwner
,
$permissions
,
time
(),
$fileSource
,
$fileTarget
));
}
}
$query
->
execute
(
array
(
$itemType
,
$itemSource
,
$groupItemTarget
,
$parent
,
$shareType
,
$shareWith
[
'group'
],
$uidOwner
,
$permissions
,
time
(),
$fileSource
,
$groupFileTarget
));
// Save this id, any extra rows for this group share will need to reference it
$parent
=
\OC_DB
::
insertid
(
'*PREFIX*share'
);
foreach
(
$uniqueTargets
as
$unique
)
{
$query
->
execute
(
array
(
$itemType
,
$itemSource
,
$unique
[
'item_target'
],
$parent
,
self
::
$shareTypeGroupUserUnique
,
$unique
[
'uid'
],
$uidOwner
,
$permissions
,
time
(),
$fileSource
,
$unique
[
'file_target'
]));
$id
=
\OC_DB
::
insertid
(
'*PREFIX*share'
);
if
(
$parentFolder
===
true
)
{
$parentFolders
[
'id'
]
=
$id
;
}
}
}
}
if
(
$parentFolder
===
true
)
{
if
(
$parentFolder
===
true
)
{
...
@@ -900,7 +893,7 @@ class Share {
...
@@ -900,7 +893,7 @@ class Share {
* @param string The suggested target originating from a reshare (optional)
* @param string The suggested target originating from a reshare (optional)
* @return string Item target
* @return string Item target
*/
*/
private
static
function
generateTarget
(
$itemType
,
$itemSource
,
$shareType
,
$shareWith
,
$uidOwner
,
$suggestedTarget
=
null
)
{
private
static
function
generateTarget
(
$itemType
,
$itemSource
,
$shareType
,
$shareWith
,
$uidOwner
,
$suggestedTarget
=
null
,
$groupParent
=
null
)
{
$backend
=
self
::
getBackend
(
$itemType
);
$backend
=
self
::
getBackend
(
$itemType
);
if
(
$shareType
==
self
::
SHARE_TYPE_LINK
)
{
if
(
$shareType
==
self
::
SHARE_TYPE_LINK
)
{
if
(
isset
(
$suggestedTarget
))
{
if
(
isset
(
$suggestedTarget
))
{
...
@@ -937,10 +930,21 @@ class Share {
...
@@ -937,10 +930,21 @@ class Share {
}
}
}
}
// Check if target already exists
// Check if target already exists
if
(
$checkTarget
=
self
::
getItems
(
$itemType
,
$target
,
$shareType
,
$shareWith
,
null
,
self
::
FORMAT_NONE
,
null
,
1
))
{
$checkTarget
=
self
::
getItems
(
$itemType
,
$target
,
$shareType
,
$shareWith
);
// If matching target is from the same owner, use the same target. The share type will be different so this isn't the same share.
if
(
!
empty
(
$checkTarget
))
{
if
(
$checkTarget
[
'uid_owner'
]
==
$uidOwner
)
{
foreach
(
$checkTarget
as
$item
)
{
return
$target
;
// Skip item if it is the group parent row
if
(
isset
(
$groupParent
)
&&
$item
[
'id'
]
==
$groupParent
)
{
if
(
count
(
$checkTarget
)
==
1
)
{
return
$target
;
}
else
{
continue
;
}
}
// If matching target is from the same owner, use the same target. The share type will be different so this isn't the same share.
if
(
$item
[
'uid_owner'
]
==
$uidOwner
)
{
return
$target
;
}
}
}
if
(
!
isset
(
$exclude
))
{
if
(
!
isset
(
$exclude
))
{
$exclude
=
array
();
$exclude
=
array
();
...
@@ -1031,7 +1035,27 @@ class Share {
...
@@ -1031,7 +1035,27 @@ class Share {
}
}
public
static
function
post_addToGroup
(
$arguments
)
{
public
static
function
post_addToGroup
(
$arguments
)
{
// TODO
// Find the group shares and check if the user needs a unique target
$query
=
\OC_DB
::
prepare
(
'SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'
);
$result
=
$query
->
execute
(
array
(
self
::
SHARE_TYPE_GROUP
,
$arguments
[
'gid'
]));
$query
=
\OC_DB
::
prepare
(
'INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)'
);
while
(
$item
=
$result
->
fetchRow
())
{
if
(
$item
[
'item_type'
]
==
'file'
||
$item
[
'item_type'
]
==
'file'
)
{
$itemTarget
=
null
;
}
else
{
$itemTarget
=
self
::
generateTarget
(
$item
[
'item_type'
],
$item
[
'item_source'
],
self
::
SHARE_TYPE_USER
,
$arguments
[
'uid'
],
$item
[
'uid_owner'
],
$item
[
'item_target'
],
$item
[
'id'
]);
}
if
(
isset
(
$item
[
'file_source'
]))
{
$fileTarget
=
self
::
generateTarget
(
$item
[
'item_type'
],
$item
[
'item_source'
],
self
::
SHARE_TYPE_USER
,
$arguments
[
'uid'
],
$item
[
'uid_owner'
],
$item
[
'file_target'
],
$item
[
'id'
]);
}
else
{
$fileTarget
=
null
;
}
// Insert an extra row for the group share if the item or file target is unique for this user
if
(
$itemTarget
!=
$item
[
'item_target'
]
||
$fileTarget
!=
$item
[
'file_target'
])
{
$query
->
execute
(
array
(
$item
[
'item_type'
],
$item
[
'item_source'
],
$itemTarget
,
$item
[
'id'
],
self
::
$shareTypeGroupUserUnique
,
$arguments
[
'uid'
],
$item
[
'uid_owner'
],
$item
[
'permissions'
],
$item
[
'stime'
],
$item
[
'file_source'
],
$fileTarget
));
$id
=
\OC_DB
::
insertid
(
'*PREFIX*share'
);
}
}
}
}
public
static
function
post_removeFromGroup
(
$arguments
)
{
public
static
function
post_removeFromGroup
(
$arguments
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/lib/share/share.php
+
13
−
12
View file @
f0f2d939
...
@@ -366,21 +366,22 @@ class Test_Share extends UnitTestCase {
...
@@ -366,21 +366,22 @@ class Test_Share extends UnitTestCase {
$this
->
assertEqual
(
count
(
$to_test
),
2
);
$this
->
assertEqual
(
count
(
$to_test
),
2
);
$this
->
assertTrue
(
in_array
(
'test.txt'
,
$to_test
));
$this
->
assertTrue
(
in_array
(
'test.txt'
,
$to_test
));
$this
->
assertTrue
(
in_array
(
'test1.txt'
,
$to_test
));
$this
->
assertTrue
(
in_array
(
'test1.txt'
,
$to_test
));
//$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt', 'test1.txt'));
//
// Valid reshare
TODO Broken
// Valid reshare
//
$this->assertTrue(OCP\Share::shareItem('test', '
test
.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE));
$this
->
assertTrue
(
OCP\Share
::
shareItem
(
'test'
,
'
share
.txt'
,
OCP\Share
::
SHARE_TYPE_USER
,
$this
->
user4
,
OCP\Share
::
PERMISSION_READ
|
OCP\Share
::
PERMISSION_SHARE
));
//
OC_User::setUserId($this->user4);
OC_User
::
setUserId
(
$this
->
user4
);
//
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test1.txt'));
$this
->
assertEqual
(
OCP\Share
::
getItemsSharedWith
(
'test'
,
Test_Share_Backend
::
FORMAT_TARGET
),
array
(
'test1.txt'
));
//
//
// Remove user from group
// Remove user from group
//
OC_Group::removeFromGroup($this->user2, $this->group1);
OC_Group
::
removeFromGroup
(
$this
->
user2
,
$this
->
group1
);
//
OC_User::setUserId($this->user2);
OC_User
::
setUserId
(
$this
->
user2
);
//
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array('test.txt'));
$this
->
assertEqual
(
OCP\Share
::
getItemsSharedWith
(
'test'
,
Test_Share_Backend
::
FORMAT_TARGET
),
array
(
'test.txt'
));
//
OC_User::setUserId($this->user4);
OC_User
::
setUserId
(
$this
->
user4
);
//
$this->assertEqual(OCP\Share::getItemsSharedWith('test', Test_Share_Backend::FORMAT_TARGET), array());
$this
->
assertEqual
(
OCP\Share
::
getItemsSharedWith
(
'test'
,
Test_Share_Backend
::
FORMAT_TARGET
),
array
());
// Add user to group
// Add user to group
OC_Group
::
addToGroup
(
$this
->
user4
,
$this
->
group1
);
$this
->
assertEqual
(
OCP\Share
::
getItemsSharedWith
(
'test'
,
Test_Share_Backend
::
FORMAT_TARGET
),
array
(
'test.txt'
));
// Remove group
// Remove group
}
}
...
...
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