[Rt-commit] r12522 - in rt/branches/3.999-DANGEROUS: lib/RT/Model

jesse at bestpractical.com jesse at bestpractical.com
Mon May 19 05:59:47 EDT 2008


Author: jesse
Date: Mon May 19 05:59:45 2008
New Revision: 12522

Modified:
   rt/branches/3.999-DANGEROUS/   (props changed)
   rt/branches/3.999-DANGEROUS/lib/RT/Model/Queue.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Model/Ticket.pm

Log:
 r31728 at 31b:  jesse | 2008-05-19 17:59:24 +0800
 minro role refactor


Modified: rt/branches/3.999-DANGEROUS/lib/RT/Model/Queue.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Model/Queue.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Model/Queue.pm	Mon May 19 05:59:45 2008
@@ -372,7 +372,7 @@
         return ( 0, _('Queue could not be Created') );
     }
 
-    my $create_ret = $self->create_queue_groups();
+    my $create_ret = $self->_create_role_groups();
     unless ($create_ret) {
         Jifty->handle->rollback();
         return ( 0, _('Queue could not be Created') );
@@ -616,10 +616,6 @@
 
 # }}}
 
-# {{{ Routines dealing with watchers.
-
-# {{{ _createQueueGroups
-
 =head2 _createQueueGroups
 
 Create the ticket groups and links for this ticket. 
@@ -629,13 +625,15 @@
 
 It will return true on success and undef on failure.
 
-
 =cut
 
-sub create_queue_groups {
+
+sub roles { qw(requestor cc admin_cc) }
+
+sub _create_role_groups {
     my $self = shift;
 
-    my @types = qw(requestor owner cc admin_cc);
+    my @types = ('owner', $self->roles);
 
     foreach my $type (@types) {
         my $type_obj = RT::Model::Group->new;
@@ -645,10 +643,7 @@
             domain   => 'RT::Model::Queue-Role'
         );
         unless ($id) {
-            Jifty->log->error(
-                "Couldn't create a queue group of type '$type' for ticket "
-                    . $self->id . ": "
-                    . $msg );
+            Jifty->log->error( "Couldn't create a queue group of type '$type' for ticket " . $self->id . ": " . $msg );
             return (undef);
         }
     }
@@ -656,11 +651,7 @@
 
 }
 
-# }}}
-
-# {{{ sub AddWatcher
-
-=head2 AddWatcher
+=head2 add_watcher
 
 AddWatcher takes a parameter hash. The keys are as follows:
 
@@ -703,9 +694,7 @@
 
         #  If it's a Requestor or Cc and they don't have
         #   'Watch' or 'ModifyTicket', bail
-        elsif (( $args{'type'} eq 'cc' )
-            or ( $args{'type'} eq 'requestor' ) )
-        {
+        elsif (( $args{'type'} eq 'cc' ) or ( $args{'type'} eq 'requestor' ) ) {
 
             unless ( $self->current_user_has_right('ModifyQueueWatchers')
                 or $self->current_user_has_right('Watch') )

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Model/Ticket.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Model/Ticket.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Model/Ticket.pm	Mon May 19 05:59:45 2008
@@ -503,7 +503,8 @@
 
 # We attempt to load or create each of the people who might have a role for this ticket
 # _outside_ the transaction, so we don't get into ticket creation races
-    foreach my $type ( "cc", "admin_cc", "requestor" ) {
+    foreach my $type ( $self->roles) {
+
         $args{$type} = [ $args{$type} ] unless ref $args{$type};
         foreach my $watcher ( splice @{ $args{$type} } ) {
             next unless $watcher;
@@ -603,7 +604,7 @@
 
     # {{{ Deal with setting up watchers
 
-    foreach my $type ( "cc", "admin_cc", "requestor" ) {
+    foreach my $type ($self->roles) {
 
         # we know it's an array ref
         foreach my $watcher ( @{ $args{$type} } ) {
@@ -693,12 +694,7 @@
                 type => $LINKTYPEMAP{$type}->{'type'},
                 $LINKTYPEMAP{$type}->{'Mode'} => $link,
                 silent => !$args{'_record_transaction'},
-                'silent_'
-                    . (
-                    $LINKTYPEMAP{$type}->{'Mode'} eq 'base'
-                    ? 'target'
-                    : 'base'
-                    ) => 1,
+                'silent_' . ( $LINKTYPEMAP{$type}->{'Mode'} eq 'base' ? 'target' : 'base') => 1,
             );
 
             push @non_fatal_errors, $wmsg unless ($wval);
@@ -804,12 +800,11 @@
 
 =cut
 
+sub roles { return ( "cc", "admin_cc", "requestor" ) ;}
 sub _create_role_groups {
     my $self = shift;
 
-    my @types = qw(requestor owner cc admin_cc);
-
-    foreach my $type (@types) {
+    foreach my $type ('owner', $self->roles) {
         my $type_obj = RT::Model::Group->new;
         my ( $id, $msg ) = $type_obj->create_role_group(
             domain   => 'RT::Model::Ticket-Role',
@@ -836,12 +831,9 @@
 
 sub role_group {
     my $self      = shift;
-    my $obj = RT::Model::Group->new;
     my $role = shift;
-    $obj->load_ticket_role_group(
-        ticket => $self->id,
-        type   => $role
-    );
+    my $obj = RT::Model::Group->new;
+    $obj->load_ticket_role_group( ticket => $self->id, type   => $role);
     return ($obj);
 }
 
@@ -2295,7 +2287,7 @@
     }
 
     #add all of this ticket's watchers to that ticket.
-    foreach my $watcher_type qw(requestor cc admin_cc) {
+    foreach my $watcher_type ($self->roles) {
 
         my $people          = $self->role_group($watcher_type)->members_obj;
 


More information about the Rt-commit mailing list