Commit f2251273 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'issue_15572_snippets_tab_under_user_profile' into 'master'

Add snippet tab under user profile

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/15572

See merge request !4001
parents 44f6e34b a22d559d
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.8.0 (unreleased) v 8.8.0 (unreleased)
- Snippets tab under user profile. !4001 (Long Nguyen)
- Fix error when using link to uploads in global snippets - Fix error when using link to uploads in global snippets
- Assign labels and milestone to target project when moving issue. !3934 (Long Nguyen) - Assign labels and milestone to target project when moving issue. !3934 (Long Nguyen)
- Use a case-insensitive comparison in sanitizing URI schemes - Use a case-insensitive comparison in sanitizing URI schemes
......
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
# Personal projects # Personal projects
# </a> # </a>
# </li> # </li>
# <li class="snippets-tab">
# <a data-action="snippets" data-target="#snippets" data-toggle="tab" href="/u/username/snippets">
# </a>
# </li>
# </ul> # </ul>
# #
# <div class="tab-content"> # <div class="tab-content">
...@@ -41,6 +45,9 @@ ...@@ -41,6 +45,9 @@
# <div class="tab-pane" id="projects"> # <div class="tab-pane" id="projects">
# Projects content # Projects content
# </div> # </div>
# <div class="tab-pane" id="snippets">
# Snippets content
# </div>
# </div> # </div>
# #
# <div class="loading-status"> # <div class="loading-status">
...@@ -100,7 +107,7 @@ class @UserTabs ...@@ -100,7 +107,7 @@ class @UserTabs
if action is 'activity' if action is 'activity'
@loadActivities(source) @loadActivities(source)
if action in ['groups', 'contributed', 'projects'] if action in ['groups', 'contributed', 'projects', 'snippets']
@loadTab(source, action) @loadTab(source, action)
loadTab: (source, action) -> loadTab: (source, action) ->
......
...@@ -10,7 +10,7 @@ class SnippetsController < ApplicationController ...@@ -10,7 +10,7 @@ class SnippetsController < ApplicationController
# Allow destroy snippet # Allow destroy snippet
before_action :authorize_admin_snippet!, only: [:destroy] before_action :authorize_admin_snippet!, only: [:destroy]
skip_before_action :authenticate_user!, only: [:index, :user_index, :show, :raw] skip_before_action :authenticate_user!, only: [:index, :show, :raw]
layout 'snippets' layout 'snippets'
respond_to :html respond_to :html
......
...@@ -58,6 +58,19 @@ class UsersController < ApplicationController ...@@ -58,6 +58,19 @@ class UsersController < ApplicationController
end end
end end
def snippets
load_snippets
respond_to do |format|
format.html { render 'show' }
format.json do
render json: {
html: view_to_html_string("snippets/_snippets", collection: @snippets)
}
end
end
end
def calendar def calendar
calendar = contributions_calendar calendar = contributions_calendar
@timestamps = calendar.timestamps @timestamps = calendar.timestamps
...@@ -116,6 +129,15 @@ class UsersController < ApplicationController ...@@ -116,6 +129,15 @@ class UsersController < ApplicationController
@groups = JoinedGroupsFinder.new(user).execute(current_user) @groups = JoinedGroupsFinder.new(user).execute(current_user)
end end
def load_snippets
@snippets = SnippetsFinder.new.execute(
current_user,
filter: :by_user,
user: user,
scope: params[:scope]
).page(params[:page])
end
def projects_for_current_user def projects_for_current_user
ProjectsFinder.new.execute(current_user) ProjectsFinder.new.execute(current_user)
end end
......
...@@ -81,6 +81,9 @@ ...@@ -81,6 +81,9 @@
%li.projects-tab %li.projects-tab
= link_to user_projects_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do = link_to user_projects_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do
Personal projects Personal projects
%li.snippets-tab
= link_to user_snippets_path, data: {target: 'div#snippets', action: 'snippets', toggle: 'tab'} do
Snippets
%div{ class: container_class } %div{ class: container_class }
.tab-content .tab-content
...@@ -104,6 +107,9 @@ ...@@ -104,6 +107,9 @@
#projects.tab-pane #projects.tab-pane
- # This tab is always loaded via AJAX - # This tab is always loaded via AJAX
#snippets.tab-pane
- # This tab is always loaded via AJAX
.loading-status .loading-status
= spinner = spinner
......
...@@ -91,7 +91,8 @@ Rails.application.routes.draw do ...@@ -91,7 +91,8 @@ Rails.application.routes.draw do
end end
end end
get '/s/:username' => 'snippets#index', as: :user_snippets, constraints: { username: /.*/ } get '/s/:username', to: redirect('/u/%{username}/snippets'),
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
# #
# Invites # Invites
...@@ -342,23 +343,18 @@ Rails.application.routes.draw do ...@@ -342,23 +343,18 @@ Rails.application.routes.draw do
end end
end end
get 'u/:username/calendar' => 'users#calendar', as: :user_calendar, scope(path: 'u/:username',
constraints: { username: /.*/ } as: :user,
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ },
get 'u/:username/calendar_activities' => 'users#calendar_activities', as: :user_calendar_activities, controller: :users) do
constraints: { username: /.*/ } get :calendar
get :calendar_activities
get 'u/:username/groups' => 'users#groups', as: :user_groups, get :groups
constraints: { username: /.*/ } get :projects
get :contributed, as: :contributed_projects
get 'u/:username/projects' => 'users#projects', as: :user_projects, get :snippets
constraints: { username: /.*/ } get '/', action: :show
end
get 'u/:username/contributed' => 'users#contributed', as: :user_contributed_projects,
constraints: { username: /.*/ }
get '/u/:username' => 'users#show', as: :user,
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
# #
# Dashboard Area # Dashboard Area
......
...@@ -112,4 +112,26 @@ describe UsersController do ...@@ -112,4 +112,26 @@ describe UsersController do
expect(response).to render_template('calendar_activities') expect(response).to render_template('calendar_activities')
end end
end end
describe 'GET #snippets' do
before do
sign_in(user)
end
context 'format html' do
it 'renders snippets page' do
get :snippets, username: user.username
expect(response.status).to eq(200)
expect(response).to render_template('show')
end
end
context 'format json' do
it 'response with snippets json data' do
get :snippets, username: user.username, format: :json
expect(response.status).to eq(200)
expect(JSON.parse(response.body)).to have_key('html')
end
end
end
end end
require 'spec_helper' require 'spec_helper'
# user GET /u/:username/
# user_groups GET /u/:username/groups(.:format)
# user_projects GET /u/:username/projects(.:format)
# user_contributed_projects GET /u/:username/contributed(.:format)
# user_snippets GET /u/:username/snippets(.:format)
# user_calendar GET /u/:username/calendar(.:format)
# user_calendar_activities GET /u/:username/calendar_activities(.:format)
describe UsersController, "routing" do
it "to #show" do
expect(get("/u/User")).to route_to('users#show', username: 'User')
end
it "to #groups" do
expect(get("/u/User/groups")).to route_to('users#groups', username: 'User')
end
it "to #projects" do
expect(get("/u/User/projects")).to route_to('users#projects', username: 'User')
end
it "to #contributed" do
expect(get("/u/User/contributed")).to route_to('users#contributed', username: 'User')
end
it "to #snippets" do
expect(get("/u/User/snippets")).to route_to('users#snippets', username: 'User')
end
it "to #calendar" do
expect(get("/u/User/calendar")).to route_to('users#calendar', username: 'User')
end
it "to #calendar_activities" do
expect(get("/u/User/calendar_activities")).to route_to('users#calendar_activities', username: 'User')
end
end
# search GET /search(.:format) search#show # search GET /search(.:format) search#show
describe SearchController, "routing" do describe SearchController, "routing" do
it "to #show" do it "to #show" do
...@@ -27,10 +64,6 @@ end ...@@ -27,10 +64,6 @@ end
# PUT /snippets/:id(.:format) snippets#update # PUT /snippets/:id(.:format) snippets#update
# DELETE /snippets/:id(.:format) snippets#destroy # DELETE /snippets/:id(.:format) snippets#destroy
describe SnippetsController, "routing" do describe SnippetsController, "routing" do
it "to #user_index" do
expect(get("/s/User")).to route_to('snippets#index', username: 'User')
end
it "to #raw" do it "to #raw" do
expect(get("/snippets/1/raw")).to route_to('snippets#raw', id: '1') expect(get("/snippets/1/raw")).to route_to('snippets#raw', id: '1')
end end
......
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