Tags:
create new tag
, view all tags

Question

I'd like to make some portions of a page appear/disappear depending on the group membership of the user. For example, I'd like to put administrative functions on a page that only members of TWikiAdminGroup will see.

Another option that would help me would be to show/hide page content based on the user's ability to edit that page.

Is there a way to form a %IF to test for either/both of these conditions?

Environment

TWiki version: TWikiRelease04x00x05
TWiki plugins:  
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  
Categories:  

-- SteveJohnson24 - 13 Jan 2007

Answer

ALERT! If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.

At this time there is no easy way to test for group membership and take conditional action based on that with an %IF.

There is however a simple solution: Simply INCLUDE a topic that has view access restriction based on a group. Those who are not in the group will not see the content. You can omit the view denied error message, see details in VarINCLUDE.

-- PeterThoeny - 14 Jan 2007

Here's a little hack to add "group" functionality to %IF... Insert the following code into lib/TWiki/If.pm, somewhere around line 86:

$defOps{group} =
  { name => 'group',
    prec => 5,
    type => 0, # unary
    exec => sub {
        my( $twiki, $a, $b ) = @_;
        my $s=$b->evaluate($twiki);
        for my $group ($twiki->{user}->getGroups) {
            return 1 if( $s eq $group->wikiName );
        }
        return 0;
    }
   };

Then you can use the following syntax:

%IF{ "group TWikiAdminGroup" then="*yes*" else="no"}%

Hope this helps.

-- SteveMokris - 28 Sep 2007

Useful for me, thanks smile

-- MartinCleaver - 12 Oct 2007

yoinc: Bugs:Item4809

-- SvenDowideit - 13 Oct 2007

I've made the if a little more generic for 4.2, and written a set of unit tests for it:

%IF{ "SvenDowideit ingroup TWikiAdminGroup" then="*yes*" else="no"}%

-- SvenDowideit - 13 Oct 2007

 
Change status to:
Topic revision: r6 - 13 Oct 2007 - 06:04:46 - SvenDowideit
 
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback