| 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 a project.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Action::SubmitEditProject;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
|
|
|
14 |
use Codestriker;
|
|
|
15 |
use Codestriker::Model::Project;
|
|
|
16 |
use Codestriker::Action::ListProjects;
|
|
|
17 |
use Codestriker::Action::EditProject;
|
|
|
18 |
|
|
|
19 |
# If the input is valid, update the appropriate project into the database.
|
|
|
20 |
sub process($$$) {
|
|
|
21 |
my ($type, $http_input, $http_response) = @_;
|
|
|
22 |
|
|
|
23 |
# Check if this operation is allowed.
|
|
|
24 |
if (Codestriker->projects_disabled()) {
|
|
|
25 |
$http_response->error("This function has been disabled");
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
my $query = $http_response->get_query();
|
|
|
29 |
|
|
|
30 |
my $project_state = $http_input->get('project_state');
|
|
|
31 |
|
|
|
32 |
# Check that the state parameter is valid.
|
|
|
33 |
my $found = 0;
|
|
|
34 |
foreach my $state (@Codestriker::project_states) {
|
|
|
35 |
if ($project_state eq $state) {
|
|
|
36 |
$found = 1;
|
|
|
37 |
last;
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
if (!$found) {
|
|
|
41 |
$http_response->error("Invalid project state: $project_state");
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
# Check if this action is allowed.
|
|
|
45 |
if ($project_state eq "Deleted") {
|
|
|
46 |
$http_response->error("This function has been disabled");
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
# Check that the appropriate fields have been filled in.
|
|
|
50 |
my $id = $http_input->get('projectid');
|
|
|
51 |
my $name = $http_input->get('project_name');
|
|
|
52 |
my $description = $http_input->get('project_description');
|
|
|
53 |
my $version = $http_input->get('version');
|
|
|
54 |
|
|
|
55 |
my $feedback = "";
|
|
|
56 |
|
|
|
57 |
if ($name eq "") {
|
|
|
58 |
$feedback .= "No project name was entered.\n";
|
|
|
59 |
}
|
|
|
60 |
if ($description eq "") {
|
|
|
61 |
$feedback .= "No project description was entered.\n";
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
# Try to update the project in the model.
|
|
|
65 |
if ($feedback eq "") {
|
|
|
66 |
my $rc;
|
|
|
67 |
|
|
|
68 |
if ($project_state eq "Deleted")
|
|
|
69 |
{
|
|
|
70 |
$rc =
|
|
|
71 |
Codestriker::Model::Project->delete($id, $version);
|
|
|
72 |
}
|
|
|
73 |
else
|
|
|
74 |
{
|
|
|
75 |
$rc =
|
|
|
76 |
Codestriker::Model::Project->update($id, $name, $description,
|
|
|
77 |
$version, $project_state);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
if ($rc == $Codestriker::INVALID_PROJECT) {
|
|
|
81 |
$feedback .=
|
|
|
82 |
"Project with name \"$name\" doesn't exist.\n";
|
|
|
83 |
} elsif ($rc == $Codestriker::STALE_VERSION) {
|
|
|
84 |
$feedback .=
|
|
|
85 |
"Project was modified by another user.\n";
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
# If there was a problem, direct control back to the edit project
|
|
|
90 |
# screen, otherwise go to the project list screen.
|
|
|
91 |
if ($feedback ne "") {
|
|
|
92 |
$http_input->{feedback} = $feedback;
|
|
|
93 |
} else {
|
|
|
94 |
$http_input->{feedback} = "Project updated.\n";
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
if ($project_state ne "Deleted")
|
|
|
98 |
{
|
|
|
99 |
Codestriker::Action::EditProject->process($http_input,
|
|
|
100 |
$http_response);
|
|
|
101 |
}
|
|
|
102 |
else
|
|
|
103 |
{
|
|
|
104 |
Codestriker::Action::ListProjects->process($http_input,
|
|
|
105 |
$http_response);
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
1;
|