Changeset 229


Ignore:
Timestamp:
Apr 20, 2006, 4:58:57 PM (14 years ago)
Author:
nick
Message:

Support for some pre plugins denying an action

Location:
wiki-toolkit/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit.pm

    r217 r229  
    241241    $args{plugins} = \@plugins if scalar @plugins;
    242242
    243     $self->store->moderate_node( %args );
     243    my $ret = $self->store->moderate_node( %args );
     244        if($ret == -1) { return $ret; }
     245        return 1;
    244246}
    245247
     
    287289        $args{wiki} = $self;
    288290
    289     $self->store->rename_node( %args );
    290 
     291    my $ret = $self->store->rename_node( %args );
     292
     293        if($ret == -1) { return $ret; }
    291294        return 1;
    292295}
     
    820823
    821824    my $store = $self->store;
    822     $store->check_and_write_node( %data ) or return 0;
     825    my $ret = $store->check_and_write_node( %data ) or return 0;
     826        if($ret == -1) { return -1; }
    823827
    824828    my $search = $self->{_search};
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Plugin.pm

    r226 r229  
    3939  my ($name_ref,$version_ref) = @args{ qw( node version ) };
    4040  $$name_ref =~ s/\s/_/g;
    41 
    42   TODO: Allow declining of moderation.
     41  return 0;
    4342
    4443=item B<post_moderate>
     
    6261  $$old_name_ref =~ s/\s/_/g;
    6362  $$new_name_ref =~ s/\s/_/g;
    64 
    65   TODO: Allow declining of the rename.
     63  return 0;
    6664
    6765=item B<post_rename>
     
    8280  my %args = @_;
    8381  my ($name_ref,$version_ref) = @args{ qw( node version ) };
    84   $$name_ref =~ s/\s/_/g;
     82  return &check_retrive_allowed($$name_ref);
    8583
    8684  TODO: Allow declining of the read.
     
    9593      @args{ qw( node content metadata ) };
    9694  $$content_ref =~ s/\bpub\b/Pub/g;
    97 
    98   TODO: Allow declining of the read.
     95  return 1;
    9996
    10097=item B<post_write>
     
    119116
    120117=back
     118
     119=head1 DECLINING ACTIONS FROM PRE_ METHODS
     120
     121  Note: This functionality is missing for pre_retrieve
     122
     123  It is possible for the pre_ methods (eg C<pre_write>) to
     124  decline the action. This could be due to an authentication
     125  check done by the plugin, due to the content, or whatever else
     126  the plugin fancies. There are three possible return values from
     127  a pre_ plugin:
     128
     129  C<-1> - Deny this action
     130  C<0> or C<undef> - I have no opinion
     131  C<1> - Allow this action
     132
     133  If you have only zeros, the action will be allowed. If you have ones
     134  and zeros, it will also be allowed.
     135
     136  If you have minus ones and zeros, it will be denied. If you have minus
     137  ones, ones and zeros, the sum will be used to decide.
     138
     139  For default deny, have one plugin return -1, and another only return 1
     140  if the action is explicity allowed)
    121141
    122142=head1 METHODS
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/Database.pm

    r226 r229  
    116116
    117117    return $self;
     118}
     119
     120# Internal method, used to handle the logic of how to add up return
     121#  values from pre_ plugins
     122sub handle_pre_plugin_ret {
     123        my ($running_total_ref,$result) = @_;
     124
     125        if($result == 0 || $result == undef) {
     126                # No opinion, no need to change things
     127        } elsif($result == -1 || $result == 1) {
     128                # Increase or decrease as requested
     129                $$running_total_ref += $result;
     130        } else {
     131                # Invalid return code
     132                warn("Pre_ plugin returned invalid accept/deny value of '$result'");
     133        }
    118134}
    119135
     
    464480    # Call pre_write on any plugins, in case they want to tweak anything
    465481    my @preplugins = @{ $args{plugins} || [ ] };
     482        my $write_allowed = 1;
    466483    foreach my $plugin (@preplugins) {
    467484        if ( $plugin->can( "pre_write" ) ) {
    468             $plugin->pre_write(
    469                                 node     => \$node,
    470                                 content  => \$content,
    471                                 metadata => \$metadata_ref );
     485                        handle_pre_plugin_ret(
     486                                \$write_allowed,
     487                                $plugin->pre_write(
     488                                        node     => \$node,
     489                                        content  => \$content,
     490                                        metadata => \$metadata_ref )
     491                        );
    472492        }
    473493    }
     494        if($write_allowed < 1) {
     495                # The plugins didn't want to allow this action
     496                return -1;
     497        }
    474498
    475499    # Either inserting a new page or updating an old one.
     
    657681    # Call pre_rename on any plugins, in case they want to tweak anything
    658682    my @preplugins = @{ $args{plugins} || [ ] };
     683        my $rename_allowed = 1;
    659684    foreach my $plugin (@preplugins) {
    660685        if ( $plugin->can( "pre_rename" ) ) {
    661             $plugin->pre_rename(
    662                                 old_name => \$old_name,
    663                                 new_name => \$new_name,
    664                                 create_new_versions => \$create_new_versions,
     686                        handle_pre_plugin_ret(
     687                                \$rename_allowed,
     688                                $plugin->pre_rename(
     689                                        old_name => \$old_name,
     690                                        new_name => \$new_name,
     691                                        create_new_versions => \$create_new_versions,
     692                                )
    665693                        );
    666694        }
    667695    }
     696        if($rename_allowed < 1) {
     697                # The plugins didn't want to allow this action
     698                return -1;
     699        }
    668700
    669701        # Get the ID of the node
     
    794826    # Call pre_moderate on any plugins.
    795827    my @plugins = @{ $args{plugins} || [ ] };
     828        my $moderation_allowed = 1;
    796829    foreach my $plugin (@plugins) {
    797830        if ( $plugin->can( "pre_moderate" ) ) {
    798             $plugin->pre_moderate(
    799                                 node     => \$name,
    800                                 version  => \$version );
     831                        handle_pre_plugin_ret(
     832                                \$moderation_allowed,
     833                                $plugin->pre_moderate(
     834                                        node     => \$name,
     835                                        version  => \$version )
     836                        );
    801837        }
    802838    }
     839        if($moderation_allowed < 1) {
     840                # The plugins didn't want to allow this action
     841                return -1;
     842        }
    803843
    804844        # Get the ID of this node
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/MySQL.pm

    r209 r229  
    6363        return 0;
    6464    }
    65     $self->write_node_post_locking( %args );
     65    my $ok = $self->write_node_post_locking( %args );
    6666    $self->_unlock_node($node) or carp "Can't unlock node";
    67     return 1;
     67    return $ok;
    6868}
    6969
Note: See TracChangeset for help on using the changeset viewer.