From 7a8a892efdf59925a95cdf6504f7c74c31b87eeb Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 25 Sep 2015 17:12:41 +0200 Subject: Add "rake gitlab:list_repos" task --- lib/tasks/gitlab/list_repos.rake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/tasks/gitlab/list_repos.rake (limited to 'lib') diff --git a/lib/tasks/gitlab/list_repos.rake b/lib/tasks/gitlab/list_repos.rake new file mode 100644 index 00000000000..1377e1ea910 --- /dev/null +++ b/lib/tasks/gitlab/list_repos.rake @@ -0,0 +1,16 @@ +namespace :gitlab do + task list_repos: :environment do + scope = Project + if ENV['SINCE'] + date = Time.parse(ENV['SINCE']) + warn "Listing repositories with activity since #{date}" + project_ids = Project.where(['last_activity_at > ?', date]).pluck(:id) + scope = scope.where(id: project_ids) + end + scope.find_each do |project| + base = File.join(Gitlab.config.gitlab_shell.repos_path, project.path_with_namespace) + puts base + '.git' + puts base + '.wiki.git' + end + end +end -- cgit v1.2.1 From 54e6c0045bb13c05cc5478cbdf47d3246bd9fe2b Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Tue, 22 Sep 2015 14:04:14 +0200 Subject: Added three rake tasks for repository maintainance Tasks added: gitlab:git:repack gitlab:git:gc gitlab:git:prune --- lib/tasks/gitlab/git.rake | 52 ++++++++++++++++++++++++++++++++++++++ lib/tasks/gitlab/task_helpers.rake | 4 +++ 2 files changed, 56 insertions(+) create mode 100644 lib/tasks/gitlab/git.rake (limited to 'lib') diff --git a/lib/tasks/gitlab/git.rake b/lib/tasks/gitlab/git.rake new file mode 100644 index 00000000000..4fbf5a9393c --- /dev/null +++ b/lib/tasks/gitlab/git.rake @@ -0,0 +1,52 @@ +namespace :gitlab do + namespace :git do + + desc "GitLab | Git | Repack" + task repack: :environment do + failures = perform_git_cmd('git repack -a --quiet', 'Git repack') + if failures.empty? + puts "Done".green + else + output_failures(failures) + end + end + + desc "GitLab | Git | Run gits garbage collection on all repo's" + task gc: :environment do + failures = perform_git_cmd('git gc --auto --quiet', "Garbage Collection") + if failures.empty? + puts "Done".green + else + output_failures(failures) + end + end + + desc "GitLab | Git | Git prune all repo's" + task prune: :environment do + failures = perform_git_cmd('git prune', 'Git Prune') + if failures.empty? + puts "Done".green + else + output_failures(failures) + end + end + + def perform_git_cmd(cmd, message) + puts "Starting #{message} on all repositories" + + failures = [] + all_repos.each do |r| + puts "Performing #{message} at #{r}" + failures << r unless system(*%w(#{cmd}), chdir: r) + end + + failures + end + + def output_failures(failures) + puts "The following repositories reported errors:".red + failures.each { |f| puts "- #{f}" } + end + + end +end diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake index c95b6540ebc..77c41bf61cb 100644 --- a/lib/tasks/gitlab/task_helpers.rake +++ b/lib/tasks/gitlab/task_helpers.rake @@ -128,4 +128,8 @@ namespace :gitlab do false end end + + def all_repos + Dir.glob(File.join(Gitlab.config.gitlab_shell.repos_path, '**/*\.git')) + end end -- cgit v1.2.1 From 8db063b579322238af43f6d04b5968d9c6ea935d Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Thu, 1 Oct 2015 13:34:41 +0200 Subject: Scalable way of requesting all repos --- lib/tasks/gitlab/git.rake | 19 +++++++++++-------- lib/tasks/gitlab/task_helpers.rake | 6 +++++- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/git.rake b/lib/tasks/gitlab/git.rake index 4fbf5a9393c..65ee430d550 100644 --- a/lib/tasks/gitlab/git.rake +++ b/lib/tasks/gitlab/git.rake @@ -3,7 +3,7 @@ namespace :gitlab do desc "GitLab | Git | Repack" task repack: :environment do - failures = perform_git_cmd('git repack -a --quiet', 'Git repack') + failures = perform_git_cmd(%W(git repack -a --quiet), "Repacking repo") if failures.empty? puts "Done".green else @@ -11,9 +11,9 @@ namespace :gitlab do end end - desc "GitLab | Git | Run gits garbage collection on all repo's" + desc "GitLab | Git | Run garbage collection on all repos" task gc: :environment do - failures = perform_git_cmd('git gc --auto --quiet', "Garbage Collection") + failures = perform_git_cmd(%W(git gc --auto --quiet), "Garbage Collecting") if failures.empty? puts "Done".green else @@ -21,9 +21,9 @@ namespace :gitlab do end end - desc "GitLab | Git | Git prune all repo's" + desc "GitLab | Git | Prune all repos" task prune: :environment do - failures = perform_git_cmd('git prune', 'Git Prune') + failures = perform_git_cmd(%W(git prune), "Git Prune") if failures.empty? puts "Done".green else @@ -35,9 +35,12 @@ namespace :gitlab do puts "Starting #{message} on all repositories" failures = [] - all_repos.each do |r| - puts "Performing #{message} at #{r}" - failures << r unless system(*%w(#{cmd}), chdir: r) + all_repos do |repo| + if system(*cmd, chdir: repo) + puts "Performed #{message} at #{repo}" + else + failures << repo + end end failures diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake index 77c41bf61cb..e35fd47c5c4 100644 --- a/lib/tasks/gitlab/task_helpers.rake +++ b/lib/tasks/gitlab/task_helpers.rake @@ -130,6 +130,10 @@ namespace :gitlab do end def all_repos - Dir.glob(File.join(Gitlab.config.gitlab_shell.repos_path, '**/*\.git')) + IO.popen(%W(find #{Gitlab.config.gitlab_shell.repos_path} -mindepth 2 -maxdepth 2 -type d -name *.git)) do |find| + find.each_line do |path| + yield path.chomp + end + end end end -- cgit v1.2.1 From 8f817c7b08bcad23e1b047f84cc60d1748104e2a Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 7 Dec 2015 17:10:40 +0100 Subject: Add API group projects endpoint. --- lib/api/groups.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/api/groups.rb b/lib/api/groups.rb index 024aeec2e14..1a14d870a4a 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -65,6 +65,18 @@ module API DestroyGroupService.new(group, current_user).execute end + # Get a list of projects in this group + # + # Example Request: + # GET /groups/:id/projects + get ":id/projects" do + group = find_group(params[:id]) + projects = group.projects + projects = filter_projects(projects) + projects = paginate projects + present projects, with: Entities::Project + end + # Transfer a project to the Group namespace # # Parameters: -- cgit v1.2.1 From 41a4785b855a082197b3c22004cb8af96e5453ee Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 8 Dec 2015 14:41:19 +0100 Subject: Fix signin with OmniAuth providers --- lib/omni_auth/request_forgery_protection.rb | 63 +++++------------------------ 1 file changed, 9 insertions(+), 54 deletions(-) (limited to 'lib') diff --git a/lib/omni_auth/request_forgery_protection.rb b/lib/omni_auth/request_forgery_protection.rb index 3557522d3c9..69155131d8d 100644 --- a/lib/omni_auth/request_forgery_protection.rb +++ b/lib/omni_auth/request_forgery_protection.rb @@ -1,66 +1,21 @@ # Protects OmniAuth request phase against CSRF. module OmniAuth - # Based on ActionController::RequestForgeryProtection. - class RequestForgeryProtection - def initialize(env) - @env = env - end - - def request - @request ||= ActionDispatch::Request.new(@env) - end - - def session - request.session - end - - def reset_session - request.reset_session - end - - def params - request.params - end - - def call - verify_authenticity_token - end + module RequestForgeryProtection + class Controller < ActionController::Base + protect_from_forgery with: :exception - def verify_authenticity_token - if !verified_request? - Rails.logger.warn "Can't verify CSRF token authenticity" if Rails.logger - handle_unverified_request + def index + head :ok end end - private - - def protect_against_forgery? - ApplicationController.allow_forgery_protection - end - - def request_forgery_protection_token - ApplicationController.request_forgery_protection_token - end - - def forgery_protection_strategy - ApplicationController.forgery_protection_strategy - end - - def verified_request? - !protect_against_forgery? || request.get? || request.head? || - form_authenticity_token == params[request_forgery_protection_token] || - form_authenticity_token == request.headers['X-CSRF-Token'] - end - - def handle_unverified_request - forgery_protection_strategy.new(self).handle_unverified_request + def self.app + @app ||= Controller.action(:index) end - # Sets the token value for the current session. - def form_authenticity_token - session[:_csrf_token] ||= SecureRandom.base64(32) + def self.call(env) + app.call(env) end end end -- cgit v1.2.1 From 23f383ef69889c9829ad36afa53b5abfbf4b5511 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 8 Dec 2015 16:06:06 +0100 Subject: Detect project and namespace changes in list:repos --- lib/tasks/gitlab/list_repos.rake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/list_repos.rake b/lib/tasks/gitlab/list_repos.rake index 1377e1ea910..c7596e7abcb 100644 --- a/lib/tasks/gitlab/list_repos.rake +++ b/lib/tasks/gitlab/list_repos.rake @@ -3,9 +3,10 @@ namespace :gitlab do scope = Project if ENV['SINCE'] date = Time.parse(ENV['SINCE']) - warn "Listing repositories with activity since #{date}" - project_ids = Project.where(['last_activity_at > ?', date]).pluck(:id) - scope = scope.where(id: project_ids) + warn "Listing repositories with activity or changes since #{date}" + project_ids = Project.where('last_activity_at > ? OR updated_at > ?', date, date).pluck(:id).sort + namespace_ids = Namespace.where(['updated_at > ?', date]).pluck(:id).sort + scope = scope.where('id IN (?) OR namespace_id in (?)', project_ids, namespace_ids) end scope.find_each do |project| base = File.join(Gitlab.config.gitlab_shell.repos_path, project.path_with_namespace) -- cgit v1.2.1 From 1d410ac96a96462d9f48ec4e43a4e819bbffdeee Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 7 Dec 2015 23:01:53 -0800 Subject: Update project repository size and commit count during import:repos task Closes #3848 --- lib/tasks/gitlab/import.rake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake index c1ee271ae2b..1c04f47f08f 100644 --- a/lib/tasks/gitlab/import.rake +++ b/lib/tasks/gitlab/import.rake @@ -64,6 +64,8 @@ namespace :gitlab do if project.persisted? puts " * Created #{project.name} (#{repo_path})".green + project.update_repository_size + project.update_commit_count else puts " * Failed trying to create #{project.name} (#{repo_path})".red puts " Errors: #{project.errors.messages}".red -- cgit v1.2.1 From bf5683f8892c4aefc4c996812ece6291b701dada Mon Sep 17 00:00:00 2001 From: Drew Blessing Date: Tue, 8 Dec 2015 09:47:42 -0600 Subject: Block LDAP user when they are no longer found in the LDAP server --- lib/gitlab/ldap/access.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/ldap/access.rb b/lib/gitlab/ldap/access.rb index 16ff03c38d4..c438a3d167b 100644 --- a/lib/gitlab/ldap/access.rb +++ b/lib/gitlab/ldap/access.rb @@ -37,13 +37,15 @@ module Gitlab # Block user in GitLab if he/she was blocked in AD if Gitlab::LDAP::Person.disabled_via_active_directory?(user.ldap_identity.extern_uid, adapter) - user.block unless user.blocked? + user.block false else user.activate if user.blocked? && !ldap_config.block_auto_created_users true end else + # Block the user if they no longer exist in LDAP/AD + user.block false end rescue -- cgit v1.2.1