... | ... |
@@ -16,123 +16,124 @@ |
16 | 16 |
# Rename project |
17 | 17 |
my $git = app->git; |
18 | 18 |
my $errors; |
19 |
- my $post = lc $self->req->method eq 'post'; |
|
20 |
- if ($op eq 'rename-project' && $post) { |
|
21 |
- |
|
22 |
- # Parameters |
|
23 |
- my $to_project = param('to-project'); |
|
24 |
- |
|
25 |
- # Validator |
|
26 |
- my $vc = app->vc; |
|
27 |
- |
|
28 |
- # Validation result |
|
29 |
- my $validation = $vc->validation; |
|
30 |
- |
|
31 |
- # "to-project" check |
|
32 |
- if (!(defined $to_project && length $to_project)) { |
|
33 |
- $validation->add_failed('to-project' => 'Repository name is empty.'); |
|
34 |
- } |
|
35 |
- elsif (!$vc->check($to_project, 'project_name')) { |
|
36 |
- $validation->add_failed('to-project' => 'Repository name contains invalid charactor.'); |
|
37 |
- } |
|
38 |
- elsif (app->manager->exists_project($user, $to_project)) { |
|
39 |
- $validation->add_failed('to-project' => "$to_project is already exists"); |
|
19 |
+ if (lc $self->req->method eq 'post') { |
|
20 |
+ if ($op eq 'rename-project') { |
|
21 |
+ |
|
22 |
+ # Parameters |
|
23 |
+ my $to_project = param('to-project'); |
|
24 |
+ |
|
25 |
+ # Validator |
|
26 |
+ my $vc = app->vc; |
|
27 |
+ |
|
28 |
+ # Validation result |
|
29 |
+ my $validation = $vc->validation; |
|
30 |
+ |
|
31 |
+ # "to-project" check |
|
32 |
+ if (!(defined $to_project && length $to_project)) { |
|
33 |
+ $validation->add_failed('to-project' => 'Repository name is empty.'); |
|
34 |
+ } |
|
35 |
+ elsif (!$vc->check($to_project, 'project_name')) { |
|
36 |
+ $validation->add_failed('to-project' => 'Repository name contains invalid charactor.'); |
|
37 |
+ } |
|
38 |
+ elsif (app->manager->exists_project($user, $to_project)) { |
|
39 |
+ $validation->add_failed('to-project' => "$to_project is already exists"); |
|
40 |
+ } |
|
41 |
+ |
|
42 |
+ if ($validation->is_valid) { |
|
43 |
+ # Rename |
|
44 |
+ eval { app->manager->rename_project($user, $project, $to_project) }; |
|
45 |
+ if (my $e = $@) { |
|
46 |
+ app->log->error($e); |
|
47 |
+ $errors = ['Internal Error']; |
|
48 |
+ } |
|
49 |
+ else { |
|
50 |
+ flash(message => "Repository name is renamed to $to_project"); |
|
51 |
+ $self->redirect_to("/$user/$to_project/settings"); |
|
52 |
+ return; |
|
53 |
+ } |
|
54 |
+ } |
|
55 |
+ else { $errors = $validation->messages } |
|
40 | 56 |
} |
41 | 57 |
|
42 |
- if ($validation->is_valid) { |
|
43 |
- # Rename |
|
44 |
- eval { app->manager->rename_project($user, $project, $to_project) }; |
|
58 |
+ # Change description |
|
59 |
+ elsif ($op eq 'change-description') { |
|
60 |
+ my $description = param('description'); |
|
61 |
+ $description = '' unless defined $description; |
|
62 |
+ |
|
63 |
+ eval { $git->description($user, $project, $description) }; |
|
45 | 64 |
if (my $e = $@) { |
46 |
- app->log->error($e); |
|
65 |
+ app->log->error("/$user/$project/settings?op=description: $e"); |
|
47 | 66 |
$errors = ['Internal Error']; |
48 | 67 |
} |
49 | 68 |
else { |
50 |
- flash(message => "Repository name is renamed to $to_project"); |
|
51 |
- $self->redirect_to("/$user/$to_project/settings"); |
|
69 |
+ flash(message => 'Description is saved.'); |
|
70 |
+ $self->redirect_to('current'); |
|
52 | 71 |
return; |
53 | 72 |
} |
54 | 73 |
} |
55 |
- else { $errors = $validation->messages } |
|
56 |
- } |
|
57 |
- |
|
58 |
- # Change description |
|
59 |
- elsif ($op eq 'change-description' && $post) { |
|
60 |
- my $description = param('description'); |
|
61 |
- $description = '' unless defined $description; |
|
62 |
- |
|
63 |
- eval { $git->description($user, $project, $description) }; |
|
64 |
- if (my $e = $@) { |
|
65 |
- app->log->error("/$user/$project/settings?op=description: $e"); |
|
66 |
- $errors = ['Internal Error']; |
|
67 |
- } |
|
68 |
- else { |
|
69 |
- flash(message => 'Description is saved.'); |
|
70 |
- $self->redirect_to('current'); |
|
71 |
- return; |
|
72 |
- } |
|
73 |
- } |
|
74 |
- |
|
75 |
- # Change default branch |
|
76 |
- elsif ($op eq 'default-branch' && $post) { |
|
77 |
- my $default_branch = param('default-branch'); |
|
78 | 74 |
|
79 |
- my $dbi = app->dbi; |
|
80 |
- eval { |
|
81 |
- $dbi->model('project')->update( |
|
82 |
- {default_branch => $default_branch}, |
|
83 |
- where => {user_id => $user, name => $project} |
|
84 |
- ); |
|
85 |
- }; |
|
86 |
- |
|
87 |
- if (my $e = $@) { |
|
88 |
- app->log->error("/$user/$project/settings?op=default-branch: $e"); |
|
89 |
- $errors = ['Internal Error']; |
|
90 |
- } |
|
91 |
- else { |
|
92 |
- flash(message => "Default branch is changed to $default_branch."); |
|
93 |
- $self->redirect_to('current'); |
|
94 |
- return; |
|
75 |
+ # Change default branch |
|
76 |
+ elsif ($op eq 'default-branch') { |
|
77 |
+ my $default_branch = param('default-branch'); |
|
78 |
+ |
|
79 |
+ my $dbi = app->dbi; |
|
80 |
+ eval { |
|
81 |
+ $dbi->model('project')->update( |
|
82 |
+ {default_branch => $default_branch}, |
|
83 |
+ where => {user_id => $user, name => $project} |
|
84 |
+ ); |
|
85 |
+ }; |
|
86 |
+ |
|
87 |
+ if (my $e = $@) { |
|
88 |
+ app->log->error("/$user/$project/settings?op=default-branch: $e"); |
|
89 |
+ $errors = ['Internal Error']; |
|
90 |
+ } |
|
91 |
+ else { |
|
92 |
+ flash(message => "Default branch is changed to $default_branch."); |
|
93 |
+ $self->redirect_to('current'); |
|
94 |
+ return; |
|
95 |
+ } |
|
95 | 96 |
} |
96 |
- } |
|
97 |
- |
|
98 |
- # Private repository |
|
99 |
- elsif ($op eq 'private' && $post) { |
|
100 |
- my $private = param('private') ? 1 : 0; |
|
101 | 97 |
|
102 |
- eval { |
|
103 |
- app->dbi->model('project')->update( |
|
104 |
- {private => $private}, |
|
105 |
- id => [$user, $project] |
|
106 |
- ); |
|
107 |
- }; |
|
108 |
- if (my $e = $@) { |
|
109 |
- app->log->error("/$user/$project/settings?op=private: $e"); |
|
110 |
- $errors = ['Internal Error']; |
|
111 |
- } |
|
112 |
- else { |
|
113 |
- my $message = 'Private status is saved. Repository is ' |
|
114 |
- . ($private ? 'private' : 'public'); |
|
115 |
- flash(message => $message); |
|
116 |
- $self->redirect_to('current'); |
|
117 |
- return; |
|
98 |
+ # Private repository |
|
99 |
+ elsif ($op eq 'private') { |
|
100 |
+ my $private = param('private') ? 1 : 0; |
|
101 |
+ |
|
102 |
+ eval { |
|
103 |
+ app->dbi->model('project')->update( |
|
104 |
+ {private => $private}, |
|
105 |
+ id => [$user, $project] |
|
106 |
+ ); |
|
107 |
+ }; |
|
108 |
+ if (my $e = $@) { |
|
109 |
+ app->log->error("/$user/$project/settings?op=private: $e"); |
|
110 |
+ $errors = ['Internal Error']; |
|
111 |
+ } |
|
112 |
+ else { |
|
113 |
+ my $message = 'Private status is saved. Repository is ' |
|
114 |
+ . ($private ? 'private' : 'public'); |
|
115 |
+ flash(message => $message); |
|
116 |
+ $self->redirect_to('current'); |
|
117 |
+ return; |
|
118 |
+ } |
|
118 | 119 |
} |
119 |
- } |
|
120 |
- |
|
121 |
- # Delete project |
|
122 |
- elsif ($op eq 'delete-project' && $post) { |
|
123 | 120 |
|
124 |
- my $user = param('user'); |
|
125 |
- my $project = param('project'); |
|
126 |
- |
|
127 |
- eval { app->manager->delete_project($user, $project) }; |
|
128 |
- if (my $e = $@) { |
|
129 |
- app->log->error("/$user/$project/settings: $e"); |
|
130 |
- $errors = ['Internal Error']; |
|
131 |
- } |
|
132 |
- else { |
|
133 |
- flash(message => "Repository $project is deleted."); |
|
134 |
- $self->redirect_to("/$user"); |
|
135 |
- return; |
|
121 |
+ # Delete project |
|
122 |
+ elsif ($op eq 'delete-project') { |
|
123 |
+ |
|
124 |
+ my $user = param('user'); |
|
125 |
+ my $project = param('project'); |
|
126 |
+ |
|
127 |
+ eval { app->manager->delete_project($user, $project) }; |
|
128 |
+ if (my $e = $@) { |
|
129 |
+ app->log->error("/$user/$project/settings: $e"); |
|
130 |
+ $errors = ['Internal Error']; |
|
131 |
+ } |
|
132 |
+ else { |
|
133 |
+ flash(message => "Repository $project is deleted."); |
|
134 |
+ $self->redirect_to("/$user"); |
|
135 |
+ return; |
|
136 |
+ } |
|
136 | 137 |
} |
137 | 138 |
} |
138 | 139 |
%> |