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
3c517499
Commit
3c517499
authored
13 years ago
by
Michael Gapczynski
Browse files
Options
Downloads
Patches
Plain Diff
OC_Share constructor refactored for user group sharing
parent
497789cd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_sharing/ajax/share.php
+5
-1
5 additions, 1 deletion
apps/files_sharing/ajax/share.php
apps/files_sharing/lib_share.php
+47
-27
47 additions, 27 deletions
apps/files_sharing/lib_share.php
with
52 additions
and
28 deletions
apps/files_sharing/ajax/share.php
+
5
−
1
View file @
3c517499
...
...
@@ -11,7 +11,11 @@ foreach ($sources as $source) {
if
(
$source
&&
OC_FILESYSTEM
::
file_exists
(
$source
)
&&
OC_FILESYSTEM
::
is_readable
(
$source
))
{
$source
=
"/"
.
OC_User
::
getUser
()
.
"/files"
.
$source
;
try
{
if
(
OC_Group
::
groupExists
(
$uid_shared_with
))
{
new
OC_Share
(
$source
,
$uid_shared_with
,
$permissions
,
true
);
}
else
{
new
OC_Share
(
$source
,
$uid_shared_with
,
$permissions
);
}
}
catch
(
Exception
$exception
)
{
echo
"false"
;
}
...
...
This diff is collapsed.
Click to expand it.
apps/files_sharing/lib_share.php
+
47
−
27
View file @
3c517499
...
...
@@ -34,23 +34,39 @@ class OC_Share {
/**
* Share an item, adds an entry into the database
* @param $source The source location of the item
* @param $uid_shared_with The user to share the item with
* @param $uid_shared_with The user
or group
to share the item with
* @param $permissions The permissions, use the constants WRITE and DELETE
*/
public
function
__construct
(
$source
,
$uid_shared_with
,
$permissions
)
{
public
function
__construct
(
$source
,
$uid_shared_with
,
$permissions
,
$group
=
false
)
{
$uid_owner
=
OC_User
::
getUser
();
$target
=
"/"
.
$uid_shared_with
.
"/files/Share/"
.
basename
(
$source
);
if
(
$group
)
{
if
(
OC_Group
::
groupExists
(
$uid_shared_with
))
{
$gid
=
$uid_shared_with
;
$uid_shared_with
=
OC_Group
::
usersInGroup
(
$gid
);
// Remove the owner from the list of users in the group, users can only share files with groups they belong to
$uid_shared_with
=
array_diff
(
$uid_shared_with
,
array
(
$uid_owner
));
}
else
{
throw
new
Exception
(
"
$uid_shared_with
is not a group"
);
}
}
else
{
if
(
OC_User
::
userExists
(
$uid_shared_with
))
{
$gid
=
null
;
$uid_shared_with
=
array
(
$uid_shared_with
);
}
else
{
throw
new
Exception
(
"
$uid_shared_with
is not a user"
);
}
}
foreach
(
$uid_shared_with
as
$uid
)
{
// Check if this item is already shared with the user
$checkSource
=
OC_DB
::
prepare
(
"SELECT source FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with = ?"
);
$resultCheckSource
=
$checkSource
->
execute
(
array
(
$source
,
$uid
_shared_with
))
->
fetchAll
();
$resultCheckSource
=
$checkSource
->
execute
(
array
(
$source
,
$uid
))
->
fetchAll
();
// TODO Check if the source is inside a folder
if
(
count
(
$resultCheckSource
)
>
0
)
{
throw
new
Exception
(
"This item is already shared with
the specified user
"
);
throw
new
Exception
(
"This item is already shared with
$uid
"
);
}
// Check if target already exists for the user, if it does append a number to the name
$checkTarget
=
OC_DB
::
prepare
(
"SELECT target FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?"
);
$resultCheckTarget
=
$checkTarget
->
execute
(
array
(
$target
,
$uid_shared_with
))
->
fetchAll
();
if
(
count
(
$resultCheckTarget
)
>
0
)
{
$target
=
"/"
.
$uid
.
"/files/Share/"
.
basename
(
$source
);
if
(
self
::
getSource
(
$target
))
{
if
(
$pos
=
strrpos
(
$target
,
"."
))
{
$name
=
substr
(
$target
,
0
,
$pos
);
$ext
=
substr
(
$target
,
$pos
);
...
...
@@ -59,15 +75,19 @@ class OC_Share {
$ext
=
""
;
}
$counter
=
1
;
while
(
count
(
$result
)
>
0
)
{
while
(
$checkTarget
!==
false
)
{
$newTarget
=
$name
.
"_"
.
$counter
.
$ext
;
$resultC
heckTarget
=
$checkTarget
->
execute
(
array
(
$newTarget
,
$uid_shared_with
))
->
fetchAll
(
);
$c
heckTarget
=
self
::
getSource
(
$newTarget
);
$counter
++
;
}
$target
=
$newTarget
;
}
if
(
isset
(
$gid
))
{
$uid
=
$uid
.
"@"
.
$gid
;
}
$query
=
OC_DB
::
prepare
(
"INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"
);
$query
->
execute
(
array
(
$uid_owner
,
$uid_shared_with
,
$source
,
$target
,
$permissions
));
$query
->
execute
(
array
(
$uid_owner
,
$uid
,
$source
,
$target
,
$permissions
));
}
}
/**
...
...
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