Commit ba8048d71019b5aaa1f92ee5c3415bfddaa9babb

Authored by Dmitriy Zaporozhets
1 parent 6b030fd4

v1.1.0

@@ -28,26 +28,34 @@ sqlite as default db @@ -28,26 +28,34 @@ sqlite as default db
28 28
29 29
30 git clone git://github.com/gitlabhq/gitlabhq.git 30 git clone git://github.com/gitlabhq/gitlabhq.git
  31 +
31 cd gitlabhq/ 32 cd gitlabhq/
32 33
33 # install this library first 34 # install this library first
34 sudo easy_install pygments 35 sudo easy_install pygments
  36 +
  37 + # give your user access to remove git repo
  38 + # Ex.
  39 + # If you are going to use user 'gitlabhq' for rails server
  40 + # gitlabhq ALL = (git) NOPASSWD: /bin/rm" | sudo tee -a /etc/sudoers
  41 + #
  42 + echo "USERNAME ALL = (git) NOPASSWD: /bin/rm" | sudo tee -a /etc/sudoers
35 43
36 sudo gem install bundler 44 sudo gem install bundler
  45 +
37 bundle 46 bundle
38 47
39 - RAILS_ENV=production rake db:setup 48 + bundle exec rake db:setup RAILS_ENV=production
40 49
41 # create admin user 50 # create admin user
42 # login....admin@local.host 51 # login....admin@local.host
43 # pass.....5iveL!fe 52 # pass.....5iveL!fe
44 - RAILS_ENV=production rake db:seed_fu 53 + bundle exec rake db:seed_fu RAILS_ENV=production
45 54
46 Install gitosis, edit conf/gitosis.yml & start server 55 Install gitosis, edit conf/gitosis.yml & start server
47 56
48 rails s -e production 57 rails s -e production
49 58
50 -  
51 == Install Gitosis 59 == Install Gitosis
52 sudo aptitude install gitosis 60 sudo aptitude install gitosis
53 61
@@ -64,6 +72,7 @@ Install gitosis, edit conf/gitosis.yml & start server @@ -64,6 +72,7 @@ Install gitosis, edit conf/gitosis.yml & start server
64 ssh-keygen -t rsa 72 ssh-keygen -t rsa
65 73
66 sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub 74 sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub
  75 +
67 sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update 76 sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
68 77
69 78
@@ -84,3 +93,8 @@ Install gitosis, edit conf/gitosis.yml &amp; start server @@ -84,3 +93,8 @@ Install gitosis, edit conf/gitosis.yml &amp; start server
84 93
85 94
86 echo "gem: --no-rdoc --no-ri" > ~/.gemrc 95 echo "gem: --no-rdoc --no-ri" > ~/.gemrc
  96 +
  97 +== Contribute
  98 +
  99 +We develop project on our private server.
  100 +Want to help? Contact us on twitter or email to become a team member.
app/assets/stylesheets/projects.css.scss
@@ -638,3 +638,12 @@ tbody tr:nth-child(2n) td, tbody tr.even td { @@ -638,3 +638,12 @@ tbody tr:nth-child(2n) td, tbody tr.even td {
638 display:none; 638 display:none;
639 } 639 }
640 } 640 }
  641 +
  642 +.field_with_errors {
  643 + input[type="text"],
  644 + input[type="password"],
  645 + textarea
  646 + {
  647 + background: none repeat scroll 0 0 #FFBBBB
  648 + }
  649 +}
app/controllers/team_members_controller.rb
@@ -8,35 +8,16 @@ class TeamMembersController &lt; ApplicationController @@ -8,35 +8,16 @@ class TeamMembersController &lt; ApplicationController
8 8
9 def show 9 def show
10 @team_member = project.users_projects.find(params[:id]) 10 @team_member = project.users_projects.find(params[:id])
11 -  
12 - respond_to do |format|  
13 - format.html # show.html.erb  
14 - format.js  
15 - end  
16 end 11 end
17 12
18 def new 13 def new
19 @team_member = project.users_projects.new 14 @team_member = project.users_projects.new
20 -  
21 - respond_to do |format|  
22 - format.html # new.html.erb  
23 - format.js  
24 - end  
25 end 15 end
26 16
27 def create 17 def create
28 @team_member = UsersProject.new(params[:team_member]) 18 @team_member = UsersProject.new(params[:team_member])
29 @team_member.project = project 19 @team_member.project = project
30 -  
31 - respond_to do |format|  
32 - if @team_member.save  
33 - format.html { redirect_to @team_member, notice: 'Team member was successfully created.' }  
34 - format.js  
35 - else  
36 - format.html { render action: "new" }  
37 - format.js  
38 - end  
39 - end 20 + @team_member.save
40 end 21 end
41 22
42 def update 23 def update
@@ -45,7 +26,12 @@ class TeamMembersController &lt; ApplicationController @@ -45,7 +26,12 @@ class TeamMembersController &lt; ApplicationController
45 26
46 respond_to do |format| 27 respond_to do |format|
47 format.js 28 format.js
48 - format.html { redirect_to team_project_path(@project)} 29 + format.html do
  30 + unless @team_member.valid?
  31 + flash[:alert] = "User should have at least one role"
  32 + end
  33 + redirect_to team_project_path(@project)
  34 + end
49 end 35 end
50 end 36 end
51 37
app/models/project.rb
@@ -35,7 +35,8 @@ class Project &lt; ActiveRecord::Base @@ -35,7 +35,8 @@ class Project &lt; ActiveRecord::Base
35 :presence => true 35 :presence => true
36 36
37 validate :check_limit 37 validate :check_limit
38 - 38 + validate :repo_name
  39 +
39 after_destroy :destroy_gitosis_project 40 after_destroy :destroy_gitosis_project
40 after_save :update_gitosis_project 41 after_save :update_gitosis_project
41 42
@@ -168,6 +169,12 @@ class Project &lt; ActiveRecord::Base @@ -168,6 +169,12 @@ class Project &lt; ActiveRecord::Base
168 errors[:base] << ("Cant check your ability to create project") 169 errors[:base] << ("Cant check your ability to create project")
169 end 170 end
170 171
  172 + def repo_name
  173 + if path == "gitosis-admin"
  174 + errors.add(:path, " like 'gitosis-admin' is not allowed")
  175 + end
  176 + end
  177 +
171 def valid_repo? 178 def valid_repo?
172 repo 179 repo
173 rescue 180 rescue
app/models/users_project.rb
@@ -9,7 +9,8 @@ class UsersProject &lt; ActiveRecord::Base @@ -9,7 +9,8 @@ class UsersProject &lt; ActiveRecord::Base
9 validates_uniqueness_of :user_id, :scope => [:project_id] 9 validates_uniqueness_of :user_id, :scope => [:project_id]
10 validates_presence_of :user_id 10 validates_presence_of :user_id
11 validates_presence_of :project_id 11 validates_presence_of :project_id
12 - 12 + validate :user_has_a_role_selected
  13 +
13 delegate :name, :email, :to => :user, :prefix => true 14 delegate :name, :email, :to => :user, :prefix => true
14 15
15 def update_gitosis_project 16 def update_gitosis_project
@@ -18,6 +19,10 @@ class UsersProject &lt; ActiveRecord::Base @@ -18,6 +19,10 @@ class UsersProject &lt; ActiveRecord::Base
18 end 19 end
19 end 20 end
20 21
  22 + def user_has_a_role_selected
  23 + errors.add(:base, "Please choose at least one Role in the Access list") unless read || write || admin
  24 + end
  25 +
21 end 26 end
22 # == Schema Information 27 # == Schema Information
23 # 28 #
app/views/commits/_diff.html.haml
1 -.file_stats  
2 - - @commit.diffs.each do |diff|  
3 - - if diff.deleted_file  
4 - %span.removed_file  
5 - %a{:href => "##{diff.a_path}"}  
6 - = diff.a_path  
7 - = image_tag "blueprint_delete.png"  
8 - - elsif diff.renamed_file  
9 - %span.moved_file  
10 - %a{:href => "##{diff.b_path}"}  
11 - = diff.a_path  
12 - = "->"  
13 - = diff.b_path  
14 - = image_tag "blueprint_notice.png"  
15 - - elsif diff.new_file  
16 - %span.new_file  
17 - %a{:href => "##{diff.b_path}"}  
18 - = diff.b_path  
19 - = image_tag "blueprint_add.png"  
20 - - else  
21 - %span.edit_file  
22 - %a{:href => "##{diff.b_path}"}  
23 - = diff.b_path  
24 - = image_tag "blueprint_info.png" 1 +.file_stats= render "commits/diff_head"
  2 +
25 - @commit.diffs.each do |diff| 3 - @commit.diffs.each do |diff|
26 - next if diff.diff.empty? 4 - next if diff.diff.empty?
27 - file = (@commit.tree / diff.b_path) 5 - file = (@commit.tree / diff.b_path)
@@ -31,24 +9,12 @@ @@ -31,24 +9,12 @@
31 - if diff.deleted_file 9 - if diff.deleted_file
32 %strong{:id => "#{diff.b_path}"}= diff.a_path 10 %strong{:id => "#{diff.b_path}"}= diff.a_path
33 - else 11 - else
34 - %strong{:id => "#{diff.b_path}"}= diff.b_path 12 + = link_to tree_file_project_path(@project, @commit.id, diff.b_path) do
  13 + %strong{:id => "#{diff.b_path}"}= diff.b_path
35 %br/ 14 %br/
36 .diff_file_content 15 .diff_file_content
37 - if file.text? 16 - if file.text?
38 - - lines_arr = diff.diff.lines.to_a  
39 - - line_old = lines_arr[2].match(/-(\d)/)[0].to_i.abs rescue 0  
40 - - line_new = lines_arr[2].match(/\+(\d)/)[0].to_i.abs rescue 0  
41 - - lines = lines_arr[3..-1].join  
42 - - lines.each_line do |line|  
43 - = diff_line(line, line_new, line_old)  
44 - - if line[0] == "+"  
45 - - line_new += 1  
46 - - elsif  
47 - - line[0] == "-"  
48 - - line_old += 1  
49 - - else  
50 - - line_new += 1  
51 - - line_old += 1 17 + = render :partial => "commits/text_file", :locals => { :diff => diff }
52 - elsif file.image? 18 - elsif file.image?
53 .diff_file_content_image 19 .diff_file_content_image
54 %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} 20 %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"}
app/views/commits/_diff_head.html.haml 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +- @commit.diffs.each do |diff|
  2 + - if diff.deleted_file
  3 + %span.removed_file
  4 + %a{:href => "##{diff.a_path}"}
  5 + = diff.a_path
  6 + = image_tag "blueprint_delete.png"
  7 + - elsif diff.renamed_file
  8 + %span.moved_file
  9 + %a{:href => "##{diff.b_path}"}
  10 + = diff.a_path
  11 + = "->"
  12 + = diff.b_path
  13 + = image_tag "blueprint_notice.png"
  14 + - elsif diff.new_file
  15 + %span.new_file
  16 + %a{:href => "##{diff.b_path}"}
  17 + = diff.b_path
  18 + = image_tag "blueprint_add.png"
  19 + - else
  20 + %span.edit_file
  21 + %a{:href => "##{diff.b_path}"}
  22 + = diff.b_path
  23 + = image_tag "blueprint_info.png"
  24 +
app/views/commits/_text_file.html.haml 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +- lines_arr = diff.diff.lines.to_a
  2 +- line_old = lines_arr[2].match(/-(\d)/)[0].to_i.abs rescue 0
  3 +- line_new = lines_arr[2].match(/\+(\d)/)[0].to_i.abs rescue 0
  4 +- lines = lines_arr[3..-1].join
  5 +- lines.each_line do |line|
  6 + = diff_line(line, line_new, line_old)
  7 + - if line[0] == "+"
  8 + - line_new += 1
  9 + - elsif
  10 + - line[0] == "-"
  11 + - line_old += 1
  12 + - else
  13 + - line_new += 1
  14 + - line_old += 1
  15 +
db/fixtures/development/001_admin.rb
1 -# Admin account  
2 admin = User.create( 1 admin = User.create(
3 :email => "admin@local.host", 2 :email => "admin@local.host",
4 :name => "Administrator", 3 :name => "Administrator",
@@ -9,3 +8,12 @@ admin = User.create( @@ -9,3 +8,12 @@ admin = User.create(
9 admin.projects_limit = 10000 8 admin.projects_limit = 10000
10 admin.admin = true 9 admin.admin = true
11 admin.save! 10 admin.save!
  11 +
  12 +if admin.valid?
  13 +puts %q[
  14 +Administrator account created:
  15 +
  16 +login.........admin@local.host
  17 +password......5iveL!fe
  18 +]
  19 +end
db/fixtures/production/001_admin.rb
@@ -8,3 +8,12 @@ admin = User.create( @@ -8,3 +8,12 @@ admin = User.create(
8 admin.projects_limit = 10000 8 admin.projects_limit = 10000
9 admin.admin = true 9 admin.admin = true
10 admin.save! 10 admin.save!
  11 +
  12 +if admin.valid?
  13 +puts %q[
  14 +Administrator account created:
  15 +
  16 +login.........admin@local.host
  17 +password......5iveL!fe
  18 +]
  19 +end
install.rb
@@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
1 -root_path = File.expand_path(File.dirname(__FILE__))  
2 -require File.join(root_path, "lib", "color")  
3 -include Color  
4 -  
5 -#  
6 -# ruby ./update.rb development # or test or production (default)  
7 -#  
8 -envs = ["production", "test", "development"]  
9 -env = if envs.include?(ARGV[0])  
10 - ARGV[0]  
11 - else  
12 - "production"  
13 - end  
14 -  
15 -puts green " == Install for ENV=#{env} ..."  
16 -  
17 -# bundle install  
18 -`bundle install`  
19 -  
20 -# migrate db  
21 -`bundle exec rake db:create RAILS_ENV=#{env}`  
22 -`bundle exec rake db:schema:load RAILS_ENV=#{env}`  
23 -`bundle exec rake db:seed_fu RAILS_ENV=#{env}`  
24 -  
25 -puts green %q[  
26 -Administrator account created:  
27 -  
28 -login.........admin@local.host  
29 -password......5iveL!fe  
30 -]  
31 -  
32 -puts green " == Done! Now you can start server"  
lib/gitosis.rb
@@ -42,7 +42,7 @@ class Gitosis @@ -42,7 +42,7 @@ class Gitosis
42 end 42 end
43 43
44 def destroy_project(project) 44 def destroy_project(project)
45 - FileUtils.rm_rf(project.path_to_repo) 45 + `sudo -u git rm -rf #{project.path_to_repo}`
46 46
47 conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf')) 47 conf = IniFile.new(File.join(@local_dir,'gitosis','gitosis.conf'))
48 48
spec/models/project_spec.rb
@@ -4,11 +4,15 @@ describe Project do @@ -4,11 +4,15 @@ describe Project do
4 describe "Associations" do 4 describe "Associations" do
5 it { should have_many(:users) } 5 it { should have_many(:users) }
6 it { should have_many(:users_projects) } 6 it { should have_many(:users_projects) }
  7 + it { should have_many(:issues) }
  8 + it { should have_many(:notes) }
  9 + it { should have_many(:snippets) }
7 end 10 end
8 11
9 describe "Validation" do 12 describe "Validation" do
10 it { should validate_presence_of(:name) } 13 it { should validate_presence_of(:name) }
11 it { should validate_presence_of(:path) } 14 it { should validate_presence_of(:path) }
  15 + it { should validate_presence_of(:code) }
12 end 16 end
13 17
14 describe "Respond to" do 18 describe "Respond to" do
@@ -31,6 +35,11 @@ describe Project do @@ -31,6 +35,11 @@ describe Project do
31 it { should respond_to(:commit) } 35 it { should respond_to(:commit) }
32 end 36 end
33 37
  38 + it "should not allow 'gitosis-admin' as repo name" do
  39 + should allow_value("blah").for(:path)
  40 + should_not allow_value("gitosis-admin").for(:path)
  41 + end
  42 +
34 it "should return valid url to repo" do 43 it "should return valid url to repo" do
35 project = Project.new(:path => "somewhere") 44 project = Project.new(:path => "somewhere")
36 project.url_to_repo.should == "git@localhost:somewhere.git" 45 project.url_to_repo.should == "git@localhost:somewhere.git"
spec/requests/team_members_spec.rb
@@ -29,19 +29,37 @@ describe &quot;TeamMembers&quot; do @@ -29,19 +29,37 @@ describe &quot;TeamMembers&quot; do
29 29
30 describe "fill in" do 30 describe "fill in" do
31 before do 31 before do
32 - check "team_member_read"  
33 click_link "Select user" 32 click_link "Select user"
34 click_link @user_1.name 33 click_link @user_1.name
35 - #select @user_1.name, :from => "team_member_user_id" 34 +
  35 + within "#team_member_new" do
  36 + check "team_member_read"
  37 + check "team_member_write"
  38 + end
36 end 39 end
37 40
38 - it { expect { click_button "Save" }.to change {UsersProject.count}.by(1) } 41 + it { expect { click_button "Save";sleep(1) }.to change {UsersProject.count}.by(1) }
39 42
40 it "should add new member to table" do 43 it "should add new member to table" do
41 click_button "Save" 44 click_button "Save"
  45 + @member = UsersProject.last
42 46
43 - page.should_not have_content("Add new member")  
44 page.should have_content @user_1.name 47 page.should have_content @user_1.name
  48 +
  49 + @member.read.should be_true
  50 + @member.write.should be_true
  51 + @member.admin.should be_false
  52 + end
  53 +
  54 + it "should not allow creation without access selected" do
  55 + within "#team_member_new" do
  56 + uncheck "team_member_read"
  57 + uncheck "team_member_write"
  58 + uncheck "team_member_admin"
  59 + end
  60 +
  61 + expect { click_button "Save" }.to_not change {UsersProject.count}
  62 + page.should have_content("Please choose at least one Role in the Access list")
45 end 63 end
46 end 64 end
47 end 65 end
update.rb
@@ -1,44 +0,0 @@ @@ -1,44 +0,0 @@
1 -root_path = File.expand_path(File.dirname(__FILE__))  
2 -require File.join(root_path, "lib", "color")  
3 -include Color  
4 -  
5 -def version  
6 - File.read("VERSION")  
7 -end  
8 -  
9 -#  
10 -# ruby ./update.rb development # or test or production (default)  
11 -#  
12 -envs = ["production", "test", "development"]  
13 -env = if envs.include?(ARGV[0])  
14 - ARGV[0]  
15 - else  
16 - "production"  
17 - end  
18 -  
19 -puts yellow "== RAILS ENV | #{env}"  
20 -current_version = version  
21 -puts yellow "Your version is #{current_version}"  
22 -puts yellow "Check for new version: $ git pull origin 1x"  
23 -`git pull origin 1x` # pull from origin  
24 -  
25 -# latest version  
26 -if version == current_version  
27 - puts yellow "You have a latest version"  
28 -else  
29 - puts green "Update to #{version}"  
30 -  
31 -`bundle install`  
32 -  
33 - # migrate db  
34 -if env == "development"  
35 -`bundle exec rake db:migrate RAILS_ENV=development`  
36 -`bundle exec rake db:migrate RAILS_ENV=test`  
37 -else  
38 -`bundle exec rake db:migrate RAILS_ENV=#{env}`  
39 -end  
40 -  
41 - puts green "== Done! Now you can start/restart server"  
42 -end  
43 -  
44 -