Skip to content

Commit

Permalink
Item14623: Make RemoveUser more flexible.
Browse files Browse the repository at this point in the history
Allow a list of topic names removed along with the user to be
configured.

Default is to remove $user topic along with $userLeftBar. NatSkin
users would not need to list the $userLeftBar. On Foswiki.org, we'll add
Sandbox.$userSandbox
  • Loading branch information
gac410 committed Feb 14, 2018
1 parent bc94398 commit d78f775
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
12 changes: 7 additions & 5 deletions TopicUserMappingContrib/data/System/RemoveUser.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1489457633" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1518572853" format="1.1" version="1"}%
%META:TOPICPARENT{name="AdminToolsCategory"}%
---+ %MAKETEXT{"Remove User"}%

Expand All @@ -8,7 +8,8 @@ The following form can be used by administrators to delete a user's account:
* The user is removed from the user database.
* The user's topic is moved to the trash web.
* The user is removed from any groups.
* Other topics like the users !LeftBar are _not_ removed.
* Other topics derived from the user's !WikiName can be specified in configure. ={Register}{CleanupOnRemove}=
* %X% *Caution:* Individual Web/Topic ACLs, and !WebNotify subscriptions are *not* updated.

*Note:* Consider leaving the user topic file in place so their past signatures and revision author entries don't end up looking like AnUncreatedTopic.
If you want to make it clear the user is no longer around, replace the topic content with a note to that effect.
Expand All @@ -30,9 +31,10 @@ The existence of the <nop>UserName topic should also prevent that username from
---++++!! Enter user to be removed
%INCLUDE{"%SYSTEMWEB%.JQueryAjaxHelper" section="userselector" INPUT_NAME="user" MULTI="false"}%
<hr />
---++++!! Remove user topic?
<input type="checkbox" id="removeTopic" name="removeTopic" checked="checked" class="foswikiCheckbox" /> _(Check to remove topic)_
Prefix for deleted topic: <input type="text" name="topicPrefix" class="foswikiInputField" value="DeletedUser" /> _(Follow topic naming rules)_
---++++!! Remove user topics?
<input type="checkbox" id="removeTopic" name="removeTopic" class="foswikiCheckbox" /> _(Check to remove topic)_
Prefix for deleted topics: <input type="text" name="topicPrefix" class="foswikiInputField" value="DeletedUser" /> _(Follow topic naming rules)_ %BR%
_Removes:_ <tt>%QUERY{"{Register}{CleanupOnRemove}"}%</tt><br/>
<hr />
<input type="hidden" name="action" value="deleteUserAccount" />
<input type="submit" class="foswikiSubmit" value="Remove User" />
Expand Down
8 changes: 8 additions & 0 deletions core/lib/Foswiki.spec
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,13 @@ $Foswiki::cfg{Register}{UniqueEmail} = $FALSE;
# =@(?!(example\.com|example\.net)$)=
$Foswiki::cfg{Register}{EmailFilter} = '';

# **STRING LABEL="Topics to remove with User"**
# Set to a comma separated list of topic names or Web.Topic names to remove, substituting the WikiName for the $user token.
# When the System.RemoveUser topic is used to de-register a user,
# a limited number of topics can be removed during cleanup. Topics are moved
# to the Trash web. If a Web name is not provided, the Usersweb is used.
$Foswiki::cfg{Register}{CleanupOnRemove} = '$user,$userLeftBar';

#---++ Environment
# Control some aspects of the environment Foswiki runs within.

Expand Down Expand Up @@ -963,6 +970,7 @@ $Foswiki::cfg{AccessibleCFG} = [
'{Register}{NeedApproval}',
'{Register}{NeedVerification}',
'{Register}{RegistrationAgentWikiName}',
'{Register}{CleanupOnRemove}',
'{ReplaceIfEditedAgainWithin}',
'{SandboxWebName}',
'{ScriptSuffix}',
Expand Down
80 changes: 48 additions & 32 deletions core/lib/Foswiki/UI/Register.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2342,49 +2342,65 @@ sub _processDeleteUser {

if ( $paramHash->{removeTopic} ) {

# Remove the users topic, moving it to trash web
( my $web, $wikiname ) =
Foswiki::Func::normalizeWebTopicName( $Foswiki::cfg{UsersWebName},
$wikiname );
if ( Foswiki::Func::topicExists( $web, $wikiname ) ) {

# Spoof the user so we can delete their topic. Don't need to
# do this for the REST handler, but we do for the registration
# abort.
my $safe = $Foswiki::Plugins::SESSION->{user};

my $newTopic = "$paramHash->{prefix}$wikiname" . time;
try {
Foswiki::Func::moveTopic( $web, $wikiname,
$Foswiki::cfg{TrashWebName}, $newTopic );
$message .=
" - user topic moved to $Foswiki::cfg{TrashWebName}.$newTopic \n";
$logMessage .=
"User topic moved to $Foswiki::cfg{TrashWebName}.$newTopic, ";
}
finally {

# Restore the original user
$Foswiki::Plugins::SESSION->{user} = $safe;
};
}
else {
$message .= " - user topic not found \n";
$logMessage .= " User topic not found, ";
my $topicList = $Foswiki::cfg{Register}{CleanupOnRemove}
|| '$user,$userLeftBar';
my @remove = split( /,/, $topicList );

foreach my $remTopic (@remove) {
$remTopic =~ s/\$user/$wikiname/;
my $retmsg = _removeUserTopic( $remTopic, $paramHash->{prefix} );
$message .= " - $retmsg \n";
$logMessage .= " $retmsg, ";
}
}
else {
$message .= " - User topic not removed \n";
$logMessage .= " User topic not removed, ";
$message .= " - User topics not removed \n";
$logMessage .= " User topics not removed, ";
}
return ( $message, $logMessage );
}

sub _removeUserTopic {
my $wikiname = shift;
my $prefix = shift;
my $message = '';

# Remove the users topic, moving it to trash web
( my $web, $wikiname ) =
Foswiki::Func::normalizeWebTopicName( $Foswiki::cfg{UsersWebName},
$wikiname );
if ( Foswiki::Func::topicExists( $web, $wikiname ) ) {

# Spoof the user so we can delete their topic. Don't need to
# do this for the REST handler, but we do for the registration
# abort.
my $safe = $Foswiki::Plugins::SESSION->{user};

my $newTopic = "$prefix$wikiname" . time;
try {
Foswiki::Func::moveTopic( $web, $wikiname,
$Foswiki::cfg{TrashWebName}, $newTopic );
$message .=
"$wikiname topic moved to $Foswiki::cfg{TrashWebName}.$newTopic";
}
finally {

# Restore the original user
$Foswiki::Plugins::SESSION->{user} = $safe;
};
}
else {
$message .= "User topic $wikiname not found";
}

return $message;
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2013 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2018 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down

0 comments on commit d78f775

Please sign in to comment.