SID-01405: List the users and Groups using search
| Status: |
Answered |
TWiki version: |
5.1.0 |
Perl version: |
|
| Category: |
CategorySearch |
Server OS: |
Linux |
Last update: |
13 years ago |
I need a search to list all the users and groups of a web in single column separated by commas something like
TWikiGroups, this will be used in a Form Field pulldown.
For example:
user1,
user2,
group1,
group2
--
RonMascarenhas - 2012-02-17
Discussion and Answer
First build two searches that return all users and all groups as a comma-space separated list. Then you convert that list into option tags of a select tag:
All users:
%SEARCH{
"META:FORM.*[U]serForm;%URLPARAM{"search" encode="quote"}%"
type="regex"
web="%USERSWEB%"
nonoise="on"
topic="RonM*"
excludetopic="UserList, *Template"
format="$topic"
separator=", "
}%
returns: (here restricted to all RonM* topics because of so many users on twiki.org)
RonMaayan, RonMargalit, RonMascarenhas, RonMatuschek, RonMcCaffertyJr, RonMiner
All groups:
%SEARCH{
"Set GROUP"
web="%USERSWEB%"
topic="*Group"
casesensitive="on"
nonoise="on"
format="$topic"
separator=", "
}%
returns:
AstroHepBrGroup, DevelopBranchGroup, Jack2021Group, NameGroup, SecurityTeamSupportGroup, StanStateGroup, TWikiAdminGroup, TWikiCommunityGroup
Now let's put this together with SET, GET and CALC to produce the html select:
View the
raw content to see how this works.
Details in
VarSEARCH,
FormattedSearch,
VarSET,
VarGET,
VarCALC,
SpreadSheetPlugin
--
PeterThoeny - 2012-02-18
This does not work on Twiki 5.0.1, is the syntax different on that release. All I get there is
$SET( "users" value="RonMascarenhas" ) $SET( "groups" value="NobodyGroup,
TWikiAdminGroup" ) and $item in the pulldown
--
RonMascarenhas - 2012-02-24
You need to install the
SetGetPlugin. Alternatively, use the
$SET() and
$GET() functions of the SpreadSheetPlugin.
--
PeterThoeny - 2012-02-24
I am trying to use this search in a form and template, I defined a Form and a topic from which to get the values from a search. The values are shown in the pulldown in the topic but I get a blank box when I attach the form to a template. Is there a way to defer the search till the template is invoked.
Form definition:
DocUser Topic:
%SET{ "users" value="%SEARCH{
"META:FORM.*[U]serForm;%URLPARAM{"search" encode="quote"}%"
type="regex"
web="%USERSWEB%"
nonoise="on"
topic="*"
excludetopic="UserList, *Template"
format="$topic"
separator=", "
}%" }%
%SET{ "groups" value="%SEARCH{
"Set GROUP"
web="Main"
topic="*Group"
casesensitive="on"
nonoise="on"
format="$topic"
separator=", "
}%" }% <select>
%CALC{$LISTJOIN($sp, $LISTMAP(|<option>$item</option>,%GET{users}%, -----, %GET{groups}%)|)}% </select>
--
RonMascarenhas - 2012-03-05
Closing this question after more than 30 days of inactivity. Feel free to reopen if needed. Consider engaging one of the
TWiki consultants if you need timely help. We invite you to
get involved with the community, it is more likely you get community support if you support the open source project!
--
PeterThoeny - 2012-07-01
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.