Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
a3cde026
Commit
a3cde026
authored
Dec 21, 2018
by
James Lopez
Committed by
Yorick Peterse
Jan 31, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix contributed projects finder shown private info
parent
57f082d9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
0 deletions
+56
-0
app/finders/contributed_projects_finder.rb
app/finders/contributed_projects_finder.rb
+7
-0
changelogs/unreleased/security-contributed-projects.yml
changelogs/unreleased/security-contributed-projects.yml
+5
-0
spec/controllers/users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+32
-0
spec/finders/contributed_projects_finder_spec.rb
spec/finders/contributed_projects_finder_spec.rb
+12
-0
No files found.
app/finders/contributed_projects_finder.rb
View file @
a3cde026
...
...
@@ -14,6 +14,9 @@ class ContributedProjectsFinder < UnionFinder
# Returns an ActiveRecord::Relation.
# rubocop: disable CodeReuse/ActiveRecord
def
execute
(
current_user
=
nil
)
# Do not show contributed projects if the user profile is private.
return
Project
.
none
unless
can_read_profile?
(
current_user
)
segments
=
all_projects
(
current_user
)
find_union
(
segments
,
Project
).
includes
(
:namespace
).
order_id_desc
...
...
@@ -22,6 +25,10 @@ class ContributedProjectsFinder < UnionFinder
private
def
can_read_profile?
(
current_user
)
Ability
.
allowed?
(
current_user
,
:read_user_profile
,
@user
)
end
def
all_projects
(
current_user
)
projects
=
[]
...
...
changelogs/unreleased/security-contributed-projects.yml
0 → 100644
View file @
a3cde026
---
title
:
Fix contributed projects info still visible when user enable private profile
merge_request
:
author
:
type
:
security
spec/controllers/users_controller_spec.rb
View file @
a3cde026
...
...
@@ -206,6 +206,38 @@ describe UsersController do
end
end
describe
'GET #contributed'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:current_user
)
{
create
(
:user
)
}
before
do
sign_in
(
current_user
)
project
.
add_developer
(
public_user
)
project
.
add_developer
(
private_user
)
end
context
'with public profile'
do
it
'renders contributed projects'
do
create
(
:push_event
,
project:
project
,
author:
public_user
)
get
:contributed
,
params:
{
username:
public_user
.
username
}
expect
(
assigns
[
:contributed_projects
]).
not_to
be_empty
end
end
context
'with private profile'
do
it
'does not render contributed projects'
do
create
(
:push_event
,
project:
project
,
author:
private_user
)
get
:contributed
,
params:
{
username:
private_user
.
username
}
expect
(
assigns
[
:contributed_projects
]).
to
be_empty
end
end
end
describe
'GET #snippets'
do
before
do
sign_in
(
user
)
...
...
spec/finders/contributed_projects_finder_spec.rb
View file @
a3cde026
...
...
@@ -31,4 +31,16 @@ describe ContributedProjectsFinder do
it
{
is_expected
.
to
match_array
([
private_project
,
internal_project
,
public_project
])
}
end
context
'user with private profile'
do
it
'does not return contributed projects'
do
private_user
=
create
(
:user
,
private_profile:
true
)
public_project
.
add_maintainer
(
private_user
)
create
(
:push_event
,
project:
public_project
,
author:
private_user
)
projects
=
described_class
.
new
(
private_user
).
execute
(
current_user
)
expect
(
projects
).
to
be_empty
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment