diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 00:09:34 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 00:09:34 +0000 |
commit | 5781a4966047232d4725f9ee4769c4bd5aed9b26 (patch) | |
tree | 0ef2b81a40931ec51f8fdd5284ed9e47cf42a923 /app | |
parent | 4d48b3cfcd74bcca0f0f305746f74cf7224dd78b (diff) | |
download | gitlab-ce-5781a4966047232d4725f9ee4769c4bd5aed9b26.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/concerns/confirm_email_warning.rb | 2 | ||||
-rw-r--r-- | app/controllers/confirmations_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/registrations_controller.rb | 26 | ||||
-rw-r--r-- | app/models/commit.rb | 16 | ||||
-rw-r--r-- | app/models/merge_request.rb | 4 | ||||
-rw-r--r-- | app/models/note.rb | 13 | ||||
-rw-r--r-- | app/models/project.rb | 6 | ||||
-rw-r--r-- | app/models/repository.rb | 9 | ||||
-rw-r--r-- | app/models/user.rb | 7 | ||||
-rw-r--r-- | app/services/issues/close_service.rb | 4 | ||||
-rw-r--r-- | app/workers/process_commit_worker.rb | 14 |
11 files changed, 60 insertions, 43 deletions
diff --git a/app/controllers/concerns/confirm_email_warning.rb b/app/controllers/concerns/confirm_email_warning.rb index f1c0bcd491d..32e1a46e580 100644 --- a/app/controllers/concerns/confirm_email_warning.rb +++ b/app/controllers/concerns/confirm_email_warning.rb @@ -10,7 +10,7 @@ module ConfirmEmailWarning protected def show_confirm_warning? - html_request? && request.get? + html_request? && request.get? && Feature.enabled?(:soft_email_confirmation) end def set_confirm_warning diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index f99345fa99d..a27c4027380 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -11,6 +11,8 @@ class ConfirmationsController < Devise::ConfirmationsController protected def after_resending_confirmation_instructions_path_for(resource) + return users_almost_there_path unless Feature.enabled?(:soft_email_confirmation) + stored_location_for(resource) || dashboard_projects_path end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 855f69a0f98..a6c5a6d8526 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -54,7 +54,7 @@ class RegistrationsController < Devise::RegistrationsController def welcome return redirect_to new_user_registration_path unless current_user - return redirect_to stored_location_or_dashboard(current_user) if current_user.role.present? && !current_user.setup_for_company.nil? + return redirect_to path_for_signed_in_user(current_user) if current_user.role.present? && !current_user.setup_for_company.nil? end def update_registration @@ -64,7 +64,7 @@ class RegistrationsController < Devise::RegistrationsController if result[:status] == :success track_experiment_event(:signup_flow, 'end') # We want this event to be tracked when the user is _in_ the experimental group set_flash_message! :notice, :signed_up - redirect_to stored_location_or_dashboard(current_user) + redirect_to path_for_signed_in_user(current_user) else render :welcome end @@ -111,14 +111,12 @@ class RegistrationsController < Devise::RegistrationsController return users_sign_up_welcome_path if experiment_enabled?(:signup_flow) - stored_location_or_dashboard(user) + path_for_signed_in_user(user) end def after_inactive_sign_up_path_for(resource) - # With the current `allow_unconfirmed_access_for` Devise setting in config/initializers/8_devise.rb, - # this method is never called. Leaving this here in case that value is set to 0. Gitlab::AppLogger.info(user_created_message) - users_almost_there_path + Feature.enabled?(:soft_email_confirmation) ? dashboard_projects_path : users_almost_there_path end private @@ -180,8 +178,20 @@ class RegistrationsController < Devise::RegistrationsController Gitlab::Utils.to_boolean(params[:terms_opt_in]) end - def stored_location_or_dashboard(user) - stored_location_for(user) || dashboard_projects_path + def path_for_signed_in_user(user) + if requires_confirmation?(user) + users_almost_there_path + else + stored_location_for(user) || dashboard_projects_path + end + end + + def requires_confirmation?(user) + return false if user.confirmed? + return false if Feature.enabled?(:soft_email_confirmation) + return false if experiment_enabled?(:signup_flow) + + true end def load_recaptcha diff --git a/app/models/commit.rb b/app/models/commit.rb index 2b8e4aa8278..681fe727456 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -242,14 +242,6 @@ class Commit data end - # Discover issues should be closed when this commit is pushed to a project's - # default branch. - def closes_issues(current_user = self.committer) - return unless repository.repo_type.project? - - Gitlab::ClosingIssueExtractor.new(project, current_user).closed_by_message(safe_message) - end - def lazy_author BatchLoader.for(author_email.downcase).batch do |emails, loader| users = User.by_any_email(emails, confirmed: true).includes(:emails) @@ -299,14 +291,6 @@ class Commit notes.includes(:author, :award_emoji) end - def merge_requests - strong_memoize(:merge_requests) do - next MergeRequest.none unless repository.repo_type.project? && project - - project.merge_requests.by_commit_sha(sha) - end - end - def method_missing(method, *args, &block) @raw.__send__(method, *args, &block) # rubocop:disable GitlabSecurity/PublicSend end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 26e3c8f38f6..0aaeed9f977 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -257,6 +257,10 @@ class MergeRequest < ApplicationRecord with_state(:opened).where(auto_merge_enabled: true) end + scope :including_metrics, -> do + includes(:metrics) + end + ignore_column :state, remove_with: '12.7', remove_after: '2019-12-22' after_save :keep_around_commit, unless: :importing? diff --git a/app/models/note.rb b/app/models/note.rb index 561391a55b6..670a981a78f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -290,6 +290,19 @@ class Note < ApplicationRecord @commit ||= project.commit(commit_id) if commit_id.present? end + # Notes on merge requests and commits can be traced back to one or several + # MRs. This method returns a relation if the note is for one of these types, + # or nil if it is a note on some other object. + def merge_requests + if for_commit? + project.merge_requests.by_commit_sha(commit_id) + elsif for_merge_request? + MergeRequest.id_in(noteable_id) + else + nil + end + end + # override to return commits, which are not active record def noteable return commit if for_commit? diff --git a/app/models/project.rb b/app/models/project.rb index d6a52b37f19..daae6544ad5 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1787,8 +1787,10 @@ class Project < ApplicationRecord # rubocop:enable Gitlab/RailsLogger def after_import - repository.after_import - wiki.repository.after_import + repository.expire_content_cache + wiki.repository.expire_content_cache + + DetectRepositoryLanguagesWorker.perform_async(id) # The import assigns iid values on its own, e.g. by re-using GitHub ids. # Flush existing InternalId records for this project for consistency reasons. diff --git a/app/models/repository.rb b/app/models/repository.rb index 534c62ec467..5603c35b419 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -437,15 +437,6 @@ class Repository expire_all_method_caches end - # Runs code after a repository has been forked/imported. - def after_import - expire_content_cache - - return unless repo_type.project? - - DetectRepositoryLanguagesWorker.perform_async(project.id) - end - # Runs code after a new commit has been pushed. def after_push_commit(branch_name) expire_statistics_caches diff --git a/app/models/user.rb b/app/models/user.rb index 0a28268bbc6..b0db21b2d1c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1683,6 +1683,13 @@ class User < ApplicationRecord super end + # override from Devise::Confirmable + def confirmation_period_valid? + return false if Feature.disabled?(:soft_email_confirmation) + + super + end + private def default_private_profile_to_false diff --git a/app/services/issues/close_service.rb b/app/services/issues/close_service.rb index 21e9a2210fb..d5a542a418d 100644 --- a/app/services/issues/close_service.rb +++ b/app/services/issues/close_service.rb @@ -52,12 +52,12 @@ module Issues end def store_first_mentioned_in_commit_at(issue, merge_request) - return unless Feature.enabled?(:store_first_mentioned_in_commit_on_issue_close, issue.project) + return unless Feature.enabled?(:store_first_mentioned_in_commit_on_issue_close, issue.project, default_enabled: true) metrics = issue.metrics return if metrics.nil? || metrics.first_mentioned_in_commit_at - first_commit_timestamp = merge_request.commits(limit: 1).first&.date + first_commit_timestamp = merge_request.commits(limit: 1).first.try(:authored_date) return unless first_commit_timestamp metrics.update!(first_mentioned_in_commit_at: first_commit_timestamp) diff --git a/app/workers/process_commit_worker.rb b/app/workers/process_commit_worker.rb index 4039ad45899..9960e812a2f 100644 --- a/app/workers/process_commit_worker.rb +++ b/app/workers/process_commit_worker.rb @@ -19,13 +19,12 @@ class ProcessCommitWorker # rubocop:disable Scalability/IdempotentWorker # commit_hash - Hash containing commit details to use for constructing a # Commit object without having to use the Git repository. # default - The data was pushed to the default branch. - # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, user_id, commit_hash, default = false) - project = Project.find_by(id: project_id) + project = Project.id_in(project_id).first return unless project - user = User.find_by(id: user_id) + user = User.id_in(user_id).first return unless user @@ -35,12 +34,11 @@ class ProcessCommitWorker # rubocop:disable Scalability/IdempotentWorker process_commit_message(project, commit, user, author, default) update_issue_metrics(commit, author) end - # rubocop: enable CodeReuse/ActiveRecord def process_commit_message(project, commit, user, author, default = false) # Ignore closing references from GitLab-generated commit messages. find_closing_issues = default && !commit.merged_merge_request?(user) - closed_issues = find_closing_issues ? commit.closes_issues(user) : [] + closed_issues = find_closing_issues ? issues_to_close(project, commit, user) : [] close_issues(project, user, author, commit, closed_issues) if closed_issues.any? commit.create_cross_references!(author, closed_issues) @@ -56,6 +54,12 @@ class ProcessCommitWorker # rubocop:disable Scalability/IdempotentWorker end end + def issues_to_close(project, commit, user) + Gitlab::ClosingIssueExtractor + .new(project, user) + .closed_by_message(commit.safe_message) + end + def update_issue_metrics(commit, author) mentioned_issues = commit.all_references(author).issues |