Skip to content

Commit

Permalink
Item12133: Allow TopicUserMapping to force emails
Browse files Browse the repository at this point in the history
Some sites using foswiki internally have requested that email addresses
be stored in the user topics and not managed by the PasswordManager.

This implements and expert config parm that allows TopicUserMapping
to not give email control to the password manager.

git-svn-id: http://svn.foswiki.org/trunk@15579 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Oct 13, 2012
1 parent cf865bb commit d4b3a5f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
18 changes: 13 additions & 5 deletions TopicUserMappingContrib/lib/Foswiki/Users/TopicUserMapping.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,9 @@ sub findUserByEmail {
my ( $this, $email ) = @_;
ASSERT($email) if DEBUG;
my @users;
if ( $this->{passwords}->isManagingEmails() ) {
if ( !$Foswiki::cfg{TopicUserMapping}{ForceManageEmails}
&& $this->{passwords}->isManagingEmails() )
{
my $logins = $this->{passwords}->findUserByEmail($email);
if ( defined $logins ) {
foreach my $l (@$logins) {
Expand Down Expand Up @@ -1289,7 +1291,9 @@ sub getEmails {
}
}
else {
if ( $this->{passwords}->isManagingEmails() ) {
if ( !$Foswiki::cfg{TopicUserMapping}{ForceManageEmails}
&& $this->{passwords}->isManagingEmails() )
{

# get emails from the password manager
foreach ( $this->{passwords}
Expand Down Expand Up @@ -1324,7 +1328,9 @@ sub setEmails {
my $this = shift;
my $user = shift;

if ( $this->{passwords}->isManagingEmails() ) {
if ( !$Foswiki::cfg{TopicUserMapping}{ForceManageEmails}
&& $this->{passwords}->isManagingEmails() )
{
$this->{passwords}->setEmails( $this->getLoginName($user), @_ );
}
else {
Expand All @@ -1336,7 +1342,8 @@ sub setEmails {
---++ StaticMethod mapper_getEmails($session, $user)
Only used if passwordManager->isManagingEmails= = =false
Only used if passwordManager->isManagingEmails= = =false or
$Foswiki::cfg{TopicUserMapping}{ForceManageEmails} is enabled.
(The emails are stored in the user topics.
Note: This method is PUBLIC because it is used by the tools/upgrade_emails.pl
Expand Down Expand Up @@ -1380,7 +1387,8 @@ sub mapper_getEmails {
---++ StaticMethod mapper_setEmails ($session, $user, @emails)
Only used if =passwordManager->isManagingEmails= = =false=.
Only used if =passwordManager->isManagingEmails= = =false=
or $Foswiki::cfg{TopicUserMapping}{ForceManageEmails} is enabled.
(emails are stored in user topics
=cut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,28 @@ sub verify_findUserByEmail_no_pwm {
$this->assert_matches( qr/JoeDoe/, join( ' ', @$u ) );
$u = $this->{session}->{users}->findUserByEmail('dont@be.silly');
$this->assert_equals( "", join( ' ', @$u ) );
my $userTopic =
Foswiki::Func::readTopicText( $Foswiki::cfg{UsersWebName}, 'JoeDoe' );
$this->assert_matches( qr/email\@home.org.au/, $userTopic );
}

sub verify_findUserByEmail_forceManage {
my $this = shift;

# Force TopicUserMapping to override PasswordManager
$Foswiki::cfg{TopicUserMapping}{ForceManageEmails} = 1;

$this->setup_new_session();
$this->set_up_user();

# emails have to come from the user topic
my $u = $this->{session}->{users}->findUserByEmail('email@home.org.au');
$this->assert_matches( qr/JoeDoe/, join( ' ', @$u ) );
$u = $this->{session}->{users}->findUserByEmail('dont@be.silly');
$this->assert_equals( "", join( ' ', @$u ) );
my $userTopic =
Foswiki::Func::readTopicText( $Foswiki::cfg{UsersWebName}, 'JoeDoe' );
$this->assert_matches( qr/email\@home.org.au/, $userTopic );
}

1;
Expand Down
16 changes: 14 additions & 2 deletions core/lib/Foswiki.spec
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,15 @@ $Foswiki::cfg{UsersTopicName} = 'WikiUsers';
# </li></ol>
$Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::TopicUserMapping';
# **BOOLEAN EXPERT DISPLAY_IF {UserMappingManager}=="Foswiki::Users::TopicUserMapping"**
# Enable this parameter to force the TopicUserMapping manager to directly manage email
# accresses, and not pass management over to the PasswordManager. When enabled, TopicUserMapping
# will store addresses in the user topics.<br />
# Default is disabled. The PasswordManager will determine what is responsible for storing email addresses.<br />
# <br />
# Note: Foswiki provides a utility to migrate emails from user topic to the password file, but
# does not provide any way to migrate emails from the password file back to user topics.
$Foswiki::cfg{TopicUserMapping}{ForceManageEmails} = $FALSE;
#---++ Access Control
# **SELECTCLASS Foswiki::Access::*Access**
Expand Down Expand Up @@ -856,9 +865,12 @@ $Foswiki::cfg{AntiSpam}{EmailPadding} = '';
# Normally Foswiki stores the user's sensitive information (such as their e-mail
# address) in a database out of public view. This is to help prevent e-mail
# spam and identity fraud.<br />
# If that is not a risk for you (e.g. you are behind a firewall) and you
# This setting controls whether or not the <code>%USERINFO%</code> macro will
# reveal details about users other than the current logged in user. It does not
# control how Foswiki actually stores email addresses.<br />
# If disclosure of emails is not a risk for you (e.g. you are behind a firewall) and you
# are happy for e-mails to be made public to all Foswiki users,
# then you can set this option.<br />
# then you can disable this option.<br />
# Note that if this option is set, then the <code>user</code> parameter to
# <code>%USERINFO</code> is ignored.
$Foswiki::cfg{AntiSpam}{HideUserDetails} = $TRUE;
Expand Down

0 comments on commit d4b3a5f

Please sign in to comment.