Commit 41d89533 authored by Stan Hu's avatar Stan Hu

Fix assorted rspec failures due to stale, cached user permissions

RequestStore is disabled in tests, but the Ability class was
caching user permissions based on the user and project ID of
previous test runs. Revise code to use RequestStore only if it
is active.
parent a16ac37e
...@@ -166,10 +166,17 @@ class Ability ...@@ -166,10 +166,17 @@ class Ability
end end
def project_abilities(user, project) def project_abilities(user, project)
rules = []
key = "/user/#{user.id}/project/#{project.id}" key = "/user/#{user.id}/project/#{project.id}"
RequestStore.store[key] ||= begin if RequestStore.active?
RequestStore.store[key] ||= uncached_project_abilities(user, project)
else
uncached_project_abilities(user, project)
end
end
def uncached_project_abilities(user, project)
rules = []
# Push abilities on the users team role # Push abilities on the users team role
rules.push(*project_team_rules(project.team, user)) rules.push(*project_team_rules(project.team, user))
...@@ -198,7 +205,6 @@ class Ability ...@@ -198,7 +205,6 @@ class Ability
rules - project_disabled_features_rules(project) rules - project_disabled_features_rules(project)
end end
end
def project_team_rules(team, user) def project_team_rules(team, user)
# Rules based on role in project # Rules based on role in project
......
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