Showing 3 changed files with 83 additions and 3 deletions
+3 -1
templates/settings.html.ep
... ...
@@ -101,7 +101,9 @@
101 101
       $errors = ['Internal Error'];
102 102
     }
103 103
     else {
104
-      flash(message => 'Private status is saved.');
104
+      my $message = 'Private status is saved. Repository is '
105
+        . ($private ? 'private' : 'public');
106
+      flash(message => $message);
105 107
       $self->redirect_to('current');
106 108
       return;
107 109
     }
BIN
xt/basic.db
Binary file not shown.
+80 -2
xt/user.t
... ...
@@ -12,8 +12,6 @@ use Encode qw/encode decode/;
12 12
 
13 13
 use Test::Mojo;
14 14
 
15
-$ENV{GITPREP_TEST} = 1;
16
-
17 15
 # Test DB
18 16
 my $db_file = $ENV{GITPREP_DB_FILE} = "$FindBin::Bin/user.db";
19 17
 
... ...
@@ -529,3 +527,83 @@ note 'import-branch';
529 527
   });
530 528
   $t->content_like(qr#Success: force import#);
531 529
 }
530
+
531
+note 'Private repository and collaborator';
532
+{
533
+  unlink $db_file;
534
+  rmtree $rep_home;
535
+
536
+  my $app = Gitprep->new;
537
+  my $t = Test::Mojo->new($app);
538
+  $t->ua->max_redirects(3);
539
+
540
+  # Create admin user
541
+  $t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'});
542
+  $t->content_like(qr/Login page/);
543
+
544
+  # Login success
545
+  $t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
546
+  $t->content_like(qr/Admin/);
547
+  
548
+  # Create user
549
+  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto', password => 'a', password2 => 'a'});
550
+  $t->content_like(qr/Success.*created/);
551
+  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto2', password => 'a', password2 => 'a'});
552
+  $t->content_like(qr/Success.*created/);
553
+
554
+  # Login as kimoto
555
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
556
+  $t->get_ok('/')->content_like(qr/kimoto/);
557
+
558
+  # Create repository
559
+  $t->post_ok('/_new?op=create', form => {project => 't1', description => 'Hello', readme => 1});
560
+  $t->content_like(qr/README/);
561
+  
562
+  # Check private repository
563
+  $t->post_ok("/kimoto/t1/settings?op=private", form => {private => 1});
564
+  $t->content_like(qr/Repository is private/);
565
+  
566
+  # Can access repository myself
567
+  $t->get_ok("/kimoto/t1");
568
+  $t->content_like(qr/README/);
569
+
570
+  # Login as kimoto2
571
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto2', password => 'a'});
572
+  $t->get_ok('/')->content_like(qr/kimoto2/);
573
+  
574
+  # Can't access private repository
575
+  $t->get_ok("/kimoto/t1");
576
+  $t->content_like(qr/t1 is private repository/);
577
+  
578
+  # Login as kimoto
579
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
580
+  $t->get_ok('/')->content_like(qr/kimoto/);
581
+  
582
+  # Add collaborator
583
+  $t->post_ok("/kimoto/t1/settings/collaboration?op=add", form => {collaborator => 'kimoto2'});
584
+  $t->content_like(qr/Collaborator kimoto2 is added/);
585
+  
586
+  # Login as kimoto2
587
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto2', password => 'a'});
588
+  $t->get_ok('/')->content_like(qr/kimoto2/);
589
+  
590
+  # Can access private repository from collaborator
591
+  $t->get_ok("/kimoto/t1");
592
+  $t->content_like(qr/README/);
593
+
594
+  # Login as kimoto
595
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
596
+  $t->get_ok('/')->content_like(qr/kimoto/);
597
+
598
+  # Delete collaborator
599
+  $t->post_ok("/kimoto/t1/settings/collaboration?op=remove", form => {collaborator => 'kimoto2'});
600
+  $t->content_like(qr/Collaborator kimoto2 is removed/);
601
+
602
+  # Login as kimoto2
603
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto2', password => 'a'});
604
+  $t->get_ok('/')->content_like(qr/kimoto2/);
605
+
606
+  # Can't access private repository
607
+  $t->get_ok("/kimoto/t1");
608
+  $t->content_like(qr/t1 is private repository/);
609
+}