incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [36/41] git commit: [#6656] ticket:437 OAuth flow in individual github import controllers
Date Thu, 14 Nov 2013 15:37:28 GMT
[#6656] ticket:437 OAuth flow in individual github import controllers


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ac8fa2c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ac8fa2c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ac8fa2c0

Branch: refs/heads/cj/6845
Commit: ac8fa2c06b2f902b0f3a4c1a8fd8ff1b109560d6
Parents: 0775036
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Oct 25 15:50:31 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Nov 13 20:46:25 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/__init__.py | 7 +++----
 ForgeImporters/forgeimporters/github/code.py     | 6 ++++--
 ForgeImporters/forgeimporters/github/project.py  | 2 +-
 ForgeImporters/forgeimporters/github/tracker.py  | 5 +++--
 ForgeImporters/forgeimporters/github/wiki.py     | 5 +++--
 5 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ac8fa2c0/ForgeImporters/forgeimporters/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
index fb34e6b..58afba3 100644
--- a/ForgeImporters/forgeimporters/github/__init__.py
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -146,19 +146,18 @@ class GitHubProjectExtractor(base.ProjectExtractor):
 class GitHubOAuthMixin(object):
     '''Support for github oauth web application flow.'''
 
-    def oauth_begin(self, controller_url):
-        '''controller_url is absolute url, refers the controller you mixed this class in'''
+    def oauth_begin(self):
         client_id = config.get('github_importer.client_id')
         secret = config.get('github_importer.client_secret')
         if not client_id or not secret:
             return  # GitHub app is not configured
         if c.user.get_tool_data('GitHubProjectImport', 'token'):
             return  # token already exists, nothing to do
-        redirect_uri = controller_url.rstrip('/') + '/oauth_callback'
+        redirect_uri = request.url.rstrip('/') + '/oauth_callback'
         oauth = OAuth2Session(client_id, redirect_uri=redirect_uri)
         auth_url, state = oauth.authorization_url('https://github.com/login/oauth/authorize')
         session['github.oauth.state'] = state  # Used in callback to prevent CSRF
-        session['github.oauth.redirect'] = controller_url
+        session['github.oauth.redirect'] = request.url
         session.save()
         redirect(auth_url)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ac8fa2c0/ForgeImporters/forgeimporters/github/code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/code.py b/ForgeImporters/forgeimporters/github/code.py
index 4ce2183..6fdd0b4 100644
--- a/ForgeImporters/forgeimporters/github/code.py
+++ b/ForgeImporters/forgeimporters/github/code.py
@@ -30,6 +30,7 @@ from tg.decorators import (
         )
 
 from allura.lib.decorators import require_post
+from allura.lib import helpers as h
 from allura.controllers import BaseController
 from allura import model as M
 
@@ -39,7 +40,7 @@ from forgeimporters.base import (
         ToolImporter,
         ToolImportForm,
         )
-from forgeimporters.github import GitHubProjectExtractor
+from forgeimporters.github import GitHubProjectExtractor, GitHubOAuthMixin
 
 
 class GitHubRepoImportForm(ToolImportForm):
@@ -47,7 +48,7 @@ class GitHubRepoImportForm(ToolImportForm):
     gh_user_name = fev.UnicodeString(not_empty=True)
 
 
-class GitHubRepoImportController(BaseController):
+class GitHubRepoImportController(BaseController, GitHubOAuthMixin):
     def __init__(self):
         self.importer = GitHubRepoImporter()
 
@@ -58,6 +59,7 @@ class GitHubRepoImportController(BaseController):
     @with_trailing_slash
     @expose('jinja:forgeimporters.github:templates/code/index.html')
     def index(self, **kw):
+        self.oauth_begin()
         return dict(importer=self.importer,
                 target_app=self.target_app)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ac8fa2c0/ForgeImporters/forgeimporters/github/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/project.py b/ForgeImporters/forgeimporters/github/project.py
index 29df780..2462617 100644
--- a/ForgeImporters/forgeimporters/github/project.py
+++ b/ForgeImporters/forgeimporters/github/project.py
@@ -53,7 +53,7 @@ class GitHubProjectImporter(base.ProjectImporter, GitHubOAuthMixin):
     @with_trailing_slash
     @expose(index_template)
     def index(self, **kw):
-        self.oauth_begin(h.absurl('/p/import_project/github/'))
+        self.oauth_begin()
         return super(self.__class__, self).index(**kw)
 
     @require_post()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ac8fa2c0/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index 288379b..cda1466 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -44,7 +44,7 @@ from ming.orm import session, ThreadLocalORMSession
 from pylons import tmpl_context as c
 from pylons import app_globals as g
 
-from . import GitHubProjectExtractor
+from . import GitHubProjectExtractor, GitHubOAuthMixin
 from ..base import ToolImporter
 from forgetracker.tracker_main import ForgeTrackerApp
 from forgetracker import model as TM
@@ -57,7 +57,7 @@ class GitHubTrackerImportForm(ToolImportForm):
     gh_user_name = fev.UnicodeString(not_empty=True)
 
 
-class GitHubTrackerImportController(BaseController):
+class GitHubTrackerImportController(BaseController, GitHubOAuthMixin):
 
     def __init__(self):
         self.importer = GitHubTrackerImporter()
@@ -69,6 +69,7 @@ class GitHubTrackerImportController(BaseController):
     @with_trailing_slash
     @expose('jinja:forgeimporters.github:templates/tracker/index.html')
     def index(self, **kw):
+        self.oauth_begin()
         return dict(importer=self.importer,
                     target_app=self.target_app)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ac8fa2c0/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index ce3214c..33801df 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -50,7 +50,7 @@ from forgeimporters.base import (
         ToolImporter,
         ToolImportForm,
         )
-from forgeimporters.github import GitHubProjectExtractor
+from forgeimporters.github import GitHubProjectExtractor, GitHubOAuthMixin
 from forgeimporters.github.utils import GitHubMarkdownConverter
 from forgewiki import model as WM
 from forgewiki.converters import mediawiki2markdown
@@ -74,7 +74,7 @@ class GitHubWikiImportForm(ToolImportForm):
     tool_option = fev.UnicodeString(if_missing=u'')
 
 
-class GitHubWikiImportController(BaseController):
+class GitHubWikiImportController(BaseController, GitHubOAuthMixin):
 
     def __init__(self):
         self.importer = GitHubWikiImporter()
@@ -86,6 +86,7 @@ class GitHubWikiImportController(BaseController):
     @with_trailing_slash
     @expose('jinja:forgeimporters.github:templates/wiki/index.html')
     def index(self, **kw):
+        self.oauth_begin()
         return dict(importer=self.importer,
                     target_app=self.target_app)
 


Mime
View raw message