Skip to content
Snippets Groups Projects
Commit ffda8a1a authored by Long Nguyen's avatar Long Nguyen
Browse files

user routings refactor

parent 5f60841d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -10,11 +10,29 @@ class SnippetsController < ApplicationController
# Allow destroy snippet
before_action :authorize_admin_snippet!, only: [:destroy]
 
skip_before_action :authenticate_user!, only: [:show, :raw]
skip_before_action :authenticate_user!, only: [:index, :show, :raw]
 
layout 'snippets'
respond_to :html
 
def index
if params[:username].present?
@user = User.find_by(username: params[:username])
render_404 and return unless @user
@snippets = SnippetsFinder.new.execute(current_user, {
filter: :by_user,
user: @user,
scope: params[:scope] }).
page(params[:page])
render 'index'
else
redirect_to(current_user ? dashboard_snippets_path : explore_snippets_path)
end
end
def new
@snippet = PersonalSnippet.new
end
Loading
Loading
@@ -43,7 +61,7 @@ class SnippetsController < ApplicationController
 
@snippet.destroy
 
redirect_to dashboard_snippets_path
redirect_to snippets_path
end
 
def raw
Loading
Loading
Loading
Loading
@@ -6,7 +6,7 @@
%span
= snippet.title
by
= link_to user_snippets_path(snippet.author) do
= link_to snippets_user_path(snippet.author) do
= image_tag avatar_icon(snippet.author_email), class: "avatar avatar-inline s16", alt: ''
= snippet.author_name
%span.light #{time_ago_with_tooltip(snippet.created_at)}
Loading
Loading
Loading
Loading
@@ -17,7 +17,7 @@
= "##{snippet_title.id}"
%span
by
= link_to user_snippets_path(snippet_title.author) do
= link_to snippets_user_path(snippet_title.author) do
= image_tag avatar_icon(snippet_title.author_email), class: "avatar avatar-inline s16", alt: ''
= snippet_title.author_name
%span.light #{time_ago_with_tooltip(snippet_title.created_at)}
Loading
Loading
@@ -16,6 +16,6 @@
= link_to snippet.project.name_with_namespace, namespace_project_path(snippet.project.namespace, snippet.project)
 
.snippet-info
= link_to user_snippets_path(snippet.author) do
= link_to snippets_user_path(snippet.author) do
= snippet.author_name
authored #{time_ago_with_tooltip(snippet.created_at)}
- page_title "By #{@user.name}", "Snippets"
%ol.breadcrumb
%li
= link_to snippets_path do
Snippets
%li
= @user.name
.pull-right.hidden-xs
= link_to user_path(@user) do
#{@user.name} profile page
= render 'snippets'
Loading
Loading
@@ -4,7 +4,7 @@
#{@timestamps.to_json},
#{@starting_year},
#{@starting_month},
'#{user_calendar_activities_path}'
'#{calendar_activities_user_path}'
);
 
.calendar-hint Summary of issues, merge requests, and push events
Loading
Loading
@@ -70,19 +70,19 @@
 
%ul.nav-links.center.user-profile-nav
%li.js-activity-tab
= link_to user_calendar_activities_path, data: {target: 'div#activity', action: 'activity', toggle: 'tab'} do
= link_to calendar_activities_user_path, data: {target: 'div#activity', action: 'activity', toggle: 'tab'} do
Activity
%li.js-groups-tab
= link_to user_groups_path, data: {target: 'div#groups', action: 'groups', toggle: 'tab'} do
= link_to groups_user_path, data: {target: 'div#groups', action: 'groups', toggle: 'tab'} do
Groups
%li.js-contributed-tab
= link_to user_contributed_projects_path, data: {target: 'div#contributed', action: 'contributed', toggle: 'tab'} do
= link_to contributed_projects_user_path, data: {target: 'div#contributed', action: 'contributed', toggle: 'tab'} do
Contributed projects
%li.projects-tab
= link_to user_projects_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do
= link_to projects_user_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do
Personal projects
%li.snippets-tab
= link_to user_snippets_path, data: {target: 'div#snippets', action: 'snippets', toggle: 'tab'} do
= link_to snippets_user_path, data: {target: 'div#snippets', action: 'snippets', toggle: 'tab'} do
Snippets
 
%div{ class: container_class }
Loading
Loading
@@ -90,7 +90,7 @@
#activity.tab-pane
.gray-content-block.calender-block.white.second-block.hidden-xs
%div{ class: container_class }
.user-calendar{data: {href: user_calendar_path}}
.user-calendar{data: {href: calendar_user_path}}
%h4.center.light
%i.fa.fa-spinner.fa-spin
.user-calendar-activities
Loading
Loading
Loading
Loading
@@ -91,6 +91,9 @@ Rails.application.routes.draw do
end
end
 
get '/s/:username', to: redirect('/u/:username/snippets'),
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
#
# Invites
#
Loading
Loading
@@ -340,26 +343,20 @@ Rails.application.routes.draw do
end
end
 
get 'u/:username/calendar' => 'users#calendar', as: :user_calendar,
constraints: { username: /.*/ }
get 'u/:username/calendar_activities' => 'users#calendar_activities', as: :user_calendar_activities,
constraints: { username: /.*/ }
get 'u/:username/groups' => 'users#groups', as: :user_groups,
constraints: { username: /.*/ }
get 'u/:username/projects' => 'users#projects', as: :user_projects,
constraints: { username: /.*/ }
get 'u/:username/contributed' => 'users#contributed', as: :user_contributed_projects,
constraints: { username: /.*/ }
get 'u/:username/snippets' => 'users#snippets', as: :user_snippets,
constraints: { username: /.*/ }
get '/u/:username' => 'users#show', as: :user,
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ }
resources(:users,
path: 'u',
param: :username,
constraints: { username: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ },
only: :show) do
member do
get :calendar, as: :calendar
get :calendar_activities, as: :calendar_activities
get :groups, as: :groups
get :projects, as: :projects
get :contributed, as: :contributed_projects
get :snippets, as: :snippets
end
end
 
#
# Dashboard Area
Loading
Loading
Loading
Loading
@@ -31,6 +31,10 @@ describe SnippetsController, "routing" do
expect(get("/snippets/1/raw")).to route_to('snippets#raw', id: '1')
end
 
it "to #index" do
expect(get("/snippets")).to route_to('snippets#index')
end
it "to #create" do
expect(post("/snippets")).to route_to('snippets#create')
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment