Skip to content

Commit

Permalink
Item652: Item710: Item2196: Clear cache
Browse files Browse the repository at this point in the history
The user is left in the mapper cache.  Clear the cache when removing the
user.  Also add a unit test for the removeUser function.

git-svn-id: http://svn.foswiki.org/trunk@14334 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Mar 15, 2012
1 parent 6c43a2d commit bc6c66e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
31 changes: 26 additions & 5 deletions TopicUserMappingContrib/lib/Foswiki/Users/TopicUserMapping.pm
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ sub addUser {
}
}

$this->{CACHED} = 0;
my $user = $this->_maintainUsersTopic( 'add', $login, $wikiname );

#can't call setEmails here - user may be in the process of being registered
Expand Down Expand Up @@ -373,9 +374,13 @@ sub _maintainUsersTopic {
Foswiki::Time::formatTime( time(), $Foswiki::cfg{DefaultDateFormat},
'gmtime' );

# add to the mapping caches
my $user = _cacheUser( $this, $wikiname, $login );
ASSERT($user) if DEBUG;
my $user;

# add to the mapping caches unless removing a user
unless ( $action eq 'del' ) {
$user = _cacheUser( $this, $wikiname, $login );
ASSERT($user) if DEBUG;
}

# add name alphabetically to list

Expand Down Expand Up @@ -442,6 +447,7 @@ sub _maintainUsersTopic {
}
$output .= $line . "\n";
}

if ( $entry && $action eq 'add' ) {

# brand new file - add to end
Expand Down Expand Up @@ -479,20 +485,35 @@ Delete the users entry. Removes the user from the password
manager and user mapping manager. Does *not* remove their personal
topics, which may still be linked.
Note that this must be called with the cUID. If any doubt, resolve the cUID
by $this->{session}->{users}->getCanonicalUserID($identity).
=cut

sub removeUser {
my ( $this, $cUID ) = @_;

my $ln = $this->getLoginName($cUID);
my $wikiname = $this->getWikiName($cUID);
$this->{passwords}->removeUser($ln) if ($ln);

# SMELL: If for some reason the login or wikiname is not found in the mapping
# Then the WikiUsers topic will not be maintained.
$this->_maintainUsersTopic( 'del', $ln, $wikiname ) if ( $ln && $wikiname );

return 1;

# SMELL: does not update the internal caches,
# needs someone to implement it
# Brutal update - invalidate them all

$this->{CACHED} = 0;
$this->{L2U} = {};
$this->{U2W} = {};
$this->{W2U} = {};
$this->{eachGroupMember} = {};
$this->{singleGroupMembers} = ();

return 1;

}

=begin TML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,47 @@ sub verify_AddUsers {
return;
}

sub verify_RemoveUsers {
my $this = shift;
my $me = $Foswiki::cfg{Register}{RegistrationAgentWikiName};

$this->assert( open( my $F, '>', $this->{ttpath} ),
"open $this->{ttpath} failed" );
print $F $initial;
$this->assert( close($F) );
chmod( 0777, $this->{ttpath} );

#my ( $this, $login, $wikiname, $password, $emails ) = @_;
$this->{session}->{users}->{mapping}->addUser( "guser", "GeorgeUser", $me );
$this->{session}->{users}->{mapping}->addUser( "auser", "AaronUser", $me );
$this->{session}->{users}->{mapping}->addUser( "xuser", "XenonUser", $me );
$this->{session}->{users}->{mapping}
->addUser( "zuser", "ZebediahUser", $me );

$this->assert( open( $F, '<', $this->{ttpath} ) );
local $/ = undef;
my $text = <$F>;
$this->assert( close($F) );
$this->assert_matches(
qr/\n\s+\* GeorgeUser - guser - \d\d \w\w\w \d\d\d\d\n/s, $text );
$this->assert_matches( qr/Aaron.*George.*Xenon.*Zebediah/s, $text );

$this->{session}->{users}->{mapping}->removeUser(
$this->{session}->{users}->getCanonicalUserID("AaronUser") );
$this->{session}->{users}->{mapping}
->removeUser( $this->{session}->{users}->getCanonicalUserID("zuser") );

$this->assert( open( $F, '<', $this->{ttpath} ) );
local $/ = undef;
$text = <$F>;
$this->assert( close($F) );
$this->assert_matches( qr/George.*Xenon/s, $text );
$this->assert_does_not_match( qr/AaronUser/, $text );
$this->assert_does_not_match( qr/zuser/, $text );

return;
}

sub verify_Load {
my $this = shift;

Expand Down

0 comments on commit bc6c66e

Please sign in to comment.