Commit 4cbb29cfadb243733185cdfaefe34e15dee35260

Authored by Dmitriy Zaporozhets
1 parent e56a47ab

Fix not_in_project scope. Added counters in admin -> users. Improved seeds

app/models/user.rb
@@ -77,7 +77,6 @@ class User < ActiveRecord::Base @@ -77,7 +77,6 @@ class User < ActiveRecord::Base
77 delegate :path, to: :namespace, allow_nil: true, prefix: true 77 delegate :path, to: :namespace, allow_nil: true, prefix: true
78 78
79 # Scopes 79 # Scopes
80 - scope :not_in_project, ->(project) { where("id not in (:ids)", ids: project.users.map(&:id) ) }  
81 scope :admins, where(admin: true) 80 scope :admins, where(admin: true)
82 scope :blocked, where(blocked: true) 81 scope :blocked, where(blocked: true)
83 scope :active, where(blocked: false) 82 scope :active, where(blocked: false)
@@ -93,6 +92,14 @@ class User < ActiveRecord::Base @@ -93,6 +92,14 @@ class User < ActiveRecord::Base
93 end 92 end
94 end 93 end
95 94
  95 + def not_in_project(project)
  96 + if project.users.present?
  97 + where("id not in (:ids)", ids: project.users.map(&:id) )
  98 + else
  99 + scoped
  100 + end
  101 + end
  102 +
96 def without_projects 103 def without_projects
97 where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)') 104 where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)')
98 end 105 end
app/views/admin/projects/index.html.haml
1 %h3.page_title 1 %h3.page_title
2 - Projects (#{@projects.count}) 2 + Projects (#{Project.count})
3 = link_to 'New Project', new_project_path, class: "btn small right" 3 = link_to 'New Project', new_project_path, class: "btn small right"
4 %br 4 %br
5 = form_tag admin_projects_path, method: :get, class: 'form-inline' do 5 = form_tag admin_projects_path, method: :get, class: 'form-inline' do
app/views/admin/users/index.html.haml
1 %h3.page_title 1 %h3.page_title
2 - Users (#{@admin_users.count}) 2 + Users
3 = link_to 'New User', new_admin_user_path, class: "btn small right" 3 = link_to 'New User', new_admin_user_path, class: "btn small right"
4 %br 4 %br
5 5
@@ -8,16 +8,21 @@ @@ -8,16 +8,21 @@
8 = submit_tag "Search", class: "btn submit primary" 8 = submit_tag "Search", class: "btn submit primary"
9 %ul.nav.nav-tabs 9 %ul.nav.nav-tabs
10 %li{class: "#{'active' unless params[:filter]}"} 10 %li{class: "#{'active' unless params[:filter]}"}
11 - = link_to "Active", admin_users_path 11 + = link_to admin_users_path do
  12 + Active
  13 + %span.badge= User.active.count
12 %li{class: "#{'active' if params[:filter] == "admins"}"} 14 %li{class: "#{'active' if params[:filter] == "admins"}"}
13 = link_to admin_users_path(filter: "admins") do 15 = link_to admin_users_path(filter: "admins") do
14 Admins 16 Admins
  17 + %span.badge= User.admins.count
15 %li{class: "#{'active' if params[:filter] == "blocked"}"} 18 %li{class: "#{'active' if params[:filter] == "blocked"}"}
16 = link_to admin_users_path(filter: "blocked") do 19 = link_to admin_users_path(filter: "blocked") do
17 Blocked 20 Blocked
  21 + %span.badge= User.blocked.count
18 %li{class: "#{'active' if params[:filter] == "wop"}"} 22 %li{class: "#{'active' if params[:filter] == "wop"}"}
19 = link_to admin_users_path(filter: "wop") do 23 = link_to admin_users_path(filter: "wop") do
20 Without projects 24 Without projects
  25 + %span.badge= User.without_projects.count
21 26
22 %table 27 %table
23 %thead 28 %thead
db/fixtures/development/001_admin.rb
@@ -9,13 +9,3 @@ User.seed(:id, [ @@ -9,13 +9,3 @@ User.seed(:id, [
9 admin: true, 9 admin: true,
10 } 10 }
11 ]) 11 ])
12 -  
13 -  
14 -Key.seed(:id, [  
15 - {  
16 - id: 1,  
17 - title: "Sample key",  
18 - key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",  
19 - user_id: 1,  
20 - }  
21 -])  
db/fixtures/development/002_project.rb
1 Group.seed(:id, [ 1 Group.seed(:id, [
  2 + { id: 99, name: "GitLab", path: 'gitlab', owner_id: 1 },
2 { id: 100, name: "Brightbox", path: 'brightbox', owner_id: 1 }, 3 { id: 100, name: "Brightbox", path: 'brightbox', owner_id: 1 },
3 { id: 101, name: "KDE", path: 'kde', owner_id: 1 }, 4 { id: 101, name: "KDE", path: 'kde', owner_id: 1 },
4 ]) 5 ])
5 6
6 Project.seed(:id, [ 7 Project.seed(:id, [
  8 +
  9 + # Global
7 { id: 1, name: "Underscore.js", path: "underscore", owner_id: 1 }, 10 { id: 1, name: "Underscore.js", path: "underscore", owner_id: 1 },
8 { id: 2, name: "Diaspora", path: "diaspora", owner_id: 1 }, 11 { id: 2, name: "Diaspora", path: "diaspora", owner_id: 1 },
  12 +
  13 + # Brightbox
9 { id: 3, namespace_id: 100, name: "Brightbox CLI", path: "brightbox-cli", owner_id: 1 }, 14 { id: 3, namespace_id: 100, name: "Brightbox CLI", path: "brightbox-cli", owner_id: 1 },
10 { id: 4, namespace_id: 100, name: "Puppet", path: "puppet", owner_id: 1 }, 15 { id: 4, namespace_id: 100, name: "Puppet", path: "puppet", owner_id: 1 },
  16 +
  17 + # KDE
11 { id: 5, namespace_id: 101, name: "kdebase", path: "kdebase", owner_id: 1}, 18 { id: 5, namespace_id: 101, name: "kdebase", path: "kdebase", owner_id: 1},
12 { id: 6, namespace_id: 101, name: "kdelibs", path: "kdelibs", owner_id: 1}, 19 { id: 6, namespace_id: 101, name: "kdelibs", path: "kdelibs", owner_id: 1},
13 { id: 7, namespace_id: 101, name: "amarok", path: "amarok", owner_id: 1}, 20 { id: 7, namespace_id: 101, name: "amarok", path: "amarok", owner_id: 1},
  21 +
  22 + # GitLab
  23 + { id: 8, namespace_id: 99, name: "gitlabhq", path: "gitlabhq", owner_id: 1},
  24 + { id: 9, namespace_id: 99, name: "gitlab-ci", path: "gitlab-ci", owner_id: 1},
  25 + { id: 10, namespace_id: 99, name: "gitlab-recipes", path: "gitlab-recipes", owner_id: 1},
14 ]) 26 ])
db/fixtures/development/003_users.rb
1 -User.seed(:id, [  
2 - { id: 2, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},  
3 - { id: 3, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},  
4 - { id: 4, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},  
5 - { id: 5, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},  
6 - { id: 6, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},  
7 - { id: 7, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},  
8 - { id: 8, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email},  
9 - { id: 9, username: Faker::Internet.user_name, name: Faker::Name.name, email: Faker::Internet.email}  
10 -])  
11 - 1 +Gitlab::Seeder.quiet do
  2 + (2..300).each do |i|
  3 + begin
  4 + User.seed(:id, [{
  5 + id: i,
  6 + username: Faker::Internet.user_name,
  7 + name: Faker::Name.name,
  8 + email: Faker::Internet.email,
  9 + }])
  10 + print '.'
  11 + rescue ActiveRecord::RecordNotSaved
  12 + print 'F'
  13 + end
  14 + end
  15 +end
db/fixtures/development/004_teams.rb
1 UsersProject.skip_callback(:save, :after, :update_repository) 1 UsersProject.skip_callback(:save, :after, :update_repository)
2 2
3 -UsersProject.seed(:id, [  
4 - { :id => 1, :project_id => 1, :user_id => 1, :project_access => UsersProject::MASTER },  
5 - { :id => 2, :project_id => 1, :user_id => 2, :project_access => UsersProject::REPORTER},  
6 - { :id => 3, :project_id => 1, :user_id => 3, :project_access => UsersProject::REPORTER},  
7 - { :id => 4, :project_id => 1, :user_id => 4, :project_access => UsersProject::REPORTER},  
8 - { :id => 5, :project_id => 1, :user_id => 5, :project_access => UsersProject::REPORTER},  
9 -  
10 - { :id => 6, :project_id => 2, :user_id => 1, :project_access => UsersProject::MASTER },  
11 - { :id => 7, :project_id => 2, :user_id => 2, :project_access => UsersProject::REPORTER},  
12 - { :id => 8, :project_id => 2, :user_id => 3, :project_access => UsersProject::REPORTER},  
13 - { :id => 9, :project_id => 2, :user_id => 4, :project_access => UsersProject::MASTER},  
14 - { :id => 11, :project_id => 2, :user_id => 5, :project_access => UsersProject::MASTER},  
15 -  
16 - { :id => 12, :project_id => 3, :user_id => 1, :project_access => UsersProject::MASTER },  
17 - { :id => 13, :project_id => 3, :user_id => 2, :project_access => UsersProject::REPORTER},  
18 - { :id => 14, :project_id => 3, :user_id => 3, :project_access => UsersProject::MASTER},  
19 - { :id => 15, :project_id => 3, :user_id => 4, :project_access => UsersProject::REPORTER},  
20 - { :id => 16, :project_id => 3, :user_id => 5, :project_access => UsersProject::MASTER}  
21 -]) 3 +Gitlab::Seeder.quiet do
  4 +
  5 + (1..300).each do |i|
  6 + # Random Project
  7 + project = Project.scoped.sample
  8 +
  9 + # Random user
  10 + user = User.not_in_project(project).sample
  11 +
  12 + next unless user
  13 +
  14 + UsersProject.seed(:id, [{
  15 + id: i,
  16 + project_id: project.id,
  17 + user_id: user.id,
  18 + project_access: UsersProject.access_roles.values.sample
  19 + }])
  20 +
  21 + print('.')
  22 + end
  23 +end
22 24
23 UsersProject.set_callback(:save, :after, :update_repository) 25 UsersProject.set_callback(:save, :after, :update_repository)
24 26
db/fixtures/development/006_wall.rb
1 Gitlab::Seeder.quiet do 1 Gitlab::Seeder.quiet do
2 (1..300).each do |i| 2 (1..300).each do |i|
3 # Random Project 3 # Random Project
4 - project_id = rand(2) + 1  
5 - project = Project.find(project_id) 4 + project = Project.all.sample
6 5
7 # Random user 6 # Random user
8 user = project.users.sample 7 user = project.users.sample
  8 +
  9 + next unless user
  10 +
9 user_id = user.id 11 user_id = user.id
10 12
11 Note.seed(:id, [{ 13 Note.seed(:id, [{
12 id: i, 14 id: i,
13 - project_id: project_id, 15 + project_id: project.id,
14 author_id: user_id, 16 author_id: user_id,
15 note: Faker::Lorem.sentence(6) 17 note: Faker::Lorem.sentence(6)
16 }]) 18 }])
db/fixtures/development/007_issues.rb
1 Gitlab::Seeder.quiet do 1 Gitlab::Seeder.quiet do
2 (1..300).each do |i| 2 (1..300).each do |i|
3 # Random Project 3 # Random Project
4 - project_id = rand(2) + 1  
5 - project = Project.find(project_id) 4 + project = Project.all.sample
6 5
7 # Random user 6 # Random user
8 user = project.users.sample 7 user = project.users.sample
  8 +
  9 + next unless user
  10 +
9 user_id = user.id 11 user_id = user.id
10 IssueObserver.current_user = user 12 IssueObserver.current_user = user
11 13
12 Issue.seed(:id, [{ 14 Issue.seed(:id, [{
13 id: i, 15 id: i,
14 - project_id: project_id, 16 + project_id: project.id,
15 author_id: user_id, 17 author_id: user_id,
16 assignee_id: user_id, 18 assignee_id: user_id,
17 closed: [true, false].sample, 19 closed: [true, false].sample,
db/fixtures/development/008_merge_requests.rb
1 Gitlab::Seeder.quiet do 1 Gitlab::Seeder.quiet do
2 (1..300).each do |i| 2 (1..300).each do |i|
3 # Random Project 3 # Random Project
4 - project_id = rand(2) + 1  
5 - project = Project.find(project_id) 4 + project = Project.all.sample
6 5
7 # Random user 6 # Random user
8 user = project.users.sample 7 user = project.users.sample
  8 +
  9 + next unless user
  10 +
9 user_id = user.id 11 user_id = user.id
10 MergeRequestObserver.current_user = user 12 MergeRequestObserver.current_user = user
11 -  
12 MergeRequest.seed(:id, [{ 13 MergeRequest.seed(:id, [{
13 id: i, 14 id: i,
14 source_branch: 'master', 15 source_branch: 'master',
15 target_branch: 'feature', 16 target_branch: 'feature',
16 - project_id: project_id, 17 + project_id: project.id,
17 author_id: user_id, 18 author_id: user_id,
18 assignee_id: user_id, 19 assignee_id: user_id,
19 closed: [true, false].sample, 20 closed: [true, false].sample,
db/fixtures/development/009_source_code.rb
1 -root = Gitlab.config.git_base_path 1 +root = Gitlab.config.gitolite.repos_path
2 2
3 projects = [ 3 projects = [
4 - { path: 'underscore.git', git: 'https://github.com/documentcloud/underscore.git' },  
5 - { path: 'diaspora.git', git: 'https://github.com/diaspora/diaspora.git' }, 4 + { path: 'underscore.git', git: 'https://github.com/documentcloud/underscore.git' },
  5 + { path: 'diaspora.git', git: 'https://github.com/diaspora/diaspora.git' },
6 { path: 'brightbox/brightbox-cli.git', git: 'https://github.com/brightbox/brightbox-cli.git' }, 6 { path: 'brightbox/brightbox-cli.git', git: 'https://github.com/brightbox/brightbox-cli.git' },
7 - { path: 'brightbox/puppet.git', git: 'https://github.com/brightbox/puppet.git' }, 7 + { path: 'brightbox/puppet.git', git: 'https://github.com/brightbox/puppet.git' },
  8 + { path: 'gitlab/gitlabhq.git', git: 'https://github.com/gitlabhq/gitlabhq.git' },
  9 + { path: 'gitlab/gitlab-ci.git', git: 'https://github.com/gitlabhq/gitlab-ci.git' },
  10 + { path: 'gitlab/gitlab-recipres.git', git: 'https://github.com/gitlabhq/gitlab-recipes.git' },
8 ] 11 ]
9 12
10 projects.each do |project| 13 projects.each do |project|
11 project_path = File.join(root, project[:path]) 14 project_path = File.join(root, project[:path])
12 15
13 -  
14 next if File.exists?(project_path) 16 next if File.exists?(project_path)
15 17
16 cmds = [ 18 cmds = [
db/fixtures/development/010_keys.rb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +Key.seed(:id, [
  2 + {
  3 + id: 1,
  4 + title: "Sample key",
  5 + key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",
  6 + user_id: 1,
  7 + }
  8 +])
lib/support/truncate_repositories.sh 0 → 100755
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +#!/bin/bash
  2 +
  3 +echo "Danger!!! Data Loss"
  4 +while true; do
  5 + read -p "Do you wish to all directories except gitolite-admin.git from /home/git/repositories/ (y/n) ?: " yn
  6 + case $yn in
  7 + [Yy]* ) sh -c "find /home/git/repositories/. -maxdepth 1 -not -name 'gitolite-admin.git' -not -name '.' | xargs sudo rm -rf"; break;;
  8 + [Nn]* ) exit;;
  9 + * ) echo "Please answer yes or no.";;
  10 + esac
  11 +done