Sharing: offer an option to allow sharing with everyone, i.e. do not check group memberships

This commit is contained in:
Arthur Schiwon 2012-07-17 14:09:01 +02:00
parent 9326f4f535
commit 0bd7d14b7a
6 changed files with 64 additions and 27 deletions

View File

@ -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');
}

View File

@ -6,10 +6,22 @@ OCP\JSON::checkAppEnabled('files_sharing');
$users = array();
$groups = array();
$self = OCP\USER::getUser();
$userGroups = OC_Group::getUserGroups($self);
$users[] = "<optgroup label='Users'>";
$groups[] = "<optgroup label='Groups'>";
foreach ($userGroups as $group) {
if(OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') {
$allGroups = OC_Group::getGroups();
foreach($allGroups as $group) {
$groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
}
$allUsers = OC_User::getUsers();
foreach($allUsers as $user) {
if($user != $self) {
$users[] = "<option value='".$user."'>".$user."</option>";
}
}
} else {
$userGroups = OC_Group::getUserGroups($self);
foreach ($userGroups as $group) {
$groupUsers = OC_Group::usersInGroup($group);
$userCount = 0;
foreach ($groupUsers as $user) {
@ -22,8 +34,9 @@ foreach ($userGroups as $group) {
if ($userCount > 0) {
$groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
}
}
$users = array_unique($users);
}
$users = array_unique($users);
$users[] = "</optgroup>";
$groups[] = "</optgroup>";
$users = array_merge($users, $groups);

View File

@ -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);
});
});

View File

@ -56,6 +56,10 @@ 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)) {
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) {
@ -68,6 +72,7 @@ class OC_Share {
if (!$inGroup) {
throw new Exception("You can't share with ".$uid_shared_with);
}
}
} else {
throw new Exception($uid_shared_with." is not a user");
}

View File

@ -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();
?>

View File

@ -1,6 +1,8 @@
<form id="resharing">
<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/>
<em><?php echo $l->t('Allow users to reshare files they don\'t own');?></em>
<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></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>
</form>