Skip to content

Commit

Permalink
Item14548: implement $registrationdate token
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Dec 1, 2017
1 parent 215bcec commit 80fe67e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
26 changes: 23 additions & 3 deletions TopicUserMappingContrib/lib/Foswiki/Users/TopicUserMapping.pm
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ sub userExists {
ASSERT($cUID) if DEBUG;

# Do this to avoid a password manager lookup
return 1 if $cUID eq $this->{session}->{user};
return 1 if $this->{session}->{user} && $cUID eq $this->{session}->{user};

my $loginName = $this->getLoginName($cUID);
return 0 unless defined($loginName);
Expand Down Expand Up @@ -1339,6 +1339,24 @@ sub getEmails {

=begin TML
---++ ObjectMethod getRegistrationDate($name) -> @emailAddress
returns the date this user has registered.
=cut

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

$this->_loadMapping();

my $user = $this->getLoginName($cUID);

return $this->{L2D}{$user};
}

=begin TML
---++ ObjectMethod setEmails($cUID, @emails) -> boolean
Set the email address(es) for the given user.
Expand Down Expand Up @@ -1606,7 +1624,7 @@ sub validateRegistrationField {

# TODO: and probably flawed in light of multiple cUIDs mapping to one wikiname
sub _cacheUser {
my ( $this, $wikiname, $login ) = @_;
my ( $this, $wikiname, $login, $date ) = @_;
ASSERT($wikiname) if DEBUG;

$login ||= $wikiname;
Expand All @@ -1624,6 +1642,8 @@ sub _cacheUser {
$this->{U2W}->{$cUID} = $wikiname;
$this->{L2U}->{$login} = $cUID;
$this->{W2U}->{$wikiname} = $cUID;
$this->{L2D}->{$login} = $date;
$this->{W2D}->{$wikiname} = $date;

return $cUID;
}
Expand Down Expand Up @@ -1713,7 +1733,7 @@ sub _loadMapping {
# * WikiGuest - guest - 10 Mar 2005
# * WikiGuest - 10 Mar 2005
$text =~
s/^\s*\* (?:$Foswiki::regex{webNameRegex}\.)?($Foswiki::regex{wikiWordRegex})\s*(?:-\s*(\S+)\s*)?-.*$/(_cacheUser( $this, $1, $2)||'')/gme;
s/^\s*\* (?:$Foswiki::regex{webNameRegex}\.)?($Foswiki::regex{wikiWordRegex})\s*(?:-\s*(\S+)\s*)?-\s*(.*?)\s*$/(_cacheUser( $this, $1, $2, $3)||'')/gme;
}
}
else {
Expand Down
3 changes: 2 additions & 1 deletion core/data/System/VarUSERINFO.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1456368117" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1512148066" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
---+ USERINFO -- retrieve details about a user
---++ Parameters
Expand All @@ -13,6 +13,7 @@ Format tokens that can be used in =format=:
| =$groups= (*) | Comma separated list of group membership. Currently only expands for users |
| =$isadmin= (*) | Has admin privileges (expands to =true= or =false=) |
| =$isgroup= | Is a group (expands to =true= or =false=) | |
| =$registrationdate= | date when a user has registered on the site | |
%T% Tokens flagged '(*)' are considered private and are hidden from other users by default.%BR%
The [[FormatTokens][standard format tokens]] are also supported.
---++ Examples
Expand Down
4 changes: 4 additions & 0 deletions core/lib/Foswiki/Macros/USERINFO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ my %USERINFO_tokens = (

return $wikiusername;
},
registrationdate => sub {
my ( $this, $user ) = @_;
return $this->{users}->getRegistrationDate($user) || "";
},
emails => sub {
my ( $this, $user ) = @_;

Expand Down
15 changes: 15 additions & 0 deletions core/lib/Foswiki/UserMapping.pm
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,21 @@ sub getEmails {

=begin TML
---++ ObjectMethod getRegistrationDate($name) -> $string
If $name is a cUID, return that user's email addresses. If it is a group,
return the addresses of everyone in the group.
Duplicates should be removed from the list.
=cut

sub getRegistrationDate {
return;
}

=begin TML
---++ ObjectMethod setEmails($cUID, @emails)
Set the email address(es) for the given user.
Expand Down
15 changes: 15 additions & 0 deletions core/lib/Foswiki/Users.pm
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,21 @@ sub getEmails {

=begin TML
---++ ObjectMethod getRegistrationDate($name) -> $string
returns the date this user has registered.
=cut

sub getRegistrationDate {
my ( $this, $name ) = @_;

return unless $name;
return $this->_getMapping($name)->getRegistrationDate($name);
}

=begin TML
---++ ObjectMethod setEmails($cUID, @emails)
Set the email address(es) for the given user.
Expand Down

0 comments on commit 80fe67e

Please sign in to comment.