summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps <info@camilstaps.nl>2019-01-27 11:18:09 +0100
committerCamil Staps <info@camilstaps.nl>2019-08-07 20:49:14 +0200
commit382826855c77986823691d74e1e6b47ad715d652 (patch)
tree7f44c9cbc542668aa7aff5a2dfedc79bf5818640
parent936d4e80e4abc2efcc5d88865d5d420c42a84370 (diff)
downloadgitlab-ce-382826855c77986823691d74e1e6b47ad715d652.tar.gz
Add "Starred projects" tab to user overview
-rw-r--r--app/assets/javascripts/pages/users/user_tabs.js2
-rw-r--r--app/controllers/users_controller.rb25
-rw-r--r--app/finders/starred_projects_finder.rb33
-rw-r--r--app/helpers/users_helper.rb2
-rw-r--r--app/views/users/show.html.haml8
-rw-r--r--config/routes/user.rb1
6 files changed, 68 insertions, 3 deletions
diff --git a/app/assets/javascripts/pages/users/user_tabs.js b/app/assets/javascripts/pages/users/user_tabs.js
index 1d8b388e935..4ac4efec45d 100644
--- a/app/assets/javascripts/pages/users/user_tabs.js
+++ b/app/assets/javascripts/pages/users/user_tabs.js
@@ -143,7 +143,7 @@ export default class UserTabs {
this.loadOverviewTab();
}
- const loadableActions = ['groups', 'contributed', 'projects', 'snippets'];
+ const loadableActions = ['groups', 'contributed', 'projects', 'starred', 'snippets'];
if (loadableActions.indexOf(action) > -1) {
this.loadTab(action, endpoint);
}
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 072d62ddf38..36687e3606e 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -17,7 +17,7 @@ class UsersController < ApplicationController
prepend_before_action(only: [:show]) { authenticate_sessionless_user!(:rss) }
before_action :user, except: [:exists]
before_action :authorize_read_user_profile!,
- only: [:calendar, :calendar_activities, :groups, :projects, :contributed_projects, :snippets]
+ only: [:calendar, :calendar_activities, :groups, :projects, :contributed_projects, :starred_projects, :snippets]
def show
respond_to do |format|
@@ -82,6 +82,19 @@ class UsersController < ApplicationController
end
end
+ def starred
+ load_starred_projects
+
+ respond_to do |format|
+ format.html { render 'show' }
+ format.json do
+ render json: {
+ html: view_to_html_string("shared/projects/_list", projects: @starred_projects)
+ }
+ end
+ end
+ end
+
def snippets
load_snippets
@@ -120,6 +133,10 @@ class UsersController < ApplicationController
ContributedProjectsFinder.new(user).execute(current_user)
end
+ def starred_projects
+ StarredProjectsFinder.new(user).execute(current_user)
+ end
+
def contributions_calendar
@contributions_calendar ||= Gitlab::ContributionsCalendar.new(user, current_user)
end
@@ -145,6 +162,12 @@ class UsersController < ApplicationController
prepare_projects_for_rendering(@contributed_projects)
end
+ def load_starred_projects
+ @starred_projects = starred_projects.joined(user)
+
+ prepare_projects_for_rendering(@starred_projects)
+ end
+
def load_groups
@groups = JoinedGroupsFinder.new(user).execute(current_user)
diff --git a/app/finders/starred_projects_finder.rb b/app/finders/starred_projects_finder.rb
new file mode 100644
index 00000000000..e5eeb19a8f3
--- /dev/null
+++ b/app/finders/starred_projects_finder.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class StarredProjectsFinder < UnionFinder
+ def initialize(user)
+ @user = user
+ end
+
+ # Finds the projects "@user" starred, limited to either public projects or
+ # projects visible to the given user.
+ #
+ # current_user - When given the list of the projects is limited to those only
+ # visible by this user.
+ #
+ # Returns an ActiveRecord::Relation.
+ # rubocop: disable CodeReuse/ActiveRecord
+ def execute(current_user = nil)
+ segments = all_projects(current_user)
+
+ find_union(segments, Project).includes(:namespace).order_id_desc
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+
+ private
+
+ def all_projects(current_user)
+ projects = []
+
+ projects << @user.starred_projects.visible_to_user(current_user) if current_user
+ projects << @user.starred_projects.public_to_user(current_user)
+
+ projects
+ end
+end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 23eafc12c38..7e8edc19a38 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -89,7 +89,7 @@ module UsersHelper
tabs = []
if can?(current_user, :read_user_profile, @user)
- tabs += [:overview, :activity, :groups, :contributed, :projects, :snippets]
+ tabs += [:overview, :activity, :groups, :contributed, :projects, :starred, :snippets]
end
tabs
diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml
index b3a73030859..73bee7c2586 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/users/show.html.haml
@@ -111,6 +111,10 @@
%li.js-projects-tab
= link_to user_projects_path, data: { target: 'div#projects', action: 'projects', toggle: 'tab', endpoint: user_projects_path(format: :json) } do
= s_('UserProfile|Personal projects')
+ - if profile_tab?(:starred)
+ %li.js-starred-tab
+ = link_to user_starred_projects_path, data: { target: 'div#starred', action: 'starred', toggle: 'tab', endpoint: user_starred_projects_path(format: :json) } do
+ = s_('UserProfile|Starred projects')
- if profile_tab?(:snippets)
%li.js-snippets-tab
= link_to user_snippets_path, data: { target: 'div#snippets', action: 'snippets', toggle: 'tab', endpoint: user_snippets_path(format: :json) } do
@@ -142,6 +146,10 @@
#projects.tab-pane
-# This tab is always loaded via AJAX
+ - if profile_tab?(:starred)
+ #starred.tab-pane
+ -# This tab is always loaded via AJAX
+
- if profile_tab?(:snippets)
#snippets.tab-pane
-# This tab is always loaded via AJAX
diff --git a/config/routes/user.rb b/config/routes/user.rb
index 80f266aa8f9..3f768d5d384 100644
--- a/config/routes/user.rb
+++ b/config/routes/user.rb
@@ -59,6 +59,7 @@ scope(constraints: { username: Gitlab::PathRegex.root_namespace_route_regex }) d
get :groups
get :projects
get :contributed, as: :contributed_projects
+ get :starred, as: :starred_projects
get :snippets
get :exists
get :activity