summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps <info@camilstaps.nl>2019-02-02 20:48:27 +0100
committerCamil Staps <info@camilstaps.nl>2019-08-07 20:49:16 +0200
commite8bdcdf0f89d88463f6fb8a67e85f315e6a9097d (patch)
treefe89a0579e118fa688d6b08deedaba672737281e
parent50f5f2e8aebf7ea3cdc9b2d133c9246925f749c4 (diff)
downloadgitlab-ce-e8bdcdf0f89d88463f6fb8a67e85f315e6a9097d.tar.gz
Expose time since starring on project/:id/starrers API endpoint; exclude private profiles here as well
-rw-r--r--app/models/user.rb9
-rw-r--r--app/models/users_star_project.rb2
-rw-r--r--doc/api/projects.md34
-rw-r--r--lib/api/entities.rb5
-rw-r--r--lib/api/projects.rb7
5 files changed, 38 insertions, 19 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 4630552e02e..d671c291ec5 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -282,6 +282,15 @@ class User < ApplicationRecord
scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) }
scope :with_emails, -> { preload(:emails) }
scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) }
+ scope :with_visible_profile, -> (user) {
+ if user.nil?
+ where(private_profile: [false, nil])
+ elsif user.admin?
+ all
+ else
+ where(private_profile: [false, nil]).or where(id: user.id)
+ end
+ }
# Limits the users to those that have TODOs, optionally in the given state.
#
diff --git a/app/models/users_star_project.rb b/app/models/users_star_project.rb
index 6eabdebd89c..e171a8220d0 100644
--- a/app/models/users_star_project.rb
+++ b/app/models/users_star_project.rb
@@ -15,7 +15,7 @@ class UsersStarProject < ApplicationRecord
scope :order_user_name_asc, -> { joins(:user).reorder('"users"."name" ASC') }
scope :order_user_name_desc, -> { joins(:user).reorder('"users"."name" DESC') }
scope :by_project, -> (project) { where(project_id: project.id) }
- scope :with_visible_profile, -> (user) { joins(:user).where('"users"."private_profile" IS NULL OR "users"."private_profile" = ? OR "users"."id" = ?', false, user.id ) }
+ scope :with_visible_profile, -> (user) { joins(:user).merge(User.with_visible_profile(user)) }
class << self
def sort_by_attribute(method)
diff --git a/doc/api/projects.md b/doc/api/projects.md
index a9c7f2c66e0..1ce9912027c 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -1358,21 +1358,27 @@ Example responses:
```json
[
{
- "id": 1,
- "username": "jane_smith",
- "name": "Jane Smith",
- "state": "active",
- "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",
- "web_url": "http://localhost:3000/jane_smith"
+ "starred_since": "2019-01-28T14:47:30.642Z",
+ "user":
+ {
+ "id": 1,
+ "username": "jane_smith",
+ "name": "Jane Smith",
+ "state": "active",
+ "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",
+ "web_url": "http://localhost:3000/jane_smith"
+ }
},
- {
- "id": 2,
- "username": "janine_smith",
- "name": "Janine Smith",
- "state": "blocked",
- "avatar_url": "http://gravatar.com/../e32131cd8.jpeg",
- "web_url": "http://localhost:3000/janine_smith"
- }
+ "starred_since": "2018-01-02T11:40:26.570Z",
+ "user":
+ {
+ "id": 2,
+ "username": "janine_smith",
+ "name": "Janine Smith",
+ "state": "blocked",
+ "avatar_url": "http://gravatar.com/../e32131cd8.jpeg",
+ "web_url": "http://localhost:3000/janine_smith"
+ }
]
```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 2f5ce3d4003..643b53f5e63 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -77,6 +77,11 @@ module API
expose :last_activity_on, as: :last_activity_at # Back-compat
end
+ class UserStarsProject < Grape::Entity
+ expose :starred_since
+ expose :user, using: Entities::UserBasic
+ end
+
class Identity < Grape::Entity
expose :provider, :extern_uid
end
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index f8f0ff48be0..6d221200372 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -128,7 +128,7 @@ module API
user = find_user(params[:user_id])
not_found!('User') unless user
- starred_projects = StarredProjectsFinder.new(user, current_user: current_user).execute
+ starred_projects = StarredProjectsFinder.new(user, params: project_finder_params, current_user: current_user).execute
present_projects starred_projects
end
end
@@ -382,10 +382,9 @@ module API
use :pagination
end
get ':id/starrers' do
- users = DeclarativePolicy.subject_scope { user_project.starrers }
- users = users.search(params[:search]) if params[:search].present?
+ starrers = UsersStarProjectsFinder.new(params, user_project, current_user: current_user).execute
- present paginate(users), with: Entities::UserBasic
+ present paginate(starrers), with: Entities::UserStarsProject
end
desc 'Get languages in project repository'