Commit 623f08b2 authored by Kerri Miller's avatar Kerri Miller

Merge branch '337062-make-sure-user-information-stays-up-to-date-on-sidebar' into 'master'

Make sure user information stays up to date on sidebar

See merge request gitlab-org/gitlab!67958
parents 4a38fc19 66e2d84c
......@@ -131,9 +131,16 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
Gitlab::PollingInterval.set_header(response, interval: 10_000)
if params[:serializer] == 'sidebar_extras' && Feature.enabled?(:merge_request_show_render_cached, @project, default_enabled: :yaml)
cache_context = [
params[:serializer],
current_user&.cache_key,
@merge_request.assignees.map(&:cache_key),
@merge_request.reviewers.map(&:cache_key)
]
render_cached(@merge_request,
with: serializer,
cache_context: -> (_) { [params[:serializer], current_user&.cache_key, project.emails_disabled?, issuable.subscribed?(current_user, project)] },
cache_context: -> (_) { [Digest::SHA256.hexdigest(cache_context.to_s)] },
serializer: params[:serializer])
else
render json: serializer.represent(@merge_request, serializer: params[:serializer])
......
......@@ -5,10 +5,18 @@ require 'spec_helper'
RSpec.describe 'merge requests actions' do
let_it_be(:project) { create(:project, :repository) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
let(:merge_request) do
create(:merge_request_with_diffs, target_project: project,
source_project: project,
assignees: [user],
reviewers: [user2])
end
let(:user) { project.owner }
let(:user2) { create(:user) }
before do
project.add_maintainer(user2)
sign_in(user)
end
......@@ -61,17 +69,11 @@ RSpec.describe 'merge requests actions' do
end
context 'when the merge request is updated' do
let(:user2) { create(:user) }
before do
project.add_maintainer(user2)
end
def update_service(params)
MergeRequests::UpdateService.new(project: project, current_user: user, params: params).execute(merge_request)
end
context 'when the user is different' do
context 'when the logged in user is different' do
before do
sign_in(user2)
end
......@@ -79,61 +81,61 @@ RSpec.describe 'merge requests actions' do
it_behaves_like 'a non-cached request'
end
context 'when the reviewer is changed' do
context 'when the assignee is changed' do
before do
update_service(reviewer_ids: [user2.id])
update_service( assignee_ids: [] )
end
it_behaves_like 'a non-cached request'
end
context 'when the assignee is changed' do
context 'when the existing assignee gets updated' do
before do
update_service( assignee_ids: [user2.id] )
user.update_attribute(:avatar, 'uploads/avatar.png')
end
it_behaves_like 'a non-cached request'
end
context 'when the time_estimate is changed' do
context 'when the reviewer is changed' do
before do
update_service(time_estimate: 7200)
update_service(reviewer_ids: [])
end
it_behaves_like 'a non-cached request'
end
context 'when the spend_time is changed' do
context 'when the existing reviewer gets updated' do
before do
update_service(spend_time: { duration: 7200, user_id: user.id, spent_at: Time.now, note_id: nil })
user2.update_attribute(:avatar, 'uploads/avatar.png')
end
it_behaves_like 'a non-cached request'
end
context 'when a user leaves a note' do
context 'when the time_estimate is changed' do
before do
# We have 1 minute ThrottledTouch to account for.
# It's not ideal as it means that our participants cache could be stale for about a day if a new note is created by another person or gets a mention.
travel_to(Time.current + 61) do
Notes::CreateService.new(project, user2, { note: 'Looks good', noteable_type: 'MergeRequest', noteable_id: merge_request.id }).execute
end
update_service(time_estimate: 7200)
end
it_behaves_like 'a non-cached request'
end
context 'when the email setting has changed in project' do
context 'when the spend_time is changed' do
before do
project.namespace.update_attribute(:emails_disabled, true)
update_service(spend_time: { duration: 7200, user_id: user.id, spent_at: Time.now, note_id: nil })
end
it_behaves_like 'a non-cached request'
end
context 'when the user changes unsubscribes' do
context 'when a user leaves a note' do
before do
merge_request.set_subscription(user, false, project)
# We have 1 minute ThrottledTouch to account for.
# It's not ideal as it means that our participants cache could be stale for about a day if a new note is created by another person or gets a mention.
travel_to(Time.current + 61) do
Notes::CreateService.new(project, user2, { note: 'Looks good', noteable_type: 'MergeRequest', noteable_id: merge_request.id }).execute
end
end
it_behaves_like 'a non-cached request'
......
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