Skip to content

Commit

Permalink
Item2172: add user to groups on registration is now functional - atm …
Browse files Browse the repository at this point in the history
…the UI lists all groups that the use can be added to using the GROUPINFO tag to generate a checkbox (but this needs work to test for Rego agent user permissions when running as guest)

git-svn-id: http://svn.foswiki.org/trunk@5597 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Nov 23, 2009
1 parent caa8ca0 commit c9de316
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 22 deletions.
55 changes: 53 additions & 2 deletions TopicUserMappingContrib/data/System/UserRegistration.txt
Expand Up @@ -317,7 +317,16 @@ else="*%MAKETEXT{"This Foswiki does _not_ support new User Registration"}%*"
</select> =<font color="red">**</font>=
</td>
</tr>
<tr>
%GROUPINFO{
header="$percntINCLUDE{\"%WEB%.%TOPIC%\" section=\"rendergroupheader\"}$percnt"
footer="$percntINCLUDE{\"%WEB%.%TOPIC%\" section=\"rendergroupfooter\"}$percnt"
format="$percntINCLUDE{\"%WEB%.%TOPIC%\"
section=\"rendergroup\"
groupname=\"$name\"
allowschange=\"$allowschange\"
}$percnt"
separator=" "
}%<tr>
<td valign="top" align="right"> %MAKETEXT{"Comments:"}%<br /> %MAKETEXT{"(optional)"}% </td>
<td><textarea %NOREGISTRATION% name="Twk0Comment" wrap="virtual" rows="4" cols="38" class="foswikiInputField"></textarea></td>
</tr>
Expand Down Expand Up @@ -346,4 +355,46 @@ else="*%MAKETEXT{"This Foswiki does _not_ support new User Registration"}%*"

<div class="foswikiHelp">
* %ICON{info}% %MAKETEXT{"If you have any questions about registration, send an e-mail to [_1]." args="<a href='mailto:%WIKIWEBMASTER%?subject=%TOPIC%&#32;Question'>%WIKIWEBMASTER%</a>"}%
</div>
</div>

<!-- GROUPINFO formaters -->
<verbatim style="display:none;">
TODO: need to make the header&footer not display if there are no groups they can join
TODO: should redo this topic to look differet between a guest registering themselves, and a registered user inviting/registering a user
<!--
parameters: groupname, allowschange
-->
%STARTSECTION{"rendergroup"}%<!-- rendergroup -->
%INCLUDE{"%WEB%.%TOPIC%"
section="%IF{"%allowschange%" then="changegroup" else="nochange"}%"
groupname="%groupname%"
}%
<!-- /rendergroup -->%ENDSECTION{"rendergroup"}%
<!--
parameters: groupname
-->
%STARTSECTION{"changegroup"}%<!-- changegroup -->
<input type="checkbox" name="Twk0AddToGroups" class="foswikiInputField" value="%groupname%" label="%groupname%" />
%IF{"not istopic '%MAINWEB%.%groupname%'" then="<nop>" else="%MAINWEB%."}%%groupname%
<!-- /changegroup -->%ENDSECTION{"changegroup"}%
<!--
parameters:
-->
%STARTSECTION{"nochange"}%<!-- nochange// --> %ENDSECTION{"nochange"}%

<!--
parameters:
-->
%STARTSECTION{"rendergroupheader"}%<!-- rendergroupheader -->
<tr>
<td align="right"> %MAKETEXT{"Wiki Groups to join:"}% </td>
<td>
<!-- //rendergroupheader -->%ENDSECTION{"rendergroupheader"}%
<!--
parameters:
-->
%STARTSECTION{"rendergroupfooter"}%<!-- rendergroupfooter -->
</td>
</tr>
<!-- //rendergroupfooter -->%ENDSECTION{"rendergroupfooter"}%
</verbatim>
16 changes: 4 additions & 12 deletions TopicUserMappingContrib/lib/Foswiki/Users/TopicUserMapping.pm
Expand Up @@ -745,26 +745,18 @@ sub addUserToGroup {
$this->{session}
->normalizeWebTopicName( $Foswiki::cfg{UsersWebName}, $Group );

#the registration code will call this function using the rego agent
my $user = $this->{session}->{user};

#open Group topic, parse for the GROUPs setting, append new user
#find where GROUP is set, use that code if we can, so that when it goes multi-line it copes
#TODO: LATER: check for duplicates
#TODO: make sure the groupName ends in Group...

#run this as calling user, if the registration is being run by an existing user
# (often done by admins), else run as registration agent
#TODO: extract this to the rego code - as we really should only allow magical group adding in specific circumstances? (or is this a pointless oddity, as any user can 'just' register a sock puppet, and then...?
my $usersObj = $this->{session}->{users};

#$this->{session}->writeDebug($usersObj->getWikiName($user)."is TRYING to add $cuid to $groupTopic, as ".$usersObj->getWikiName($cuid)) if DEBUG;
if ( ( $usersObj->getWikiName($user) eq $Foswiki::cfg{DefaultUserWikiName} )
or ( $user eq $cuid ) )
{
$user =
$usersObj->findUserByWikiName(
$Foswiki::cfg{Register}{RegistrationAgentWikiName} );
}
my $usersObj = $this->{session}->{users};

#print STDERR "$user, aka ".$usersObj->getWikiName($user)." is TRYING to add $cuid to $groupName, as ".$usersObj->getWikiName($cuid)."\n";

if (
$usersObj->isGroup($groupName)
Expand Down
29 changes: 21 additions & 8 deletions core/lib/Foswiki/UI/Register.pm
Expand Up @@ -572,11 +572,11 @@ sub addUserToGroup {
my $groupName = $query->param('groupname');
my $create = Foswiki::isTrue( $query->param('create'), 0);
if (
(length(@userNames) <= 0) or
($#userNames <= 0) or
($userNames[0] eq '')){
throw Foswiki::OopsException( 'attention', def => 'no_users_to_add_to_group' );
}
if (length(@userNames) == 1) {
if ($#userNames == 1) {
@userNames = split(/,\s*/, $userNames[0]);
}
if (!$groupName or $groupName eq '') {
Expand Down Expand Up @@ -639,11 +639,11 @@ sub removeUserFromGroup {
my @userNames = $query->param('username');
my $groupName = $query->param('groupname');
if (
(length(@userNames) <= 0) or
($#userNames <= 0) or
($userNames[0] eq '')){
throw Foswiki::OopsException( 'attention', def => 'no_users_to_remove_from_group' );
}
if (length(@userNames) == 1) {
if ($#userNames == 1) {
@userNames = split(/,\s+/, $userNames[0]);
}
if (!$groupName or $groupName eq '') {
Expand Down Expand Up @@ -742,6 +742,20 @@ sub _complete {
);
my $log = _createUserTopic( $session, $data );
$users->setEmails( $cUID, $data->{Email} );

#convert to rego agent user copied from _writeRegistrationDetailsToTopic
my $safe = $session->{user};
my $regoAgent = $session->{users}->getCanonicalUserID($Foswiki::cfg{Register}{RegistrationAgentWikiName});
foreach my $groupName (split(/,/, $data->{AddToGroups})) {
$session->{user} = $regoAgent;
try {
$users->addUserToGroup($cUID, $groupName);
}
finally {
$session->{user} = $safe;
};
}

}
catch Error::Simple with {
my $e = shift;
Expand Down Expand Up @@ -1348,15 +1362,14 @@ sub _getDataFromQuery {

# get all parameters from the form
my $data = {};
foreach ( $query->param() ) {
if (/^(Twk([0-9])(.*))/) {
my @values = $query->param($1) || ();
foreach my $key ( $query->param() ) {
if ($key =~ /^(Twk([0-9])(.*))/) {
my @values = $query->param($key);
my $required = $2;
my $name = $3;

# deal with multivalue fields like checkboxen
my $value = join( ',', @values );

# Note: field values are unvalidated (and therefore tainted).
# This is because the registration code does not have enough
# information to validate the data - for example, it cannot
Expand Down

0 comments on commit c9de316

Please sign in to comment.