Commit c5e1751a authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '339097-fix-discussions-cache-current-user-role' into 'master'

Fix stale MR discussion cache when current user role changes

See merge request gitlab-org/gitlab!69969
parents 739891a7 becce866
...@@ -159,7 +159,9 @@ module IssuableActions ...@@ -159,7 +159,9 @@ module IssuableActions
discussions = Discussion.build_collection(notes, issuable) discussions = Discussion.build_collection(notes, issuable)
if issuable.is_a?(MergeRequest) && Feature.enabled?(:merge_request_discussion_cache, issuable.target_project, default_enabled: :yaml) if issuable.is_a?(MergeRequest) && Feature.enabled?(:merge_request_discussion_cache, issuable.target_project, default_enabled: :yaml)
render_cached(discussions, with: discussion_serializer, context: self) cache_context = [current_user&.cache_key, project.team.human_max_access(current_user&.id)].join(':')
render_cached(discussions, with: discussion_serializer, cache_context: -> (_) { cache_context }, context: self)
else else
render json: discussion_serializer.represent(discussions, context: self) render json: discussion_serializer.represent(discussions, context: self)
end end
......
...@@ -5,11 +5,13 @@ require 'spec_helper' ...@@ -5,11 +5,13 @@ require 'spec_helper'
RSpec.describe 'merge requests discussions' do RSpec.describe 'merge requests discussions' do
# Further tests can be found at merge_requests_controller_spec.rb # Further tests can be found at merge_requests_controller_spec.rb
describe 'GET /:namespace/:project/-/merge_requests/:iid/discussions' do describe 'GET /:namespace/:project/-/merge_requests/:iid/discussions' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository, :public) }
let(:user) { project.owner } let(:owner) { project.owner }
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
before do before do
project.add_maintainer(owner)
project.add_developer(user) project.add_developer(user)
login_as(user) login_as(user)
end end
...@@ -232,7 +234,17 @@ RSpec.describe 'merge requests discussions' do ...@@ -232,7 +234,17 @@ RSpec.describe 'merge requests discussions' do
context 'when author role changes' do context 'when author role changes' do
before do before do
Members::UpdateService.new(user, access_level: Gitlab::Access::GUEST).execute(author_membership) Members::UpdateService.new(owner, access_level: Gitlab::Access::GUEST).execute(author_membership)
end
it_behaves_like 'cache miss' do
let(:changed_notes) { [first_note, second_note] }
end
end
context 'when current_user role changes' do
before do
Members::UpdateService.new(owner, access_level: Gitlab::Access::GUEST).execute(project.project_member(user))
end end
it_behaves_like 'cache miss' do it_behaves_like 'cache miss' do
......
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