Skip to content

Commit

Permalink
fixed: don't find banned users in autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jun 4, 2019
1 parent d073b70 commit f0dd509
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
26 changes: 18 additions & 8 deletions views/json/resources/livesearch/group_owner_transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
/**
* Livesearch endpoint to search for users who are a member of the provided group
*
* @uses get_input('limit') (int) number of results to return
* @uses get_input('term') (string) search term (for username and displayname)
* @uses get_input('name') (string) the input name to be used when submitting the selected value
* @uses get_input('group_guid') (int) the GUID of the group to search members in
* @uses $vars['limit'] (int) number of results to return
* @uses $vars['term'] (string) search term (for username and displayname)
* @uses $vars['name'] (string) the input name to be used when submitting the selected value
* @uses $vars['group_guid'] (int) the GUID of the group to search members in
* @uses $vars['include_banned'] (bool) include banned users in search results
*
* @throws Elgg\EntityNotFoundException if the group_guid doesn't match a group
*/
Expand All @@ -15,10 +16,11 @@

elgg_gatekeeper();

$limit = get_input('limit', elgg_get_config('default_limit'));
$query = get_input('term', get_input('q'));
$input_name = get_input('name');
$group_guid = (int) get_input('group_guid');
$limit = (int) elgg_extract('limit', $vars, elgg_get_config('default_limit'));
$query = elgg_extract('term', $vars, elgg_extract('q', $vars));
$input_name = elgg_extract('name', $vars);
$group_guid = (int) elgg_extract('group_guid', $vars);
$include_banned = (bool) elgg_extract('include_banned', $vars, false);

$group = get_entity($group_guid);
if (!$group instanceof ElggGroup) {
Expand Down Expand Up @@ -61,8 +63,16 @@ function(QueryBuilder $qb, $main_alias) use ($group_guid) {
return $qb->merge($subs, 'OR');
},
],
'metadata_name_value_pairs' => [],
];

if (!$include_banned) {
$options['metadata_name_value_pairs'][] = [
'name' => 'banned',
'value' => 'no',
];
}

$body = elgg_list_entities($options, 'elgg_search');

echo elgg_view_page('', $body);
30 changes: 24 additions & 6 deletions views/json/resources/livesearch/non_group_members.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<?php
/**
* Livesearch endpoint to search for users to invite to a group. These users aren't already member of the group
*
* @uses $vars['limit'] (int) number of results to return
* @uses $vars['term'] (string) search term (for username and displayname)
* @uses $vars['name'] (string) the input name to be used when submitting the selected value
* @uses $vars['group_guid'] (int) the GUID of the group to search members in
* @uses $vars['include_banned'] (bool) include banned users in search results
*/

elgg_gatekeeper();

$limit = get_input('limit', elgg_get_config('default_limit'));
$query = get_input('term', get_input('q'));
$group_guid = (int) get_input('group_guid');
$input_name = get_input('name');
$limit = (int) elgg_extract('limit', $vars, elgg_get_config('default_limit'));
$query = elgg_extract('term', $vars, elgg_extract('q', $vars));
$input_name = elgg_extract('name', $vars);
$group_guid = (int) elgg_extract('group_guid', $vars);
$include_banned = (bool) elgg_extract('include_banned', $vars, false);

$options = [
'query' => $query,
Expand All @@ -16,19 +26,27 @@
'fields' => ['metadata' => ['name', 'username']],
'item_view' => 'search/entity',
'input_name' => $input_name,
'metadata_name_value_pairs' => [],
];

if ($group_guid) {
$options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb) use ($group_guid) {
$options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($group_guid) {
$subquery = $qb->subquery('entity_relationships', 'er');
$subquery->select('er.guid_one')
->where($qb->compare('er.relationship', '=', 'member', ELGG_VALUE_STRING))
->andWhere($qb->compare('er.guid_two', '=', $group_guid, ELGG_VALUE_INTEGER));

return $qb->compare("e.guid", 'NOT IN', $subquery->getSQL());
return $qb->compare("{$main_alias}.guid", 'NOT IN', $subquery->getSQL());
};
}

if (!$include_banned) {
$options['metadata_name_value_pairs'][] = [
'name' => 'banned',
'value' => 'no',
];
}

$body = elgg_list_entities($options, 'elgg_search');

echo elgg_view_page('', $body);

0 comments on commit f0dd509

Please sign in to comment.