← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/git-import-no-push into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/git-import-no-push into lp:launchpad.

Commit message:
Don't show push directions for imported repositories.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1642694 in Launchpad itself: "git-to-git imports say they can be pushed to by owner"
  https://bugs.launchpad.net/launchpad/+bug/1642694

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/git-import-no-push/+merge/311213
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/git-import-no-push into lp:launchpad.
=== modified file 'lib/lp/code/browser/tests/test_gitrepository.py'
--- lib/lp/code/browser/tests/test_gitrepository.py	2016-11-09 17:18:21 +0000
+++ lib/lp/code/browser/tests/test_gitrepository.py	2016-11-17 23:27:17 +0000
@@ -7,6 +7,7 @@
 
 from datetime import datetime
 import doctest
+from textwrap import dedent
 
 from BeautifulSoup import BeautifulSoup
 from fixtures import FakeLogger
@@ -46,6 +47,8 @@
     HasQueryCount,
     )
 from lp.testing.pages import (
+    extract_text,
+    find_tag_by_id,
     get_feedback_messages,
     setupBrowser,
     setupBrowserForUser,
@@ -113,6 +116,101 @@
             view = create_initialized_view(repository, "+index")
             self.assertFalse(view.user_can_push)
 
+    def test_push_directions_not_logged_in_individual(self):
+        # If the user is not logged in, they are given appropriate
+        # directions for a repository owned by a person.
+        repository = self.factory.makeGitRepository()
+        browser = self.getViewBrowser(repository, no_login=True)
+        directions = find_tag_by_id(browser.contents, "push-directions")
+        login_person(self.user)
+        self.assertThat(directions.renderContents(), DocTestMatches(dedent("""
+            Only <a
+            href="http://launchpad.dev/~{owner.name}";>{owner.display_name}</a>
+            can upload to this repository. If you are {owner.display_name}
+            please <a href="+login">log in</a> for upload directions.
+            """).format(owner=repository.owner),
+            flags=doctest.NORMALIZE_WHITESPACE))
+
+    def test_push_directions_not_logged_in_team(self):
+        # If the user is not logged in, they are given appropriate
+        # directions for a repository owned by a team.
+        team = self.factory.makeTeam()
+        repository = self.factory.makeGitRepository(owner=team)
+        browser = self.getViewBrowser(repository, no_login=True)
+        directions = find_tag_by_id(browser.contents, "push-directions")
+        login_person(self.user)
+        self.assertThat(directions.renderContents(), DocTestMatches(dedent("""
+            Members of <a
+            href="http://launchpad.dev/~{owner.name}";>{owner.display_name}</a>
+            can upload to this repository. <a href="+login">Log in</a> for
+            directions.
+            """).format(owner=repository.owner),
+            flags=doctest.NORMALIZE_WHITESPACE))
+
+    def test_push_directions_logged_in_can_push(self):
+        # If the user is logged in and can push to the repository, we
+        # explain how to do so.
+        self.factory.makeSSHKey(person=self.user, send_notification=False)
+        repository = self.factory.makeGitRepository(owner=self.user)
+        browser = self.getViewBrowser(repository)
+        directions = find_tag_by_id(browser.contents, "push-directions")
+        login_person(self.user)
+        self.assertThat(extract_text(directions), DocTestMatches(dedent("""
+            Update this repository:
+            git push git+ssh://git.launchpad.dev/{repository.shortened_path}
+            """).format(repository=repository),
+            flags=doctest.NORMALIZE_WHITESPACE))
+
+    def test_push_directions_logged_in_can_push_no_sshkeys(self):
+        # If the user is logged in and can push to the repository but has no
+        # SSH key registered, we point to the SSH keys form.
+        repository = self.factory.makeGitRepository(owner=self.user)
+        browser = self.getViewBrowser(repository)
+        directions = find_tag_by_id(browser.contents, "ssh-key-directions")
+        login_person(self.user)
+        self.assertThat(directions.renderContents(), DocTestMatches(dedent("""
+            To authenticate with the Launchpad Git hosting service, you need
+            to <a href="http://launchpad.dev/~{user.name}/+editsshkeys";>
+            register an SSH key</a>.
+            """).format(user=self.user),
+            flags=doctest.NORMALIZE_WHITESPACE))
+
+    def test_push_directions_logged_in_cannot_push_individual(self):
+        # If the user is logged in but cannot push to a repository owned by
+        # a person, we explain who can push.
+        repository = self.factory.makeGitRepository()
+        browser = self.getViewBrowser(repository)
+        directions = find_tag_by_id(browser.contents, "push-directions")
+        login_person(self.user)
+        self.assertThat(directions.renderContents(), DocTestMatches(dedent("""
+            You cannot push to this repository. Only <a
+            href="http://launchpad.dev/~{owner.name}";>{owner.display_name}</a>
+            can push to this repository.
+            """).format(owner=repository.owner),
+            flags=doctest.NORMALIZE_WHITESPACE))
+
+    def test_push_directions_logged_in_cannot_push_team(self):
+        # If the user is logged in but cannot push to a repository owned by
+        # a team, we explain who can push.
+        team = self.factory.makeTeam()
+        repository = self.factory.makeGitRepository(owner=team)
+        browser = self.getViewBrowser(repository)
+        directions = find_tag_by_id(browser.contents, "push-directions")
+        login_person(self.user)
+        self.assertThat(directions.renderContents(), DocTestMatches(dedent("""
+            You cannot push to this repository. Members of <a
+            href="http://launchpad.dev/~{owner.name}";>{owner.display_name}</a>
+            can push to this repository.
+            """).format(owner=repository.owner),
+            flags=doctest.NORMALIZE_WHITESPACE))
+
+    def test_no_push_directions_for_imported_repository(self):
+        # Imported repositories never show push directions.
+        repository = self.factory.makeGitRepository(
+            repository_type=GitRepositoryType.IMPORTED)
+        browser = self.getViewBrowser(repository)
+        self.assertIsNone(find_tag_by_id(browser.contents, "push-directions"))
+
     def test_view_for_user_with_artifact_grant(self):
         # Users with an artifact grant for a repository related to a private
         # project can view the main repository page.

=== modified file 'lib/lp/code/stories/branches/xx-upload-directions.txt'
--- lib/lp/code/stories/branches/xx-upload-directions.txt	2013-03-09 09:15:47 +0000
+++ lib/lp/code/stories/branches/xx-upload-directions.txt	2016-11-17 23:27:17 +0000
@@ -81,7 +81,7 @@
 
 == SSH key directions ==
 
-If the user has the permission to upload to a branch, but does not have a SSH
+If the user has the permission to upload to a branch, but does not have an SSH
 key registered, point to the SSH keys form.
 
 First, unregister the existing SSH key for Sample Person.
@@ -90,7 +90,7 @@
     >>> name12_browser.getLink(url='editsshkeys').click()
     >>> name12_browser.getControl('Remove').click()
 
-The branch page now displays directions and a link to register a SSH key.
+The branch page now displays directions and a link to register an SSH key.
 
     >>> name12_browser.open(branch_page)
     >>> content = name12_browser.contents
@@ -98,11 +98,11 @@
     >>> print instructions.renderContents()
     To authenticate with the Launchpad branch upload service, you need to
     <a href="http://launchpad.dev/~name12/+editsshkeys";>
-    register a SSH key </a>.
+    register an SSH key</a>.
 
 Click the link and register a key.
 
-    >>> name12_browser.getLink('register a SSH key').click()
+    >>> name12_browser.getLink('register an SSH key').click()
     >>> name12_browser.getControl(name='sshkey').value = some_sshkey
     >>> name12_browser.getControl('Import Public Key').click()
 

=== modified file 'lib/lp/code/templates/branch-management.pt'
--- lib/lp/code/templates/branch-management.pt	2013-03-09 09:15:47 +0000
+++ lib/lp/code/templates/branch-management.pt	2016-11-17 23:27:17 +0000
@@ -57,7 +57,7 @@
           <p tal:condition="not:view/user/sshkeys" id="ssh-key-directions">
             To authenticate with the Launchpad branch upload service, you need
             to <a tal:attributes="href string:${view/user/fmt:url}/+editsshkeys">
-              register a SSH key </a>.
+              register an SSH key</a>.
           </p>
         </tal:can-upload>
 

=== modified file 'lib/lp/code/templates/git-macros.pt'
--- lib/lp/code/templates/git-macros.pt	2016-05-19 14:54:33 +0000
+++ lib/lp/code/templates/git-macros.pt	2016-11-17 23:27:17 +0000
@@ -36,22 +36,23 @@
     </dd>
   </dl>
 
-  <div id="upload-directions">
+  <div id="push-directions"
+       tal:condition="context/repository_type/enumvalue:HOSTED">
     <tal:not-logged-in condition="not:view/user">
       <tal:individual condition="not:context/owner/is_team">
-          Only
-          <a tal:attributes="href context/owner/fmt:url"
-             tal:content="context/owner/displayname">Person</a>
-          can upload to this <tal:kind replace="kind" />. If you are
-          <tal:branch-owner replace="context/owner/displayname"/>
-          please <a href="+login">log in</a> for upload directions.
+        Only
+        <a tal:attributes="href context/owner/fmt:url"
+           tal:content="context/owner/displayname">Person</a>
+        can upload to this <tal:kind replace="kind" />. If you are
+        <tal:branch-owner replace="context/owner/displayname"/>
+        please <a href="+login">log in</a> for upload directions.
       </tal:individual>
       <tal:team tal:condition="context/owner/is_team">
-          Members of
-          <a tal:attributes="href context/owner/fmt:url"
-             tal:content="context/owner/displayname">Team</a>
-          can upload to this <tal:kind replace="kind" />.
-          <a href="+login">Log in</a> for directions.
+        Members of
+        <a tal:attributes="href context/owner/fmt:url"
+           tal:content="context/owner/displayname">Team</a>
+        can upload to this <tal:kind replace="kind" />.
+        <a href="+login">Log in</a> for directions.
       </tal:team>
     </tal:not-logged-in>
 
@@ -70,23 +71,23 @@
         <p tal:condition="not:view/user/sshkeys" id="ssh-key-directions">
           To authenticate with the Launchpad Git hosting service, you need to
           <a tal:attributes="href string:${view/user/fmt:url}/+editsshkeys">
-            register a SSH key</a>.
+            register an SSH key</a>.
         </p>
       </tal:can-push>
 
       <tal:cannot-push condition="not:view/user_can_push">
-        <div id="push-directions" tal:condition="not:context/owner/is_team">
+        <tal:individual condition="not:context/owner/is_team">
           You cannot push to this <tal:kind replace="kind" />. Only
           <a tal:attributes="href context/owner/fmt:url"
              tal:content="context/owner/displayname">Person</a>
           can push to this <tal:kind replace="kind" />.
-        </div>
-        <div id="push-directions" tal:condition="context/owner/is_team">
+        </tal:individual>
+        <tal:team condition="context/owner/is_team">
           You cannot push to this <tal:kind replace="kind" />. Members of
           <a tal:attributes="href context/owner/fmt:url"
              tal:content="context/owner/displayname">Team</a>
           can push to this <tal:kind replace="kind" />.
-        </div>
+        </tal:team>
       </tal:cannot-push>
     </tal:logged-in>
 

=== modified file 'lib/lp/code/templates/product-branch-summary.pt'
--- lib/lp/code/templates/product-branch-summary.pt	2015-12-15 23:45:52 +0000
+++ lib/lp/code/templates/product-branch-summary.pt	2016-11-17 23:27:17 +0000
@@ -107,7 +107,7 @@
         <br/>To authenticate with the Launchpad branch upload service,
         you need to
         <a tal:attributes="href string:${view/user/fmt:url}/+editsshkeys">
-          register a SSH key</a>.
+          register an SSH key</a>.
       </tal:no-keys>
     </p>
   </tal:has-user>

=== modified file 'lib/lp/codehosting/sshserver/tests/test_daemon.py'
--- lib/lp/codehosting/sshserver/tests/test_daemon.py	2015-01-06 12:47:59 +0000
+++ lib/lp/codehosting/sshserver/tests/test_daemon.py	2016-11-17 23:27:17 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for the codehosting SSH server glue."""
@@ -72,8 +72,8 @@
         return server_transport
 
     def test_authentication_uses_our_userauth_service(self):
-        # The service of a SSHServerTransport after authentication has started
-        # is an instance of our SSHUserAuthServer class.
+        # The service of an SSHServerTransport after authentication has
+        # started is an instance of our SSHUserAuthServer class.
         factory = self.makeFactory()
         transport = self.beginAuthentication(factory)
         self.assertIsInstance(transport.service, SSHUserAuthServer)

=== modified file 'lib/lp/registry/templates/productseries-codesummary.pt'
--- lib/lp/registry/templates/productseries-codesummary.pt	2014-12-06 10:40:29 +0000
+++ lib/lp/registry/templates/productseries-codesummary.pt	2016-11-17 23:27:17 +0000
@@ -36,7 +36,7 @@
               <br/>To authenticate with the Launchpad branch upload service,
               you need to
               <a tal:attributes="href string:${view/user/fmt:url}/+editsshkeys">
-                register a SSH key</a>.
+                register an SSH key</a>.
             </tal:no-keys>
         </li>
 


Follow ups