Showing 2 changed files with 82 additions and 47 deletions
+71 -47
lib/Gitprep.pm
... ...
@@ -236,60 +236,84 @@ sub startup {
236 236
         {
237 237
           my $r = $r->route('/:project', project => $id_re);
238 238
           
239
-          # Home
240
-          $r->get('/' => template '/project');
241
-          
242
-          # Commit
243
-          $r->get('/commit/*diff' => template '/commit');
244
-          
245
-          # Commits
246
-          $r->get('/commits/*rev_file' => template '/commits');
247
-          
248
-          # Branches
249
-          $r->any('/branches/*base_branch' => {base_branch => undef} => template '/branches');
239
+          {
240
+            my $r = $r->under(sub {
241
+              my $self = shift;
242
+              
243
+              # Private
244
+              my $session_user = $self->session('user');
245
+              my $user = $self->param('user');
246
+              my $project = $self->param('project');
247
+              my $private = $self->app->manager->is_private_project($user, $project);
248
+              if ($private) {
249
+                if ($session_user eq $user) {
250
+                  return 1;
251
+                }
252
+                else {
253
+                  $self->render('private');
254
+                  return 0;
255
+                }
256
+              }
257
+              else {
258
+                return 1;
259
+              }
260
+            });
261
+            
262
+            # Home
263
+            $r->get('/' => template '/project');
264
+            
265
+            # Commit
266
+            $r->get('/commit/*diff' => template '/commit');
267
+            
268
+            # Commits
269
+            $r->get('/commits/*rev_file' => template '/commits');
270
+            
271
+            # Branches
272
+            $r->any('/branches/*base_branch' => {base_branch => undef} => template '/branches');
250 273
 
251
-          # Tags
252
-          $r->get('/tags' => template '/tags');
274
+            # Tags
275
+            $r->get('/tags' => template '/tags');
253 276
 
254
-          # Tree
255
-          $r->get('/tree/*rev_dir' => template '/tree');
256
-          
257
-          # Blob
258
-          $r->get('/blob/*rev_file' => template '/blob');
259
-          
260
-          # Sub module
261
-          $r->get('/submodule/*rev_file' => template '/submodule');
277
+            # Tree
278
+            $r->get('/tree/*rev_dir' => template '/tree');
279
+            
280
+            # Blob
281
+            $r->get('/blob/*rev_file' => template '/blob');
282
+            
283
+            # Sub module
284
+            $r->get('/submodule/*rev_file' => template '/submodule');
262 285
 
263
-          # Raw
264
-          $r->get('/raw/*rev_file' => template '/raw');
286
+            # Raw
287
+            $r->get('/raw/*rev_file' => template '/raw');
265 288
 
266
-          # Blame
267
-          $r->get('/blame/*rev_file' => template '/blame');
268
-          
269
-          # Archive
270
-          $r->get('/archive/(*rev).tar.gz' => template '/archive')->to(archive_type => 'tar');
271
-          $r->get('/archive/(*rev).zip' => template '/archive')->to(archive_type => 'zip' );
272
-          
273
-          # Compare
274
-          $r->get('/compare/(*rev1)...(*rev2)' => template '/compare');
275
-          
276
-          # Settings
277
-          $r->any('/settings' => template '/settings');
278
-          
279
-          # Fork
280
-          $r->any('/fork' => template '/fork');
289
+            # Blame
290
+            $r->get('/blame/*rev_file' => template '/blame');
291
+            
292
+            # Archive
293
+            $r->get('/archive/(*rev).tar.gz' => template '/archive')->to(archive_type => 'tar');
294
+            $r->get('/archive/(*rev).zip' => template '/archive')->to(archive_type => 'zip' );
295
+            
296
+            # Compare
297
+            $r->get('/compare/(*rev1)...(*rev2)' => template '/compare');
298
+            
299
+            # Settings
300
+            $r->any('/settings' => template '/settings');
301
+            
302
+            # Fork
303
+            $r->any('/fork' => template '/fork');
281 304
 
282
-          # Network
283
-          $r->get('/network' => template '/network');
305
+            # Network
306
+            $r->get('/network' => template '/network');
284 307
 
285
-          # Network Graph
286
-          $r->get('/network/graph/(*rev1)...(*rev2_abs)' => template '/network/graph');
308
+            # Network Graph
309
+            $r->get('/network/graph/(*rev1)...(*rev2_abs)' => template '/network/graph');
287 310
 
288
-          # Import branch
289
-          $r->any('/import-branch/:remote_user/:remote_project' => template '/import-branch');
290
-          
291
-          # Get branches and tags
292
-          $r->get('/api/revs' => template '/api/revs');
311
+            # Import branch
312
+            $r->any('/import-branch/:remote_user/:remote_project' => template '/import-branch');
313
+            
314
+            # Get branches and tags
315
+            $r->get('/api/revs' => template '/api/revs');
316
+          }
293 317
         }
294 318
       }
295 319
     }
+11
templates/private.html.ep
... ...
@@ -0,0 +1,11 @@
1
+% layout 'common', title => 'Private repository';
2
+
3
+  %= include '/include/header';
4
+  
5
+  <div class="container">
6
+    <div class="well" style="background:white;text-align:center;font-size:20px;">
7
+      <%= $project %> is private repository
8
+    </div>
9
+  </div>
10
+
11
+  %= include '/include/footer';