Skip to content

Commit

Permalink
Item1484: port WebPermissionPlugin.
Browse files Browse the repository at this point in the history
Added support for WEBPERMISSIONSPLUGIN_DEBUG
Removed TRACE_ACLS; replaced w/ &Foswiki::Func::writeDebug.


git-svn-id: http://svn.foswiki.org/trunk/WebPermissionsPlugin@7700 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
AaronScamehorn authored and AaronScamehorn committed Jun 8, 2010
1 parent 3291043 commit 67a99bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
7 changes: 7 additions & 0 deletions lib/Foswiki/Plugins/WebPermissionsPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@
# permissions in a big table that can easily be edited. It updates WebPreferences
# in each affected web.

# ========================
package Foswiki::Plugins::WebPermissionsPlugin;

use strict;

# ========================
use Foswiki::Func ();

our $debug = 0;
our $VERSION = '$Rev: 160$';
our $RELEASE = '21 Apr 2009';
our $SHORTDESCRIPTION = 'View and edit web permissions';

# ========================
sub initPlugin {
my ( $topic, $web, $user, $installWeb ) = @_;

Expand All @@ -55,6 +59,9 @@ sub initPlugin {

Foswiki::Func::registerRESTHandler( 'change', \&_changeHandler );

# Get preferences values
$debug = &Foswiki::Func::getPreferencesFlag( "WEBPERMISSIONSPLUGIN_DEBUG" );

return 1;
}

Expand Down
28 changes: 17 additions & 11 deletions lib/Foswiki/Plugins/WebPermissionsPlugin/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@
# This plugin helps with permissions management by displaying the web
# permissions in a big table that can easily be edited. It updates
# WebPreferences in each affected web.
#
# =========================

package Foswiki::Plugins::WebPermissionsPlugin::Core;

use strict;

use CGI (':all');
use Foswiki::Meta ();

# =========================
our $antiBeforeSaveRecursion;

sub TRACE_ACLS { 1 };
my $debug = $Foswiki::Plugins::WebPermissionsPlugin::debug;

# =========================

# Handle %WEBPERMISSIONS% for Display and Edit
sub WEBPERMISSIONS {
Expand Down Expand Up @@ -394,6 +400,8 @@ sub beforeSaveHandler {
my $action = $query->param('topic_permissions_action');
return unless ( defined($action) ); #nothing to do with this plugin

&Foswiki::Func::writeDebug( "WebPermissionsPlugin::Core::beforeSaveHandler: action=" . $action ) if ( $debug );

if ( $action ne 'Save' ) {

# SMELL: canceling out from, or just stopping a save seems
Expand Down Expand Up @@ -570,7 +578,7 @@ sub _getACLs {
$context = 'WEB';
$topic = $Foswiki::cfg{WebPrefsTopicName};
}
print STDERR "ACL: GET $context $web.$topic\n" if TRACE_ACLS;
&Foswiki::Func::writeDebug( "WebPermissionsPlugin::Core::_getACLs: GET $context $web.$topic" ) if ( $debug );
my @knownusers = _getListOfUsers();
push( @knownusers, _getListOfGroups() );

Expand All @@ -593,9 +601,9 @@ sub _getACLs {
"$perm$context$mode" );

if (defined $users) {
print STDERR "ACL: $perm$context$mode=$users\n" if TRACE_ACLS;
&Foswiki::Func::writeDebug( "WebPermissionsPlugin::Core::_getACLs: $perm$context$mode=$users" ) if ( $debug );
} else {
print STDERR "ACL: no $perm$context$mode defined\n";
&Foswiki::Func::writeWarning( "WebPermissionsPlugin::Core::_getACLs: no $perm$context$mode defined" );
}

next unless $users;
Expand Down Expand Up @@ -635,19 +643,19 @@ sub _getACLs {
# so change the default for all other users to 0.
foreach my $user (@knownusers) {

print STDERR "ACL: Disallow $mode $user\n" if TRACE_ACLS;
&Foswiki::Func::writeDebug( "WebPermissionsPlugin::Core::_getACLs: Disallow $mode $user" ) if ( $debug );
$acls{$user}->{$mode} = 0;
}
foreach my $user (@users) {

print STDERR "ACL: Allow $mode $user\n" if TRACE_ACLS;
&Foswiki::Func::writeDebug( "WebPermissionsPlugin::Core::_getACLs: Allow $mode $user" ) if ( $debug );
$acls{$user}->{$mode} = 1;
}
}
else {
foreach my $user (@users) {

print STDERR "ACL: Deny $mode $user\n" if TRACE_ACLS;
&Foswiki::Func::writeDebug( "WebPermissionsPlugin::Core::_getACLs: Deny $mode $user " ) if ( $debug );
$acls{$user}->{$mode} = 0;
}
}
Expand Down Expand Up @@ -689,7 +697,7 @@ sub _setACLs {
$topic = $Foswiki::cfg{WebPrefsTopicName};
}

print STDERR "ACL: SET $context $web.$topic\n" if TRACE_ACLS;
&Foswiki::Func::writeDebug( "WebPermissionsPlugin::Core::_setACLs: SET $context $web.$topic " ) if ( $debug );
my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );

my @knownusers = _getListOfUsers();
Expand Down Expand Up @@ -731,9 +739,7 @@ sub _setACLs {
}
);
}
if (TRACE_ACLS) {
print STDERR "ACL: $name = ".join( ' ', @$set ) . "\n";
}
&Foswiki::Func::writeDebug( "WebPermissionsPlugin::Core::_setACLs: $name = " . join( ' ', @$set ) ) if ( $debug );
}
}

Expand Down

0 comments on commit 67a99bd

Please sign in to comment.