Commit 06081856 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add `approved_by_users` relation to merge_requests

This could be a relation that is easily preloaded.
parent 25b0543c
......@@ -41,10 +41,12 @@ module EE
return super unless APPROVAL_RENDERING_ACTIONS.include?(action_name.to_sym)
@issuable = @merge_request ||= project.merge_requests
.includes(approvals: :user,
approvers: :user,
approver_groups: :group)
.includes(
:approved_by_users,
approvers: :user
)
.find_by!(iid: params[:id])
super
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
......
......@@ -79,7 +79,7 @@ module Approvable
approvers_relation = approvers_overwritten? ? approvers : target_project.approvers
approvers_relation = approvers_relation.where.not(user_id: author.id) if author
approvers_relation
approvers_relation.includes(:user)
end
def overall_approver_groups
......@@ -144,10 +144,6 @@ module Approvable
remaining_approvals.zero? || remaining_approvals > approvers_left.count
end
def approved_by_users
approvals.map(&:user)
end
def approver_ids=(value)
value.split(",").map(&:strip).each do |user_id|
next if author && user_id == author.id
......
......@@ -6,6 +6,7 @@ module EE
included do
has_many :approvals, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :approved_by_users, through: :approvals, source: :user
has_many :approvers, as: :target, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :approver_groups, as: :target, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
......
......@@ -11,6 +11,7 @@ describe MergeRequest do
it { is_expected.to have_many(:approvals).dependent(:delete_all) }
it { is_expected.to have_many(:approvers).dependent(:delete_all) }
it { is_expected.to have_many(:approver_groups).dependent(:delete_all) }
it { is_expected.to have_many(:approved_by_users) }
end
describe '#squash_in_progress?' do
......
......@@ -95,6 +95,7 @@ merge_requests:
- timelogs
- head_pipeline
- latest_merge_request_diff
- approved_by_users
merge_request_diff:
- merge_request
- merge_request_diff_commits
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment