Commit 2f6342978bfb0bd7aafc345a36bb0846b73cc80d
1 parent
61eb0509
Exists in
master
and in
4 other branches
Public projects feature - step2
* Render right layout depends on current_user * show sample git username/email when repo is empty * Show extra info when browsing public area * Fixed some tests related to public projects * show comments in read-only for public projects * Remove old public routing
Showing
10 changed files
with
72 additions
and
44 deletions
Show diff stats
app/assets/stylesheets/sections/projects.scss
| @@ -79,21 +79,6 @@ ul.nav.nav-projects-tabs { | @@ -79,21 +79,6 @@ ul.nav.nav-projects-tabs { | ||
| 79 | margin: 0px; | 79 | margin: 0px; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | -.public-projects { | ||
| 83 | - li { | ||
| 84 | - .project-title { | ||
| 85 | - font-size: 14px; | ||
| 86 | - line-height: 2; | ||
| 87 | - font-weight: normal; | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - .description { | ||
| 91 | - margin-left: 15px; | ||
| 92 | - color: #aaa; | ||
| 93 | - } | ||
| 94 | - } | ||
| 95 | -} | ||
| 96 | - | ||
| 97 | .my-projects { | 82 | .my-projects { |
| 98 | li { | 83 | li { |
| 99 | .project-title { | 84 | .project-title { |
| @@ -110,7 +95,6 @@ ul.nav.nav-projects-tabs { | @@ -110,7 +95,6 @@ ul.nav.nav-projects-tabs { | ||
| 110 | } | 95 | } |
| 111 | } | 96 | } |
| 112 | 97 | ||
| 113 | - | ||
| 114 | .public-clone { | 98 | .public-clone { |
| 115 | background: #333; | 99 | background: #333; |
| 116 | color: #f5f5f5; | 100 | color: #f5f5f5; |
| @@ -123,3 +107,11 @@ ul.nav.nav-projects-tabs { | @@ -123,3 +107,11 @@ ul.nav.nav-projects-tabs { | ||
| 123 | position: relative; | 107 | position: relative; |
| 124 | top: -5px; | 108 | top: -5px; |
| 125 | } | 109 | } |
| 110 | + | ||
| 111 | +.public-projects .repo-info { | ||
| 112 | + color: #777; | ||
| 113 | + | ||
| 114 | + a { | ||
| 115 | + color: #777; | ||
| 116 | + } | ||
| 117 | +} |
app/controllers/projects/application_controller.rb
| @@ -20,7 +20,7 @@ class Projects::ApplicationController < ApplicationController | @@ -20,7 +20,7 @@ class Projects::ApplicationController < ApplicationController | ||
| 20 | if current_user | 20 | if current_user |
| 21 | 'projects' | 21 | 'projects' |
| 22 | else | 22 | else |
| 23 | - 'public' | 23 | + 'public_projects' |
| 24 | end | 24 | end |
| 25 | end | 25 | end |
| 26 | end | 26 | end |
app/controllers/projects_controller.rb
| @@ -55,10 +55,9 @@ class ProjectsController < Projects::ApplicationController | @@ -55,10 +55,9 @@ class ProjectsController < Projects::ApplicationController | ||
| 55 | end | 55 | end |
| 56 | 56 | ||
| 57 | def show | 57 | def show |
| 58 | - return authenticate_user! unless @project.public | 58 | + return authenticate_user! unless @project.public || current_user |
| 59 | 59 | ||
| 60 | limit = (params[:limit] || 20).to_i | 60 | limit = (params[:limit] || 20).to_i |
| 61 | - | ||
| 62 | @events = @project.events.recent | 61 | @events = @project.events.recent |
| 63 | @events = event_filter.apply_filter(@events) | 62 | @events = event_filter.apply_filter(@events) |
| 64 | @events = @events.limit(limit).offset(params[:offset] || 0) | 63 | @events = @events.limit(limit).offset(params[:offset] || 0) |
| @@ -70,12 +69,12 @@ class ProjectsController < Projects::ApplicationController | @@ -70,12 +69,12 @@ class ProjectsController < Projects::ApplicationController | ||
| 70 | respond_to do |format| | 69 | respond_to do |format| |
| 71 | format.html do | 70 | format.html do |
| 72 | if @project.empty_repo? | 71 | if @project.empty_repo? |
| 73 | - render "projects/empty" | 72 | + render "projects/empty", layout: user_layout |
| 74 | else | 73 | else |
| 75 | if current_user | 74 | if current_user |
| 76 | @last_push = current_user.recent_push(@project.id) | 75 | @last_push = current_user.recent_push(@project.id) |
| 77 | end | 76 | end |
| 78 | - render :show, layout: current_user ? "project" : "public" | 77 | + render :show, layout: user_layout |
| 79 | end | 78 | end |
| 80 | end | 79 | end |
| 81 | format.js | 80 | format.js |
| @@ -126,4 +125,8 @@ class ProjectsController < Projects::ApplicationController | @@ -126,4 +125,8 @@ class ProjectsController < Projects::ApplicationController | ||
| 126 | def set_title | 125 | def set_title |
| 127 | @title = 'New Project' | 126 | @title = 'New Project' |
| 128 | end | 127 | end |
| 128 | + | ||
| 129 | + def user_layout | ||
| 130 | + current_user ? "projects" : "public_projects" | ||
| 131 | + end | ||
| 129 | end | 132 | end |
app/helpers/projects_helper.rb
| @@ -103,4 +103,20 @@ module ProjectsHelper | @@ -103,4 +103,20 @@ module ProjectsHelper | ||
| 103 | 103 | ||
| 104 | nav_tabs.flatten | 104 | nav_tabs.flatten |
| 105 | end | 105 | end |
| 106 | + | ||
| 107 | + def git_user_name | ||
| 108 | + if current_user | ||
| 109 | + current_user.name | ||
| 110 | + else | ||
| 111 | + "Your name" | ||
| 112 | + end | ||
| 113 | + end | ||
| 114 | + | ||
| 115 | + def git_user_email | ||
| 116 | + if current_user | ||
| 117 | + current_user.email | ||
| 118 | + else | ||
| 119 | + "your@email.com" | ||
| 120 | + end | ||
| 121 | + end | ||
| 106 | end | 122 | end |
app/views/projects/empty.html.haml
| @@ -16,8 +16,8 @@ | @@ -16,8 +16,8 @@ | ||
| 16 | %legend Git global setup: | 16 | %legend Git global setup: |
| 17 | %pre.dark | 17 | %pre.dark |
| 18 | :preserve | 18 | :preserve |
| 19 | - git config --global user.name "#{current_user.name}" | ||
| 20 | - git config --global user.email "#{current_user.email}" | 19 | + git config --global user.name "#{git_user_name}" |
| 20 | + git config --global user.email "#{git_user_email}" | ||
| 21 | 21 | ||
| 22 | %fieldset | 22 | %fieldset |
| 23 | %legend Create Repository | 23 | %legend Create Repository |
app/views/projects/notes/_note.html.haml
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | %i.icon-link | 5 | %i.icon-link |
| 6 | Link here | 6 | Link here |
| 7 | | 7 | |
| 8 | - - if(note.author_id == current_user.id) || can?(current_user, :admin_note, @project) | 8 | + - if(note.author_id == current_user.try(:id)) || can?(current_user, :admin_note, @project) |
| 9 | = link_to "#", title: "Edit comment", class: "js-note-edit" do | 9 | = link_to "#", title: "Edit comment", class: "js-note-edit" do |
| 10 | %i.icon-edit | 10 | %i.icon-edit |
| 11 | Edit | 11 | Edit |
app/views/public/projects/index.html.haml
| @@ -2,29 +2,40 @@ | @@ -2,29 +2,40 @@ | ||
| 2 | .span6 | 2 | .span6 |
| 3 | %h3.page-title | 3 | %h3.page-title |
| 4 | Projects (#{@projects.total_count}) | 4 | Projects (#{@projects.total_count}) |
| 5 | - %small with read-only access | 5 | + .light |
| 6 | + You can browse public projects in read-only mode until signed in. | ||
| 7 | + | ||
| 6 | .span6 | 8 | .span6 |
| 7 | .pull-right | 9 | .pull-right |
| 8 | = form_tag public_projects_path, method: :get, class: 'form-inline' do |f| | 10 | = form_tag public_projects_path, method: :get, class: 'form-inline' do |f| |
| 9 | .search-holder | 11 | .search-holder |
| 10 | - .controls | ||
| 11 | - = search_field_tag :search, params[:search], placeholder: "Filter by name", class: "span3 search-text-input", id: "projects_search" | ||
| 12 | - = submit_tag 'Search', class: "btn btn-primary wide" | ||
| 13 | - | 12 | + = search_field_tag :search, params[:search], placeholder: "Filter by name", class: "span3 search-text-input", id: "projects_search" |
| 13 | + = submit_tag 'Search', class: "btn btn-primary wide" | ||
| 14 | +%hr | ||
| 14 | .public-projects | 15 | .public-projects |
| 15 | - %ul.bordered-list | 16 | + %ul.bordered-list.top-list |
| 16 | - @projects.each do |project| | 17 | - @projects.each do |project| |
| 17 | %li | 18 | %li |
| 18 | - .project-title | ||
| 19 | - %i.icon-share.cgray | 19 | + %h4 |
| 20 | = link_to project_path(project) do | 20 | = link_to project_path(project) do |
| 21 | - %strong= project.name_with_namespace | 21 | + = project.name_with_namespace |
| 22 | .pull-right | 22 | .pull-right |
| 23 | %pre.public-clone git clone #{project.http_url_to_repo} | 23 | %pre.public-clone git clone #{project.http_url_to_repo} |
| 24 | 24 | ||
| 25 | - if project.description.present? | 25 | - if project.description.present? |
| 26 | - %div.description | 26 | + %p |
| 27 | = project.description | 27 | = project.description |
| 28 | + | ||
| 29 | + .repo-info | ||
| 30 | + - unless project.empty_repo? | ||
| 31 | + = link_to pluralize(project.repository.round_commit_count, 'commit'), project_commits_path(project, project.default_branch) | ||
| 32 | + · | ||
| 33 | + = link_to pluralize(project.repository.branch_names.count, 'branch'), project_branches_path(project) | ||
| 34 | + · | ||
| 35 | + = link_to pluralize(project.repository.tag_names.count, 'tag'), project_tags_path(project) | ||
| 36 | + - else | ||
| 37 | + %i.icon-warning-sign | ||
| 38 | + Empty repository | ||
| 28 | - unless @projects.present? | 39 | - unless @projects.present? |
| 29 | %h3.nothing_here_message No public projects | 40 | %h3.nothing_here_message No public projects |
| 30 | 41 |
config/routes.rb
| @@ -55,8 +55,6 @@ Gitlab::Application.routes.draw do | @@ -55,8 +55,6 @@ Gitlab::Application.routes.draw do | ||
| 55 | # | 55 | # |
| 56 | namespace :public do | 56 | namespace :public do |
| 57 | resources :projects, only: [:index] | 57 | resources :projects, only: [:index] |
| 58 | - resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:show] | ||
| 59 | - | ||
| 60 | root to: "projects#index" | 58 | root to: "projects#index" |
| 61 | end | 59 | end |
| 62 | 60 |
features/public/public_projects.feature
| @@ -9,11 +9,10 @@ Feature: Public Projects Feature | @@ -9,11 +9,10 @@ Feature: Public Projects Feature | ||
| 9 | And I should not see project "Enterprise" | 9 | And I should not see project "Enterprise" |
| 10 | 10 | ||
| 11 | Scenario: I visit public project page | 11 | Scenario: I visit public project page |
| 12 | - When I visit public page for "Community" project | ||
| 13 | - Then I should see public project details | ||
| 14 | - And I should see project readme | 12 | + When I visit project "Community" page |
| 13 | + Then I should see project "Community" home page | ||
| 15 | 14 | ||
| 16 | Scenario: I visit an empty public project page | 15 | Scenario: I visit an empty public project page |
| 17 | Given public empty project "Empty Public Project" | 16 | Given public empty project "Empty Public Project" |
| 18 | - When I visit empty public project page | ||
| 19 | - Then I should see empty public project details | ||
| 20 | \ No newline at end of file | 17 | \ No newline at end of file |
| 18 | + When I visit empty project page | ||
| 19 | + Then I should see empty public project details |
features/steps/public/projects_feature.rb
| @@ -31,19 +31,28 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps | @@ -31,19 +31,28 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps | ||
| 31 | create :project, name: 'Empty Public Project', public: true | 31 | create :project, name: 'Empty Public Project', public: true |
| 32 | end | 32 | end |
| 33 | 33 | ||
| 34 | - step 'I visit empty public project page' do | 34 | + step 'I visit empty project page' do |
| 35 | project = Project.find_by_name('Empty Public Project') | 35 | project = Project.find_by_name('Empty Public Project') |
| 36 | - visit public_project_path(project) | 36 | + visit project_path(project) |
| 37 | + end | ||
| 38 | + | ||
| 39 | + step 'I visit project "Community" page' do | ||
| 40 | + project = Project.find_by_name('Community') | ||
| 41 | + visit project_path(project) | ||
| 37 | end | 42 | end |
| 38 | 43 | ||
| 39 | step 'I should see empty public project details' do | 44 | step 'I should see empty public project details' do |
| 40 | - page.should have_content 'Empty Repository' | 45 | + page.should have_content 'Git global setup' |
| 41 | end | 46 | end |
| 42 | 47 | ||
| 43 | step 'private project "Enterprise"' do | 48 | step 'private project "Enterprise"' do |
| 44 | create :project, name: 'Enterprise' | 49 | create :project, name: 'Enterprise' |
| 45 | end | 50 | end |
| 46 | 51 | ||
| 52 | + step 'I should see project "Community" home page' do | ||
| 53 | + page.should have_content 'Repo size is' | ||
| 54 | + end | ||
| 55 | + | ||
| 47 | private | 56 | private |
| 48 | 57 | ||
| 49 | def project | 58 | def project |