Commit cc193d70 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix 404 for invited projects

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 4e9f7c21
...@@ -141,9 +141,29 @@ class ProjectTeam ...@@ -141,9 +141,29 @@ class ProjectTeam
access << group.users_groups.find_by(user_id: user_id).try(:access_field) access << group.users_groups.find_by(user_id: user_id).try(:access_field)
end end
if project.invited_groups.any?
access << max_invited_level(user_id)
end
access.compact.max access.compact.max
end end
def max_invited_level(user_id)
project.project_group_links.map do |group_link|
invited_group = group_link.group
access = invited_group.users_groups.find_by(user_id: user_id).try(:access_field)
# If group member has higher access level we should restrict it
# to max allowed access level
if access && access > group_link.group_access
access = group_link.group_access
end
access
end.compact.max
end
private private
def fetch_members(level = nil) def fetch_members(level = nil)
......
...@@ -62,5 +62,23 @@ describe ProjectTeam do ...@@ -62,5 +62,23 @@ describe ProjectTeam do
it { project.team.master?(nonmember).should be_false } it { project.team.master?(nonmember).should be_false }
end end
end end
end
describe :max_invited_level do
let(:group) { create(:group) }
let(:project) { create(:empty_project) }
before do
project.project_group_links.create(
group: group,
group_access: Gitlab::Access::DEVELOPER
)
group.add_user(master, Gitlab::Access::MASTER)
group.add_user(reporter, Gitlab::Access::REPORTER)
end
it { project.team.max_invited_level(master.id).should == Gitlab::Access::DEVELOPER }
it { project.team.max_invited_level(reporter.id).should == Gitlab::Access::REPORTER }
it { project.team.max_invited_level(nonmember.id).should be_nil }
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