SID-02278: Display Members of a Group
| Status: |
Answered |
TWiki version: |
6.0.1 |
Perl version: |
|
| Category: |
CategoryAccessControl |
Server OS: |
|
Last update: |
9 years ago |
Is there a way to display the usernames of all members of a group if the parent group contains nested groups?
%SEARCH{ "Set GROUP =" web="Main" topic="TWikiAdminGroup" nosearch="on" nototal="on" multiple="on" format="$percntCALC{$SET(list, $pattern(.*\= *([^\n]*).*)) $GET(list) }$percnt" }%
The above works if the group contains
ONLY individual users however if the group contains other groups the output returns the group name.
If this doesn't exist would a good strategy be to modify the
GROUPS variable be modified to allow for an individual group name to be entered as a parameter?
--
Jani Hamalainen - 2016-11-24
Discussion and Answer
I agree with the enhancement to
GROUPS to limit output to a single group.
By the way: There is (there
always seems to be) a way to leverage the
GROUPS variable to do what you want:
- Use
GROUPS to populate a SpreadSheetPlugin-hash mapping group names to group members
- Use
$GETHASH to retrieve a single group.
%GROUPS{header="" format="$percntCALC{$SETHASH(groups,$group,$members)}$percnt"}%
Members of !TopLevelGroup: %CALC{$GETHASH(groups,TopLevelGroup)}%
Other formats of the user list can be achieved by mangling the
GETHASH result through the amazing functions of the
SpreadSheetPlugin. Get a sorted bullet list like this (note there are exactly three spaces before
CALC to get the first entry right):
%CALC{$LISTJOIN($n$sp$sp$sp,$LISTEACH($index $item,$LISTSORT($GETHASH(groups,TopLevelGroup))))}%
--
Harald Jörg - 2016-11-24
Brilliant! Thank you Harald!
I've submitted this as a Feature Proposal as well -
GroupsAdditionalFunctionality.
--
Jani Hamalainen - 2016-11-24
For anyone else coming across this support request I've added the info below if you want to use the results of the hash as Main.Harald posted above as values in a form.
I believe that the
$SETHASH must be provided for
each formfield value.
For example, a topic defining a form:
---+ %TOPIC%
| *Name* | *Type* | *Size* | *Values* | *Tooltip message* | *Attributes* |
| PaintReviewers | checkbox | 5 | %CALCULATE{%GROUPS{header="none" format="$SETHASH(groups,$group,$members)" memberformat="$wikiname" separator=""}%$GETHASH(groups, PaintReviewerGroup)}%| | |
| PaintApprovers | checkbox | 5 | %CALCULATE{%GROUPS{header="none" format="$SETHASH(groups,$group,$members)" memberformat="$wikiname" separator=""}%$GETHASH(groups, PaintApproverGroup)}% | | |
If the hash is defined outside of the
Values column of the form table the HASH itself is not defined and the result is no options in your form.
%EDITFORMFIELD{"PaintReviewer" topic="%TOPIC%"}%
An alternative is defining the hash ($SETHASH) in each topic that the form is used however I believe this is a better way.
--
Jani Hamalainen - 2016-11-30
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.