Skip to content

Commit

Permalink
Merge branch 'Release02x01'
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Nov 10, 2016
2 parents 3a028c5 + 496badb commit 9ee4286
Show file tree
Hide file tree
Showing 31 changed files with 1,018 additions and 5 deletions.
29 changes: 29 additions & 0 deletions UnitTestContrib/test/unit/RegisterTests.pm
Expand Up @@ -2921,6 +2921,16 @@ sub verify_registerVerifyOKApproved {
}
);
$query->path_info("/$this->{users_web}/UserRegistration");

# Registration should be listed under verification
$this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin}, $query );
my $regReport = Foswiki::Func::expandCommonVariables(
'%PENDINGREGISTRATIONS{verification}%');
$this->assert_matches( qr/^\| WalterPigeon \|/ms, $regReport );
$regReport =
Foswiki::Func::expandCommonVariables('%PENDINGREGISTRATIONS{approval}%');
$this->assert_str_equals( '', $regReport );

$this->createNewFoswikiSession( $Foswiki::cfg{DefaultUserLogin}, $query );
$this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail );

Expand Down Expand Up @@ -2977,6 +2987,16 @@ sub verify_registerVerifyOKApproved {
}
);
$query->path_info("/$this->{users_web}/UserRegistration");

# Registration should be listed under approval
$this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin}, $query );
$regReport = Foswiki::Func::expandCommonVariables(
'%PENDINGREGISTRATIONS{verification}%');
$this->assert_str_equals( '', $regReport );
$regReport =
Foswiki::Func::expandCommonVariables('%PENDINGREGISTRATIONS{approval}%');
$this->assert_matches( qr/\Q| WalterPigeon | \E/ms, $regReport );

$this->createNewFoswikiSession( $Foswiki::cfg{DefaultUserLogin}, $query );

# Make sure we get bounced unless we are logged in
Expand Down Expand Up @@ -3029,6 +3049,15 @@ sub verify_registerVerifyOKApproved {
$this->assert( 0, "expected an oops redirect" );
};

# Registration reports should be empty.
$this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin}, $query );
$regReport = Foswiki::Func::expandCommonVariables(
'%PENDINGREGISTRATIONS{verification}%');
$this->assert_str_equals( '', $regReport );
$regReport =
Foswiki::Func::expandCommonVariables('%PENDINGREGISTRATIONS{approval}%');
$this->assert_str_equals( '', $regReport );

$this->assert(
$this->{session}->topicExists(
$Foswiki::cfg{UsersWebName},
Expand Down
11 changes: 11 additions & 0 deletions core/data/System/PendingRegistrations.txt
@@ -0,0 +1,11 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1478750101" format="1.1" version="1"}%
---+ %MAKETEXT{"Pending Registrations"}%
---++ %MAKETEXT{"Registrations awaiting Email verification"}%

%PENDINGREGISTRATIONS{"Verification"}%

---++ %MAKETEXT{"Registrations awaiting approval"}%

%MAKETEXT{"You can use the \"approve\" or \"reject\" links to approve or reject these registrations"}%

%PENDINGREGISTRATIONS{"Approval"}%
39 changes: 39 additions & 0 deletions core/data/System/PendingRegistrationsTemplate.txt
@@ -0,0 +1,39 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1476996032" format="1.1" version="1"}%
---+!! Pending Registrations Template
%TOC%
---++ Tailoring instructions:
The contents of the Pending Registrations report can be modified to report any fields collected on a customized UserRegistration form. Each formfield name
is substituted with the similarly named token in the row definition: For example, if your User Registration form includes the =Organization= field, it can
be included by adding =$Organization= to the below !ApprovalRow and !VerificationRow templates.

Both this topic, and the PendingRegistrations topic must be in the same web for the override to work:
1 Copy this template topic to %IF{"istopic '%USERSWEB%.PendingRegistrationsTemplate'" else="!$percntUSERSWEB$percnt.PendingRegistrationsTemplate" then="[[$percntUSERSWEB$percnt.PendingRegistrationsTemplate]] ...done"}%
1 Edit %IF{"istopic '%USERSWEB%.PendingRegistrationsTemplate'" else="!$percntUSERSWEB$percnt.PendingRegistrationsTemplate" then="[[$percntUSERSWEB$percnt.PendingRegistrationsTemplate]]"}% and make the desired changes.
1 Copy %SYSTEMWEB%.PendingRegistrations to %IF{"istopic '%USERSWEB%.PendingRegistrations'" else="!$percntUSERSWEB$percnt.PendingRegistrations" then="[[$percntUSERSWEB$percnt.PendingRegistrations]] ...done"}%.
1 %USERSWEB%.PendingRegistrations will now generate a report using your tailored layout.

---++ Templates for "Pending Approval" registrations
<verbatim>
%TMPL:DEF{"ApprovalHeader"}%<noautolink>
| *WikiName* | *Email* | *LastName* | *FirstName* | *LoginName* | *Code* | *Action* |
%TMPL:END%

%TMPL:DEF{"ApprovalRow"}%| $WikiName | $Email | $LastName | $FirstName | $LoginName | $ApprovalCode |\
[[%SCRIPTURLPATH{"register" action="approve" code="$ApprovalCode" referee="%WIKINAME%"}%][%MAKETEXT{"Approve"}%]] / \
[[%SCRIPTURLPATH{"register" action="disapprove" code="$ApprovalCode" referee="%WIKINAME%"}%][%MAKETEXT{"Reject"}%]] |
%TMPL:END%
</verbatim>

---++ Templates for "Pending Verification" registrations
<verbatim>
%TMPL:DEF{"VerificationHeader"}%<noautolink>
| *WikiName* | *Email* | *LastName* | *FirstName* | *LoginName* | *Code* |
%TMPL:END%

%TMPL:DEF{"VerificationRow"}%| $WikiName | $Email | $LastName | $FirstName | $LoginName | $VerificationCode |%TMPL:END%
</verbatim>

---++ Common templates
<verbatim>
%TMPL:DEF{"accessdenied"}%<div class="foswikiAlert">%MAKETEXT{"Access to pending registrations is restricted to administrators"}%</div>%TMPL:END%
</verbatim>
1 change: 1 addition & 0 deletions core/lib/Foswiki.pm
Expand Up @@ -271,6 +271,7 @@ BEGIN {
META => undef, # deprecated
METASEARCH => undef, # deprecated
NONCE => undef,
PENDINGREGISTRATIONS => undef,
PERLDEPENDENCYREPORT => undef,
NOP =>

Expand Down
46 changes: 43 additions & 3 deletions core/lib/Foswiki/Configure/FileUtil.pm
Expand Up @@ -698,6 +698,35 @@ sub listDir {
return @names;
}

sub _getTarFamily {
my ($tarCmd) = @_;
`$tarCmd --version` =~ /(bsd|gnu)/i;
return lc $1;
}

sub _getTar {
my $tarCmd = 'tar';
my $tarFamily = _getTarFamily($tarCmd);

if ( $tarFamily eq 'bsd' ) {

# Trying to find gnutar in order to keep as much compatibility with
# linux as we can.
my $gnutar = `which gnutar`;
if ( $? == 0 && $gnutar ) {
chomp $gnutar;
if ( _getTarFamily($gnutar) eq 'gnu' ) {
$tarCmd = $gnutar;
$tarFamily = 'gnu';
}

}

}

return ( $tarCmd, $tarFamily );
}

=begin TML
---++ StaticMethod createArchive($name, $dir, $delete )
Expand Down Expand Up @@ -727,9 +756,20 @@ sub createArchive {
chdir("$dir/$name");

if ( !defined $test || ( defined $test && $test eq 'tar' ) ) {
$results .= `tar -czvf "../$name.tgz" .`;
my ( $tarCmd, $tarFamily ) = _getTar();
my $redirect = '';
if ( $tarFamily eq 'bsd' ) {

# BSD tar sends listing to STDERR while create an archive.
$redirect = '2>&1';
}

$results = `$tarCmd -czvf "../$name.tgz" . $redirect`;

if ( $results && !$@ ) {
if ( $? != 0 ) {
$results = '';
}
else {
$file = "$dir/$name.tgz";
}
}
Expand All @@ -740,7 +780,7 @@ sub createArchive {
if ( !defined $test || ( defined $test && $test eq 'zip' ) ) {
$results .= `zip -r "../$name.zip" .`;

if ( $results && !$@ ) {
if ( $results && !$? ) {
$file = "$dir/$name.zip";
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/lib/Foswiki/Contrib/core/MANIFEST
Expand Up @@ -132,6 +132,8 @@ data/System/ObjectMethod.txt 0644
data/System/PackageForm.txt 0644
data/System/PageCaching.txt 0644
data/System/ParentList.txt 0644
data/System/PendingRegistrations.txt 0644
data/System/PendingRegistrationsTemplate.txt 0644
data/System/PerlDependencyReport.txt 0644
data/System/PerlDoc.txt 0644
data/System/PlainSkin.txt 0644
Expand Down Expand Up @@ -559,6 +561,7 @@ lib/Foswiki/Macros/MAKETEXT.pm 0444
lib/Foswiki/Macros/META.pm 0444
lib/Foswiki/Macros/METASEARCH.pm 0444
lib/Foswiki/Macros/NONCE.pm 0444
lib/Foswiki/Macros/PENDINGREGISTRATIONS.pm 0444
lib/Foswiki/Macros/PERLDEPENDENCYREPORT.pm 0444 Configuration
lib/Foswiki/Macros/PUBURL.pm 0444
lib/Foswiki/Macros/PUBURLPATH.pm 0444
Expand Down
112 changes: 112 additions & 0 deletions core/lib/Foswiki/Macros/PENDINGREGISTRATIONS.pm
@@ -0,0 +1,112 @@
# See bottom of file for license and copyright information
package Foswiki;

use strict;
use warnings;

use File::Spec;
use Data::Dumper;
use Foswiki::Func;
use Config;
use Storable;

sub PENDINGREGISTRATIONS {
my ( $this, $params ) = @_;

Foswiki::Func::loadTemplate('PendingRegistrations');

my $report;

if ( ( !defined $params->{_DEFAULT} )
|| lc( $params->{_DEFAULT} ) eq 'approval' )
{
$report .= $this->_checkPendingRegistrations('Approval');
}

if ( ( !defined $params->{_DEFAULT} )
|| lc( $params->{_DEFAULT} ) eq 'verification' )
{
$report .= $this->_checkPendingRegistrations('Verification');
}

return $report;
}

sub _checkAccess {
my $this = shift;

return (
$this->{users}->isAdmin( $this->{user} )
|| ( $Foswiki::cfg{Register}{Approvers}
&& $Foswiki::cfg{Register}{Approvers} =~ m/\b\Q$this->{user}\E\b/ )
);
}

# Check pending registrations for duplicate email, or expiration
sub _checkPendingRegistrations {
my $this = shift;
my $check = shift;
my $report = '';

unless ( $this->_checkAccess() ) {
return Foswiki::Func::expandTemplate('accessdenied');
}

my $dir = "$Foswiki::cfg{WorkingDir}/registration_approvals/";

if ( opendir( my $d, "$dir" ) ) {
foreach my $f ( grep { /^.*\.[0-9]{1,8}$/ } readdir $d ) {
my $regFile = Foswiki::Sandbox::untaintUnchecked("$dir$f");

my $data = Storable::retrieve($regFile);
next unless defined $data;
next unless $data->{ $check . 'Code' };
$report .= _reportPending( $data, $check );
}
closedir($d);
}
my $header = '';
if ($report) {
$header = Foswiki::Func::expandTemplate( $check . 'Header' );
}
return $header . $report;
}

sub _reportPending {
my $hashref = shift;
my $check = shift;

my $tmpl = Foswiki::Func::expandTemplate( $check . 'Row' );

my $report = '';
foreach my $field ( sort { lc($a) cmp lc($b) } keys %$hashref ) {
next if $field eq 'form';
next if $field eq 'Confirm'; # Never show a user's password
next if $field eq 'Password';
$field =~ s/\$/&#36;/g; # Encode any $, so they are not removed later
$tmpl =~ s/\$$field/$hashref->{$field}/g;
}
$tmpl =~ s/\$\w+//g; # Remove any unused fields
return "$tmpl";
}

1;

__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2014-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
30 changes: 30 additions & 0 deletions core/locale/Foswiki.pot
Expand Up @@ -593,6 +593,10 @@ msgstr ""
msgid "Access keys:"
msgstr ""

#: core/data/System/PendingRegistrationsTemplate.txt:38
msgid "Access to pending registrations is restricted to administrators"
msgstr ""

#: core/templates/attachtables.tmpl:4 core/templates/attachtables.tmpl:43
#: core/templates/changeform.tmpl:9
msgid "Action"
Expand Down Expand Up @@ -742,6 +746,10 @@ msgid ""
"Any changes you made to the topic before coming to this page are preserved."
msgstr ""

#: core/data/System/PendingRegistrationsTemplate.txt:22
msgid "Approve"
msgstr ""

#: core/templates/viewtopicactionbuttons.tmpl:69
msgid "Attach"
msgstr ""
Expand Down Expand Up @@ -2963,6 +2971,10 @@ msgstr ""
msgid "Passwords do not match"
msgstr ""

#: core/data/System/PendingRegistrations.txt:2
msgid "Pending Registrations"
msgstr ""

#: core/templates/registermessages.tmpl:41
msgid "Pending registration not found"
msgstr ""
Expand Down Expand Up @@ -3271,10 +3283,22 @@ msgid ""
"Check the configuration for errors."
msgstr ""

#: core/data/System/PendingRegistrations.txt:3
msgid "Registrations awaiting Email verification"
msgstr ""

#: core/data/System/PendingRegistrations.txt:7
msgid "Registrations awaiting approval"
msgstr ""

#: core/data/System/WebSearch.txt:201
msgid "Regular expression search"
msgstr ""

#: core/data/System/PendingRegistrationsTemplate.txt:23
msgid "Reject"
msgstr ""

#: core/data/System/UserName.txt:44
msgid "Related Topics for Administrators:"
msgstr ""
Expand Down Expand Up @@ -5134,6 +5158,12 @@ msgstr ""
msgid "You can give this web a different name."
msgstr ""

#: core/data/System/PendingRegistrations.txt:9
msgid ""
"You can use the \"approve\" or \"reject\" links to approve or reject these "
"registrations"
msgstr ""

#: core/templates/registermessages.tmpl:423
#: core/templates/registermessages.tmpl:429
msgid ""
Expand Down

0 comments on commit 9ee4286

Please sign in to comment.