... | ... |
@@ -5,74 +5,82 @@ |
5 | 5 |
my $user_id = param('id'); |
6 | 6 |
|
7 | 7 |
my $errors; |
8 |
- if ($op eq 'update') { |
|
9 |
- |
|
10 |
- # Parameters |
|
11 |
- my $id = param('id'); |
|
12 |
- my $name = param('name'); |
|
13 |
- my $email = param('email'); |
|
14 |
- |
|
15 |
- # Validator |
|
16 |
- my $vc = app->vc; |
|
17 |
- |
|
18 |
- # Validation result |
|
19 |
- my $validation = $vc->validation; |
|
20 |
- |
|
21 |
- # "id" check |
|
22 |
- if (!(defined $id && length $id)) { |
|
23 |
- $validation->add_failed(id => 'User id is empty.'); |
|
24 |
- } |
|
8 |
+ if (lc $self->req->method eq 'post') { |
|
9 |
+ if ($op eq 'update') { |
|
25 | 10 |
|
26 |
- # "name" check |
|
27 |
- $name //= ''; |
|
28 |
- |
|
29 |
- # "email" check |
|
30 |
- if (!(defined $email && length $email)) { |
|
31 |
- $validation->add_failed(email => "Mail must be not empty"); |
|
32 |
- } |
|
33 |
- elsif ($email !~ /\@/) { |
|
34 |
- $validation->add_failed(email => "Invalid mail address"); |
|
35 |
- } |
|
36 |
- else { |
|
37 |
- my $where = app->dbi->where; |
|
38 |
- my $clause = [ |
|
39 |
- 'and', |
|
40 |
- ':email{=}', |
|
41 |
- ':id{<>}' |
|
42 |
- ]; |
|
43 |
- my $param = { |
|
44 |
- email => $email, |
|
45 |
- id => $user_id |
|
46 |
- }; |
|
47 |
- $where->clause($clause); |
|
48 |
- $where->param($param); |
|
11 |
+ # Parameters |
|
12 |
+ my $id = param('id'); |
|
13 |
+ my $name = param('name'); |
|
14 |
+ my $email = param('email'); |
|
15 |
+ |
|
16 |
+ # Validator |
|
17 |
+ my $vc = app->vc; |
|
49 | 18 |
|
50 |
- my $row = app->dbi->model('user')->select(where => $where)->one; |
|
51 |
- if ($row) { |
|
52 |
- $validation->add_failed(email => "Mail $email already exists"); |
|
19 |
+ # Validation result |
|
20 |
+ my $validation = $vc->validation; |
|
21 |
+ |
|
22 |
+ # "id" check |
|
23 |
+ if (!(defined $id && length $id)) { |
|
24 |
+ $validation->add_failed(id => 'User id is empty.'); |
|
25 |
+ } |
|
26 |
+ elsif (length $name > 300) { |
|
27 |
+ $validation->add_failed(id => 'User id is too long.'); |
|
53 | 28 |
} |
54 |
- } |
|
55 |
- |
|
56 |
- if ($validation->is_valid) { |
|
57 | 29 |
|
58 |
- # Encrypt password |
|
59 |
- my $params = {}; |
|
60 |
- $params->{name} = $name; |
|
61 |
- $params->{email} = $email; |
|
30 |
+ # "name" check |
|
31 |
+ $name //= ''; |
|
62 | 32 |
|
63 |
- # Update user |
|
64 |
- eval { app->dbi->model('user')->update($params, where => {id => $id}) }; |
|
65 |
- if (my $e = $@) { |
|
66 |
- app->log->error(url_for . ": $e"); |
|
67 |
- $errors = ['Internal Error']; |
|
33 |
+ # "email" check |
|
34 |
+ if (!(defined $email && length $email)) { |
|
35 |
+ $validation->add_failed(email => "Mail must be not empty"); |
|
36 |
+ } |
|
37 |
+ elsif (length $email > 300) { |
|
38 |
+ $validation->add_failed(email => "Mail is too long"); |
|
39 |
+ } |
|
40 |
+ elsif ($email !~ /\@/) { |
|
41 |
+ $validation->add_failed(email => "Invalid mail address"); |
|
68 | 42 |
} |
69 | 43 |
else { |
70 |
- $self->flash(success => 1); |
|
71 |
- $self->flash(id => $id); |
|
72 |
- $self->redirect_to(url_for->query(id => $id)); |
|
44 |
+ my $where = app->dbi->where; |
|
45 |
+ my $clause = [ |
|
46 |
+ 'and', |
|
47 |
+ ':email{=}', |
|
48 |
+ ':id{<>}' |
|
49 |
+ ]; |
|
50 |
+ my $param = { |
|
51 |
+ email => $email, |
|
52 |
+ id => $user_id |
|
53 |
+ }; |
|
54 |
+ $where->clause($clause); |
|
55 |
+ $where->param($param); |
|
56 |
+ |
|
57 |
+ my $row = app->dbi->model('user')->select(where => $where)->one; |
|
58 |
+ if ($row) { |
|
59 |
+ $validation->add_failed(email => "Mail $email already exists"); |
|
60 |
+ } |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ if ($validation->is_valid) { |
|
64 |
+ |
|
65 |
+ # Encrypt password |
|
66 |
+ my $params = {}; |
|
67 |
+ $params->{name} = $name; |
|
68 |
+ $params->{email} = $email; |
|
69 |
+ |
|
70 |
+ # Update user |
|
71 |
+ eval { app->dbi->model('user')->update($params, where => {id => $id}) }; |
|
72 |
+ if (my $e = $@) { |
|
73 |
+ app->log->error(url_for . ": $e"); |
|
74 |
+ $errors = ['Internal Error']; |
|
75 |
+ } |
|
76 |
+ else { |
|
77 |
+ $self->flash(success => 1); |
|
78 |
+ $self->flash(id => $id); |
|
79 |
+ $self->redirect_to(url_for->query(id => $id)); |
|
80 |
+ } |
|
73 | 81 |
} |
82 |
+ else { $errors = $validation->messages } |
|
74 | 83 |
} |
75 |
- else { $errors = $validation->messages } |
|
76 | 84 |
} |
77 | 85 |
|
78 | 86 |
my $user = app->dbi->model('user')->select( |
... | ... |
@@ -6,7 +6,7 @@ |
6 | 6 |
if ($op eq 'delete' && lc $self->req->method eq 'post') { |
7 | 7 |
|
8 | 8 |
# Parameters |
9 |
- my $user = param('user'); |
|
9 |
+ my $user_id = param('user'); |
|
10 | 10 |
|
11 | 11 |
# Validator |
12 | 12 |
my $vc = app->vc; |
... | ... |
@@ -15,7 +15,7 @@ |
15 | 15 |
my $validation = $vc->validation; |
16 | 16 |
|
17 | 17 |
# "user" check |
18 |
- if (!(defined $user && length $user)) { |
|
18 |
+ if (!(defined $user_id && length $user_id)) { |
|
19 | 19 |
$validation->add_failed(user => 'User name is empty.'); |
20 | 20 |
} |
21 | 21 |
|
... | ... |
@@ -23,17 +23,17 @@ |
23 | 23 |
|
24 | 24 |
# Delete user |
25 | 25 |
my $count; |
26 |
- eval { $count = app->manager->delete_user($user) }; |
|
26 |
+ eval { $count = app->manager->delete_user($user_id) }; |
|
27 | 27 |
if (my $e = $@) { |
28 | 28 |
app->log->error(url_for . ": $e"); |
29 | 29 |
$errors = ['Internal Error']; |
30 | 30 |
} |
31 | 31 |
elsif ($count == 0) { |
32 |
- app->log->error("/_admin/users?op=delete: User $user not exists"); |
|
32 |
+ app->log->error("/_admin/users?op=delete: User $user_id not exists"); |
|
33 | 33 |
$errors = ['Internal Error']; |
34 | 34 |
} |
35 | 35 |
else { |
36 |
- $self->flash(message => "User $user is deleted."); |
|
36 |
+ $self->flash(message => "User $user_id is deleted."); |
|
37 | 37 |
$self->redirect_to('current'); |
38 | 38 |
return; |
39 | 39 |
} |
... | ... |
@@ -13,66 +13,74 @@ |
13 | 13 |
} |
14 | 14 |
|
15 | 15 |
my $errors; |
16 |
- if ($op eq 'create') { |
|
17 |
- # Parameters |
|
18 |
- my $project_id = param('project'); |
|
19 |
- my $description = param('description'); |
|
20 |
- my $readme = param('readme'); |
|
21 |
- my $private = param('private'); |
|
22 |
- |
|
23 |
- # Validator |
|
24 |
- my $vc = app->vc; |
|
25 |
- |
|
26 |
- # Validation |
|
27 |
- my $validation = $vc->validation; |
|
28 |
- |
|
29 |
- # "project" |
|
30 |
- if (!(defined $project_id && length $project_id)) { |
|
31 |
- $validation->add_failed(project => 'Repository name is empty'); |
|
32 |
- } |
|
33 |
- elsif (!$vc->check($project_id, 'project_name')) { |
|
34 |
- $validation->add_failed(project => 'Invalid repository name'); |
|
35 |
- } |
|
36 |
- elsif (app->manager->exists_project($session_user->{id}, $project_id)) { |
|
37 |
- $validation->add_failed(project => 'Repository already exists'); |
|
38 |
- } |
|
39 |
- |
|
40 |
- # "description" |
|
41 |
- $description ||= ''; |
|
42 |
- |
|
43 |
- # "readme" |
|
44 |
- $readme = $readme ? 1 :0; |
|
45 |
- |
|
46 |
- # "private" |
|
47 |
- $private = $private ? 1 : 0; |
|
48 |
- |
|
49 |
- # Git |
|
50 |
- if ($validation->is_valid) { |
|
51 |
- # Not logined |
|
52 |
- unless ($api->logined) { |
|
53 |
- return $self->reply->exception; |
|
54 |
- } |
|
16 |
+ if (lc $self->req->method eq 'post') { |
|
17 |
+ if ($op eq 'create') { |
|
18 |
+ # Parameters |
|
19 |
+ my $project_id = param('project'); |
|
20 |
+ my $description = param('description'); |
|
21 |
+ my $readme = param('readme'); |
|
22 |
+ my $private = param('private'); |
|
55 | 23 |
|
56 |
- my $manager = app->manager; |
|
57 |
- # Create repository |
|
58 |
- eval { |
|
59 |
- $manager->create_project( |
|
60 |
- $session_user->{id}, |
|
61 |
- $project_id, |
|
62 |
- {description => $description, readme => $readme, private => $private} |
|
63 |
- ); |
|
64 |
- }; |
|
24 |
+ # Validator |
|
25 |
+ my $vc = app->vc; |
|
65 | 26 |
|
66 |
- if (my $e = $@) { |
|
67 |
- app->log->error(url_for . ": $e"); |
|
68 |
- $errors = ['Internal error']; |
|
27 |
+ # Validation |
|
28 |
+ my $validation = $vc->validation; |
|
29 |
+ |
|
30 |
+ # "project" |
|
31 |
+ if (!(defined $project_id && length $project_id)) { |
|
32 |
+ $validation->add_failed(project => 'Repository name is empty'); |
|
33 |
+ } |
|
34 |
+ elsif (length $project_id > 300) { |
|
35 |
+ $validation->add_failed(project => 'Repository name is too long'); |
|
36 |
+ } |
|
37 |
+ elsif (!$vc->check($project_id, 'project_name')) { |
|
38 |
+ $validation->add_failed(project => 'Invalid repository name'); |
|
69 | 39 |
} |
70 |
- else { |
|
71 |
- $self->redirect_to("/$session_user->{id}/$project_id"); |
|
72 |
- return; |
|
40 |
+ elsif (app->manager->exists_project($session_user->{id}, $project_id)) { |
|
41 |
+ $validation->add_failed(project => 'Repository already exists'); |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ # "description" |
|
45 |
+ $description ||= ''; |
|
46 |
+ if (length $description > 300) { |
|
47 |
+ $validation->add_failed(description => 'description is too long'); |
|
48 |
+ } |
|
49 |
+ |
|
50 |
+ # "readme" |
|
51 |
+ $readme = $readme ? 1 :0; |
|
52 |
+ |
|
53 |
+ # "private" |
|
54 |
+ $private = $private ? 1 : 0; |
|
55 |
+ |
|
56 |
+ # Git |
|
57 |
+ if ($validation->is_valid) { |
|
58 |
+ # Not logined |
|
59 |
+ unless ($api->logined) { |
|
60 |
+ return $self->reply->exception; |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ my $manager = app->manager; |
|
64 |
+ # Create repository |
|
65 |
+ eval { |
|
66 |
+ $manager->create_project( |
|
67 |
+ $session_user->{id}, |
|
68 |
+ $project_id, |
|
69 |
+ {description => $description, readme => $readme, private => $private} |
|
70 |
+ ); |
|
71 |
+ }; |
|
72 |
+ |
|
73 |
+ if (my $e = $@) { |
|
74 |
+ app->log->error(url_for . ": $e"); |
|
75 |
+ $errors = ['Internal error']; |
|
76 |
+ } |
|
77 |
+ else { |
|
78 |
+ $self->redirect_to("/$session_user->{id}/$project_id"); |
|
79 |
+ return; |
|
80 |
+ } |
|
73 | 81 |
} |
82 |
+ else { $errors = $validation->messages } |
|
74 | 83 |
} |
75 |
- else { $errors = $validation->messages } |
|
76 | 84 |
} |
77 | 85 |
%> |
78 | 86 |
|
... | ... |
@@ -40,92 +40,121 @@ |
40 | 40 |
# Git |
41 | 41 |
my $git = $self->app->git; |
42 | 42 |
|
43 |
+ my $errors; |
|
43 | 44 |
if (lc $self->req->method eq 'post') { |
44 | 45 |
my $op = param('op'); |
45 | 46 |
|
46 | 47 |
if ($op eq 'create-pull-request') { |
48 |
+ |
|
49 |
+ # Parameters |
|
47 | 50 |
my $title = param('title'); |
48 | 51 |
my $message = param('message'); |
49 | 52 |
|
50 |
- my $project_row_id = app->dbi->model('project')->select( |
|
51 |
- 'project.row_id', |
|
52 |
- where => {'__user.id' => $base_user_id, 'project.id' => $base_project_id} |
|
53 |
- )->value; |
|
53 |
+ # Validation |
|
54 |
+ my $vc = app->vc; |
|
55 |
+ my $validation = $vc->validation; |
|
54 | 56 |
|
55 |
- my $pull_request = app->dbi->model('pull_request')->select( |
|
56 |
- where => { |
|
57 |
- base_project => $project_row_id, |
|
58 |
- base_branch => $base_branch, |
|
59 |
- target_project => $target_project->{id}, |
|
60 |
- target_branch => $target_branch |
|
61 |
- } |
|
62 |
- )->one; |
|
57 |
+ # Check title |
|
58 |
+ if (!(defined $title && length $title)) { |
|
59 |
+ $validation->add_failed(title => 'title is empty'); |
|
60 |
+ } |
|
61 |
+ elsif (length $title > 300) { |
|
62 |
+ $validation->add_failed(title => 'title is too long'); |
|
63 |
+ } |
|
63 | 64 |
|
64 |
- if ($pull_request) { |
|
65 |
- $self->redirect_to("/$base_user_id/$base_project_id/pull/$pull_request->{row_id}"); |
|
66 |
- return; |
|
65 |
+ # Message |
|
66 |
+ if (!(defined $message && length $message)) { |
|
67 |
+ $message = ''; |
|
68 |
+ if (length $message > 1000) { |
|
69 |
+ $validation->add_failed(message => 'message is too long'); |
|
70 |
+ } |
|
67 | 71 |
} |
68 |
- else { |
|
69 |
- my $now_tm = Time::Moment->now_utc; |
|
70 |
- my $now_epoch = $now_tm->epoch; |
|
71 |
- my $user_row_id = app->dbi->model('user')->select( |
|
72 |
- 'row_id', |
|
73 |
- where => {id => $base_user_id} |
|
72 |
+ |
|
73 |
+ if ($validation->is_valid) { |
|
74 |
+ |
|
75 |
+ my $project_row_id = app->dbi->model('project')->select( |
|
76 |
+ 'project.row_id', |
|
77 |
+ where => {'__user.id' => $base_user_id, 'project.id' => $base_project_id} |
|
74 | 78 |
)->value; |
75 | 79 |
|
76 |
- my $new_pull_request_row_id; |
|
77 |
- my $session_user_row_id = $api->session_user_row_id; |
|
78 |
- app->dbi->connector->txn(sub { |
|
79 |
- # New pull request |
|
80 |
- my $new_pull_request_params = { |
|
80 |
+ my $pull_request = app->dbi->model('pull_request')->select( |
|
81 |
+ where => { |
|
81 | 82 |
base_project => $project_row_id, |
82 | 83 |
base_branch => $base_branch, |
83 |
- target_project => $target_project->{row_id}, |
|
84 |
- target_branch => $target_branch, |
|
85 |
- title => $title, |
|
86 |
- open => 1, |
|
87 |
- open_time => $now_epoch, |
|
88 |
- open_user => $session_user_row_id |
|
89 |
- }; |
|
90 |
- |
|
91 |
- app->dbi->model('pull_request')->insert($new_pull_request_params); |
|
92 |
- |
|
93 |
- $new_pull_request_row_id = app->dbi->model('pull_request')->select( |
|
84 |
+ target_project => $target_project->{id}, |
|
85 |
+ target_branch => $target_branch |
|
86 |
+ } |
|
87 |
+ )->one; |
|
88 |
+ |
|
89 |
+ if ($pull_request) { |
|
90 |
+ $self->redirect_to("/$base_user_id/$base_project_id/pull/$pull_request->{row_id}"); |
|
91 |
+ return; |
|
92 |
+ } |
|
93 |
+ else { |
|
94 |
+ my $now_tm = Time::Moment->now_utc; |
|
95 |
+ my $now_epoch = $now_tm->epoch; |
|
96 |
+ my $user_row_id = app->dbi->model('user')->select( |
|
94 | 97 |
'row_id', |
95 |
- where => { |
|
98 |
+ where => {id => $base_user_id} |
|
99 |
+ )->value; |
|
100 |
+ |
|
101 |
+ my $new_pull_request_row_id; |
|
102 |
+ my $session_user_row_id = $api->session_user_row_id; |
|
103 |
+ app->dbi->connector->txn(sub { |
|
104 |
+ # New pull request |
|
105 |
+ my $new_pull_request_params = { |
|
96 | 106 |
base_project => $project_row_id, |
97 | 107 |
base_branch => $base_branch, |
98 | 108 |
target_project => $target_project->{row_id}, |
99 |
- target_branch => $target_branch |
|
100 |
- } |
|
101 |
- )->value; |
|
102 |
- |
|
103 |
- # Get pull request message number |
|
104 |
- my $number = app->dbi->model('pull_request_message')->select( |
|
105 |
- 'max(number)', |
|
106 |
- where => {pull_request => $new_pull_request_row_id}, |
|
107 |
- append => 'group by number' |
|
108 |
- )->value; |
|
109 |
- |
|
110 |
- $number //= 0; |
|
111 |
- |
|
112 |
- my $new_number = $number + 1; |
|
109 |
+ target_branch => $target_branch, |
|
110 |
+ title => $title, |
|
111 |
+ open => 1, |
|
112 |
+ open_time => $now_epoch, |
|
113 |
+ open_user => $session_user_row_id |
|
114 |
+ }; |
|
115 |
+ |
|
116 |
+ app->dbi->model('pull_request')->insert($new_pull_request_params); |
|
117 |
+ |
|
118 |
+ $new_pull_request_row_id = app->dbi->model('pull_request')->select( |
|
119 |
+ 'row_id', |
|
120 |
+ where => { |
|
121 |
+ base_project => $project_row_id, |
|
122 |
+ base_branch => $base_branch, |
|
123 |
+ target_project => $target_project->{row_id}, |
|
124 |
+ target_branch => $target_branch |
|
125 |
+ } |
|
126 |
+ )->value; |
|
127 |
+ |
|
128 |
+ # Get pull request message number |
|
129 |
+ my $number = app->dbi->model('pull_request_message')->select( |
|
130 |
+ 'max(number)', |
|
131 |
+ where => {pull_request => $new_pull_request_row_id}, |
|
132 |
+ append => 'group by number' |
|
133 |
+ )->value; |
|
134 |
+ |
|
135 |
+ $number //= 0; |
|
136 |
+ |
|
137 |
+ my $new_number = $number + 1; |
|
138 |
+ |
|
139 |
+ # New pull request message |
|
140 |
+ my $new_pull_request_message_params = { |
|
141 |
+ pull_request => $new_pull_request_row_id, |
|
142 |
+ number => $new_number, |
|
143 |
+ message => $message, |
|
144 |
+ create_time => $now_epoch, |
|
145 |
+ update_time => $now_epoch, |
|
146 |
+ user => $session_user_row_id |
|
147 |
+ }; |
|
148 |
+ |
|
149 |
+ app->dbi->model('pull_request_message')->insert($new_pull_request_message_params); |
|
150 |
+ }); |
|
113 | 151 |
|
114 |
- # New pull request message |
|
115 |
- my $new_pull_request_message_params = { |
|
116 |
- pull_request => $new_pull_request_row_id, |
|
117 |
- number => $new_number, |
|
118 |
- message => $message, |
|
119 |
- create_time => $now_epoch, |
|
120 |
- update_time => $now_epoch, |
|
121 |
- user => $session_user_row_id |
|
122 |
- }; |
|
123 |
- |
|
124 |
- app->dbi->model('pull_request_message')->insert($new_pull_request_message_params); |
|
125 |
- }); |
|
126 |
- |
|
127 |
- $self->redirect_to("/$base_user_id/$base_project_id/pull/$new_pull_request_row_id"); |
|
128 |
- return; |
|
152 |
+ $self->redirect_to("/$base_user_id/$base_project_id/pull/$new_pull_request_row_id"); |
|
153 |
+ return; |
|
154 |
+ } |
|
155 |
+ } |
|
156 |
+ else { |
|
157 |
+ $errors = $validation->messages; |
|
129 | 158 |
} |
130 | 159 |
} |
131 | 160 |
} |
... | ... |
@@ -321,6 +350,8 @@ |
321 | 350 |
%= include '/include/header'; |
322 | 351 |
|
323 | 352 |
<div class="container"> |
353 |
+ %= include '/include/errors', errors => $errors; |
|
354 |
+ |
|
324 | 355 |
<div class="topic1"> |
325 | 356 |
% if ($can_open_pull_request) { |
326 | 357 |
Open a pull request |
... | ... |
@@ -1,182 +0,0 @@ |
1 |
-<% |
|
2 |
- |
|
3 |
- my $api = gitprep_api; |
|
4 |
- |
|
5 |
- my $user = param('user'); |
|
6 |
- my $project = param('project'); |
|
7 |
- my $remote_user = param('remote_user'); |
|
8 |
- my $remote_project = param('remote_project'); |
|
9 |
- my $remote_branch = param('remote-branch'); |
|
10 |
- |
|
11 |
- # Authentication |
|
12 |
- unless ($api->logined($user)) { |
|
13 |
- $self->redirect_to('/'); |
|
14 |
- return; |
|
15 |
- } |
|
16 |
- |
|
17 |
- # Branches |
|
18 |
- my $git = app->git; |
|
19 |
- my $remote_branches = $git->branches($self->app->rep_info($remote_user, $remote_project)); |
|
20 |
- my $remote_branch_names = [map { $_->{name} } @$remote_branches]; |
|
21 |
- |
|
22 |
- my $op = param('op') || ''; |
|
23 |
- my $errors; |
|
24 |
- if ($op eq 'import' && lc $self->req->method eq 'post') { |
|
25 |
- # Parameters |
|
26 |
- my $user = param('user'); |
|
27 |
- my $project = param('project'); |
|
28 |
- my $branch = param('branch'); |
|
29 |
- my $remote_user = param('remote_user'); |
|
30 |
- my $remote_project = param('remote_project'); |
|
31 |
- my $remote_branch = param('remote-branch'); |
|
32 |
- my $force = param('force'); |
|
33 |
- |
|
34 |
- # Validator |
|
35 |
- my $vc = app->vc; |
|
36 |
- |
|
37 |
- # Validation result |
|
38 |
- my $validation = $vc->validation; |
|
39 |
- |
|
40 |
- # "user" |
|
41 |
- if (!$vc->check($user, 'user_name')) { |
|
42 |
- $validation->add_failed('User name is invalid.'); |
|
43 |
- } |
|
44 |
- |
|
45 |
- # "project" |
|
46 |
- if (!$vc->check($project, 'project_name')) { |
|
47 |
- $validation->add_failed('Repository name is invalid.'); |
|
48 |
- } |
|
49 |
- |
|
50 |
- # "branch" |
|
51 |
- if (!(defined $branch && length $branch)) { |
|
52 |
- $validation->add_failed('Branch name is empty.'); |
|
53 |
- } |
|
54 |
- |
|
55 |
- # "remote_user" |
|
56 |
- if (!$vc->check($remote_user, 'user_name')) { |
|
57 |
- $validation->add_failed('Remote User name is invalid.'); |
|
58 |
- } |
|
59 |
- |
|
60 |
- # "remote_project" |
|
61 |
- if (!$vc->check($remote_project, 'project_name')) { |
|
62 |
- $validation->add_failed('Remote repository is invalid.'); |
|
63 |
- } |
|
64 |
- |
|
65 |
- # "remote-branch" |
|
66 |
- if (!(defined $remote_branch && length $remote_branch)) { |
|
67 |
- $validation->add_failed('Remote branch name is empty.'); |
|
68 |
- } |
|
69 |
- |
|
70 |
- # "force" |
|
71 |
- $force = $force ? 1 : 0; |
|
72 |
- |
|
73 |
- if ($validation->is_valid) { |
|
74 |
- |
|
75 |
- # Check branch name |
|
76 |
- my $branches = $git->branches($self->app->rep_info($user, $project)); |
|
77 |
- |
|
78 |
- if (!$force && grep { $branch eq $_->{name} } @$branches) { |
|
79 |
- $errors = ["Branch \"$branch\" is already exists. If you want to import this branch, check force option."]; |
|
80 |
- } |
|
81 |
- else { |
|
82 |
- eval { |
|
83 |
- $git->import_branch( |
|
84 |
- app->rep_info($user, $project), |
|
85 |
- $branch, |
|
86 |
- app->rep_info($remote_user, $remote_project), |
|
87 |
- $remote_branch, |
|
88 |
- {force => $force} |
|
89 |
- ); |
|
90 |
- }; |
|
91 |
- |
|
92 |
- if (my $e = $@) { |
|
93 |
- $errors = ['Internal Error']; |
|
94 |
- app->log->error(url_for . ": $e"); |
|
95 |
- } |
|
96 |
- else { |
|
97 |
- flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\""); |
|
98 |
- $self->redirect_to('current'); |
|
99 |
- return; |
|
100 |
- } |
|
101 |
- } |
|
102 |
- } |
|
103 |
- else { |
|
104 |
- $errors = $validation->messages; |
|
105 |
- } |
|
106 |
- } |
|
107 |
- |
|
108 |
- layout 'common', title => "Import branch"; |
|
109 |
-%> |
|
110 |
- |
|
111 |
- %= include 'include/header'; |
|
112 |
- |
|
113 |
- %= javascript begin |
|
114 |
- $('document').ready(function () { |
|
115 |
- |
|
116 |
- // Select remote branch |
|
117 |
- $('[name=copy-branch-name]').on('click', function () { |
|
118 |
- $('[name=branch]').val($('[name=remote-branch]').val()); |
|
119 |
- return false; |
|
120 |
- }); |
|
121 |
- }); |
|
122 |
- % end |
|
123 |
- |
|
124 |
- <div class="container"> |
|
125 |
- % if (my $message = flash('message')) { |
|
126 |
- <div class="alert alert-success"> |
|
127 |
- <button type="button" class="close" data-dismiss="alert">×</button> |
|
128 |
- <%= $message %> |
|
129 |
- </div> |
|
130 |
- % } |
|
131 |
- % if ($errors) { |
|
132 |
- <div class="alert alert-error"> |
|
133 |
- <button type="button" class="close" data-dismiss="alert">×</button> |
|
134 |
- % for my $error (@$errors) { |
|
135 |
- <p><%= $error %></p> |
|
136 |
- % } |
|
137 |
- </div> |
|
138 |
- % } |
|
139 |
- <h3 class="topic1">Import branch</h3> |
|
140 |
- <form action="<%= url_for("/$user/$project/import-branch/$remote_user/$remote_project")->query(op => 'import') %>" method="post"> |
|
141 |
- <div class="import-branch"> |
|
142 |
- <div class="left"> |
|
143 |
- <div class="import-branch-to"> |
|
144 |
- <div> |
|
145 |
- %= "$user / $project"; |
|
146 |
- </div> |
|
147 |
- <div> |
|
148 |
- %= text_field 'branch', placeholder => "Branch name", style => "width:250px"; |
|
149 |
- <button name="copy-branch-name", class="btn" style="font-size:12px; padding-left:3px;padding-right:3px;color:#666">Copy Branch Name</button> |
|
150 |
- </div> |
|
151 |
- <div class="import-branch-button-panel"> |
|
152 |
- <div> |
|
153 |
- %= submit_button 'Import', class => "btn btn-info"; |
|
154 |
- </div> |
|
155 |
- <div> |
|
156 |
- <%= check_box force => 1 %> |
|
157 |
- </div> |
|
158 |
- <div> |
|
159 |
- Force |
|
160 |
- </div> |
|
161 |
- </div> |
|
162 |
- </div> |
|
163 |
- </div> |
|
164 |
- <div class="center"> |
|
165 |
- ⇐ |
|
166 |
- </div> |
|
167 |
- <div class="right"> |
|
168 |
- <div class="import-branch-from"> |
|
169 |
- <div> |
|
170 |
- %= "$remote_user / $remote_project"; |
|
171 |
- </div> |
|
172 |
- <div> |
|
173 |
- % param('remote-branch' => $remote_branch); |
|
174 |
- %= select_field 'remote-branch' => $remote_branch_names, style => "width:250px"; |
|
175 |
- </div> |
|
176 |
- </div> |
|
177 |
- </div> |
|
178 |
- </div> |
|
179 |
- </form> |
|
180 |
- </div> |
|
181 |
- |
|
182 |
- %= include '/include/footer'; |
... | ... |
@@ -70,18 +70,6 @@ |
70 | 70 |
location.href = '<%= url_for("/$user_id/$project_id/network/graph/") %>' + branch + '...' |
71 | 71 |
+ remote_member + '/' + remote_project + '/' + remote_branch; |
72 | 72 |
}); |
73 |
- |
|
74 |
- // Click import button |
|
75 |
- $('[name=import-btn]').on('click', function () { |
|
76 |
- var branch = $('[name=branch]').val(); |
|
77 |
- var remote = $(this).closest('[name=remote]'); |
|
78 |
- var remote_member = remote.find('[name=remote-member]').text(); |
|
79 |
- var remote_project = remote.find('[name=remote-project]').text(); |
|
80 |
- var remote_branch = remote.find('[name=remote-branch]').val(); |
|
81 |
- |
|
82 |
- location.href = '<%= url_for("/$user_id/$project_id/import-branch/") %>' |
|
83 |
- + remote_member + '/' + remote_project + '?remote-branch=' + remote_branch; |
|
84 |
- }); |
|
85 | 73 |
}); |
86 | 74 |
% end |
87 | 75 |
|
... | ... |
@@ -119,9 +107,6 @@ |
119 | 107 |
</div> |
120 | 108 |
<div class="last-child"> |
121 | 109 |
<button name="compare-btn" class="btn" style="margin-top:5px">Compare</button> |
122 |
- % if ($api->logined($user_id)) { |
|
123 |
- <button name="import-btn" class="btn" style="margin-top:5px">Import</button> |
|
124 |
- % } |
|
125 | 110 |
</div> |
126 | 111 |
</li> |
127 | 112 |
% } |
... | ... |
@@ -34,6 +34,9 @@ |
34 | 34 |
if (!(defined $to_project && length $to_project)) { |
35 | 35 |
$validation->add_failed('to-project' => 'Repository name is empty.'); |
36 | 36 |
} |
37 |
+ elsif (length $to_project > 300) { |
|
38 |
+ $validation->add_failed('to-project' => 'Repository name is too long.'); |
|
39 |
+ } |
|
37 | 40 |
elsif (!$vc->check($to_project, 'project_name')) { |
38 | 41 |
$validation->add_failed('to-project' => 'Repository name contains invalid charactor.'); |
39 | 42 |
} |
... | ... |
@@ -59,18 +62,32 @@ |
59 | 62 |
|
60 | 63 |
# Change description |
61 | 64 |
elsif ($op eq 'change-description') { |
65 |
+ |
|
66 |
+ # Parameters |
|
62 | 67 |
my $description = param('description'); |
63 | 68 |
$description = '' unless defined $description; |
69 |
+ |
|
70 |
+ # Validator |
|
71 |
+ my $vc = app->vc; |
|
64 | 72 |
|
65 |
- eval { $git->description(app->rep_info($user_id, $project_id), $description) }; |
|
66 |
- if (my $e = $@) { |
|
67 |
- app->log->error("/$user_id/$project_id/settings?op=description: $e"); |
|
68 |
- $errors = ['Internal Error']; |
|
73 |
+ # Validation result |
|
74 |
+ my $validation = $vc->validation; |
|
75 |
+ |
|
76 |
+ if (length $description > 300) { |
|
77 |
+ $validation->add_failed(description => 'description is too long'); |
|
69 | 78 |
} |
70 |
- else { |
|
71 |
- flash(message => 'Description is saved.'); |
|
72 |
- $self->redirect_to('current'); |
|
73 |
- return; |
|
79 |
+ |
|
80 |
+ if ($validation->is_valid) { |
|
81 |
+ eval { $git->description(app->rep_info($user_id, $project_id), $description) }; |
|
82 |
+ if (my $e = $@) { |
|
83 |
+ app->log->error("/$user_id/$project_id/settings?op=description: $e"); |
|
84 |
+ $errors = ['Internal Error']; |
|
85 |
+ } |
|
86 |
+ else { |
|
87 |
+ flash(message => 'Description is saved.'); |
|
88 |
+ $self->redirect_to('current'); |
|
89 |
+ return; |
|
90 |
+ } |
|
74 | 91 |
} |
75 | 92 |
} |
76 | 93 |
|
... | ... |
@@ -82,16 +99,39 @@ |
82 | 99 |
my $private = param('private'); |
83 | 100 |
my $ignore_space_change = param('ignore_space_change'); |
84 | 101 |
my $guess_encoding = param('guess_encoding'); |
102 |
+ |
|
103 |
+ # Validator |
|
104 |
+ my $vc = app->vc; |
|
105 |
+ |
|
106 |
+ # Validation result |
|
107 |
+ my $validation = $vc->validation; |
|
108 |
+ |
|
109 |
+ # Check default branch |
|
110 |
+ if (length $default_branch > 300) { |
|
111 |
+ $validation->add_failed('default-branch' => 'default branch is too long'); |
|
112 |
+ } |
|
113 |
+ |
|
114 |
+ # Check private |
|
115 |
+ $private = $private ? 1 : 0; |
|
116 |
+ |
|
117 |
+ # Check ignore space change |
|
118 |
+ $ignore_space_change = $ignore_space_change ? 1 : 0; |
|
119 |
+ |
|
120 |
+ # Check guess encoding |
|
121 |
+ $guess_encoding //= ''; |
|
122 |
+ if (length $guess_encoding > 300) { |
|
123 |
+ $validation->add_failed(guess_encoding => 'guess_encoding is too long'); |
|
124 |
+ } |
|
85 | 125 |
|
86 | 126 |
my $params = {}; |
87 | 127 |
if (defined $default_branch) { |
88 | 128 |
$params->{default_branch} = $default_branch; |
89 | 129 |
} |
90 | 130 |
if (defined $private) { |
91 |
- $params->{private} = $private ? 1 : 0; |
|
131 |
+ $params->{private} = $private; |
|
92 | 132 |
}; |
93 | 133 |
if (defined $ignore_space_change) { |
94 |
- $params->{ignore_space_change} = $ignore_space_change ? 1 : 0; |
|
134 |
+ $params->{ignore_space_change} = $ignore_space_change; |
|
95 | 135 |
} |
96 | 136 |
if (defined $guess_encoding) { |
97 | 137 |
$params->{guess_encoding} = $guess_encoding; |
... | ... |
@@ -1,9 +1,10 @@ |
1 | 1 |
<% |
2 |
- my $user = param('user'); |
|
2 |
+ my $user_id = param('user'); |
|
3 | 3 |
|
4 |
- warn param('user.keys'); |
|
5 |
- |
|
6 |
- my $keys = app->dbi->model('ssh_public_key')->select(where => {user_id => $user})->all; |
|
4 |
+ my $keys = app->dbi->model('ssh_public_key')->select( |
|
5 |
+ where => {'__user.id' => $user_id}, |
|
6 |
+ append => 'order by title' |
|
7 |
+ )->all; |
|
7 | 8 |
my $keys_str = ''; |
8 | 9 |
for my $key (@$keys) { |
9 | 10 |
$keys_str .= "$key->{key}\n"; |
... | ... |
@@ -4,10 +4,10 @@ |
4 | 4 |
|
5 | 5 |
# Parameters |
6 | 6 |
my $op = param('op') || ''; |
7 |
- my $user = param('user') || ''; |
|
7 |
+ my $user_id = param('user') || ''; |
|
8 | 8 |
|
9 | 9 |
# Authentication |
10 |
- unless ($api->logined($user)) { |
|
10 |
+ unless ($api->logined($user_id)) { |
|
11 | 11 |
$self->redirect_to('/'); |
12 | 12 |
return; |
13 | 13 |
} |
... | ... |
@@ -49,6 +49,9 @@ |
49 | 49 |
if (!(defined $original_key && length $original_key)) { |
50 | 50 |
$validation->add_failed(key => 'key is empty'); |
51 | 51 |
} |
52 |
+ elsif (length $original_key > 2000) { |
|
53 |
+ $validation->add_failed(key => 'key is too long'); |
|
54 |
+ } |
|
52 | 55 |
else { |
53 | 56 |
my $type; |
54 | 57 |
my $original_key_edit; |
... | ... |
@@ -99,8 +102,9 @@ |
99 | 102 |
|
100 | 103 |
# Register ssh key |
101 | 104 |
if ($validation->is_valid) { |
105 |
+ my $session_user_row_id = $api->session_user_row_id; |
|
102 | 106 |
my $p = { |
103 |
- user_id => $user, |
|
107 |
+ user => $session_user_row_id, |
|
104 | 108 |
title => $title, |
105 | 109 |
key => $key |
106 | 110 |
}; |
... | ... |
@@ -128,6 +132,7 @@ |
128 | 132 |
# Delete ssh public key |
129 | 133 |
elsif ($op eq 'delete') { |
130 | 134 |
my $row_id = param('row-id'); |
135 |
+ |
|
131 | 136 |
eval { |
132 | 137 |
app->dbi->connector->txn(sub { |
133 | 138 |
app->dbi->model('ssh_public_key')->delete(where => {row_id => $row_id}); |
... | ... |
@@ -146,7 +151,13 @@ |
146 | 151 |
} |
147 | 152 |
} |
148 | 153 |
|
149 |
- my $keys = app->dbi->model('ssh_public_key')->select(where => {user_id => $user})->all; |
|
154 |
+ my $keys = app->dbi->model('ssh_public_key')->select( |
|
155 |
+ { |
|
156 |
+ __MY__ => '*' |
|
157 |
+ }, |
|
158 |
+ where => {'__user.id' => $user_id}, |
|
159 |
+ append => 'order by title' |
|
160 |
+ )->all; |
|
150 | 161 |
%> |
151 | 162 |
|
152 | 163 |
% layout 'common', title => 'SSH keys'; |
... | ... |
@@ -158,10 +169,10 @@ |
158 | 169 |
<div class="left"> |
159 | 170 |
<ul> |
160 | 171 |
<li> |
161 |
- <a href="<%= url_for("/$user/_settings") %>">Profile</a> |
|
172 |
+ <a href="<%= url_for("/$user_id/_settings") %>">Profile</a> |
|
162 | 173 |
</li> |
163 | 174 |
<li class="active"> |
164 |
- <a href="<%= url_for("/$user/_settings/ssh") %>">SSH keys</a> |
|
175 |
+ <a href="<%= url_for("/$user_id/_settings/ssh") %>">SSH keys</a> |
|
165 | 176 |
</li> |
166 | 177 |
</ul> |
167 | 178 |
</div> |
... | ... |
@@ -172,7 +183,7 @@ |
172 | 183 |
<div class="user-settings-container ssh-keys"> |
173 | 184 |
<div> |
174 | 185 |
<div> |
175 |
- <span>SSH Keys</span> (<a href="<%= url_for("/$user.keys") %>">see</a>) |
|
186 |
+ <span>SSH Keys</span> (<a href="<%= url_for("/$user_id.keys") %>">see</a>) |
|
176 | 187 |
</div> |
177 | 188 |
</div> |
178 | 189 |
<div> |
... | ... |
@@ -498,75 +498,6 @@ note 'Delete branch'; |
498 | 498 |
$t->content_unlike(qr/tmp_branch/); |
499 | 499 |
} |
500 | 500 |
|
501 |
-note 'import-branch'; |
|
502 |
-{ |
|
503 |
- system("$FindBin::Bin/../setup_database", $db_file) == 0 |
|
504 |
- or die "Can't setup $db_file"; |
|
505 |
- my $app = Mojo::Server->new->load_app("$FindBin::Bin/../script/gitprep"); |
|
506 |
- |
|
507 |
- my $t = Test::Mojo->new($app); |
|
508 |
- $t->ua->max_redirects(3); |
|
509 |
- |
|
510 |
- # Login as kimoto1 |
|
511 |
- $t->post_ok('/_login?op=login', form => {id => 'kimoto1', password => 'a'}); |
|
512 |
- $t->get_ok('/')->content_like(qr/Logined as kimoto1 /); |
|
513 |
- |
|
514 |
- # Create project |
|
515 |
- $t->post_ok('/_new?op=create', form => {project => 'import-branch1', description => '', readme => 1}); |
|
516 |
- $t->get_ok('/kimoto1')->content_like(qr/import-branch1/); |
|
517 |
- |
|
518 |
- # Login as kimoto2 |
|
519 |
- $t->post_ok('/_login?op=login', form => {id => 'kimoto2', password => 'a'}); |
|
520 |
- $t->get_ok('/')->content_like(qr/Logined as kimoto2 /); |
|
521 |
- |
|
522 |
- # Fork kimoto1/import-branch1 |
|
523 |
- $t->get_ok("/kimoto1/import-branch1/fork"); |
|
524 |
- $t->content_like(qr#Repository is forked from /kimoto1/import-branch1#); |
|
525 |
- |
|
526 |
- # Access not valid user |
|
527 |
- $t->get_ok('/kimoto1/import-branch1/network'); |
|
528 |
- $t->content_like(qr/Network/); |
|
529 |
- $t->content_unlike(qr/Import/); |
|
530 |
- $t->get_ok('/kimoto1/import-branch1/import-branch/kimoto2/import-branch1?remote-branch=master'); |
|
531 |
- $t->content_like(qr/ Index page /); |
|
532 |
- |
|
533 |
- # Show network page import button |
|
534 |
- $t->get_ok('/kimoto2/import-branch1/network'); |
|
535 |
- $t->content_like(qr/Network/); |
|
536 |
- $t->content_like(qr/Import/); |
|
537 |
- |
|
538 |
- # Import branch page access |
|
539 |
- $t->get_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?remote-branch=master'); |
|
540 |
- $t->content_like(qr/Import branch/); |
|
541 |
- |
|
542 |
- # Invalid parameters |
|
543 |
- $t->post_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?remote-branch=master&op=import'); |
|
544 |
- $t->content_like(qr/Branch name is empty/); |
|
545 |
- |
|
546 |
- # Import branch |
|
547 |
- $t->post_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?op=import', form => { |
|
548 |
- branch => 'new1', |
|
549 |
- 'remote-branch' => 'master' |
|
550 |
- }); |
|
551 |
- $t->content_like(qr#Success: import#); |
|
552 |
- $t->get_ok('/kimoto2/import-branch1/branches')->content_like(qr/new1/); |
|
553 |
- |
|
554 |
- # Import same name branch fail |
|
555 |
- $t->post_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?op=import', form => { |
|
556 |
- branch => 'new1', |
|
557 |
- 'remote-branch' => 'master' |
|
558 |
- }); |
|
559 |
- $t->content_like(qr#already exists#); |
|
560 |
- |
|
561 |
- # Import force |
|
562 |
- $t->post_ok('/kimoto2/import-branch1/import-branch/kimoto1/import-branch1?op=import', form => { |
|
563 |
- branch => 'new1', |
|
564 |
- 'remote-branch' => 'master', |
|
565 |
- force => 1 |
|
566 |
- }); |
|
567 |
- $t->content_like(qr#Success: force import#); |
|
568 |
-} |
|
569 |
- |
|
570 | 501 |
note 'Private repository and collaborator'; |
571 | 502 |
{ |
572 | 503 |
unlink $db_file; |