Sharing: offer an option to allow sharing with everyone, i.e. do not check group memberships
This commit is contained in:
parent
9326f4f535
commit
0bd7d14b7a
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
OCP\JSON::checkAppEnabled('files_sharing');
|
||||||
|
OCP\JSON::checkAdminUser();
|
||||||
|
if ($_POST['allowSharingWithEveryone'] == true) {
|
||||||
|
OCP\Config::setAppValue('files_sharing', 'allowSharingWithEveryone', 'yes');
|
||||||
|
} else {
|
||||||
|
OCP\Config::setAppValue('files_sharing', 'allowSharingWithEveryone', 'no');
|
||||||
|
}
|
|
@ -6,24 +6,37 @@ OCP\JSON::checkAppEnabled('files_sharing');
|
||||||
$users = array();
|
$users = array();
|
||||||
$groups = array();
|
$groups = array();
|
||||||
$self = OCP\USER::getUser();
|
$self = OCP\USER::getUser();
|
||||||
$userGroups = OC_Group::getUserGroups($self);
|
|
||||||
$users[] = "<optgroup label='Users'>";
|
$users[] = "<optgroup label='Users'>";
|
||||||
$groups[] = "<optgroup label='Groups'>";
|
$groups[] = "<optgroup label='Groups'>";
|
||||||
foreach ($userGroups as $group) {
|
if(OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') {
|
||||||
$groupUsers = OC_Group::usersInGroup($group);
|
$allGroups = OC_Group::getGroups();
|
||||||
$userCount = 0;
|
foreach($allGroups as $group) {
|
||||||
foreach ($groupUsers as $user) {
|
$groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
|
||||||
if ($user != $self) {
|
}
|
||||||
|
$allUsers = OC_User::getUsers();
|
||||||
|
foreach($allUsers as $user) {
|
||||||
|
if($user != $self) {
|
||||||
$users[] = "<option value='".$user."'>".$user."</option>";
|
$users[] = "<option value='".$user."'>".$user."</option>";
|
||||||
$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[] = "<option value='".$user."'>".$user."</option>";
|
||||||
|
$userCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Don't include the group if only the current user is a member of it
|
||||||
|
if ($userCount > 0) {
|
||||||
|
$groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Don't include the group if only the current user is a member of it
|
$users = array_unique($users);
|
||||||
if ($userCount > 0) {
|
|
||||||
$groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$users = array_unique($users);
|
|
||||||
$users[] = "</optgroup>";
|
$users[] = "</optgroup>";
|
||||||
$groups[] = "</optgroup>";
|
$groups[] = "</optgroup>";
|
||||||
$users = array_merge($users, $groups);
|
$users = array_merge($users, $groups);
|
||||||
|
|
|
@ -6,4 +6,11 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
$.post(OC.filePath('files_sharing','ajax','toggleresharing.php'), 'resharing='+checked);
|
$.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);
|
||||||
|
});
|
||||||
});
|
});
|
|
@ -21,7 +21,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manages shared items within the database.
|
* This class manages shared items within the database.
|
||||||
*/
|
*/
|
||||||
class OC_Share {
|
class OC_Share {
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class OC_Share {
|
||||||
const PUBLICLINK = "public";
|
const PUBLICLINK = "public";
|
||||||
|
|
||||||
private $token;
|
private $token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Share an item, adds an entry into the database
|
* Share an item, adds an entry into the database
|
||||||
* @param $source The source location of the item
|
* @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
|
// Remove the owner from the list of users in the group
|
||||||
$uid_shared_with = array_diff($uid_shared_with, array($uid_owner));
|
$uid_shared_with = array_diff($uid_shared_with, array($uid_owner));
|
||||||
} else if (OCP\User::userExists($uid_shared_with)) {
|
} else if (OCP\User::userExists($uid_shared_with)) {
|
||||||
$userGroups = OC_Group::getUserGroups($uid_owner);
|
if(OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') {
|
||||||
// Check if the user is in one of the owner's groups
|
$gid = null;
|
||||||
foreach ($userGroups as $group) {
|
$uid_shared_with = array($uid_shared_with);
|
||||||
if ($inGroup = OC_Group::inGroup($uid_shared_with, $group)) {
|
} else {
|
||||||
$gid = null;
|
$userGroups = OC_Group::getUserGroups($uid_owner);
|
||||||
$uid_shared_with = array($uid_shared_with);
|
// Check if the user is in one of the owner's groups
|
||||||
break;
|
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 {
|
} else {
|
||||||
throw new Exception($uid_shared_with." is not a user");
|
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
|
* 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 $oldTarget The current target location
|
||||||
* @param $newTarget The new target location
|
* @param $newTarget The new target location
|
||||||
*/
|
*/
|
||||||
public static function setTarget($oldTarget, $newTarget) {
|
public static function setTarget($oldTarget, $newTarget) {
|
||||||
$oldTarget = self::cleanPath($oldTarget);
|
$oldTarget = self::cleanPath($oldTarget);
|
||||||
|
|
|
@ -4,6 +4,7 @@ OCP\User::checkAdminUser();
|
||||||
OCP\Util::addscript('files_sharing', 'settings');
|
OCP\Util::addscript('files_sharing', 'settings');
|
||||||
$tmpl = new OCP\Template('files_sharing', 'settings');
|
$tmpl = new OCP\Template('files_sharing', 'settings');
|
||||||
$tmpl->assign('allowResharing', OCP\Config::getAppValue('files_sharing', 'resharing', 'yes'));
|
$tmpl->assign('allowResharing', OCP\Config::getAppValue('files_sharing', 'resharing', 'yes'));
|
||||||
|
$tmpl->assign('allowSharingWithEveryone', OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no'));
|
||||||
return $tmpl->fetchPage();
|
return $tmpl->fetchPage();
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -1,6 +1,8 @@
|
||||||
<form id="resharing">
|
<form id="resharing">
|
||||||
<fieldset class="personalblock">
|
<fieldset class="personalblock">
|
||||||
<input type="checkbox" name="allowResharing" id="allowResharing" value="1" <?php if ($_['allowResharing'] == 'yes') echo ' checked="checked"'; ?> /> <label for="allowResharing"><?php echo $l->t('Enable Resharing'); ?></label> <br/>
|
<p><input type="checkbox" name="allowResharing" id="allowResharing" value="1" <?php if ($_['allowResharing'] == 'yes') echo ' checked="checked"'; ?> /> <label for="allowResharing"><?php echo $l->t('Enable Resharing'); ?></label> <br/>
|
||||||
<em><?php echo $l->t('Allow users to reshare files they don\'t own');?></em>
|
<em><?php echo $l->t('Allow users to reshare files they don\'t own');?></em></p>
|
||||||
|
<p><input type="checkbox" name="allowSharingWithEveryone" id="allowSharingWithEveryone" value="1" <?php if ($_['allowSharingWithEveryone'] == 'yes') echo ' checked="checked"'; ?> /> <label for="allowSharingWithEveryone"><?php echo $l->t('Enable sharing with everyone'); ?></label> <br/>
|
||||||
|
<em><?php echo $l->t('Allow users to share files with everyone');?></em></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
Loading…
Reference in New Issue