Commit 4c6224aad173a26f1fbe20588b4b155f031d779f
1 parent
eb626edd
Exists in
master
and in
4 other branches
Public git read-only access via http
Showing
10 changed files
with
89 additions
and
15 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +class Public::ProjectsController < ApplicationController | |
| 2 | + skip_before_filter :authenticate_user!, | |
| 3 | + :reject_blocked, :set_current_user_for_observers, | |
| 4 | + :add_abilities | |
| 5 | + | |
| 6 | + layout 'public' | |
| 7 | + | |
| 8 | + def index | |
| 9 | + @projects = Project.where(public: true) | |
| 10 | + end | |
| 11 | +end | ... | ... |
app/models/project.rb
| ... | ... | @@ -28,7 +28,7 @@ class Project < ActiveRecord::Base |
| 28 | 28 | attr_accessible :name, :path, :description, :default_branch, :issues_enabled, |
| 29 | 29 | :wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin] |
| 30 | 30 | |
| 31 | - attr_accessible :namespace_id, :creator_id, as: :admin | |
| 31 | + attr_accessible :namespace_id, :creator_id, :public, as: :admin | |
| 32 | 32 | |
| 33 | 33 | attr_accessor :error_code |
| 34 | 34 | ... | ... |
app/views/admin/projects/_form.html.haml
| ... | ... | @@ -44,6 +44,13 @@ |
| 44 | 44 | .input= f.check_box :wiki_enabled |
| 45 | 45 | |
| 46 | 46 | %fieldset.features |
| 47 | + %legend Public mode: | |
| 48 | + .clearfix | |
| 49 | + = f.label :public do | |
| 50 | + %span Allow public http clone | |
| 51 | + .input= f.check_box :public | |
| 52 | + | |
| 53 | + %fieldset.features | |
| 47 | 54 | %legend Transfer: |
| 48 | 55 | .control-group |
| 49 | 56 | = f.label :namespace_id do | ... | ... |
app/views/admin/projects/show.html.haml
| ... | ... | @@ -77,6 +77,13 @@ |
| 77 | 77 | SSH: |
| 78 | 78 | %td |
| 79 | 79 | = link_to @project.ssh_url_to_repo |
| 80 | + - if @project.public | |
| 81 | + %tr.bgred | |
| 82 | + %td | |
| 83 | + %b | |
| 84 | + Public Read-Only Code access: | |
| 85 | + %td | |
| 86 | + = check_box_tag 'public', nil, @project.public | |
| 80 | 87 | |
| 81 | 88 | - if @repository |
| 82 | 89 | %table.zebra-striped | ... | ... |
| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | +!!! 5 | |
| 2 | +%html{ lang: "en"} | |
| 3 | + = render "layouts/head", title: "Error" | |
| 4 | + %body{class: "#{app_theme} application"} | |
| 5 | + %header.navbar.navbar-static-top.navbar-gitlab | |
| 6 | + .navbar-inner | |
| 7 | + .container | |
| 8 | + %div.app_logo | |
| 9 | + %span.separator | |
| 10 | + = link_to public_root_path, class: "home" do | |
| 11 | + %h1 GITLAB | |
| 12 | + %span.separator | |
| 13 | + %h1.project_name Public | |
| 14 | + .container | |
| 15 | + .content | |
| 16 | + .prepend-top-20 | |
| 17 | + = yield | ... | ... |
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +%h3.page_title | |
| 2 | + Projects | |
| 3 | + %small Read-Only Access | |
| 4 | +%hr | |
| 5 | + | |
| 6 | +%ul.well-list | |
| 7 | + - @projects.each do |project| | |
| 8 | + %li.clearfix | |
| 9 | + %h5 | |
| 10 | + %i.icon-star.cgreen | |
| 11 | + = project.name_with_namespace | |
| 12 | + .right | |
| 13 | + %span.monospace.tiny | |
| 14 | + git clone #{project.http_url_to_repo} | ... | ... |
config/routes.rb
| ... | ... | @@ -37,6 +37,14 @@ Gitlab::Application.routes.draw do |
| 37 | 37 | get 'help/raketasks' => 'help#raketasks' |
| 38 | 38 | |
| 39 | 39 | # |
| 40 | + # Public namespace | |
| 41 | + # | |
| 42 | + namespace :public do | |
| 43 | + resources :projects, only: [:index] | |
| 44 | + root to: "projects#index" | |
| 45 | + end | |
| 46 | + | |
| 47 | + # | |
| 40 | 48 | # Admin Area |
| 41 | 49 | # |
| 42 | 50 | namespace :admin do | ... | ... |
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 12 | # It's strongly recommended to check this file into your version control system. |
| 13 | 13 | |
| 14 | -ActiveRecord::Schema.define(:version => 20130102143055) do | |
| 14 | +ActiveRecord::Schema.define(:version => 20130110172407) do | |
| 15 | 15 | |
| 16 | 16 | create_table "events", :force => true do |t| |
| 17 | 17 | t.string "target_type" |
| ... | ... | @@ -145,16 +145,17 @@ ActiveRecord::Schema.define(:version => 20130102143055) do |
| 145 | 145 | t.string "name" |
| 146 | 146 | t.string "path" |
| 147 | 147 | t.text "description" |
| 148 | - t.datetime "created_at", :null => false | |
| 149 | - t.datetime "updated_at", :null => false | |
| 150 | - t.boolean "private_flag", :default => true, :null => false | |
| 148 | + t.datetime "created_at", :null => false | |
| 149 | + t.datetime "updated_at", :null => false | |
| 150 | + t.boolean "private_flag", :default => true, :null => false | |
| 151 | 151 | t.integer "creator_id" |
| 152 | 152 | t.string "default_branch" |
| 153 | - t.boolean "issues_enabled", :default => true, :null => false | |
| 154 | - t.boolean "wall_enabled", :default => true, :null => false | |
| 155 | - t.boolean "merge_requests_enabled", :default => true, :null => false | |
| 156 | - t.boolean "wiki_enabled", :default => true, :null => false | |
| 153 | + t.boolean "issues_enabled", :default => true, :null => false | |
| 154 | + t.boolean "wall_enabled", :default => true, :null => false | |
| 155 | + t.boolean "merge_requests_enabled", :default => true, :null => false | |
| 156 | + t.boolean "wiki_enabled", :default => true, :null => false | |
| 157 | 157 | t.integer "namespace_id" |
| 158 | + t.boolean "public", :default => false, :null => false | |
| 158 | 159 | end |
| 159 | 160 | |
| 160 | 161 | add_index "projects", ["creator_id"], :name => "index_projects_on_owner_id" | ... | ... |
lib/gitlab/backend/grack_auth.rb
| ... | ... | @@ -3,6 +3,16 @@ module Grack |
| 3 | 3 | attr_accessor :user, :project |
| 4 | 4 | |
| 5 | 5 | def valid? |
| 6 | + # Find project by PATH_INFO from env | |
| 7 | + if m = /^\/([\w\.\/-]+)\.git/.match(@request.path_info).to_a | |
| 8 | + self.project = Project.find_with_namespace(m.last) | |
| 9 | + return false unless project | |
| 10 | + end | |
| 11 | + | |
| 12 | + if @request.get? && project.public | |
| 13 | + return true | |
| 14 | + end | |
| 15 | + | |
| 6 | 16 | # Authentication with username and password |
| 7 | 17 | login, password = @auth.credentials |
| 8 | 18 | |
| ... | ... | @@ -17,12 +27,6 @@ module Grack |
| 17 | 27 | # Pass Gitolite update hook |
| 18 | 28 | ENV['GL_BYPASS_UPDATE_HOOK'] = "true" |
| 19 | 29 | |
| 20 | - # Find project by PATH_INFO from env | |
| 21 | - if m = /^\/([\w\.\/-]+)\.git/.match(@request.path_info).to_a | |
| 22 | - self.project = Project.find_with_namespace(m.last) | |
| 23 | - return false unless project | |
| 24 | - end | |
| 25 | - | |
| 26 | 30 | # Git upload and receive |
| 27 | 31 | if @request.get? |
| 28 | 32 | validate_get_request | ... | ... |