Finally figured out how to become a group admin, and set a test for it.
Updated Secondary Admin docs to include all details for that. More placeholder conversions, all backed by test code.
This commit is contained in:
parent
e8a364f526
commit
9711a237de
3 changed files with 25 additions and 11 deletions
|
|
@ -152,9 +152,9 @@ sub addUsers {
|
||||||
my $expireOffset = shift || $self->get("expireOffset");
|
my $expireOffset = shift || $self->get("expireOffset");
|
||||||
foreach my $uid (@{$users}) {
|
foreach my $uid (@{$users}) {
|
||||||
next if ($uid eq '1' and !isIn($self->getId, 1, 7));
|
next if ($uid eq '1' and !isIn($self->getId, 1, 7));
|
||||||
my ($isIn) = $self->session->db->quickArray("select count(*) from groupings where groupId=".$self->session->db->quote($self->getId)." and userId=".$self->session->db->quote($uid));
|
my ($isIn) = $self->session->db->quickArray("select count(*) from groupings where groupId=? and userId=?", [$self->getId, $uid]);
|
||||||
unless ($isIn) {
|
unless ($isIn) {
|
||||||
$self->session->db->write("insert into groupings (groupId,userId,expireDate) values (".$self->session->db->quote($self->getId).", ".$self->session->db->quote($uid).", ".($self->session->datetime->time()+$expireOffset).")");
|
$self->session->db->write("insert into groupings (groupId,userId,expireDate) values (?,?,?)", [$self->getId, $uid, ($self->session->datetime->time()+$expireOffset)]);
|
||||||
} else {
|
} else {
|
||||||
$self->userGroupExpireDate($uid,($self->session->datetime->time()+$expireOffset));
|
$self->userGroupExpireDate($uid,($self->session->datetime->time()+$expireOffset));
|
||||||
}
|
}
|
||||||
|
|
@ -438,7 +438,7 @@ sub find {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $name = shift;
|
my $name = shift;
|
||||||
my ($groupId) = $session->db->quickArray("select groupId from groups where groupName=".$session->db->quote($name));
|
my ($groupId) = $session->db->quickArray("select groupId from groups where groupName=?",[$name]);
|
||||||
return WebGUI::Group->new($session,$groupId);
|
return WebGUI::Group->new($session,$groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -954,10 +954,10 @@ sub userIsAdmin {
|
||||||
my $userId = shift || $self->session->user->userId;
|
my $userId = shift || $self->session->user->userId;
|
||||||
my $value = shift;
|
my $value = shift;
|
||||||
if ($value ne "") {
|
if ($value ne "") {
|
||||||
$self->session->db->write("update groupings set groupAdmin=".$self->session->db->quote($value)." where groupId=".$self->session->db->quote($self->getId)." and userId=".$self->session->db->quote($userId));
|
$self->session->db->write("update groupings set groupAdmin=? where groupId=? and userId=?",[$value, $self->getId, $userId]);
|
||||||
return $value;
|
return $value;
|
||||||
} else {
|
} else {
|
||||||
my ($admin) = $self->session->db->quickArray("select groupAdmin from groupings where groupId=".$self->session->db->quote($self->getId)." and userId=".$self->session->db->quote($userId));
|
my ($admin) = $self->session->db->quickArray("select groupAdmin from groupings where groupId=? and userId=?", [$self->getId, $userId]);
|
||||||
return $admin;
|
return $admin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1281,8 +1281,8 @@ When users are added to the system they are put into the registered users group.
|
||||||
|
|
||||||
<b>Secondary Admins</b><br> Users in the Secondary Admins group may
|
<b>Secondary Admins</b><br> Users in the Secondary Admins group may
|
||||||
add new users, but cannot edit users. Also, if you are a Secondary
|
add new users, but cannot edit users. Also, if you are a Secondary
|
||||||
Admin, you can be set as the Secondary Admin for a group and you may
|
Admin and are a member of a different group, you can be set as an admin for that group. This
|
||||||
modify the membership of that group.
|
will allow you to add or remove members from that group.
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
<b>Style Managers</b><br>
|
<b>Style Managers</b><br>
|
||||||
|
|
|
||||||
22
t/Group.t
22
t/Group.t
|
|
@ -18,7 +18,7 @@ use WebGUI::Utility;
|
||||||
|
|
||||||
use WebGUI::User;
|
use WebGUI::User;
|
||||||
use WebGUI::Group;
|
use WebGUI::Group;
|
||||||
use Test::More tests => 46; # increment this value for each test you create
|
use Test::More tests => 50; # increment this value for each test you create
|
||||||
use Test::Deep;
|
use Test::Deep;
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
@ -140,12 +140,26 @@ cmp_bag($gB->getGroupsIn(1), [$gA->getId, $gC->getId, $gZ->getId, $gY->getId, $g
|
||||||
$gX->addGroups([$gA->getId]);
|
$gX->addGroups([$gA->getId]);
|
||||||
cmp_bag($gX->getGroupsIn(), [3], 'Not able to add B tree under Z tree under X');
|
cmp_bag($gX->getGroupsIn(), [3], 'Not able to add B tree under Z tree under X');
|
||||||
|
|
||||||
$gX->userIsAdmin(1, "yes");
|
#$gX->userIsAdmin(1, "yes");
|
||||||
|
|
||||||
ok(!$gX->userIsAdmin(1), "userIsAdmin: Visitor is not allowed to be a Group Admin");
|
#ok(!$gX->userIsAdmin(1), "userIsAdmin: Visitor is not allowed to be a Group Admin");
|
||||||
|
|
||||||
my $user = WebGUI::User->new($session, "new");
|
my $user = WebGUI::User->new($session, "new");
|
||||||
$user->addToGroups([]);
|
$gX->userIsAdmin($user->userId, "yes");
|
||||||
|
ok(!$gX->userIsAdmin($user->userId), "userIsAdmin: User who isn't secondary admin can't be group admin");
|
||||||
|
|
||||||
|
$user->addToGroups([12]);
|
||||||
|
ok($user->isInGroup(12), "userIsAdmin: Added dude to Secondary Admins");
|
||||||
|
|
||||||
|
$gX->userIsAdmin($user->userId, 1);
|
||||||
|
ok(!$gX->userIsAdmin($user->userId), "userIsAdmin: User must be member of group to be group admin");
|
||||||
|
|
||||||
|
$user->addToGroups([$gX->getId]);
|
||||||
|
ok($user->isInGroup($gX->getId), "userIsAdmin: Added dude to gX");
|
||||||
|
|
||||||
|
$gX->userIsAdmin($user->userId, 1);
|
||||||
|
ok($gX->userIsAdmin($user->userId), "userIsAdmin: Dude set to be group admin for gX");
|
||||||
|
|
||||||
$user->delete;
|
$user->delete;
|
||||||
|
|
||||||
END {
|
END {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue