Commit d819b9d4 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Merge branch 'show_shared_groups' into 'master'

Show shared groups

Fixes #134

See merge request !148
parents 2ec7339c 81430a61
......@@ -32,20 +32,29 @@ class ProjectsFinder
# internal projects
# joined projects
#
group.projects.where(
"projects.id IN (?) OR projects.visibility_level IN (?)",
projects_members.pluck(:project_id),
Project.public_and_internal_levels
)
projects_ids = projects_members.pluck(:project_id)
else
# User has no access to group or group projects
# or has access through shared project
#
# Return only:
# public projects
# internal projects
#
group.projects.public_and_internal_only
# shared projects
projects_ids = []
ProjectGroupLink.where(project_id: group.projects).each do |shared_project|
if shared_project.group.users.include?(current_user) || shared_project.project.users.include?(current_user)
projects_ids << shared_project.project.id
end
end
end
group.projects.where(
"projects.id IN (?) OR projects.visibility_level IN (?)",
projects_ids,
Project.public_and_internal_levels
)
end
else
# Not authenticated
......
......@@ -3,11 +3,16 @@ require 'spec_helper'
describe ProjectsFinder do
let(:user) { create :user }
let(:group) { create :group }
let(:group2) { create :group }
let(:project1) { create(:empty_project, :public, group: group) }
let(:project2) { create(:empty_project, :internal, group: group) }
let(:project3) { create(:empty_project, :private, group: group) }
let(:project4) { create(:empty_project, :private, group: group) }
let(:project5) { create(:empty_project, :private, group: group2) }
let(:project6) { create(:empty_project, :internal, group: group2) }
let(:project7) { create(:empty_project, :public, group: group2) }
let(:project8) { create(:empty_project, :private, group: group2) }
context 'non authenticated' do
subject { ProjectsFinder.new.execute(nil, group: group) }
......@@ -48,4 +53,18 @@ describe ProjectsFinder do
it { should include(project3) }
it { should include(project4) }
end
context 'authenticated, group member with project shared with group' do
before {
group.add_user(user, Gitlab::Access::DEVELOPER)
project5.project_group_links.create group_access: Gitlab::Access::MASTER, group: group
}
subject { ProjectsFinder.new.execute(user, group: group2) }
it { should include(project5) }
it { should include(project6) }
it { should include(project7) }
it { should_not include(project8) }
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