fix #11965: FriendMgr pagination and getUsersNotIn
This commit is contained in:
parent
ee80f8d011
commit
5f89a281e9
4 changed files with 49 additions and 7 deletions
Binary file not shown.
|
|
@ -202,7 +202,7 @@ sub www_editFriends {
|
|||
my @manageableUsers = ();
|
||||
if ($groupName) {
|
||||
my $group = WebGUI::Group->find($session, $groupName);
|
||||
push @manageableUsers, @{ $group->getUsersNotIn($user->{_user}->{'friendsGroup'}, 'withoutExpired') };
|
||||
push @manageableUsers, @{ $group->getUsersNotIn($user->friends->getId, 'withoutExpired') };
|
||||
}
|
||||
else {
|
||||
my $groupIds = $session->setting->get('groupsToManageFriends');
|
||||
|
|
@ -210,7 +210,7 @@ sub www_editFriends {
|
|||
foreach my $groupId (@groupIds) {
|
||||
my $group = WebGUI::Group->new($session, $groupId);
|
||||
next GROUP unless $group->getId || $group->getId eq 'new';
|
||||
push @manageableUsers, @{ $group->getUsersNotIn($user->{_user}->{'friendsGroup'}, 'withoutExpired') };
|
||||
push @manageableUsers, @{ $group->getUsersNotIn($user->friends->getId, 'withoutExpired') };
|
||||
}
|
||||
@manageableUsers = uniq @manageableUsers;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -979,24 +979,33 @@ sub getUsersNotIn {
|
|||
if($groupId eq "") {
|
||||
return $self->getUsers($withoutExpired);
|
||||
}
|
||||
my $selfWhere;
|
||||
if ( $self->getId ne '2' ) {
|
||||
$selfWhere = "and groupId=" . $self->session->db->dbh->quote( $self->getId );
|
||||
}
|
||||
else {
|
||||
$selfWhere = 'and userId != ' . $self->session->db->dbh->quote( "1" );
|
||||
}
|
||||
|
||||
my $expireTime = 0;
|
||||
if ($withoutExpired) {
|
||||
$expireTime = time();
|
||||
}
|
||||
|
||||
my $sql = q{
|
||||
my $sql = qq{
|
||||
select
|
||||
userId
|
||||
from
|
||||
groupings
|
||||
users
|
||||
left join
|
||||
groupings using (userId)
|
||||
where
|
||||
expireDate > ?
|
||||
and groupId=?
|
||||
$selfWhere
|
||||
and userId not in (select userId from groupings where expireDate > ? and groupId=?)
|
||||
};
|
||||
|
||||
my @users = $self->session->db->buildArray($sql, [$expireTime,$self->getId,$expireTime,$groupId]);
|
||||
my @users = $self->session->db->buildArray($sql, [$expireTime,$expireTime,$groupId]);
|
||||
return \@users;
|
||||
|
||||
}
|
||||
|
|
|
|||
35
t/Group.t
35
t/Group.t
|
|
@ -93,7 +93,7 @@ my @ldapTests = (
|
|||
);
|
||||
|
||||
|
||||
plan tests => (168 + (scalar(@scratchTests) * 2) + scalar(@ipTests)); # increment this value for each test you create
|
||||
plan tests => (172 + (scalar(@scratchTests) * 2) + scalar(@ipTests)); # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
my $testCache = WebGUI::Cache->new($session, 'myTestKey');
|
||||
|
|
@ -832,4 +832,37 @@ ok( WebGUI::Group->vitalGroup(3), '... 3');
|
|||
ok( WebGUI::Group->vitalGroup('pbgroup000000000000015'), '... pbgroup000000000000015');
|
||||
ok(! WebGUI::Group->vitalGroup('27'), '... 27 is not vital');
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# getUsersNotIn
|
||||
|
||||
# Normal group
|
||||
my $happyDude = WebGUI::User->create( $session );
|
||||
$happyDude->username(" Happy Dude ");
|
||||
addToCleanup( $happyDude );
|
||||
|
||||
$gA->addUsers([ $happyDude->getId ]);
|
||||
$gB->addUsers([ $happyDude->getId ]);
|
||||
cmp_deeply(
|
||||
$gA->getUsersNotIn( $gZ->getId ),
|
||||
superbagof( $happyDude->getId ),
|
||||
"get the users not in the group",
|
||||
);
|
||||
ok(
|
||||
!grep( { $_ eq $happyDude->getId } @{$gA->getUsersNotIn( $gB->getId )}),
|
||||
"don't get the users in both groups",
|
||||
);
|
||||
|
||||
# Special-case Registered Users
|
||||
my $regUser = WebGUI::Group->new( $session, "2" );
|
||||
cmp_deeply(
|
||||
$regUser->getUsersNotIn( $gZ->getId ),
|
||||
superbagof( $happyDude->getId ),
|
||||
"registered users: get the users not in the group",
|
||||
);
|
||||
ok(
|
||||
!grep( { $_ eq $happyDude->getId } @{$regUser->getUsersNotIn( $gA->getId )}),
|
||||
"registered users: don't get the users in both groups",
|
||||
);
|
||||
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue