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
Léo-Paul Géneau
gitlab-ce
Commits
a4fc8112
Commit
a4fc8112
authored
Nov 18, 2015
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Project.visible_to_user
This method can be used to filter projects to those visible to a given user.
parent
a74d6d20
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
app/models/project.rb
app/models/project.rb
+4
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+19
-0
No files found.
app/models/project.rb
View file @
a4fc8112
...
@@ -286,6 +286,10 @@ class Project < ActiveRecord::Base
...
@@ -286,6 +286,10 @@ class Project < ActiveRecord::Base
joins
(
join_body
).
reorder
(
'join_note_counts.amount DESC'
)
joins
(
join_body
).
reorder
(
'join_note_counts.amount DESC'
)
end
end
def
visible_to_user
(
user
)
where
(
id:
user
.
authorized_projects
.
select
(
:id
).
reorder
(
nil
))
end
end
end
def
team
def
team
...
...
spec/models/project_spec.rb
View file @
a4fc8112
...
@@ -464,4 +464,23 @@ describe Project do
...
@@ -464,4 +464,23 @@ describe Project do
end
end
end
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
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