You are here: Foswiki>Tasks Web>Item9450 (12 Aug 2010, GeorgeClark)Edit Attach

Item9450: USERINFO doesn't work with another user specified as the first parameter

pencil
Priority: Normal
Current State: No Action Required
Released In:
Target Release: n/a
Applies To: Engine
Component: Foswiki.pm
Branches:
Reported By: LeilaPearson
Waiting For:
Last Change By: GeorgeClark
I'm setting up my new Foswiki site, and I'm using LDAP user mapping and the LDAP password manager. I'm also using the NewUserPlugin. While trying to set up my custom new user template, I noticed that I could not get USERINFO when specifying a user like this:

%USERINFO{"LeilaPearson" format="$emails"}%

or, in the case of my user topics, where the topic name == WikiName, like this:

%USERINFO{"%TOPIC%" format="$emails"}%
I did some debugging, and it looks to me like there is a bug in USERINFO subroutine in Foswiki.pm :

    if ( $params->{_DEFAULT} ) {
        $user = $params->{_DEFAULT};

    # At this point, $user will be something like this:  LeilaPearson format="$emails"

    return '' if !$user;

    # map wikiname to a login name
    $user = $this->{users}->getCanonicalUserID($user);

    # At this point, $user is undefined because getCanonicalUserID doesn't handle a WikiName with a format string following it.

I got it working by adding the following before calling getCanonicalUserID:

   # strip of format parameter
   $user =~ s/\s*format.*//i;

I'm not 100% certain that the substitution above is robust (my Perl and regexp are both a bit rusty), but it seems to do the trick for me. I don't have my own development environment set up yet, so I'm hoping someone who does might take this on? The bug is pretty frustrating for people trying to get their user pages working.

-- LeilaPearson - 10 Aug 2010

There is something wrong with the analysis above

The $params->{_DEFAULT} ) is the parameter without a name in a macro. It is not the entire content between the { and }

Ie %USERNAME{"%TOPIC%" format="$emails"}% will set $params->{_DEFAULT} = the value of %TOPIC%.

If you see something else then there is something wrong with the way you use USERNAME. Did you get the quotes right in the USERNAME macro?

Also remember that USERNAME only shows emails for your own name unless you are an admin. Unless you have {AntiSpam}{HideUserDetails} disabled in configure.

-- KennethLavrsen - 11 Aug 2010

Sorry about that. You're right. I just tried again after commenting out that line, and it still showed my email, so it does work as you're saying.

I had noticed at some point during my debugging that sometimes the quotes were not there on the first parameter, and remember fixing that more than once. I was deleting and recreating my own user topic over and over and it looks like my CustomNewUserTemplate was wrong at some point. For some reason I thought the quotes were being stripped off as the result of editing the page or template - not being simply left out in the template - but if that was the case, I can't reproduce the problem.

Thanks for looking into this. It can be closed.

-- LeilaPearson - 11 Aug 2010
 

ItemTemplate edit

Summary USERINFO doesn't work with another user specified as the first parameter
ReportedBy LeilaPearson
Codebase 1.0.9
SVN Range
AppliesTo Engine
Component Foswiki.pm
Priority Normal
CurrentState No Action Required
WaitingFor
Checkins
TargetRelease n/a
ReleasedIn
Topic revision: r4 - 12 Aug 2010, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy