Commit 99c02ed5 authored by Stan Hu's avatar Stan Hu

Only use RequestStore in ProjectTeam#max_member_access_for_user if it is active

parent aa727434
...@@ -138,8 +138,13 @@ class ProjectTeam ...@@ -138,8 +138,13 @@ class ProjectTeam
def max_member_access_for_user_ids(user_ids) def max_member_access_for_user_ids(user_ids)
user_ids = user_ids.uniq user_ids = user_ids.uniq
key = "max_member_access:#{project.id}" key = "max_member_access:#{project.id}"
access = {}
if RequestStore.active?
RequestStore.store[key] ||= {} RequestStore.store[key] ||= {}
access = RequestStore.store[key] access = RequestStore.store[key]
end
# Lookup only the IDs we need # Lookup only the IDs we need
user_ids = user_ids - access.keys user_ids = user_ids - access.keys
......
...@@ -199,7 +199,19 @@ describe ProjectTeam, models: true do ...@@ -199,7 +199,19 @@ describe ProjectTeam, models: true do
end end
end end
shared_examples_for "#max_member_access_for_users" do |enable_request_store|
describe "#max_member_access_for_users" do describe "#max_member_access_for_users" do
before do
RequestStore.begin! if enable_request_store
end
after do
if enable_request_store
RequestStore.end!
RequestStore.clear!
end
end
it 'returns correct roles for different users' do it 'returns correct roles for different users' do
master = create(:user) master = create(:user)
reporter = create(:user) reporter = create(:user)
...@@ -243,4 +255,13 @@ describe ProjectTeam, models: true do ...@@ -243,4 +255,13 @@ describe ProjectTeam, models: true do
expect(project.team.max_member_access_for_user_ids(users)).to eq(expected) expect(project.team.max_member_access_for_user_ids(users)).to eq(expected)
end end
end end
end
describe '#max_member_access_for_users with RequestStore' do
it_behaves_like "#max_member_access_for_users", true
end
describe '#max_member_access_for_users without RequestStore' do
it_behaves_like "#max_member_access_for_users", false
end
end end
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