From df2022292dafe87b438688de01b2683cf41be147 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 23 2017 18:19:32 +0000 Subject: [PATCH 1/3] Add support for a custom user in the SSH URL Fixes https://pagure.io/pagure/issue/2524 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/repo_info.html b/pagure/templates/repo_info.html index 7ac00ba..e2c33d3 100644 --- a/pagure/templates/repo_info.html +++ b/pagure/templates/repo_info.html @@ -162,7 +162,7 @@ git push -u origin master
SSH
+ git_url_ssh }}{{ repo.fullname }}.git" readonly>
@@ -182,7 +182,7 @@ git push -u origin master
SSH
+ git_url_ssh }}docs/{{ repo.fullname }}.git" readonly>
{% endif %} @@ -202,7 +202,7 @@ git push -u origin master
SSH
+ git_url_ssh }}tickets/{{ repo.fullname }}.git" readonly>
{% endif %} @@ -211,7 +211,7 @@ git push -u origin master
SSH
+ git_url_ssh }}requests/{{ repo.fullname }}.git" readonly>
{% endif %} diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index e9e8038..15cd712 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -51,7 +51,7 @@ import pagure.forms import pagure import pagure.ui.plugins from pagure import (APP, SESSION, __get_file_in_tree, login_required, - admin_session_timedout) + admin_session_timedout, authenticated) from pagure.lib import encoding_utils @@ -123,6 +123,14 @@ def view_repo(repo, username=None, namespace=None): 'view_raw_file', username=username, repo=repo_db.name, identifier=branchname, filename='')) + git_url_ssh = APP.config.get('GIT_URL_SSH') + if authenticated(): + try: + git_url_ssh = git_url_ssh.format( + username=flask.g.fas_user.username) + except (KeyError, IndexError): + pass + return flask.render_template( 'repo_info.html', select='overview', @@ -136,6 +144,7 @@ def view_repo(repo, username=None, namespace=None): last_commits=last_commits, tree=tree, form=pagure.forms.ConfirmationForm(), + git_url_ssh=git_url_ssh, ) From 7f5772637d0056ebbf77683b64deef0e1164490a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 23 2017 18:19:32 +0000 Subject: [PATCH 2/3] Do not show the SSH url when the user isn't logged in --- diff --git a/pagure/api/project.py b/pagure/api/project.py index 904673d..2d0798b 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -184,9 +184,17 @@ def api_project_git_urls(repo, username=None, namespace=None): if repo is None: raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOPROJECT) git_urls = {} - if pagure.APP.config.get('GIT_URL_SSH'): - git_urls['ssh'] = '{0}{1}.git'.format( - pagure.APP.config['GIT_URL_SSH'], repo.fullname) + + git_url_ssh = APP.config.get('GIT_URL_SSH') + if authenticated() and git_url_ssh: + try: + git_url_ssh = git_url_ssh.format( + username=flask.g.fas_user.username) + except (KeyError, IndexError): + pass + + if git_url_ssh: + git_urls['ssh'] = '{0}{1}.git'.format(git_url_ssh, repo.fullname) if pagure.APP.config.get('GIT_URL_GIT'): git_urls['git'] = '{0}{1}.git'.format( pagure.APP.config['GIT_URL_GIT'], repo.fullname) diff --git a/pagure/templates/repo_info.html b/pagure/templates/repo_info.html index e2c33d3..c81a3ed 100644 --- a/pagure/templates/repo_info.html +++ b/pagure/templates/repo_info.html @@ -158,6 +158,7 @@ git push -u origin master aria-expanded="false" aria-controls="moregiturls" id="more_gits">more{%endif%}
+ {% if authenticated and g.repo_committer %}
SSH
@@ -165,6 +166,7 @@ git push -u origin master git_url_ssh }}{{ repo.fullname }}.git" readonly>
+ {% endif %}
GIT
diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 15cd712..d09d3c3 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -124,7 +124,7 @@ def view_repo(repo, username=None, namespace=None): repo=repo_db.name, identifier=branchname, filename='')) git_url_ssh = APP.config.get('GIT_URL_SSH') - if authenticated(): + if authenticated() and git_url_ssh: try: git_url_ssh = git_url_ssh.format( username=flask.g.fas_user.username) From 8a18c8d449caf7f665b22496a89c190c86bdd52a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 23 2017 18:19:32 +0000 Subject: [PATCH 3/3] Document the possibility to customize {username} in the SSH URL --- diff --git a/doc/configuration.rst b/doc/configuration.rst index 671b734..6af2ccc 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -74,6 +74,13 @@ The URL should end with a slash ``/``. Defaults to: ``'ssh://git@pagure.org/'`` +.. note:: If you are using a custom setup for your deployment where every + user has an account on the machine you may want to tweak this URL + to include the username. If that is the case, you can use + ``{username}`` in the URL and it will be expanded to the username + of the user viewing the page when rendered. + For example: ``'ssh://{username}@pagure.org/'`` + GIT_URL_GIT ~~~~~~~~~~~