From: Chris W. <la...@us...> - 2005-03-04 02:50:13
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Manage/Website In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10564/Manage/Website Modified Files: CreateSecurity.pm Added Files: CreateSecurityForAction.pm CreateSecurityForSPOPS.pm Log Message: OIN-140: add new management task for creating action security, and move common security creation code into parent class for the SPOPS and action tasks --- NEW FILE: CreateSecurityForAction.pm --- package OpenInteract2::Manage::Website::CreateSecurityForAction; # $Id: CreateSecurityForAction.pm,v 1.1 2005/03/04 02:50:01 lachoy Exp $ use strict; use base qw( OpenInteract2::Manage::Website::CreateSecurity ); $OpenInteract2::Manage::Website::CreateSecurityForAction::VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); sub get_name { return 'secure_action'; } sub get_brief_description { return "Assign security settings for an OI2 action."; } sub get_parameters { my ( $self ) = @_; my $params = $self->SUPER::get_parameters(); $params->{action} = { description => "Action name for which you'd like to set security", is_required => 'yes', }; return $params; } sub _assign_create_params { my ( $self, $creator ) = @_; $creator->action( $self->param( 'action' ) ); } OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ ); 1; __END__ =head1 NAME OpenInteract2::Manage::Website::CreateSecurityForAction - Create security for an OI2 action =head1 SYNOPSIS #!/usr/bin/perl use strict; use OpenInteract2::Manage; my $website_dir = '/home/httpd/mysite'; my %PARAMS = ( scope => 'group', scope_id => 4, action => 'news', level => 'write', website_dir => $website_dir, ); my $task = OpenInteract2::Manage->new( 'secure_action', \%PARAMS ); my @status = $task->execute; foreach my $s ( @status ) { my $ok_label = ( $s->{is_ok} eq 'yes' ) ? 'OK' : 'NOT OK'; print "Status OK? $s->{is_ok}\n", "$s->{message}\n"; } =head1 REQUIRED OPTIONS =over 4 =item B<scope>=(user|group|world) Scope of security you're setting =item B<scope_id>=ID of 'scope' Scope ID of security you're setting. Not used with 'world' scope. =item B<action>=action-name The name of the action class to which you're adding/modifying security. For instance, 'news' if you're trying to set security to the 'OpenInteract2::Action::News' class. For a list of actions see L<OpenInteract2::Manage::Website::ListActions>, or just run C<oi2_manage list_actions>. =back =head1 STATUS INFORMATION Each status hashref includes: =over 4 =item B<is_ok> Set to 'yes' if the task succeeded, 'no' if not. =item B<message> Success/failure message. =back =head1 SEE ALSO L<OpenInteract2::Manage::Website::CreateSecurity> L<OpenInteract2::CreateSecurity> =head1 COPYRIGHT Copyright (C) 2003-2004 Chris Winters. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHORS Chris Winters E<lt>ch...@cw...E<gt> --- NEW FILE: CreateSecurityForSPOPS.pm --- package OpenInteract2::Manage::Website::CreateSecurityForSPOPS; # $Id: CreateSecurityForSPOPS.pm,v 1.1 2005/03/04 02:50:01 lachoy Exp $ use strict; use base qw( OpenInteract2::Manage::Website::CreateSecurity ); $OpenInteract2::Manage::Website::CreateSecurityForSPOPS::VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); # METADATA sub get_name { return 'secure_spops'; } sub get_brief_description { return "Create security settings for multiple SPOPS objects at once."; } sub get_parameters { my ( $self ) = @_; my $params = $self->SUPER::get_parameters(); $params->{spops} = { description => "SPOPS object tag for class you'd like to set security", is_required => 'yes', }; $params->{where} = { description => "A 'where' clause to restrict the objects for which you'll set security", is_required => 'no', }; return $params; } sub _assign_create_params { my ( $self, $creator ) = @_; $creator->spops( $self->param( 'spops' ) ); $creator->where( $self->param( 'where' ) ); } OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ ); 1; __END__ =head1 NAME OpenInteract2::Manage::Website::CreateSecurityForSPOPS - Create security for multiple SPOPS objects =head1 SYNOPSIS #!/usr/bin/perl use strict; use OpenInteract2::Manage; my $website_dir = '/home/httpd/mysite'; my %PARAMS = ( scope => 'group', scope_id => 4, spops => 'news', level => 'read', website_dir => $website_dir, ); my $task = OpenInteract2::Manage->new( 'secure_spops', \%PARAMS ); my @status = $task->execute; foreach my $s ( @status ) { my $ok_label = ( $s->{is_ok} eq 'yes' ) ? 'OK' : 'NOT OK'; print "Status OK? $s->{is_ok}\n", "$s->{message}\n"; } =head1 REQUIRED OPTIONS =over 4 =item B<scope>=(user|group|world) Scope of security you're setting =item B<scope_id>=ID of 'scope' Scope ID of security you're setting. Ignored with 'world' scope. =item B<spops>=object-key The key used for the SPOPS objects you're trying to add security to. For instance you'd use 'news' if you're trying to add security to 'OpenInteract2::News' objects. =item B<where>=WHERE-clause If you want to restrict the objects you assign security to pass in a WHERE clause. For instance, if you want to only set security for objects created this year: oi2_manage create_spops_security ... --where "posted_on >= '2005-01-01'" =back =head1 STATUS INFORMATION Each status hashref includes: =over 4 =item B<is_ok> Set to 'yes' if the task succeeded, 'no' if not. =item B<message> Success/failure message. =back =head1 SEE ALSO L<OpenInteract2::CreateSecurity|OpenInteract2::CreateSecurity> =head1 COPYRIGHT Copyright (C) 2003-2004 Chris Winters. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHORS Chris Winters E<lt>ch...@cw...E<gt> Index: CreateSecurity.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Manage/Website/CreateSecurity.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CreateSecurity.pm 13 Jun 2004 18:19:54 -0000 1.4 --- CreateSecurity.pm 4 Mar 2005 02:50:01 -0000 1.5 *************** *** 12,25 **** $OpenInteract2::Manage::Website::CreateSecurity::VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/); - # METADATA - - sub get_name { - return 'create_security'; - } - - sub get_brief_description { - return "Create security settings for multiple SPOPS objects at once."; - } - sub get_parameters { my ( $self ) = @_; --- 12,15 ---- *************** *** 41,49 **** is_required => 'yes', }, - spops => { - description => - "SPOPS object tag for class you'd like to set security", - is_required => 'yes', - } }; } --- 31,34 ---- *************** *** 60,75 **** $self->_setup_context; my $creator = OpenInteract2::CreateSecurity->new({ ! scope => $self->param( 'scope' ), ! scope_id => $self->param( 'scope_id' ), ! level => $self->param( 'level' ), ! class => $self->param( 'spops' ), ! website_dir => $self->param( 'website_dir' ), }); unless ( $creator->validate ) { my $errors = $creator->errors_with_params; - if ( $errors->{class} ) { - $errors->{spops} = $errors->{class}; - delete $errors->{class}; - } oi_param_error "One or more parameters were invalid", { parameter_fail => $errors }; --- 45,56 ---- $self->_setup_context; my $creator = OpenInteract2::CreateSecurity->new({ ! scope => $self->param( 'scope' ), ! scope_id => $self->param( 'scope_id' ), ! level => $self->param( 'level' ), ! website_dir => $self->param( 'website_dir' ), }); + $self->_assign_create_params( $creator ); unless ( $creator->validate ) { my $errors = $creator->errors_with_params; oi_param_error "One or more parameters were invalid", { parameter_fail => $errors }; *************** *** 78,81 **** --- 59,67 ---- } + sub _assign_create_params { + my ( $self ) = @_; + oi_error ref( $self ), " must implement '_assign_create_params()'"; + } + # RUN *************** *** 88,92 **** my ( $self ) = @_; my $creator = $self->param( 'creator' ); ! my $count = $creator->run; my $msg = join( '', "Processed ", $creator->num_processed, " and ", "encountered ", $creator->num_failed, " failures. " ); --- 74,78 ---- my ( $self ) = @_; my $creator = $self->param( 'creator' ); ! $creator->run; my $msg = join( '', "Processed ", $creator->num_processed, " and ", "encountered ", $creator->num_failed, " failures. " ); *************** *** 94,99 **** } - OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ ); - 1; --- 80,83 ---- *************** *** 113,120 **** my $website_dir = '/home/httpd/mysite'; my %PARAMS = ( ! scope => 4, ! scope_id => 4, ! spops => 'news', ! level => 'read', website_dir => $website_dir, ); --- 97,104 ---- my $website_dir = '/home/httpd/mysite'; my %PARAMS = ( ! scope => 'group', ! scope_id => 4, ! spops => 'news', ! level => 'read', website_dir => $website_dir, ); *************** *** 138,142 **** =item B<scope_id>=ID of 'scope' ! Scope ID of security you're setting. Not used with 'world' scope. =item B<spops>=object-key --- 122,126 ---- =item B<scope_id>=ID of 'scope' ! Scope ID of security you're setting. Ignored with 'world' scope. =item B<spops>=object-key *************** *** 166,171 **** =head1 SEE ALSO ! L<OpenInteract2::CreateSecurity|OpenInteract2::CreateSecurity> (in ! 'base_security' package) =head1 COPYRIGHT --- 150,154 ---- =head1 SEE ALSO ! L<OpenInteract2::CreateSecurity|OpenInteract2::CreateSecurity> =head1 COPYRIGHT |