diff options
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/backend/grack_auth.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/client.rb | 23 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/importer.rb | 34 | ||||
-rw-r--r-- | lib/gitlab/current_settings.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/github_import/importer.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/gitlab_import/importer.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/import_formatter.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ldap/user.rb | 11 |
8 files changed, 71 insertions, 25 deletions
diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb index 12292f614e9..dc87aa52a3e 100644 --- a/lib/gitlab/backend/grack_auth.rb +++ b/lib/gitlab/backend/grack_auth.rb @@ -26,12 +26,8 @@ module Grack auth! if project && authorized_request? - if ENV['GITLAB_GRACK_AUTH_ONLY'] == '1' - # Tell gitlab-git-http-server the request is OK, and what the GL_ID is - render_grack_auth_ok - else - @app.call(env) - end + # Tell gitlab-git-http-server the request is OK, and what the GL_ID is + render_grack_auth_ok elsif @user.nil? && !@gitlab_ci unauthorized else @@ -132,7 +128,9 @@ module Grack case git_cmd when *Gitlab::GitAccess::DOWNLOAD_COMMANDS - if user + if !Gitlab.config.gitlab_shell.upload_pack + false + elsif user Gitlab::GitAccess.new(user, project).download_access_check.allowed? elsif project.public? # Allow clone/fetch for public projects @@ -141,7 +139,9 @@ module Grack false end when *Gitlab::GitAccess::PUSH_COMMANDS - if user + if !Gitlab.config.gitlab_shell.receive_pack + false + elsif user # Skip user authorization on upload request. # It will be done by the pre-receive hook in the repository. true diff --git a/lib/gitlab/bitbucket_import/client.rb b/lib/gitlab/bitbucket_import/client.rb index aec44b8c87b..d88a6eaac6b 100644 --- a/lib/gitlab/bitbucket_import/client.rb +++ b/lib/gitlab/bitbucket_import/client.rb @@ -52,11 +52,26 @@ module Gitlab end def issues(project_identifier) - JSON.parse(get("/api/1.0/repositories/#{project_identifier}/issues").body) + all_issues = [] + offset = 0 + per_page = 50 # Maximum number allowed by Bitbucket + index = 0 + + begin + issues = JSON.parse(get(issue_api_endpoint(project_identifier, per_page, offset)).body) + # Find out how many total issues are present + total = issues["count"] if index == 0 + all_issues.concat(issues["issues"]) + offset += issues["issues"].count + index += 1 + end while all_issues.count < total + + all_issues end def issue_comments(project_identifier, issue_id) - JSON.parse(get("/api/1.0/repositories/#{project_identifier}/issues/#{issue_id}/comments").body) + comments = JSON.parse(get("/api/1.0/repositories/#{project_identifier}/issues/#{issue_id}/comments").body) + comments.sort_by { |comment| comment["utc_created_on"] } end def project(project_identifier) @@ -100,6 +115,10 @@ module Gitlab response end + def issue_api_endpoint(project_identifier, per_page, offset) + "/api/1.0/repositories/#{project_identifier}/issues?sort=utc_created_on&limit=#{per_page}&start=#{offset}" + end + def config Gitlab.config.omniauth.providers.find { |provider| provider.name == "bitbucket"} end diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index d8a7d29f1bf..2355b3c6ddc 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -20,8 +20,18 @@ module Gitlab #Issues && Comments issues = client.issues(project_identifier) - issues["issues"].each do |issue| - body = @formatter.author_line(issue["reported_by"]["username"], issue["content"]) + issues.each do |issue| + body = '' + reporter = nil + author = 'Anonymous' + + if issue["reported_by"] && issue["reported_by"]["username"] + reporter = issue["reported_by"]["username"] + author = reporter + end + + body = @formatter.author_line(author) + body += issue["content"] comments = client.issue_comments(project_identifier, issue["local_id"]) @@ -30,14 +40,20 @@ module Gitlab end comments.each do |comment| - body += @formatter.comment(comment["author_info"]["username"], comment["utc_created_on"], comment["content"]) + author = 'Anonymous' + + if comment["author_info"] && comment["author_info"]["username"] + author = comment["author_info"]["username"] + end + + body += @formatter.comment(author, comment["utc_created_on"], comment["content"]) end project.issues.create!( description: body, title: issue["title"], state: %w(resolved invalid duplicate wontfix).include?(issue["status"]) ? 'closed' : 'opened', - author_id: gl_user_id(project, issue["reported_by"]["username"]) + author_id: gl_user_id(project, reporter) ) end @@ -47,9 +63,13 @@ module Gitlab private def gl_user_id(project, bitbucket_id) - user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s) - (user && user.id) || project.creator_id - end + if bitbucket_id + user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s) + (user && user.id) || project.creator_id + else + project.creator_id + end + end end end end diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 1a2a50a14d0..7ad3ed8728f 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -4,7 +4,7 @@ module Gitlab key = :current_application_settings RequestStore.store[key] ||= begin - if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('application_settings') + if ActiveRecord::Base.connection.active? && ActiveRecord::Base.connection.table_exists?('application_settings') ApplicationSetting.current || ApplicationSetting.create_from_defaults else fake_application_settings diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb index 8c106a61735..bd7340a80f1 100644 --- a/lib/gitlab/github_import/importer.rb +++ b/lib/gitlab/github_import/importer.rb @@ -18,7 +18,8 @@ module Gitlab direction: :asc).each do |issue| if issue.pull_request.nil? - body = @formatter.author_line(issue.user.login, issue.body) + body = @formatter.author_line(issue.user.login) + body += issue.body if issue.comments > 0 body += @formatter.comments_header diff --git a/lib/gitlab/gitlab_import/importer.rb b/lib/gitlab/gitlab_import/importer.rb index 50594d2b24f..e24b94d6159 100644 --- a/lib/gitlab/gitlab_import/importer.rb +++ b/lib/gitlab/gitlab_import/importer.rb @@ -18,7 +18,8 @@ module Gitlab issues = client.issues(project_identifier) issues.each do |issue| - body = @formatter.author_line(issue["author"]["name"], issue["description"]) + body = @formatter.author_line(issue["author"]["name"]) + body += issue["description"] comments = client.issue_comments(project_identifier, issue["id"]) diff --git a/lib/gitlab/import_formatter.rb b/lib/gitlab/import_formatter.rb index 72e041a90b1..3e54456e936 100644 --- a/lib/gitlab/import_formatter.rb +++ b/lib/gitlab/import_formatter.rb @@ -8,8 +8,8 @@ module Gitlab "\n\n\n**Imported comments:**\n" end - def author_line(author, body) - "*Created by: #{author}*\n\n#{body}" + def author_line(author) + "*Created by: #{author}*\n\n" end end end diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index f7f3ba9ad7d..04a22237478 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -44,9 +44,14 @@ module Gitlab gl_user.skip_reconfirmation! gl_user.email = auth_hash.email - # Build new identity only if we dont have have same one - gl_user.identities.find_or_initialize_by(provider: auth_hash.provider, - extern_uid: auth_hash.uid) + # find_or_initialize_by doesn't update `gl_user.identities`, and isn't autosaved. + identity = gl_user.identities.find { |identity| identity.provider == auth_hash.provider } + identity ||= gl_user.identities.build(provider: auth_hash.provider) + + # For a new user set extern_uid to the LDAP DN + # For an existing user with matching email but changed DN, update the DN. + # For an existing user with no change in DN, this line changes nothing. + identity.extern_uid = auth_hash.uid gl_user end |