diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-06-02 16:31:50 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-06-02 16:31:50 +0400 |
commit | 2c46b35b100be89e0549336616391aef2337454d (patch) | |
tree | 65460161315b06da8df51242bb926adb4e1fdf34 | |
parent | 28cc199128d64d8a84b555bea76fde0af9c7a783 (diff) | |
parent | e9de569458b55b43a0d09dceef07c3c5d583af24 (diff) |
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
-rw-r--r-- | app/controllers/users_controller.rb | 6 | ||||
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | app/views/users/_projects.html.haml | 2 | ||||
-rw-r--r-- | app/views/users/show.html.haml | 3 | ||||
-rw-r--r-- | features/steps/shared/project.rb | 12 | ||||
-rw-r--r-- | features/user.feature | 22 |
6 files changed, 28 insertions, 21 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9461174b950..d42c2db9e5f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,10 +4,12 @@ class UsersController < ApplicationController def show @user = User.find_by_username!(params[:username]) - @projects = @user.authorized_projects.accessible_to(current_user) - if !current_user && @projects.empty? + @projects = Project.personal(@user).accessible_to(current_user) + + unless current_user || @user.public_profile? return authenticate_user! end + @groups = @user.groups.accessible_to(current_user) @events = @user.recent_events.where(project_id: @projects.pluck(:id)).limit(20) @title = @user.name diff --git a/app/models/user.rb b/app/models/user.rb index f1b6139745e..0fbc9284dd8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -478,4 +478,8 @@ class User < ActiveRecord::Base def generate_tmp_oauth_email self.email = "temp-email-for-oauth-#{username}@gitlab.localhost" end + + def public_profile? + authorized_projects.public_only.any? + end end diff --git a/app/views/users/_projects.html.haml b/app/views/users/_projects.html.haml index 2d97c4545b9..bcaec4a27e7 100644 --- a/app/views/users/_projects.html.haml +++ b/app/views/users/_projects.html.haml @@ -1,5 +1,5 @@ .panel.panel-default - .panel-heading Projects + .panel-heading Personal projects %ul.well-list - @projects.each do |project| %li diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index edcaf3acf98..948b59fead1 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -20,4 +20,5 @@ = render @events .col-md-4 = render 'profile', user: @user - = render 'projects' + - if @projects.present? + = render 'projects' diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb index f8cb753b78f..40362fee0bc 100644 --- a/features/steps/shared/project.rb +++ b/features/steps/shared/project.rb @@ -102,24 +102,24 @@ module SharedProject page.should_not have_content "Community" end - step '"John Doe" is authorized to private project "Enterprise"' do + step '"John Doe" owns private project "Enterprise"' do user = user_exists("John Doe", username: "john_doe") project = Project.find_by(name: "Enterprise") - project ||= create(:project, name: "Enterprise", namespace: user.namespace) + project ||= create(:empty_project, name: "Enterprise", namespace: user.namespace) project.team << [user, :master] end - step '"John Doe" is authorized to internal project "Internal"' do + step '"John Doe" owns internal project "Internal"' do user = user_exists("John Doe", username: "john_doe") project = Project.find_by(name: "Internal") - project ||= create :project, :internal, name: 'Internal' + project ||= create :empty_project, :internal, name: 'Internal', namespace: user.namespace project.team << [user, :master] end - step '"John Doe" is authorized to public project "Community"' do + step '"John Doe" owns public project "Community"' do user = user_exists("John Doe", username: "john_doe") project = Project.find_by(name: "Community") - project ||= create :project, :public, name: 'Community' + project ||= create :empty_project, :public, name: 'Community', namespace: user.namespace project.team << [user, :master] end end diff --git a/features/user.feature b/features/user.feature index d4198c08de9..a2167935fd2 100644 --- a/features/user.feature +++ b/features/user.feature @@ -1,13 +1,13 @@ Feature: User Background: Given User "John Doe" exists - And "John Doe" is authorized to private project "Enterprise" + And "John Doe" owns private project "Enterprise" # Signed out - Scenario: I visit user "John Doe" page while not signed in when he is authorized to a public project - Given "John Doe" is authorized to internal project "Internal" - And "John Doe" is authorized to public project "Community" + Scenario: I visit user "John Doe" page while not signed in when he owns a public project + Given "John Doe" owns internal project "Internal" + And "John Doe" owns public project "Community" When I visit user "John Doe" page Then I should see user "John Doe" page And I should not see project "Enterprise" @@ -15,15 +15,15 @@ Feature: User And I should see project "Community" Scenario: I visit user "John Doe" page while not signed in when he is not authorized to a public project - Given "John Doe" is authorized to internal project "Internal" + Given "John Doe" owns internal project "Internal" When I visit user "John Doe" page Then I should be redirected to sign in page # Signed in as someone else - Scenario: I visit user "John Doe" page while signed in as someone else when he is authorized to a public project - Given "John Doe" is authorized to public project "Community" - And "John Doe" is authorized to internal project "Internal" + Scenario: I visit user "John Doe" page while signed in as someone else when he owns a public project + Given "John Doe" owns public project "Community" + And "John Doe" owns internal project "Internal" And I sign in as a user When I visit user "John Doe" page Then I should see user "John Doe" page @@ -32,7 +32,7 @@ Feature: User And I should see project "Community" Scenario: I visit user "John Doe" page while signed in as someone else when he is not authorized to a public project - Given "John Doe" is authorized to internal project "Internal" + Given "John Doe" owns internal project "Internal" And I sign in as a user When I visit user "John Doe" page Then I should see user "John Doe" page @@ -51,8 +51,8 @@ Feature: User # Signed in as the user himself Scenario: I visit user "John Doe" page while signed in as "John Doe" when he has a public project - Given "John Doe" is authorized to internal project "Internal" - And "John Doe" is authorized to public project "Community" + Given "John Doe" owns internal project "Internal" + And "John Doe" owns public project "Community" And I sign in as "John Doe" When I visit user "John Doe" page Then I should see user "John Doe" page |