[Rt-commit] r17933 - in rt/3.999/branches/merge_to_3.8.2: . lib/RT lib/RT/Approval/Rule
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Tue Jan 27 06:59:10 EST 2009
Author: sunnavy
Date: Tue Jan 27 06:59:08 2009
New Revision: 17933
Added:
rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/
rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval.pm
rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/
rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule.pm
rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Created.pm
rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/NewPending.pm
rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Passed.pm
rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Rejected.pm
Modified:
rt/3.999/branches/merge_to_3.8.2/ (props changed)
Log:
r19069 at sunnavys-mb: sunnavy | 2009-01-27 19:52:55 +0800
added lib/RT/Approval* and case fixes
Added: rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval.pm Tue Jan 27 06:59:08 2009
@@ -0,0 +1,64 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+# <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+package RT::Approval;
+use strict;
+use warnings;
+
+use RT::Ruleset;
+
+RT::Ruleset->add(
+ name => 'Approval',
+ rules => [
+ 'RT::Approval::Rule::NewPending',
+ 'RT::Approval::Rule::Rejected',
+ 'RT::Approval::Rule::Passed',
+ 'RT::Approval::Rule::Created',
+ ]);
+
+1;
Added: rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule.pm Tue Jan 27 06:59:08 2009
@@ -0,0 +1,75 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+# <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+package RT::Approval::Rule;
+use strict;
+use warnings;
+
+use base 'RT::Rule';
+
+use constant _Queue => '___Approvals';
+
+sub prepare {
+ my $self = shift;
+ return unless $self->SUPER::prepare();
+ $self->ticket_obj->type eq 'approval';
+}
+
+sub get_template {
+ my ($self, $template_name, %args) = @_;
+ my $template = RT::Template->new( current_user => $self->CurrentUser);
+ $template->load($template_name) or return;
+ my ($result, $msg) = $template->parse(%args);
+
+ # XXX: error handling
+
+ return $template;
+}
+
+1;
+
Added: rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Created.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Created.pm Tue Jan 27 06:59:08 2009
@@ -0,0 +1,71 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+# <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+package RT::Approval::Rule::Created;
+use strict;
+use warnings;
+use base 'RT::Approval::Rule';
+
+use constant _Stage => 'TransactionBatch';
+
+use constant Description => "Notify Owner of their ticket has been approved by some or all approvers"; # loc
+
+sub prepare {
+ my $self = shift;
+ return unless $self->SUPER::prepare();
+
+ $self->transaction_obj->type eq 'Create' &&
+ !$self->ticket_obj->has_unresolved_dependencies( type => 'approval' );
+}
+
+sub commit {
+ my $self = shift;
+ $self->run_scrip_action('Open Tickets' => 'Blank');
+}
+
+1;
Added: rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/NewPending.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/NewPending.pm Tue Jan 27 06:59:08 2009
@@ -0,0 +1,96 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+# <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+package RT::Approval::Rule::NewPending;
+use strict;
+use warnings;
+use base 'RT::Approval::Rule';
+
+use constant Description => "When an approval ticket is created, notify the Owner and AdminCc of the item awaiting their approval"; # loc
+
+sub prepare {
+ my $self = shift;
+ return unless $self->SUPER::prepare();
+
+ $self->on_status_change('open') and
+ eval { $T::Approving = ($self->ticket_obj->all_depended_on_by( type => 'ticket' ))[0] }
+}
+
+sub commit {
+ my $self = shift;
+ my ($top) = $self->ticket_obj->all_depended_on_by( type => 'ticket' );
+ my $t = $self->ticket_obj->transactions;
+ my $to;
+ while ( my $o = $t->next ) {
+ $to = $o, last if $o->type eq 'Create';
+ }
+
+ # XXX: this makes the owner incorrect so notify owner won't work
+ # local $self->{ticket_obj} = $top;
+
+ # first txn entry of the approval ticket
+ local $self->{transaction_obj} = $to;
+ $self->run_scrip_action('Notify Owner', 'New Pending Approval', @_);
+
+ return;
+
+ # this generates more correct content of the message, but not sure
+ # if ccmessageto is the right way to do this.
+ my $template = $self->get_template('New Pending Approval',
+ ticket_obj => $top,
+ transaction_obj => $to)
+ or return;
+
+ my ( $result, $msg ) = $template->parse(
+ ticket_obj => $top,
+ );
+ $self->ticket_obj->comment( cc_message_to => $self->ticket_obj->owner_obj->email, mime_obj => $template->mime_obj );
+
+}
+
+1;
Added: rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Passed.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Passed.pm Tue Jan 27 06:59:08 2009
@@ -0,0 +1,101 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+# <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+package RT::Approval::Rule::Passed;
+use strict;
+use warnings;
+use base 'RT::Approval::Rule';
+
+use constant Description => "Notify Owner of their ticket has been approved by some or all approvers"; # loc
+
+sub prepare {
+ my $self = shift;
+ return unless $self->SUPER::prepare();
+
+ $self->on_status_change('resolved');
+}
+
+sub commit {
+ my $self = shift;
+ my $note;
+ my $t = $self->ticket_obj->transactions;
+
+ while ( my $o = $t->next ) {
+ next unless $o->type eq 'Correspond';
+ $note .= $o->content . "\n" if $o->content_obj;
+ }
+ my ($top) = $self->ticket_obj->all_depended_on_by( Type => 'ticket' );
+ my $links = $self->ticket_obj->depended_on_by;
+
+ while ( my $link = $links->next ) {
+ my $obj = $link->base_obj;
+ next unless $obj->type eq 'approval';
+ next if $obj->has_unresolved_dependencies( type => 'approval' );
+
+ $obj->set_status( status => 'open', force => 1 );
+ }
+
+ my $passed = !$top->has_unresolved_dependencies( type => 'approval' );
+ my $template = $self->get_template(
+ $passed ? 'All Approvals Passed' : 'Approval Passed',
+ ticket_obj => $top,
+ approval => $self->ticket_obj,
+ notes => $note,
+ ) or die;
+
+ $top->correspond( mime_obj => $template->mime_obj );
+
+ if ($passed) {
+ $self->run_scrip_action('Notify Owner', 'Approval Ready for Owner',
+ ticket_obj => $top);
+ }
+
+ return;
+}
+
+1;
Added: rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Rejected.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/merge_to_3.8.2/lib/RT/Approval/Rule/Rejected.pm Tue Jan 27 06:59:08 2009
@@ -0,0 +1,105 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+# <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+package RT::Approval::Rule::Rejected;
+use strict;
+use warnings;
+use base 'RT::Approval::Rule';
+
+use constant Description => "If an approval is rejected, reject the original and delete pending approvals"; # loc
+
+sub prepare {
+ my $self = shift;
+ return unless $self->SUPER::prepare();
+
+ return (0)
+ unless $self->on_status_change('rejected') or $self->on_status_change('deleted')
+}
+
+sub commit { # XXX: from custom prepare code
+ my $self = shift;
+ if ( my ($rejected) =
+ $self->ticket_obj->all_depended_on_by( type => 'ticket' ) ) {
+ my $template = $self->GetTemplate('Approval Rejected',
+ ticket_obj => $rejected,
+ approval => $self->ticket_obj,
+ notes => '');
+
+ $rejected->Correspond( mime_obj => $template->mime_obj );
+ $rejected->SetStatus(
+ status => 'rejected',
+ force => 1,
+ );
+ }
+ my $links = $self->ticket_obj->depended_on_by;
+ foreach my $link ( @{ $links->items_array_ref } ) {
+ my $obj = $link->base_obj;
+ if ( $obj->queue_obj->is_active_status( $obj->status ) ) {
+ if ( $obj->type eq 'approval' ) {
+ $obj->set_status(
+ status => 'deleted',
+ force => 1,
+ );
+ }
+ }
+ }
+
+ $links = $self->ticket_obj->depends_on;
+ foreach my $link ( @{ $links->items_array_ref } ) {
+ my $obj = $link->target_obj;
+ if ( $obj->queue_obj->is_active_status( $obj->status ) ) {
+ $obj->set_status(
+ status => 'deleted',
+ force => 1,
+ );
+ }
+ }
+
+}
+
+1;
More information about the Rt-commit
mailing list