Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
38a75f59809d
Commit
38a75f59
authored
Nov 18, 2015
by
Yorick Peterse
Browse files
Added Project.visible_to_user
This method can be used to filter projects to those visible to a given user.
parent
ab8697eb09f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/models/project.rb
View file @
38a75f59
...
...
@@ -286,6 +286,10 @@
joins
(
join_body
).
reorder
(
'join_note_counts.amount DESC'
)
end
def
visible_to_user
(
user
)
where
(
id:
user
.
authorized_projects
.
select
(
:id
).
reorder
(
nil
))
end
end
def
team
...
...
spec/models/project_spec.rb
View file @
38a75f59
...
...
@@ -464,4 +464,23 @@
end
end
end
describe
'.visible_to_user'
do
let!
(
:project
)
{
create
(
:project
,
:private
)
}
let!
(
:user
)
{
create
(
:user
)
}
subject
{
described_class
.
visible_to_user
(
user
)
}
describe
'when a user has access to a project'
do
before
do
project
.
team
.
add_user
(
user
,
Gitlab
::
Access
::
MASTER
)
end
it
{
is_expected
.
to
eq
([
project
])
}
end
describe
'when a user does not have access to any projects'
do
it
{
is_expected
.
to
eq
([])
}
end
end
end
Write
Preview
Supports
Markdown
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