Skip to content

Commit 96d97c4

Browse files
committed
Fix routing. Finalize user show page
1 parent 70690e1 commit 96d97c4

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

Diff for: app/controllers/users_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class UsersController < ApplicationController
22
def show
3-
@user = User.find_by_username(params[:username])
3+
@user = User.find_by_username!(params[:username])
44
@projects = @user.authorized_projects.where('projects.id in (?)', current_user.authorized_projects.map(&:id))
55
@events = @user.recent_events.where(project_id: @projects.map(&:id)).limit(20)
66
end

Diff for: app/models/team.rb

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def << args
2121
end
2222
end
2323

24+
def get_tm user_id
25+
project.users_projects.find_by_user_id(user_id)
26+
end
27+
2428
def add_user(user, access)
2529
add_users_ids([user.id], access)
2630
end

Diff for: app/views/users/_projects.html.haml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.ui-box
2+
%h5.title Projects
3+
%ul.well-list
4+
- @projects.each do |project|
5+
%li
6+
= link_to project_path(project), class: dom_class(project) do
7+
- if project.namespace
8+
= project.namespace.human_name
9+
\/
10+
%strong.well-title
11+
= truncate(project.name, length: 45)
12+
%span.right.light
13+
- if project.owner == @user
14+
%i.icon-wrench
15+
- tm = project.team.get_tm(@user.id)
16+
- if tm
17+
= tm.project_access_human
18+
%p.light
19+
%i.icon-wrench
20+
&ndash; user is a project owner

Diff for: app/views/users/show.html.haml

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
%h3.page_title
44
= image_tag gravatar_icon(@user.email, 90), class: "avatar s90"
55
= @user.name
6-
%span.light (@#{@user.username})
6+
%br
7+
%small @#{@user.username}
8+
%br
9+
%small member since #{@user.created_at.stamp("Nov 12, 2031")}
710
.clearfix
811
%hr
912
%h5 Recent events
@@ -31,14 +34,4 @@
3134
%li
3235
%strong Bio
3336
%span.right= @user.bio
34-
.ui-box
35-
%h5.title Projects
36-
%ul.well-list
37-
- @projects.each do |project|
38-
%li
39-
= link_to project_path(project), class: dom_class(project) do
40-
- if project.namespace
41-
= project.namespace.human_name
42-
\/
43-
%strong.well-title
44-
= truncate(project.name, length: 45)
37+
= render 'projects'

Diff for: config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
end
9898

9999
resources :keys
100-
match "/u/:username" => "users#show", as: :user
100+
match "/u/:username" => "users#show", as: :user, constraints: { username: /.*/ }
101101

102102

103103

0 commit comments

Comments
 (0)