summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2015-12-09 16:52:43 +0000
committerRobert Speicher <robert@gitlab.com>2015-12-09 16:52:43 +0000
commitc3676aa156981092b7f03f1a3e74bb819cfa2fc3 (patch)
tree3b56ade62c92598f80f4263238c94c568c0245ae
parent1954bd6ee0e17d29061ed201cbd0f509e6b2a49d (diff)
parentbb79573c01ad77d6b52245d3af262bc56f79693f (diff)
downloadgitlab-ce-c3676aa156981092b7f03f1a3e74bb819cfa2fc3.tar.gz
Merge branch 'default_clone_protocol_based_on_user_keys' into 'master'
When rendering the clone page, check user profile to decide default clone protocol If the user has uploaded SSH-keys, use SSH; otherwise, use http(s). Closes #3504. See merge request !1998
-rw-r--r--app/helpers/projects_helper.rb12
-rw-r--r--features/explore/projects.feature21
-rw-r--r--features/project/create.feature2
-rw-r--r--features/steps/explore/projects.rb1
-rw-r--r--features/steps/project/create.rb1
-rw-r--r--features/steps/shared/user.rb8
6 files changed, 41 insertions, 4 deletions
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 48729e5260e..d061136b7b8 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -175,11 +175,19 @@ module ProjectsHelper
end
def default_url_to_repo(project = @project)
- current_user ? project.url_to_repo : project.http_url_to_repo
+ if default_clone_protocol == "ssh"
+ project.ssh_url_to_repo
+ else
+ project.http_url_to_repo
+ end
end
def default_clone_protocol
- current_user ? "ssh" : "http"
+ if !current_user || current_user.require_ssh_key?
+ "http"
+ else
+ "ssh"
+ end
end
def project_last_activity(project)
diff --git a/features/explore/projects.feature b/features/explore/projects.feature
index 5d3870827f5..629859e960d 100644
--- a/features/explore/projects.feature
+++ b/features/explore/projects.feature
@@ -31,8 +31,17 @@ Feature: Explore Projects
Then I should see empty public project details
And I should see empty public project details with http clone info
- Scenario: I visit an empty public project page as user
+ Scenario: I visit an empty public project page as user with no ssh-keys
Given I sign in as a user
+ And I have no ssh keys
+ And public empty project "Empty Public Project"
+ When I visit empty project page
+ Then I should see empty public project details
+ And I should see empty public project details with http clone info
+
+ Scenario: I visit an empty public project page as user with an ssh-key
+ Given I sign in as a user
+ And I have an ssh key
And public empty project "Empty Public Project"
When I visit empty project page
Then I should see empty public project details
@@ -57,8 +66,16 @@ Feature: Explore Projects
Then I should see project "Community" home page
And I should see an http link to the repository
- Scenario: I visit public project page as user
+ Scenario: I visit public project page as user with no ssh-keys
+ Given I sign in as a user
+ And I have no ssh keys
+ When I visit project "Community" page
+ Then I should see project "Community" home page
+ And I should see an http link to the repository
+
+ Scenario: I visit public project page as user with an ssh-key
Given I sign in as a user
+ And I have an ssh key
When I visit project "Community" page
Then I should see project "Community" home page
And I should see an ssh link to the repository
diff --git a/features/project/create.feature b/features/project/create.feature
index e9dc4fe6b3c..a86079143e5 100644
--- a/features/project/create.feature
+++ b/features/project/create.feature
@@ -7,6 +7,7 @@ Feature: Project Create
Scenario: User create a project
Given I sign in as a user
When I visit new project page
+ And I have an ssh key
And fill project form with valid data
Then I should see project page
And I should see empty project instuctions
@@ -14,6 +15,7 @@ Feature: Project Create
@javascript
Scenario: Empty project instructions
Given I sign in as a user
+ And I have an ssh key
When I visit new project page
And fill project form with valid data
Then I see empty project instuctions
diff --git a/features/steps/explore/projects.rb b/features/steps/explore/projects.rb
index 8b498e7b4a6..f819dec2192 100644
--- a/features/steps/explore/projects.rb
+++ b/features/steps/explore/projects.rb
@@ -2,6 +2,7 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedProject
+ include SharedUser
step 'I should see project "Empty Public Project"' do
expect(page).to have_content "Empty Public Project"
diff --git a/features/steps/project/create.rb b/features/steps/project/create.rb
index 0d39e1997b5..f90218f3791 100644
--- a/features/steps/project/create.rb
+++ b/features/steps/project/create.rb
@@ -1,6 +1,7 @@
class Spinach::Features::ProjectCreate < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
+ include SharedUser
step 'fill project form with valid data' do
fill_in 'project_path', with: 'Empty'
diff --git a/features/steps/shared/user.rb b/features/steps/shared/user.rb
index 250cc5b94f3..33c146f6dbc 100644
--- a/features/steps/shared/user.rb
+++ b/features/steps/shared/user.rb
@@ -18,4 +18,12 @@ module SharedUser
def user_exists(name, options = {})
User.find_by(name: name) || create(:user, { name: name, admin: false }.merge(options))
end
+
+ step 'I have an ssh key' do
+ create(:key, user: @user, title: "An ssh-key", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+L3TbFegm3k8QjejSwemk4HhlRh+DuN679Pc5ckqE/MPhVtE/+kZQDYCTB284GiT2aIoGzmZ8ee9TkaoejAsBwlA+Wz2Q3vhz65X6sMgalRwpdJx8kSEUYV8ZPV3MZvPo8KdNg993o4jL6G36GDW4BPIyO6FPZhfsawdf6liVD0Xo5kibIK7B9VoE178cdLQtLpS2YolRwf5yy6XR6hbbBGQR+6xrGOdP16eGZDb1CE2bMvvJijjloFqPscGktWOqW+nfh5txwFfBzlfARDTBsS8WZtg3Yoj1kn33kPsWRlgHfNutFRAIynDuDdQzQq8tTtVwm+Yi75RfcPHW8y3P Work")
+ end
+
+ step 'I have no ssh keys' do
+ Key.delete_all
+ end
end