Showing 5 changed files with 114 additions and 17 deletions
+1
.gitignore
... ...
@@ -29,3 +29,4 @@ setup/latest-build
29 29
 setup/work/*
30 30
 setup/build.log
31 31
 xt/admin.db
32
+xt/admin
+13 -7
templates/auto/_new.html.ep
... ...
@@ -1,5 +1,15 @@
1 1
 <%
2
+  # API
3
+  my $api = gitprep_api;
4
+
2 5
   my $op = param('op') || '';
6
+
7
+  # Authentication
8
+  unless ($api->logined) {
9
+    $self->redirect_to('/');
10
+    $self->finish_rendering;
11
+    return;
12
+  }
3 13
   
4 14
   my $errors;
5 15
   if ($op eq 'create') {
... ...
@@ -8,15 +18,10 @@
8 18
     
9 19
     # Validation
10 20
     my $params = $api->params;
11
-    my $keyword_check = sub {
12
-      my $value = shift;
13
-      
14
-      return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/
15
-    };
16 21
     my $rule = [
17 22
       project => [
18 23
         ['not_blank' => 'Repository name is empty'],
19
-        [$keyword_check => 'Invalid repository name']
24
+        ['project_name' => 'Invalid repository name']
20 25
       ],
21 26
       description => [
22 27
         'any'
... ...
@@ -62,7 +67,8 @@
62 67
         }
63 68
         else {
64 69
           $self->redirect_to("/$user/$project");
65
-          return 1;
70
+          $self->finish_rendering;
71
+          return;
66 72
         }
67 73
       }
68 74
     }
+15 -10
templates/settings.html.ep
... ...
@@ -1,19 +1,20 @@
1 1
 <%
2
+  # API
2 3
   my $api = gitprep_api;
3
-  my $logined = $api->logined;
4
-  my $user_is_valid = $logined && $user eq session('user');
5
-  my $default_branch_name = app->manager->default_branch($user, $project);
6
-
7
-  my $git = app->git;
8
-
4
+  
5
+  # Parameters
9 6
   my $op = param('op') || '';
7
+  my $user = param('user') || '';
10 8
   
11
-  unless ($user_is_valid) {
12
-    $self->render_exception('Forbidden');
13
-    $self->res->code(403);
9
+  # Authentication
10
+  unless ($api->logined($user)) {
11
+    $self->redirect_to('/');
12
+    $self->finish_rendering;
14 13
     return;
15 14
   }
16 15
   
16
+  # Rename project
17
+  my $git = app->git;
17 18
   if ($op eq 'rename-project') {
18 19
   
19 20
     # Validation
... ...
@@ -53,6 +54,8 @@
53 54
       $self->render(json => {ok => 0, message => 'Invalid Parameters'});
54 55
     }
55 56
   }
57
+  
58
+  # Change description
56 59
   elsif ($op eq 'change_description') {
57 60
     my $description = param('description');
58 61
     $description = '' unless defined $description;
... ...
@@ -61,6 +64,8 @@
61 64
     $self->render(json => {ok => 1});
62 65
     return $self->res->body;
63 66
   }
67
+  
68
+  # Delete project
64 69
   elsif ($op eq 'delete-project') {
65 70
   
66 71
     # Validation
... ...
@@ -218,7 +223,7 @@
218 223
         Default Branch
219 224
         % my $branches = $git->branches($user, $project);
220 225
         % my $branch_names = [map { $_->{name} } @$branches];
221
-        % push @$branch_names, $default_branch_name unless @$branch_names;
226
+        % push @$branch_names, app->manager->default_branch($user, $project) unless @$branch_names;
222 227
         %= select_field 'default_branch' => $branch_names, style => 'margin-top:5px';
223 228
       </div>
224 229
     </div>
+16
templates/user-settings.html.ep
... ...
@@ -1,3 +1,19 @@
1
+<%
2
+  # API
3
+  my $api = gitprep_api;
4
+  
5
+  # Parameters
6
+  my $op = param('op') || '';
7
+  my $user = param('user') || '';
8
+  
9
+  # Authentication
10
+  unless ($api->logined($user)) {
11
+    $self->redirect_to('/');
12
+    $self->finish_rendering;
13
+    return;
14
+  }
15
+%>
16
+
1 17
 % layout 'common';
2 18
   
3 19
   %= include '/include/header';
+69
xt/admin.t
... ...
@@ -5,6 +5,7 @@ use utf8;
5 5
 use lib "$FindBin::Bin/../mojo/lib";
6 6
 use lib "$FindBin::Bin/../lib";
7 7
 use lib "$FindBin::Bin/../extlib/lib/perl5";
8
+use File::Path 'rmtree';
8 9
 use Encode qw/encode decode/;
9 10
 
10 11
 use Test::Mojo;
... ...
@@ -268,3 +269,71 @@ note 'Reset password';
268 269
   $t->post_ok('/_login?op=login', form => {id => 'kimoto1', password => 'b'});
269 270
   $t->get_ok('/')->content_like(qr/kimoto1/);
270 271
 }
272
+
273
+note 'User Account Settings';
274
+{
275
+  unlink $db_file;
276
+  rmtree $rep_home;
277
+
278
+  my $app = Gitprep->new;
279
+  my $t = Test::Mojo->new($app);
280
+  $t->ua->max_redirects(3);
281
+
282
+  # Create admin user
283
+  $t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'})
284
+    ->content_like(qr/Login Page/);
285
+  ;
286
+
287
+  # Login as admin
288
+  $t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
289
+
290
+  # Create user
291
+  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto1', password => 'a', password2 => 'a'})
292
+    ->content_like(qr/kimoto1/);
293
+  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto2', password => 'a', password2 => 'a'})
294
+    ->content_like(qr/kimoto2/);
295
+  
296
+  # Login as kimoto1
297
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto1', password => 'a'});
298
+
299
+  # User account settings
300
+  $t->get_ok('/kimoto1/_settings')
301
+    ->content_like(qr/User Account Settings/)
302
+  ;
303
+  
304
+  # Other user can't access
305
+  $t->get_ok('/kimoto2/_settings')
306
+    ->content_like(qr/Users/)
307
+  ;
308
+  
309
+  note 'Create repository';
310
+  {
311
+    # Create repository page
312
+    $t->get_ok('/_new')
313
+      ->content_like(qr/Create repository/)
314
+    ;
315
+    
316
+    # Not logined user can't access
317
+    $t->get_ok('/_logout');
318
+    $t->get_ok('/_new')
319
+      ->content_like(qr/Users/)
320
+    ;
321
+    $t->post_ok('/_login?op=login', form => {id => 'kimoto1', password => 'a'});
322
+    
323
+    # Create repository
324
+    $t->post_ok('/_new?op=create', form => {project => 't1', description => 'Hello'})
325
+      ->content_like(qr/Create a new repository on the command line/)
326
+      ->content_like(qr/t1\.git/)
327
+      ->content_like(qr/Hello/)
328
+    ;
329
+
330
+    # Create repository(with readme)
331
+    $t->post_ok('/_new?op=create', form => {project => 't2', description => 'Hello', readme => 1})
332
+      ->content_like(qr/first commit/)
333
+      ->content_like(qr/t2\.git/)
334
+      ->content_like(qr/README/)
335
+    ;    
336
+  }
337
+}
338
+
339
+