Skip to content
Snippets Groups Projects
Commit 41d89533 authored by Stan Hu's avatar Stan Hu
Browse files

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
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -166,38 +166,44 @@ class Ability
end
 
def project_abilities(user, project)
rules = []
key = "/user/#{user.id}/project/#{project.id}"
 
RequestStore.store[key] ||= begin
# Push abilities on the users team role
rules.push(*project_team_rules(project.team, user))
if RequestStore.active?
RequestStore.store[key] ||= uncached_project_abilities(user, project)
else
uncached_project_abilities(user, project)
end
end
 
owner = user.admin? ||
project.owner == user ||
(project.group && project.group.has_owner?(user))
def uncached_project_abilities(user, project)
rules = []
# Push abilities on the users team role
rules.push(*project_team_rules(project.team, user))
 
if owner
rules.push(*project_owner_rules)
end
owner = user.admin? ||
project.owner == user ||
(project.group && project.group.has_owner?(user))
 
if project.public? || (project.internal? && !user.external?)
rules.push(*public_project_rules)
if owner
rules.push(*project_owner_rules)
end
 
# Allow to read builds for internal projects
rules << :read_build if project.public_builds?
if project.public? || (project.internal? && !user.external?)
rules.push(*public_project_rules)
 
unless owner || project.team.member?(user) || project_group_member?(project, user)
rules << :request_access if project.request_access_enabled
end
end
# Allow to read builds for internal projects
rules << :read_build if project.public_builds?
 
if project.archived?
rules -= project_archived_rules
unless owner || project.team.member?(user) || project_group_member?(project, user)
rules << :request_access if project.request_access_enabled
end
end
 
rules - project_disabled_features_rules(project)
if project.archived?
rules -= project_archived_rules
end
rules - project_disabled_features_rules(project)
end
 
def project_team_rules(team, user)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment