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
a9f63322eb4e
Commit
a9f63322
authored
May 23, 2017
by
Toon Claes
Browse files
Add starred_by scope to Project
Add a scope to search for the projects that are starred by a certain user.
parent
c8989aafafd6
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/models/project.rb
View file @
a9f63322
...
...
@@ -242,6 +242,7 @@
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 @@
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 @
a9f63322
...
...
@@ -557,7 +557,7 @@
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 @
a9f63322
...
...
@@ -948,6 +948,20 @@
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
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