From 0bd7d14b7aeb5961172ff21c2f046efc94edfaa9 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 17 Jul 2012 14:09:01 +0200 Subject: [PATCH] Sharing: offer an option to allow sharing with everyone, i.e. do not check group memberships --- .../ajax/togglesharewitheveryone.php | 9 +++++ apps/files_sharing/ajax/userautocomplete.php | 37 +++++++++++++------ apps/files_sharing/js/settings.js | 7 ++++ apps/files_sharing/lib_share.php | 31 +++++++++------- apps/files_sharing/settings.php | 1 + apps/files_sharing/templates/settings.php | 6 ++- 6 files changed, 64 insertions(+), 27 deletions(-) create mode 100644 apps/files_sharing/ajax/togglesharewitheveryone.php diff --git a/apps/files_sharing/ajax/togglesharewitheveryone.php b/apps/files_sharing/ajax/togglesharewitheveryone.php new file mode 100644 index 0000000000..dc1105f2f3 --- /dev/null +++ b/apps/files_sharing/ajax/togglesharewitheveryone.php @@ -0,0 +1,9 @@ +"; $groups[] = ""; -foreach ($userGroups as $group) { - $groupUsers = OC_Group::usersInGroup($group); - $userCount = 0; - foreach ($groupUsers as $user) { - if ($user != $self) { +if(OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') { + $allGroups = OC_Group::getGroups(); + foreach($allGroups as $group) { + $groups[] = ""; + } + $allUsers = OC_User::getUsers(); + foreach($allUsers as $user) { + if($user != $self) { $users[] = ""; - $userCount++; + } + } +} else { + $userGroups = OC_Group::getUserGroups($self); + foreach ($userGroups as $group) { + $groupUsers = OC_Group::usersInGroup($group); + $userCount = 0; + foreach ($groupUsers as $user) { + if ($user != $self) { + $users[] = ""; + $userCount++; + } + } + // Don't include the group if only the current user is a member of it + if ($userCount > 0) { + $groups[] = ""; } } - // Don't include the group if only the current user is a member of it - if ($userCount > 0) { - $groups[] = ""; - } + $users = array_unique($users); } -$users = array_unique($users); $users[] = ""; $groups[] = ""; $users = array_merge($users, $groups); diff --git a/apps/files_sharing/js/settings.js b/apps/files_sharing/js/settings.js index bb7d79fecb..c276521b7b 100644 --- a/apps/files_sharing/js/settings.js +++ b/apps/files_sharing/js/settings.js @@ -6,4 +6,11 @@ $(document).ready(function() { } $.post(OC.filePath('files_sharing','ajax','toggleresharing.php'), 'resharing='+checked); }); + $('#allowSharingWithEveryone').bind('change', function() { + var checked = 1; + if (!this.checked) { + checked = 0; + } + $.post(OC.filePath('files_sharing','ajax','togglesharewitheveryone.php'), 'allowSharingWithEveryone='+checked); + }); }); \ No newline at end of file diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 31170f07fd..c0d0a1f18b 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -21,7 +21,7 @@ */ /** - * This class manages shared items within the database. + * This class manages shared items within the database. */ class OC_Share { @@ -31,7 +31,7 @@ class OC_Share { const PUBLICLINK = "public"; private $token; - + /** * Share an item, adds an entry into the database * @param $source The source location of the item @@ -56,17 +56,22 @@ class OC_Share { // Remove the owner from the list of users in the group $uid_shared_with = array_diff($uid_shared_with, array($uid_owner)); } else if (OCP\User::userExists($uid_shared_with)) { - $userGroups = OC_Group::getUserGroups($uid_owner); - // Check if the user is in one of the owner's groups - foreach ($userGroups as $group) { - if ($inGroup = OC_Group::inGroup($uid_shared_with, $group)) { - $gid = null; - $uid_shared_with = array($uid_shared_with); - break; + if(OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') { + $gid = null; + $uid_shared_with = array($uid_shared_with); + } else { + $userGroups = OC_Group::getUserGroups($uid_owner); + // Check if the user is in one of the owner's groups + foreach ($userGroups as $group) { + if ($inGroup = OC_Group::inGroup($uid_shared_with, $group)) { + $gid = null; + $uid_shared_with = array($uid_shared_with); + break; + } + } + if (!$inGroup) { + throw new Exception("You can't share with ".$uid_shared_with); } - } - if (!$inGroup) { - throw new Exception("You can't share with ".$uid_shared_with); } } else { throw new Exception($uid_shared_with." is not a user"); @@ -379,7 +384,7 @@ class OC_Share { * You must use the pullOutOfFolder() function to change the target location of a file inside a shared folder if the target location differs from the folder * * @param $oldTarget The current target location - * @param $newTarget The new target location + * @param $newTarget The new target location */ public static function setTarget($oldTarget, $newTarget) { $oldTarget = self::cleanPath($oldTarget); diff --git a/apps/files_sharing/settings.php b/apps/files_sharing/settings.php index 7b63a26515..fcae7e0370 100644 --- a/apps/files_sharing/settings.php +++ b/apps/files_sharing/settings.php @@ -4,6 +4,7 @@ OCP\User::checkAdminUser(); OCP\Util::addscript('files_sharing', 'settings'); $tmpl = new OCP\Template('files_sharing', 'settings'); $tmpl->assign('allowResharing', OCP\Config::getAppValue('files_sharing', 'resharing', 'yes')); +$tmpl->assign('allowSharingWithEveryone', OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no')); return $tmpl->fetchPage(); ?> \ No newline at end of file diff --git a/apps/files_sharing/templates/settings.php b/apps/files_sharing/templates/settings.php index 5b6ba5f33e..533a5c0c0c 100644 --- a/apps/files_sharing/templates/settings.php +++ b/apps/files_sharing/templates/settings.php @@ -1,6 +1,8 @@
- />
- t('Allow users to reshare files they don\'t own');?> +

/>
+ t('Allow users to reshare files they don\'t own');?>

+

/>
+ t('Allow users to share files with everyone');?>

\ No newline at end of file