Commit 38282685 authored by Camil Staps's avatar Camil Staps

Add "Starred projects" tab to user overview

parent 936d4e80
......@@ -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);
}
......
......@@ -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)
......
# 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
......@@ -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
......
......@@ -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
......
......@@ -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
......
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