[Bps-public-commit] RT-BugTracker branch, master, updated. 3e774a2a9760eaba350ad9aa770ac6390e731267

Thomas Sibley trs at bestpractical.com
Thu May 30 02:15:36 EDT 2013


The branch, master has been updated
       via  3e774a2a9760eaba350ad9aa770ac6390e731267 (commit)
       via  9dc3eae102b4d608a4579c78dbb563292a4018cd (commit)
      from  d3d379c8bd1139ce762abed8d24f908a3be7b969 (commit)

Summary of changes:
 etc/BugTracker_Config.pm          | 11 +++++
 etc/upgrade/subject-tags/content  | 19 +++++++++
 html/Dist/Elements/EditSubjectTag |  8 +++-
 lib/RT/BugTracker.pm              | 88 ++++++++++++++-------------------------
 4 files changed, 68 insertions(+), 58 deletions(-)
 create mode 100644 etc/BugTracker_Config.pm
 create mode 100644 etc/upgrade/subject-tags/content

- Log -----------------------------------------------------------------
commit 9dc3eae102b4d608a4579c78dbb563292a4018cd
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed May 29 23:14:16 2013 -0700

    Reimplement distribution subject tags that work on 4.0
    
    Requires an upgrade:
    
        sbin/rt-setup-database --action insert --datafile etc/upgrade/subject-tags/content

diff --git a/etc/BugTracker_Config.pm b/etc/BugTracker_Config.pm
new file mode 100644
index 0000000..c9fae3d
--- /dev/null
+++ b/etc/BugTracker_Config.pm
@@ -0,0 +1,11 @@
+# If you use a custom EmailSubjectTagRegex already, it's recommended to copy
+# these lines into your own RT_SiteConfig.pm.
+
+Set( $DistributionSubjectTagAllowed, qr/[a-z0-9 ._-]/i );
+Set( $EmailSubjectTagRegex, qr/$EmailSubjectTagRegex(?:\s+$DistributionSubjectTagAllowed+)?/ );
+
+# Necessary because RT_Config.pm's default is evaluated before we change the
+# regex above.
+Set( $ExtractSubjectTagNoMatch, qr/\[$EmailSubjectTagRegex #\d+\]/ );
+
+1;
diff --git a/etc/upgrade/subject-tags/content b/etc/upgrade/subject-tags/content
new file mode 100644
index 0000000..65dd7b2
--- /dev/null
+++ b/etc/upgrade/subject-tags/content
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+our @Initial = (sub {
+    my $attributes = RT::Attributes->new(RT->SystemUser);
+    $attributes->Limit( FIELD => "ObjectType", VALUE => "RT::Queue" );
+    $attributes->Limit( FIELD => "Name", VALUE => "SubjectTag" );
+    while (my $attr = $attributes->Next) {
+        my $tag   = $attr->Content;
+        my $queue = $attr->Object;
+        RT->Logger->info("Migrating tag '$tag' for queue @{[$queue->Name]}");
+        my ($ok, $msg) = $queue->SetSubjectTag($tag);
+        unless ($ok) {
+            RT->Logger->error("Unable to set subject tag for queue @{[$queue->Name]}: $msg");
+            next;
+        }
+        $attr->Delete;
+    }
+});
diff --git a/html/Dist/Elements/EditSubjectTag b/html/Dist/Elements/EditSubjectTag
index 45abb07..6a9e035 100644
--- a/html/Dist/Elements/EditSubjectTag
+++ b/html/Dist/Elements/EditSubjectTag
@@ -1,5 +1,5 @@
 <label class="dist-subjecttag"><% loc('Subject tag in addition to default') %>
-(<% loc('be reasonable') %>):
+(<% loc('be reasonable') %>, <code><% RT->Config->Get("DistributionSubjectTagAllowed") %></code> is allowed, <code>rt.cpan.org</code> will be prepended):
 <input size="120" name="Queue-<% $Queue->id %>-SubjectTag" value="<% $value || '' %>" /></label><br />
 <%ARGS>
 $Queue => undef
@@ -18,7 +18,11 @@ my $value = $ARGS{'Queue-'. $Queue->id .'-SubjectTag'};
 
 return () if ($Queue->SubjectTag || '') eq ($value || '');
 
-my ($status, $msg) = $Queue->SetSubjectTag( $value );
+my $QueueAsSystem = RT::Queue->new( RT->SystemUser );
+$QueueAsSystem->Load($Queue->id);
+return () if not $QueueAsSystem->id == $Queue->id;
+
+my ($status, $msg) = $QueueAsSystem->SetSubjectTag( $value );
 return $msg;
 </%INIT>
 </%METHOD>
diff --git a/lib/RT/BugTracker.pm b/lib/RT/BugTracker.pm
index 3643e2e..618d447 100644
--- a/lib/RT/BugTracker.pm
+++ b/lib/RT/BugTracker.pm
@@ -172,30 +172,30 @@ sub SetNotifyAddresses {
     );
 }
 
-# XXX: should go with 3.8 port
-sub SubjectTagRE {
-    return qr/[a-z0-9 ._-]/i;
-}
-
-{
-no warnings 'redefine';
-sub SubjectTag {
-    return (shift)->_AttributeBasedField(
-        SubjectTag => @_
-    ) || '';
-}
+{ no warnings 'redefine';
 sub SetSubjectTag {
     my ($self, $value) = (shift, shift);
-    if ( defined $value ) {
-        my $re = $self->SubjectTagRE;
-        return (0, $self->loc("Invalid characters in SubjectTag"))
-            unless $value =~ /^$re*$/;
+    if ( defined $value and length $value ) {
+        $value =~ s/(^\s+|\s+$)//g;
+
+        unless ($value =~ /^\Q$RT::rtname\E\b/) {
+            # Prepend the $rtname before we get into the database so we don't
+            # have to munge it on the way out.
+            $value = "$RT::rtname $value";
+        }
+
+        # We just prepended the $rtname if necessary, so the full subject tag
+        # regex should match.  If it doesn't, the subject tag contains
+        # prohibited characters (or we have a bug, but catching that is good so
+        # we don't mishandle incoming mail).
+        my $re = RT->Config->Get("EmailSubjectTagRegex");
+        unless ($value =~ /^$re$/) {
+            RT->Logger->warning("Subject tag for queue @{[$self->Name]} contains prohibited characters: '$value'");
+            return (0, $self->loc("Subject tag contains prohibited characters"));
+        }
     }
-    return $self->_SetAttributeBasedField(
-        SubjectTag => $value, @_
-    );
-}
-}
+    return $self->_Set( Field => 'SubjectTag', Value => $value );
+}}
 
 sub _AttributeBasedField {
     my $self = shift;
@@ -234,31 +234,6 @@ sub _SetAttributeBasedField {
     return ( 1, $self->loc("[_1] changed", $self->loc($name)) );
 }
 
-require RT::Action::SendEmail;
-package RT::Action::SendEmail;
-
-my $tag_re = RT::Queue->SubjectTagRE;
-$RT::EmailSubjectTagRegex = qr/\Q$RT::rtname\E(?:\s+$tag_re+)?/;
-
-no warnings 'redefine';
-my $old = \&SetSubjectToken;
-*RT::Action::SendEmail::SetSubjectToken = sub {
-    my $self = shift;
-    $old->($self, @_);
-
-    my $tag = $self->TicketObj->QueueObj->SubjectTag;
-    return unless defined $tag && length $tag;
-
-    my $id = $self->TicketObj->id;
-    my $head = $self->TemplateObj->MIMEObj->head;
-    my $subject = $head->get('Subject');
-    my $tmp = $subject;
-    $tmp =~ s{\[\Q$RT::rtname\E\s+#$id\]}{[$RT::rtname $tag #$id]}i;
-    return if $tmp eq $subject;
-
-    $head->replace( Subject => $tmp );
-};
-
 =head1 SEE ALSO
 
 L<RT::BugTracker::Public>, L<RT::Extension::rt_cpan_org>

commit 3e774a2a9760eaba350ad9aa770ac6390e731267
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed May 29 23:15:20 2013 -0700

    Clean up some POD, add authors, bump version to match RT major version

diff --git a/lib/RT/BugTracker.pm b/lib/RT/BugTracker.pm
index 618d447..9adceae 100644
--- a/lib/RT/BugTracker.pm
+++ b/lib/RT/BugTracker.pm
@@ -52,7 +52,7 @@ use warnings;
 package RT::BugTracker;
 
 use 5.008003;
-our $VERSION = '0.06_01';
+our $VERSION = '4.0';
 
 =head1 NAME
 
@@ -60,12 +60,11 @@ RT::BugTracker - Adds a UI designed for bug-tracking for developers to RT
 
 =head1 DESCRIPTION
 
-This extension changes RT's UI to make more useful when you want to
-track bug reports in many distributions. This extension is a start
-for setups like L<http://rt.cpan.org>. It's been developed to help
-authors of perl modules.
+This extension changes RT's interface to be more useful when you want to track
+bug reports in many distributions. This extension is a start for setups like
+L<http://rt.cpan.org>. It's been developed to help authors of Perl modules.
 
-It follows several rules to achieve the goal:
+It follows two basic rules to achieve the goal:
 
 =over 4
 
@@ -74,10 +73,6 @@ It follows several rules to achieve the goal:
 =item Queue's AdminCc list is used for maintainers of the
 coresponding distribution.
 
-=item Not everything was possible to implement using callbacks
-and other clean extending methods, so some files have been
-overriden. We currently in sync with RT 3.6.6.
-
 =back
 
 =cut
@@ -240,6 +235,12 @@ L<RT::BugTracker::Public>, L<RT::Extension::rt_cpan_org>
 
 =head1 AUTHOR
 
+Thomas Sibley E<lt>trs at bestpractical.comE<gt>
+
+Ruslan Zaikarov E<lt>ruz at bestpractical.comE<gt>
+
+sunnavy E<lt>sunnavy at bestpractical.comE<gt>
+
 Kevin Riggle E<lt>kevinr at bestpractical.comE<gt>
 
 =head1 LICENSE

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list