User: sits    
  Date: 06/06/11 00:54:02

  Modified:    lib      Codestriker.pm
               lib/Codestriker/Action SubmitEditTopicProperties.pm
               lib/Codestriker/TopicListeners BugTracking.pm Manager.pm
                        TopicListener.pm
  Log:
  Introduced a new topic listener callback topic_pre_changed which can
  stop a topic's properties being changed.  This hook is used by
  BugTracking.pm, in the case where the topic's bug ID is changed
  to an invalid bug ID.
  
  
  
  Index: Codestriker.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker.pm,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- Codestriker.pm    10 Jun 2006 02:58:33 -0000      1.91
  +++ Codestriker.pm    11 Jun 2006 07:54:01 -0000      1.92
  @@ -53,6 +53,7 @@
   $Codestriker::DUPLICATE_PROJECT_NAME = 5;
   $Codestriker::UNSUPPORTED_OPERATION = 6;
   $Codestriker::DIFF_TOO_BIG = 7;
  +$Codestriker::LISTENER_ABORT = 8;
   
   # Revision number constants used in the filetable with special meanings.
   $Codestriker::ADDED_REVISION = "1.0";
  
  
  
  
  
  Index: SubmitEditTopicProperties.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Action/SubmitEditTopicProperties.pm,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SubmitEditTopicProperties.pm      20 Apr 2006 23:51:34 -0000      1.12
  +++ SubmitEditTopicProperties.pm      11 Jun 2006 07:54:01 -0000      1.13
  @@ -44,11 +44,6 @@
       # Retrieve the current state of the topic.
       my $topic = Codestriker::Model::Topic->new($topicid);
   
  -    # Create a clone of this topic, which will contain the original state of
  -    # the topic, used for the topic listeners below.  Note we should really
  -    # have a clone() method but for now... XXX.
  -    my $topic_orig = Codestriker::Model::Topic->new($topicid);
  -
       my $feedback = "";
       my $rc = $Codestriker::OK;
   
  @@ -91,6 +86,12 @@
       }
   
       if ($feedback eq "") {
  +     # Create a clone of this topic, which will contain the
  +     # original state of the topic, and the proposed new state,
  +     # used for the topic listeners below.
  +     my $topic_orig = Codestriker::Model::Topic->new($topicid);
  +     my $topic_new = Codestriker::Model::Topic->new($topicid);
  +
        if ($topic_state eq "Deleted") {
            $rc = $topic->delete();
            if ($rc == $Codestriker::INVALID_TOPIC) {
  @@ -109,24 +110,48 @@
            return;
        }
        else {
  -         # The input looks good, update the database.
  -         $rc = $topic->update($topic_title, $author, $reviewers, $cc,
  -                              $repository_url, $bug_ids, $projectid,
  -                              $topic_description, $topic_state);
  -         if ($rc == $Codestriker::INVALID_TOPIC) {
  -             $feedback .= "Topic no longer exists.\n";
  -         } elsif ($rc == $Codestriker::STALE_VERSION) {
  -             $feedback .=
  -                 "Topic was modified by another user, no changes done.\n";
  -         } elsif ($rc == $Codestriker::OK) {
  -             $feedback .= "Topic properties successfully updated.\n";
  +         # Set the fields into the new topic object for checking.
  +         $topic_new->{title} = $topic_title;
  +         $topic_new->{author} = $author;
  +         $topic_new->{reviewers} = $reviewers;
  +         $topic_new->{cc} = $cc;
  +         $topic_new->{repository} = $repository_url;
  +         $topic_new->{bug_ids} = $bug_ids;
  +         $topic_new->{project_id} = $projectid;
  +         $topic_new->{description} = $topic_description;
  +         $topic_new->{topic_state} = $topic_state;
  +
  +         # Make sure all the topic listeners are happy with this change
  +         # before allowing it.
  +         $feedback =
  +             Codestriker::TopicListeners::Manager::topic_pre_changed($email,
  +                                                                     
$topic_orig,
  +                                                                     
$topic_new);
  +         if ($feedback eq '') {
  +             # Topic listeners are happy with this change.
  +             $rc = $topic->update($topic_title, $author, $reviewers, $cc,
  +                                  $repository_url, $bug_ids, $projectid,
  +                                  $topic_description, $topic_state);
  +             if ($rc == $Codestriker::INVALID_TOPIC) {
  +                 $feedback .= "Topic no longer exists.\n";
  +             } elsif ($rc == $Codestriker::STALE_VERSION) {
  +                 $feedback .=
  +                     "Topic was modified by another user, no changes 
done.\n";
  +             } elsif ($rc == $Codestriker::OK) {
  +                 $feedback .= "Topic properties successfully updated.\n";
  +             }
  +         }
  +         else {
  +             $rc = $Codestriker::LISTENER_ABORT;
            }
        }
   
        # Indicate to the topic listeners that the topic has changed.
  -     Codestriker::TopicListeners::Manager::topic_changed($email,
  -                                                         $topic_orig,
  -                                                         $topic);
  +     if ($rc == $Codestriker::OK) {
  +         Codestriker::TopicListeners::Manager::topic_changed($email,
  +                                                             $topic_orig,
  +                                                             $topic);
  +     }
       }
   
       # Direct control to the appropriate action class, depending on the result
  
  
  
  
  
  Index: BugTracking.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/TopicListeners/BugTracking.pm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BugTracking.pm    16 Jan 2006 21:22:59 -0000      1.3
  +++ BugTracking.pm    11 Jun 2006 07:54:01 -0000      1.4
  @@ -78,6 +78,29 @@
       return '';
   }
   
  +# If the bugids have been changed, make sure they exist in the bug database.
  +sub topic_pre_changed($$$) {
  +    my ($self, $user, $topic_orig, $topic) = @_;
  +
  +    my $feedback = '';
  +    if ($topic_orig->{bug_ids} ne $topic->{bug_ids}) {
  +     # Make sure that the new bug IDs specified are valid, if they have
  +     # changed.
  +     my @bug_ids = split /, /, $topic->{bug_ids};
  +     my $bug_db_connection =
  +         Codestriker::BugDB::BugDBConnectionFactory->getBugDBConnection();
  +     foreach my $bug_id (@bug_ids) {
  +         if (!$bug_db_connection->bugid_exists($bug_id)) {
  +             $feedback .= "Bug ID $bug_id does not exist.\n";
  +         }
  +     }
  +     $bug_db_connection->release_connection();
  +    }
  +    
  +    return $feedback;
  +}
  +
  +
   sub topic_changed($$$$) {
       my ($self, $user, $topic_orig, $topic) = @_;
   
  
  
  
  
  
  Index: Manager.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/TopicListeners/Manager.pm,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Manager.pm        16 Jan 2006 21:22:59 -0000      1.7
  +++ Manager.pm        11 Jun 2006 07:54:01 -0000      1.8
  @@ -51,6 +51,23 @@
       return $returnValue;
   }
   
  +sub topic_pre_changed {
  +    _create_listeners();
  +    
  +    # Call all of the topic listeners that are created. If any of the
  +    # topic listeners return a non-empty string, it is treated as a 
  +    # request to reject the requested state change, and display the 
  +    # returned string as the user error message.
  +    my $returnValue = '';
  +    
  +    foreach my $listener (@topic_listeners) {
  +       $returnValue .= $listener->topic_pre_changed(@_);
  +       last if length($returnValue);
  +    }
  +    
  +    return $returnValue;
  +}
  +
   sub topic_changed {
       _create_listeners();
       
  
  
  
  
  
  Index: TopicListener.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/TopicListeners/TopicListener.pm,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TopicListener.pm  16 Jan 2006 21:22:59 -0000      1.7
  +++ TopicListener.pm  11 Jun 2006 07:54:01 -0000      1.8
  @@ -38,6 +38,15 @@
       return '';    
   }
   
  +sub topic_pre_changed($$$) {
  +    my ($self, $user, $topic_orig, $topic) = @_;
  +
  +    # Default version of function that does nothing, and allowed the
  +    # event to continue.
  +    
  +    return '';    
  +}
  +
   sub topic_changed($$$) {
       my ($self, $user, $topic_orig, $topic) = @_;
   
  
  
  


_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits

Reply via email to