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 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.

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:
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2007-10-13 - SvenDowideit
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.