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
8e72ad70
Commit
8e72ad70
authored
May 23, 2017
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add starred_by scope to Project
Add a scope to search for the projects that are starred by a certain user.
parent
07fc79e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
2 deletions
+17
-2
app/models/project.rb
app/models/project.rb
+2
-1
app/models/user.rb
app/models/user.rb
+1
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+14
-0
No files found.
app/models/project.rb
View file @
8e72ad70
...
...
@@ -242,6 +242,7 @@ class Project < ActiveRecord::Base
scope
:in_namespace
,
->
(
namespace_ids
)
{
where
(
namespace_id:
namespace_ids
)
}
scope
:personal
,
->
(
user
)
{
where
(
namespace_id:
user
.
namespace_id
)
}
scope
:joined
,
->
(
user
)
{
where
(
'namespace_id != ?'
,
user
.
namespace_id
)
}
scope
:starred_by
,
->
(
user
)
{
joins
(
:users_star_projects
).
where
(
'users_star_projects.user_id'
:
user
.
id
)
}
scope
:visible_to_user
,
->
(
user
)
{
where
(
id:
user
.
authorized_projects
.
select
(
:id
).
reorder
(
nil
))
}
scope
:non_archived
,
->
{
where
(
archived:
false
)
}
scope
:for_milestones
,
->
(
ids
)
{
joins
(
:milestones
).
where
(
'milestones.id'
=>
ids
).
distinct
}
...
...
@@ -350,7 +351,7 @@ class Project < ActiveRecord::Base
where
(
"projects.id IN (
#{
union
.
to_sql
}
)"
)
end
def
search_by_visibility
(
level
)
def
search_by_visibility
(
level
)
# DEPRECATED: remove with API V3
where
(
visibility_level:
Gitlab
::
VisibilityLevel
.
string_options
[
level
])
end
...
...
app/models/user.rb
View file @
8e72ad70
...
...
@@ -557,7 +557,7 @@ class User < ActiveRecord::Base
authorized_projects
(
Gitlab
::
Access
::
REPORTER
).
where
(
id:
projects
)
end
def
viewable_starred_projects
def
viewable_starred_projects
# DEPRECATED: Use ProjectFinder instead. Remove together with API V3
starred_projects
.
where
(
"projects.visibility_level IN (?) OR projects.id IN (?)"
,
[
Project
::
PUBLIC
,
Project
::
INTERNAL
],
authorized_projects
.
select
(
:project_id
))
...
...
spec/models/project_spec.rb
View file @
8e72ad70
...
...
@@ -948,6 +948,20 @@ describe Project, models: true do
end
end
describe
'.starred_by'
do
it
'returns only projects starred by the given user'
do
user1
=
create
(
:user
)
user2
=
create
(
:user
)
project1
=
create
(
:empty_project
)
project2
=
create
(
:empty_project
)
create
(
:empty_project
)
user1
.
toggle_star
(
project1
)
user2
.
toggle_star
(
project2
)
expect
(
Project
.
starred_by
(
user1
)).
to
contain_exactly
(
project1
)
end
end
describe
'.visible_to_user'
do
let!
(
:project
)
{
create
(
:empty_project
,
:private
)
}
let!
(
:user
)
{
create
(
:user
)
}
...
...
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