SID-00465: How do I display data dependant on TWikiGroup membership
For the whole topic it is easy: follow
TWikiAccessControl.
I would like to optionally display
part of a topic dependant on whether the current user is or is not a member of a particular
TWikiGroup.
I can easily enough determine which groups the active user is a member of
%USERINFO{format="$groups"}%
but how do I then use that information to grant/deny access to part of a topic?
--
JeremyWolstenCroft - 2009-08-06
Discussion and Answer
You should be able to do that with conditional
IfStatements. Here is an untested example:
%IF{ "'%USERINFO{$format="$groups"}%' ~ '*SomeSpecialGroup*'" then="I am in the special group" else="I am not in the special group" }%
Note that the condition is enclosed in double quotes and compares strings enclosed in single quotes.
See details in
VarIF,
IfStatements,
QuerySearch,
TWikiAccessControl.
--
PeterThoeny - 2009-08-07
Almost. This does not appear to work.
'%USERINFO{$format="$groups"}%' evaluates correctly but the ~ operator does not appear to be working. I get an error equivalent to:
IF{ "'Main.DepartmentOneGroup,
DepartmentTwoGroup,
DepartmentTwoManagementGroup,
DepartmentThreeGroup,
TWikiLibrarianGroup'~'DepartmentTwoManagementGroup'" else="" then="style='display: none;'" }: Bad expression at ~'DepartmentTwoManagementGroup'
--
JeremyWolstenCroft - 2009-08-07
You are missing the asteriscs:
'*DepartmentTwoManagementGroup*'
--
PeterThoeny - 2009-08-07
Could you use a similar statement to show content only if the user has a certain permission? Say user is part of group that has view access to some pages, but not edit access. Could you put statements in the various template sections to cause edit buttons/links to only appear if the user has permission to edit the topic?
--
DavidWolfe - 2009-08-07
You could simply
%INCLUDE{AnyRestrictedPage}%
, users with no access to the restriicted page will not see the content.
It is possible to conditionally show/hide the edit buttons. You need a custom style sheet. Start at
PatternSkinCustomization and
PatternSkinCssCookbook.
--
PeterThoeny - 2009-08-09
Overall I am trying to achieve the visibility/invisibility of a form (not a TWiki form) on a topic page. I would like the majority of the topic to be displayed (and editable) all the time but the form should only be visible if the user of the TWiki web has the correct access rights.
The suggestion Peter Theony has made with %INCLUDE{AnyRestrictedPage}% is a good one and I think may well work better than the use of an %IF as otherwise the access restrictions can be subverted easily.
My reason for wanting this difference is so that certain users are not bothered with functionality that isn't relevant to them. It's not actually out of a need to truly restrict access.
Oh and making sure that the syntax is '*DepartmentTwoManagementGroup*' not 'DepartmentTwoManagementGroup' does not make any difference. the error is still:
=Bad expression at ~'*DepartmentTwoManagementGroup*' =
--
JeremyWolstenCroft - 2009-08-11
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 - 2009-10-02
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.