Commit e8bdcdf0 authored by Camil Staps's avatar Camil Staps

Expose time since starring on project/:id/starrers API endpoint; exclude...

Expose time since starring on project/:id/starrers API endpoint; exclude private profiles here as well
parent 50f5f2e8
...@@ -282,6 +282,15 @@ class User < ApplicationRecord ...@@ -282,6 +282,15 @@ class User < ApplicationRecord
scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) } scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) }
scope :with_emails, -> { preload(:emails) } scope :with_emails, -> { preload(:emails) }
scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) } 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. # Limits the users to those that have TODOs, optionally in the given state.
# #
......
...@@ -15,7 +15,7 @@ class UsersStarProject < ApplicationRecord ...@@ -15,7 +15,7 @@ class UsersStarProject < ApplicationRecord
scope :order_user_name_asc, -> { joins(:user).reorder('"users"."name" ASC') } scope :order_user_name_asc, -> { joins(:user).reorder('"users"."name" ASC') }
scope :order_user_name_desc, -> { joins(:user).reorder('"users"."name" DESC') } scope :order_user_name_desc, -> { joins(:user).reorder('"users"."name" DESC') }
scope :by_project, -> (project) { where(project_id: project.id) } 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 class << self
def sort_by_attribute(method) def sort_by_attribute(method)
......
...@@ -1358,21 +1358,27 @@ Example responses: ...@@ -1358,21 +1358,27 @@ Example responses:
```json ```json
[ [
{ {
"id": 1, "starred_since": "2019-01-28T14:47:30.642Z",
"username": "jane_smith", "user":
"name": "Jane Smith", {
"state": "active", "id": 1,
"avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg", "username": "jane_smith",
"web_url": "http://localhost:3000/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": "2018-01-02T11:40:26.570Z",
"id": 2, "user":
"username": "janine_smith", {
"name": "Janine Smith", "id": 2,
"state": "blocked", "username": "janine_smith",
"avatar_url": "http://gravatar.com/../e32131cd8.jpeg", "name": "Janine Smith",
"web_url": "http://localhost:3000/janine_smith" "state": "blocked",
} "avatar_url": "http://gravatar.com/../e32131cd8.jpeg",
"web_url": "http://localhost:3000/janine_smith"
}
] ]
``` ```
......
...@@ -77,6 +77,11 @@ module API ...@@ -77,6 +77,11 @@ module API
expose :last_activity_on, as: :last_activity_at # Back-compat expose :last_activity_on, as: :last_activity_at # Back-compat
end end
class UserStarsProject < Grape::Entity
expose :starred_since
expose :user, using: Entities::UserBasic
end
class Identity < Grape::Entity class Identity < Grape::Entity
expose :provider, :extern_uid expose :provider, :extern_uid
end end
......
...@@ -128,7 +128,7 @@ module API ...@@ -128,7 +128,7 @@ module API
user = find_user(params[:user_id]) user = find_user(params[:user_id])
not_found!('User') unless user 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 present_projects starred_projects
end end
end end
...@@ -382,10 +382,9 @@ module API ...@@ -382,10 +382,9 @@ module API
use :pagination use :pagination
end end
get ':id/starrers' do get ':id/starrers' do
users = DeclarativePolicy.subject_scope { user_project.starrers } starrers = UsersStarProjectsFinder.new(params, user_project, current_user: current_user).execute
users = users.search(params[:search]) if params[:search].present?
present paginate(users), with: Entities::UserBasic present paginate(starrers), with: Entities::UserStarsProject
end end
desc 'Get languages in project repository' desc 'Get languages in project repository'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment