Commit 2c46b35b100be89e0549336616391aef2337454d

Authored by Dmitriy Zaporozhets
2 parents 28cc1991 e9de5694

Merge branch 'profile-personal-projects' into 'master'

Show only personal projects on user page

When I visit user profile page I see all projects he have access too (if i can also access same projects).
That means I see a list of hundreds projects if he joined several groups. ![Screenshot 2014-05-30 18.24.43](https://dev.gitlab.org/uploads/dzaporozhets/gitlabhq/5209c0cb01/Screenshot_2014-05-30_18.24.43.png)

It inefficient because:

* Slow page load if a lot of projects
* Hard to find his personal projects

I propose to replace it with `Personal projects` list.

It has next advantages:

* we don't load huge useless list of projects
* I can see if user have personal projects I have access to
* faster page load. We don't load all projects from all groups where user invited

![Screenshot 2014-05-30 18.20.29](https://dev.gitlab.org/uploads/dzaporozhets/gitlabhq/8a5d02a00d/Screenshot_2014-05-30_18.20.29.png)

Partly fixes #1135
app/controllers/users_controller.rb
... ... @@ -4,10 +4,12 @@ class UsersController < ApplicationController
4 4  
5 5 def show
6 6 @user = User.find_by_username!(params[:username])
7   - @projects = @user.authorized_projects.accessible_to(current_user)
8   - if !current_user && @projects.empty?
  7 + @projects = Project.personal(@user).accessible_to(current_user)
  8 +
  9 + unless current_user || @user.public_profile?
9 10 return authenticate_user!
10 11 end
  12 +
11 13 @groups = @user.groups.accessible_to(current_user)
12 14 @events = @user.recent_events.where(project_id: @projects.pluck(:id)).limit(20)
13 15 @title = @user.name
... ...
app/models/user.rb
... ... @@ -478,4 +478,8 @@ class User < ActiveRecord::Base
478 478 def generate_tmp_oauth_email
479 479 self.email = "temp-email-for-oauth-#{username}@gitlab.localhost"
480 480 end
  481 +
  482 + def public_profile?
  483 + authorized_projects.public_only.any?
  484 + end
481 485 end
... ...
app/views/users/_projects.html.haml
1 1 .panel.panel-default
2   - .panel-heading Projects
  2 + .panel-heading Personal projects
3 3 %ul.well-list
4 4 - @projects.each do |project|
5 5 %li
... ...
app/views/users/show.html.haml
... ... @@ -20,4 +20,5 @@
20 20 = render @events
21 21 .col-md-4
22 22 = render 'profile', user: @user
23   - = render 'projects'
  23 + - if @projects.present?
  24 + = render 'projects'
... ...
features/steps/shared/project.rb
... ... @@ -102,24 +102,24 @@ module SharedProject
102 102 page.should_not have_content "Community"
103 103 end
104 104  
105   - step '"John Doe" is authorized to private project "Enterprise"' do
  105 + step '"John Doe" owns private project "Enterprise"' do
106 106 user = user_exists("John Doe", username: "john_doe")
107 107 project = Project.find_by(name: "Enterprise")
108   - project ||= create(:project, name: "Enterprise", namespace: user.namespace)
  108 + project ||= create(:empty_project, name: "Enterprise", namespace: user.namespace)
109 109 project.team << [user, :master]
110 110 end
111 111  
112   - step '"John Doe" is authorized to internal project "Internal"' do
  112 + step '"John Doe" owns internal project "Internal"' do
113 113 user = user_exists("John Doe", username: "john_doe")
114 114 project = Project.find_by(name: "Internal")
115   - project ||= create :project, :internal, name: 'Internal'
  115 + project ||= create :empty_project, :internal, name: 'Internal', namespace: user.namespace
116 116 project.team << [user, :master]
117 117 end
118 118  
119   - step '"John Doe" is authorized to public project "Community"' do
  119 + step '"John Doe" owns public project "Community"' do
120 120 user = user_exists("John Doe", username: "john_doe")
121 121 project = Project.find_by(name: "Community")
122   - project ||= create :project, :public, name: 'Community'
  122 + project ||= create :empty_project, :public, name: 'Community', namespace: user.namespace
123 123 project.team << [user, :master]
124 124 end
125 125 end
... ...
features/user.feature
1 1 Feature: User
2 2 Background:
3 3 Given User "John Doe" exists
4   - And "John Doe" is authorized to private project "Enterprise"
  4 + And "John Doe" owns private project "Enterprise"
5 5  
6 6 # Signed out
7 7  
8   - Scenario: I visit user "John Doe" page while not signed in when he is authorized to a public project
9   - Given "John Doe" is authorized to internal project "Internal"
10   - And "John Doe" is authorized to public project "Community"
  8 + Scenario: I visit user "John Doe" page while not signed in when he owns a public project
  9 + Given "John Doe" owns internal project "Internal"
  10 + And "John Doe" owns public project "Community"
11 11 When I visit user "John Doe" page
12 12 Then I should see user "John Doe" page
13 13 And I should not see project "Enterprise"
... ... @@ -15,15 +15,15 @@ Feature: User
15 15 And I should see project "Community"
16 16  
17 17 Scenario: I visit user "John Doe" page while not signed in when he is not authorized to a public project
18   - Given "John Doe" is authorized to internal project "Internal"
  18 + Given "John Doe" owns internal project "Internal"
19 19 When I visit user "John Doe" page
20 20 Then I should be redirected to sign in page
21 21  
22 22 # Signed in as someone else
23 23  
24   - Scenario: I visit user "John Doe" page while signed in as someone else when he is authorized to a public project
25   - Given "John Doe" is authorized to public project "Community"
26   - And "John Doe" is authorized to internal project "Internal"
  24 + Scenario: I visit user "John Doe" page while signed in as someone else when he owns a public project
  25 + Given "John Doe" owns public project "Community"
  26 + And "John Doe" owns internal project "Internal"
27 27 And I sign in as a user
28 28 When I visit user "John Doe" page
29 29 Then I should see user "John Doe" page
... ... @@ -32,7 +32,7 @@ Feature: User
32 32 And I should see project "Community"
33 33  
34 34 Scenario: I visit user "John Doe" page while signed in as someone else when he is not authorized to a public project
35   - Given "John Doe" is authorized to internal project "Internal"
  35 + Given "John Doe" owns internal project "Internal"
36 36 And I sign in as a user
37 37 When I visit user "John Doe" page
38 38 Then I should see user "John Doe" page
... ... @@ -51,8 +51,8 @@ Feature: User
51 51 # Signed in as the user himself
52 52  
53 53 Scenario: I visit user "John Doe" page while signed in as "John Doe" when he has a public project
54   - Given "John Doe" is authorized to internal project "Internal"
55   - And "John Doe" is authorized to public project "Community"
  54 + Given "John Doe" owns internal project "Internal"
  55 + And "John Doe" owns public project "Community"
56 56 And I sign in as "John Doe"
57 57 When I visit user "John Doe" page
58 58 Then I should see user "John Doe" page
... ...