Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
###############################################################################
2
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
3
# sits@users.sourceforge.net
4
#
5
# This program is free software; you can redistribute it and modify it under
6
# the terms of the GPL.
7
 
8
# Action object for handling the submission of editing the properties of a
9
# topic.
10
 
11
package Codestriker::Action::SubmitEditTopicProperties;
12
 
13
use strict;
14
 
15
use Codestriker::Model::Topic;
16
use Codestriker::Action::ListTopics;
17
 
18
# Attempt to change the topic's state, or to delete it.
19
sub process($$$) {
20
    my ($type, $http_input, $http_response) = @_;
21
 
22
    my $query = $http_response->get_query();
23
 
24
    # Check that the appropriate fields have been filled in.
25
    my $topicid = $http_input->get('topic');
26
    my $mode = $http_input->get('mode');
27
    my $version = $http_input->get('version');
28
    my $topic_title = $http_input->get('topic_title');
29
    my $topic_description = $http_input->get('topic_description');
30
    my $reviewers = $http_input->get('reviewers');
31
    my $email = $http_input->get('email');
32
    my $author = $http_input->get('author');
33
    my $cc = $http_input->get('cc');
34
    my $topic_state = $http_input->get('topic_state');
35
    my $bug_ids = $http_input->get('bug_ids');
36
    my $repository_name = $http_input->get('repository');
37
    my $projectid = $http_input->get('projectid');
38
 
39
    # Check if this action is allowed, and that the state is valid.
40
    if (! grep /^$topic_state$/, @Codestriker::topic_states) {
41
	$http_response->error("Topic state $topic_state unrecognised");
42
    }
43
 
44
    # Retrieve the current state of the topic.
45
    my $topic = Codestriker::Model::Topic->new($topicid);
46
 
47
    my $feedback = "";
48
    my $rc = $Codestriker::OK;
49
 
50
    # Make sure the topic being operated on is the most recent version.
51
    if ($topic->check_for_stale($version)) {
52
	$feedback .= "Topic properties have been modified by another user.";
53
    }
54
 
55
    # Check that the topic properties are valid.
56
    if ($topic_title eq "") {
57
	$feedback .= "Topic title cannot be empty.\n";
58
    }
59
    if ($topic_description eq "") {
60
	$feedback .= "Topic description cannot be empty.\n";
61
    }
62
 
63
    if ($Codestriker::antispam_email == 0) {
64
	if ($author eq "") {
65
	    $feedback .= "Author cannot be empty.\n";
66
	}
67
	if ($reviewers eq "") {
68
	    $feedback .= "Reviewers cannot be empty.\n";
69
	}
70
    } else {
71
	# Note if anti_spam email is on, don't allow the user to
72
	# change the $author, $reviewers or $cc properties.
73
	$author = $topic->{author};
74
	$reviewers = $topic->{reviewers};
75
	$cc = $topic->{cc};
76
    }
77
 
78
    # Make sure the repository value is correct.
79
    my $repository_url = '';
80
    if (defined $repository_name && $repository_name ne '') {
81
	$repository_url = $Codestriker::repository_url_map->{$repository_name};
82
	if ($repository_url eq "") {
83
	    $feedback .= "Repository name \"$repository_name\" is unknown.\n" .
84
		"Update your codestriker.conf file with this entry.\n";
85
	}
86
    }
87
 
88
    if ($feedback eq "") {
89
	# Create a clone of this topic, which will contain the
90
	# original state of the topic, and the proposed new state,
91
	# used for the topic listeners below.
92
	my $topic_orig = Codestriker::Model::Topic->new($topicid);
93
	my $topic_new = Codestriker::Model::Topic->new($topicid);
94
 
95
	if ($topic_state eq "Deleted") {
96
	    $rc = $topic->delete();
97
	    if ($rc == $Codestriker::INVALID_TOPIC) {
98
		$feedback .= "Topic no longer exists.\n";
99
	    } elsif ($rc == $Codestriker::OK) {
100
		$feedback = "Topic has been deleted.";
101
	    }
102
	}
103
	elsif ($topic_state eq "Obsoleted") {
104
	    # Redirect to the create topic screen with this topic being
105
	    # the one to obsolete.
106
	    my $url_builder = Codestriker::Http::UrlBuilder->new($query);
107
	    my $create_topic_url =
108
		$url_builder->create_topic_url("$topicid,$version");
109
	    print $query->redirect(-URI=>$create_topic_url);
110
	    return;
111
	}
112
	else {
113
	    # Set the fields into the new topic object for checking.
114
	    $topic_new->{title} = $topic_title;
115
	    $topic_new->{author} = $author;
116
	    $topic_new->{reviewers} = $reviewers;
117
	    $topic_new->{cc} = $cc;
118
	    $topic_new->{repository} = $repository_url;
119
	    $topic_new->{bug_ids} = $bug_ids;
120
	    $topic_new->{project_id} = $projectid;
121
	    $topic_new->{description} = $topic_description;
122
	    $topic_new->{topic_state} = $topic_state;
123
 
124
	    # Make sure all the topic listeners are happy with this change
125
	    # before allowing it.
126
	    $feedback =
127
		Codestriker::TopicListeners::Manager::topic_pre_changed($email,
128
									$topic_orig,
129
									$topic_new);
130
	    if ($feedback eq '') {
131
		# Topic listeners are happy with this change.
132
		$rc = $topic->update($topic_title, $author, $reviewers, $cc,
133
				     $repository_url, $bug_ids, $projectid,
134
				     $topic_description, $topic_state);
135
		if ($rc == $Codestriker::INVALID_TOPIC) {
136
		    $feedback .= "Topic no longer exists.\n";
137
		} elsif ($rc == $Codestriker::STALE_VERSION) {
138
		    $feedback .=
139
			"Topic was modified by another user, no changes done.\n";
140
		} elsif ($rc == $Codestriker::OK) {
141
		    $feedback .= "Topic properties successfully updated.\n";
142
		}
143
	    }
144
	    else {
145
		$rc = $Codestriker::LISTENER_ABORT;
146
	    }
147
	}
148
 
149
	# Indicate to the topic listeners that the topic has changed.
150
	if ($rc == $Codestriker::OK) {
151
	    Codestriker::TopicListeners::Manager::topic_changed($email,
152
								$topic_orig,
153
								$topic);
154
	}
155
    }
156
 
157
    # Direct control to the appropriate action class, depending on the result
158
    # of the above operation, and what screens are enabled. The feedback
159
    # var is not html escaped in the template, so it must be done directly
160
    # with HTML::Entities::encode if needed.
161
    $feedback =~ s/\n/<BR>/g;
162
    $http_input->{feedback} = $feedback;
163
    if ($rc == $Codestriker::INVALID_TOPIC ||
164
	($rc == $Codestriker::OK && $topic_state eq "Deleted")) {
165
	if ($Codestriker::allow_searchlist) {
166
	    # Go to the topic list screen for just open topics.
167
	    $http_input->{sstate} = "0";
168
	    Codestriker::Action::ListTopics->process($http_input,
169
						     $http_response);
170
	} else {
171
	    # Go to the create topic screen.
172
	    Codestriker::Action::CreateTopic->process($http_input,
173
						      $http_response);
174
        }
175
    } else {
176
	# Go to the view topic properties screen.
177
	Codestriker::Action::ViewTopicProperties->process($http_input,
178
							  $http_response);
179
    }	
180
}
181
 
182
1;