Showing 3 changed files with 57 additions and 56 deletions
+26 -52
templates/fork.html.ep
... ...
@@ -1,62 +1,36 @@
1 1
 <%
2
+  # API
2 3
   my $api = gitprep_api;
3
-  my $logined = $api->logined;
4 4
   
5
-  # Validation
6
-  my $params = $api->params;
7
-  my $rule = [
8
-    user => [
9
-      'user_name'
10
-    ],
11
-    project => [
12
-      'project_name'
13
-    ]
14
-  ];
15
-  my $vresult = app->validator->validate($params, $rule);
5
+  # Paramters
6
+  my $user = param('user');
7
+  my $project = param('project');
8
+  my $current_user = session('user');
16 9
   
17
-  # Fork project
18
-  if ($vresult->is_ok) {
19
-    unless ($logined) {
20
-      $self->redirect_to("/$user/$project");
21
-      $self->finish_rendering;
22
-      return;
23
-    }
24
-    
25
-    my $login_user = session('user');
26
-    my $data = $vresult->data;
27
-    my $user = $data->{user};
28
-    my $project = $data->{project};
29
-    
30
-    if ($login_user eq $user) {
31
-      $self->redirect_to("/$user/$project");
32
-      $self->finish_rendering;
33
-      return;
34
-    }
35
-    
36
-    # Already exists
37
-    if (app->manager->exists_project($login_user, $project)) {
38
-      $self->redirect_to("/$login_user/$project");
39
-      $self->finish_rendering;
40
-      return;
10
+  # Can fork?
11
+  unless ($api->logined) {
12
+    $self->redirect_to('/');
13
+    $self->finish_rendering;
14
+    return;
15
+  }
16
+  
17
+  # Repository is already exists
18
+  if (app->manager->exists_project($current_user, $project)) {
19
+    $self->redirect_to("/$current_user/$project");
20
+    $self->finish_rendering;
21
+    return;
22
+  }
23
+  # Fork
24
+  else {
25
+    eval { app->manager->fork_project($current_user, $user, $project) };
26
+    if ($@) {
27
+      $self->render_exception('Internal Error');
28
+      app->log->error("/$user/$project/fork: $@");
41 29
     }
42
-    # Fork
43 30
     else {
44
-      eval { app->manager->fork_project($login_user, $user, $project) };
45
-      if ($@) {
46
-        $self->render_exception($@);
47
-        $self->finish_rendering;
48
-        return;
49
-      }
50
-      else {
51
-        flash('original_project', "$user/$project");
52
-        $self->redirect_to("/$login_user/$project");
53
-        $self->finish_rendering;
54
-        return;
55
-      }
31
+      flash(message => "Repository is forked from /$user/$project.");
32
+      $self->redirect_to("/$current_user/$project");
56 33
     }
57
-  }
58
-  else {
59
-    $self->redirect_to("/$user/$project");
60 34
     $self->finish_rendering;
61 35
     return;
62 36
   }
+3 -1
templates/project.html.ep
... ...
@@ -107,10 +107,12 @@
107 107
   %= include '/include/header';
108 108
   
109 109
   <div class="container">
110
+    %= include '/include/message', message => flash('message');
111
+    
110 112
     % if (my $original_project = flash('original_project')) {
111 113
       <div class="alert alert-success">
112 114
         <button type="button" class="close" data-dismiss="alert">&times;</button>
113
-        Repository is forked from <%= $original_project %>.
115
+        
114 116
       </div>
115 117
     % }
116 118
     
+28 -3
xt/user.t
... ...
@@ -367,10 +367,35 @@ note 'User Account Settings';
367 367
     
368 368
     note 'Delete project';
369 369
     {
370
-      $t->post_ok('/kimoto1/t2/settings?op=delete-project');
371
-      $t->content_like(qr/Repository t2 is deleted/);
370
+      $t->post_ok('/kimoto1/t1/settings?op=delete-project');
371
+      $t->content_like(qr/Repository t1 is deleted/);
372 372
       $t->get_ok('/kimoto1');
373
-      $t->content_unlike(qr/t2/);
373
+      $t->content_unlike(qr/t1/);
374 374
     }
375 375
   }
376 376
 }
377
+
378
+note 'fork';
379
+{
380
+  my $app = Gitprep->new;
381
+  my $t = Test::Mojo->new($app);
382
+  $t->ua->max_redirects(3);
383
+  
384
+  # Don't logind
385
+  $t->get_ok("/kimoto1/t2/fork");
386
+  $t->content_like(qr/Users/);
387
+
388
+  # Login as kimoto2
389
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto2', password => 'a'});
390
+  
391
+  # Fork kimoto1/t2
392
+  $t->get_ok("/kimoto1/t2/fork");
393
+  $t->content_like(qr#Repository is forked from /kimoto1/t2#);
394
+  
395
+  # Fork kimoto1/t2 again
396
+  $t->get_ok("/kimoto1/t2/fork");
397
+  $t->content_like(qr/forked from/);
398
+  $t->content_like(qr#kimoto1/t2#);
399
+  $t->content_unlike(qr/Repository is forked from/);
400
+  
401
+}