Created
December 26, 2012 23:17
-
-
Save jippi/4383880 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/app/models/users_project.rb b/app/models/users_project.rb | |
| index 3d76a4d..00e7b59 100644 | |
| --- a/app/models/users_project.rb | |
| +++ b/app/models/users_project.rb | |
| @@ -95,13 +95,21 @@ class UsersProject < ActiveRecord::Base | |
| def user_bulk_import(user, project_ids, project_access) | |
| UsersProject.transaction do | |
| + has_keys = user.keys.count > 0 | |
| project_ids.each do |project_id| | |
| users_project = UsersProject.new( | |
| project_access: project_access, | |
| ) | |
| users_project.project_id = project_id | |
| users_project.user_id = user.id | |
| - users_project.save | |
| + | |
| + if has_keys | |
| + users_project.save | |
| + else | |
| + skip_callback(:save, :after, :update_repository) | |
| + users_project.save | |
| + set_callback(:save, :after, :update_repository) | |
| + end | |
| end | |
| end | |
| end | |
| diff --git a/config/environments/production.rb b/config/environments/production.rb | |
| index 52fb887..4d3c227 100644 | |
| --- a/config/environments/production.rb | |
| +++ b/config/environments/production.rb | |
| @@ -28,7 +28,7 @@ Gitlab::Application.configure do | |
| # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx | |
| # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. | |
| - # config.force_ssl = true | |
| + config.force_ssl = true | |
| # See everything in the log (default is :info) | |
| # config.log_level = :debug | |
| diff --git a/lib/support/rewrite-hooks.sh b/lib/support/rewrite-hooks.sh | |
| index 6688785..67f632d 100755 | |
| --- a/lib/support/rewrite-hooks.sh | |
| +++ b/lib/support/rewrite-hooks.sh | |
| @@ -2,18 +2,16 @@ | |
| src="/home/git/repositories" | |
| -for dir in `ls "$src/"` | |
| +for dir in `find $src -maxdepth 2 -type d -name "*.git"` | |
| do | |
| - if [ -d "$src/$dir" ]; then | |
| + base=`basename $dir` | |
| + if [ "$base" = "gitolite-admin.git" ] | |
| + then | |
| + continue; | |
| + fi | |
| - if [ "$dir" = "gitolite-admin.git" ] | |
| - then | |
| - continue | |
| - fi | |
| + project_hook="$dir/hooks/post-receive" | |
| + gitolite_hook="/home/git/.gitolite/hooks/common/post-receive" | |
| - project_hook="$src/$dir/hooks/post-receive" | |
| - gitolite_hook="/home/git/.gitolite/hooks/common/post-receive" | |
| - | |
| - ln -s -f $gitolite_hook $project_hook | |
| - fi | |
| + ln -s -f $gitolite_hook $project_hook | |
| done | |
| diff --git a/lib/tasks/gitlab/bulk_add_permission.rake b/lib/tasks/gitlab/bulk_add_permission.rake | |
| index 36c51d0..01eb4b9 100644 | |
| --- a/lib/tasks/gitlab/bulk_add_permission.rake | |
| +++ b/lib/tasks/gitlab/bulk_add_permission.rake | |
| @@ -13,12 +13,24 @@ namespace :gitlab do | |
| end | |
| end | |
| - desc "GITLAB | Add a specific user to all projects (as a developer)" | |
| - task :user_to_projects, [:email] => :environment do |t, args| | |
| + desc "GITLAB | Add a specific user to all projects by namespace (as a master)" | |
| + task :user_to_projects, [:email, :namespace, :role] => :environment do |t, args| | |
| + raise "Missing 1st argument (email, namespace, role)" if args.email.nil? | |
| + raise "Missing 2nd argument (email, namespace, role)" if args.namespace.nil? | |
| + raise "Missing 3rd argument (email, namespace, role)" if args.namespace.nil? | |
| + | |
| user = User.find_by_email args.email | |
| - project_ids = Project.pluck(:id) | |
| + raise "User could not be found" if user.nil? | |
| + | |
| + namespace = Namespace.find_by_name args.namespace | |
| + raise "Namespace could not be found" if namespace.nil? | |
| - UsersProject.user_bulk_import(user, project_ids, UsersProject::DEVELOPER) | |
| + roles = UsersProject.access_roles | |
| + raise "Invalid user role (#{roles.keys.join(", ")})" unless roles.keys.include? args.role | |
| + | |
| + project_ids = Project.where("namespace_id = ?", namespace.id).pluck(:id) | |
| + UsersProject.user_bulk_import(user, project_ids, roles[args.role]) | |
| end | |
| + | |
| end | |
| -end | |
| \ No newline at end of file | |
| +end | |
| diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake | |
| index 4bf9110..00364a1 100644 | |
| --- a/lib/tasks/gitlab/import.rake | |
| +++ b/lib/tasks/gitlab/import.rake | |
| @@ -13,15 +13,19 @@ namespace :gitlab do | |
| task :repos => :environment do | |
| git_base_path = Gitlab.config.gitolite.repos_path | |
| - repos_to_import = Dir.glob(git_base_path + '/*') | |
| - | |
| + repos_to_import = Dir.glob(git_base_path + '/*/*') | |
| namespaces = Namespace.pluck(:path) | |
| + namespaces = ["sys"] | |
| repos_to_import.each do |repo_path| | |
| - repo_name = File.basename repo_path | |
| + Dir.chdir(git_base_path) | |
| + | |
| + repo_name = File.basename repo_path | |
| + repo_rel_path = repo_path.sub(git_base_path + '/', "").sub(".git", "") | |
| + repo_ns = repo_rel_path.split('/')[0] | |
| # Skip if group or user | |
| - next if namespaces.include?(repo_name) | |
| + next if namespaces.include?(repo_ns) | |
| # skip if not git repo | |
| next unless repo_name =~ /.git$/ | |
| @@ -31,9 +35,9 @@ namespace :gitlab do | |
| path = repo_name.sub(/\.git$/, '') | |
| - project = Project.find_with_namespace(path) | |
| - | |
| - puts "Processing #{repo_name}".yellow | |
| + puts "Processing #{repo_rel_path}".yellow | |
| + project = Project.find_with_namespace(repo_rel_path) | |
| + namespace = Namespace.where("name = :name", name: repo_ns).first | |
| if project | |
| puts " * #{project.name} (#{repo_name}) exists" | |
| @@ -42,6 +46,7 @@ namespace :gitlab do | |
| project_params = { | |
| :name => path, | |
| + :namespace_id => namespace.id | |
| } | |
| project = Project.create_by_user(project_params, user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment