Don't show self or already shared with users and groups in the share with search
This commit is contained in:
parent
8729119d4b
commit
8d01e1a355
|
@ -66,14 +66,37 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item']
|
|||
break;
|
||||
case 'getShareWith':
|
||||
if (isset($_GET['search'])) {
|
||||
// TODO Include contacts
|
||||
$shareWith = array();
|
||||
$users = OC_User::getUsers($_GET['search'], 4);
|
||||
foreach ($users as $user) {
|
||||
$shareWith[] = array('label' => $user, 'value' => array('shareType' => OCP\Share::SHARE_TYPE_USER, 'shareWith' => $user));
|
||||
$count = 0;
|
||||
$users = array();
|
||||
$limit = 0;
|
||||
$offset = 0;
|
||||
while ($count < 4 && count($users) == $limit) {
|
||||
$limit = 4 - $count;
|
||||
$users = OC_User::getUsers($_GET['search'], $limit, $offset);
|
||||
$offset += $limit;
|
||||
foreach ($users as $user) {
|
||||
if ((!isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]) || !in_array($user, $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])) && $user != OC_User::getUser()) {
|
||||
$shareWith[] = array('label' => $user, 'value' => array('shareType' => OCP\Share::SHARE_TYPE_USER, 'shareWith' => $user));
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$groups = OC_Group::getGroups($_GET['search'], 4);
|
||||
foreach ($groups as $group) {
|
||||
$shareWith[] = array('label' => $group.' (group)', 'value' => array('shareType' => OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => $group));
|
||||
$count = 0;
|
||||
$groups = array();
|
||||
$limit = 0;
|
||||
$offset = 0;
|
||||
while ($count < 4 && count($groups) == $limit) {
|
||||
$limit = 4 - $count;
|
||||
$groups = OC_Group::getGroups($_GET['search'], $limit, $offset);
|
||||
$offset += $limit;
|
||||
foreach ($groups as $group) {
|
||||
if (!isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) || !in_array($group, $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP])) {
|
||||
$shareWith[] = array('label' => $group.' (group)', 'value' => array('shareType' => OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => $group));
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
OC_JSON::success(array('data' => $shareWith));
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ OC.Share={
|
|||
PERMISSION_UPDATE:2,
|
||||
PERMISSION_DELETE:8,
|
||||
PERMISSION_SHARE:16,
|
||||
item:[],
|
||||
itemShares:[],
|
||||
statuses:[],
|
||||
loadIcons:function(itemType) {
|
||||
// Load all share icons
|
||||
|
@ -91,6 +91,7 @@ OC.Share={
|
|||
OC.Share.showPrivateLink(item, share.share_with);
|
||||
} else {
|
||||
OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ OC.Share={
|
|||
// if (cache[search.term]) {
|
||||
// response(cache[search.term]);
|
||||
// } else {
|
||||
$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term }, function(result) {
|
||||
$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) {
|
||||
if (result.status == 'success' && result.data.length > 0) {
|
||||
response(result.data);
|
||||
} else {
|
||||
|
@ -136,6 +137,10 @@ OC.Share={
|
|||
});
|
||||
},
|
||||
addShareWith:function(shareType, shareWith, permissions, possiblePermissions) {
|
||||
if (!OC.Share.itemShares[shareType]) {
|
||||
OC.Share.itemShares[shareType] = [];
|
||||
}
|
||||
OC.Share.itemShares[shareType].push(shareWith);
|
||||
var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = '';
|
||||
if (permissions & OC.Share.PERMISSION_CREATE) {
|
||||
createChecked = 'checked="checked"';
|
||||
|
|
Loading…
Reference in New Issue