diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7d978b54e..12faee2a8 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -15,4 +15,4 @@ - fix: Pagination not working in User Management System - fix: Upgrade 6.8.10 to 6.99.5 (Thanks to Erik Svanberg for the patch) - fix: Adding Survey Choices - + - fix: User/Group problem diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index 833e085f3..ff80db5cd 100755 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -80,7 +80,15 @@ These methods are available from this class: sub _create { my $self = shift; my $override = shift; - $self->{_groupId} = $self->session->db->setRow("groups","groupId",{ + $self->{_groupId} = $self->session->db->setRow("groups","groupId", $self->_defaults, $override); + $self->addGroups([3]); +} + + +#------------------------------------------------------------------- +sub _defaults { + my $self = shift; + return { groupId=>"new", dateCreated=>$self->session->datetime->time(), expireOffset=>314496000, @@ -91,9 +99,12 @@ sub _create { expireNotify=>0, databaseLinkId=>0, groupCacheTimeout=>3600, - lastUpdated=>$self->session->datetime->time() - }, $override); - $self->addGroups([3]); + lastUpdated=>$self->session->datetime->time(), + autoAdd=>0, + autoDelete=>0, + isEditable=>1, + showInForms=>1, + }; } @@ -971,7 +982,12 @@ sub new { my $cached = $self->{_session}->stow->get("groupObj"); return $cached->{$self->{_groupId}} if ($cached->{$self->{_groupId}}); bless $self, $class; - $self->_create($override) if ($self->{_groupId} eq "new"); + if ($self->{_groupId} eq "new") { + $self->_create($override); + } + elsif ($self->{_groupId} eq "") { + $self->{_group} = $self->_defaults(); + } $cached->{$self->{_groupId}} = $self; $self->{_session}->stow->set("groupObj", $cached); return $self; diff --git a/t/Group.t b/t/Group.t index de2d12713..0d926bc9b 100644 --- a/t/Group.t +++ b/t/Group.t @@ -75,35 +75,46 @@ my @ipTests = ( ); -plan tests => (103 + scalar(@scratchTests) + scalar(@ipTests)); # increment this value for each test you create +plan tests => (118 + scalar(@scratchTests) + scalar(@ipTests)); # increment this value for each test you create my $session = WebGUI::Test->session; my $testCache = WebGUI::Cache->new($session, 'myTestKey'); $testCache->flush; +foreach my $gid ('new', '') { + my $g = WebGUI::Group->new($session, $gid); + + ##Check defaults + is (ref $g, "WebGUI::Group", "Group object creation"); + isnt ($g->getId, "new", "Group assigned new groupId, not new"); + is ($g->name(), 'New Group', 'Default name'); + is ($g->expireOffset(), 314496000, 'Default expireOffset'); + is ($g->karmaThreshold(), 1_000_000_000, 'Default karma threshold'); + is ($g->expireNotifyOffset(), -14, 'Default expire notify offset time'); + is ($g->deleteOffset(), 14, 'Default delete offset time'); + is ($g->expireNotify(), 0, 'Default expire notify time'); + is ($g->databaseLinkId(), 0, 'Default databaseLinkId'); + is ($g->groupCacheTimeout(), 3600, 'Default external database cache timeout'); + is ($g->dateCreated(), $g->lastUpdated(), 'lastUpdated = create time'); + is ($g->autoAdd(), 0, 'auto Add is off by default'); + is ($g->autoDelete(), 0, 'auto Delete is off by default'); + is ($g->isEditable(), 1, 'isEditable is on by default'); + is ($g->showInForms(), 1, 'show in forms is on by default'); + + $g->delete; +} + +my $empty = WebGUI::Group->new($session, ''); + my $g = WebGUI::Group->new($session, "new"); -is (ref $g, "WebGUI::Group", "Group object creation"); my $gid = $g->getId; -isnt ($gid, "new", "Group assigned new groupId, not new"); is (length($gid), 22, "GroupId is proper length"); -is ($g->name(), 'New Group', 'Default name'); -is ($g->expireOffset(), 314496000, 'Default karma threshold'); -is ($g->karmaThreshold(), 1_000_000_000, 'Default karma threshold'); -is ($g->expireNotifyOffset(), -14, 'Default expire notify offset time'); -is ($g->deleteOffset(), 14, 'Default delete offset time'); -is ($g->expireNotify(), 0, 'Default expire notify time'); -is ($g->databaseLinkId(), 0, 'Default databaseLinkId'); -is ($g->groupCacheTimeout(), 3600, 'Default external database cache timeout'); -is ($g->dateCreated(), $g->lastUpdated(), 'lastUpdated = create time'); + is_deeply ($g->getGroupsIn(), [3], 'Admin group added by default to this group'); is_deeply ($g->getGroupsFor(), [], 'Group not added to any other group'); is_deeply ($g->getUsers(), [], 'No users added by default'); is_deeply ($g->getAllUsers(), [3], 'No users added by default in any method'); -is ($g->autoAdd(), 0, 'auto Add is off by default'); -is ($g->autoDelete(), 0, 'auto Delete is off by default'); -is ($g->isEditable(), 1, 'isEditable is on by default'); -is ($g->showInForms(), 1, 'show in forms is on by default'); my $gname = '**TestGroup**'; is ($g->name($gname), $gname, 'Set name');