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,38 +166,44 @@ class Ability ...@@ -166,38 +166,44 @@ 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?
# Push abilities on the users team role RequestStore.store[key] ||= uncached_project_abilities(user, project)
rules.push(*project_team_rules(project.team, user)) else
uncached_project_abilities(user, project)
end
end
owner = user.admin? || def uncached_project_abilities(user, project)
project.owner == user || rules = []
(project.group && project.group.has_owner?(user)) # Push abilities on the users team role
rules.push(*project_team_rules(project.team, user))
if owner owner = user.admin? ||
rules.push(*project_owner_rules) project.owner == user ||
end (project.group && project.group.has_owner?(user))
if project.public? || (project.internal? && !user.external?) if owner
rules.push(*public_project_rules) rules.push(*project_owner_rules)
end
# Allow to read builds for internal projects if project.public? || (project.internal? && !user.external?)
rules << :read_build if project.public_builds? rules.push(*public_project_rules)
unless owner || project.team.member?(user) || project_group_member?(project, user) # Allow to read builds for internal projects
rules << :request_access if project.request_access_enabled rules << :read_build if project.public_builds?
end
end
if project.archived? unless owner || project.team.member?(user) || project_group_member?(project, user)
rules -= project_archived_rules rules << :request_access if project.request_access_enabled
end end
end
rules - project_disabled_features_rules(project) if project.archived?
rules -= project_archived_rules
end end
rules - project_disabled_features_rules(project)
end end
def project_team_rules(team, user) def project_team_rules(team, user)
......
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