You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/09/17 00:34:32 UTC
[1/3] git commit: [#6529] Added docstring and example config entry
for login_overlay
Updated Branches:
refs/heads/master 68c74e40c -> a1779fa8d
[#6529] Added docstring and example config entry for login_overlay
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/a1779fa8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/a1779fa8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/a1779fa8
Branch: refs/heads/master
Commit: a1779fa8d9ff0cabf61399fe7911a5d7b351b306
Parents: b930a63
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Mon Sep 16 20:54:58 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Sep 16 22:34:13 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/helpers.py | 35 +++++++++++++++++++++++++++++++++++
Allura/development.ini | 1 +
2 files changed, 36 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a1779fa8/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 0b92968..76bedbc 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1017,6 +1017,41 @@ def daterange(start_date, end_date):
@contextmanager
def login_overlay(exceptions=None):
+ """
+ Override the default behavior of redirecting to the auth.login_url and
+ instead display an overlay with content from auth.login_fragment_url.
+
+ This is to allow pages that require authentication for any actions but
+ not for the initial view to be more apparent what you will get once
+ logged in.
+
+ This should be wrapped around call to `require_access()` (presumably in
+ the `_check_security()` method on a controller). The `exceptions` param
+ can be given a list of exposed views to leave with the original behavior.
+
+ For example:
+
+ class MyController(BaseController);
+ def _check_security(self):
+ with login_overlay(exceptions=['process']):
+ require_access(self.neighborhood, 'register')
+
+ @expose
+ def index(self, *args, **kw):
+ return {}
+
+ @expose
+ def list(self, *args, **kw):
+ return {}
+
+ @expose
+ def process(self, *args, **kw):
+ return {}
+
+ This would show the overlay to unauthenticated users who visit `/`
+ or `/list` but would perform the normal redirect when `/process` is
+ visited.
+ """
try:
yield
except HTTPUnauthorized as e:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a1779fa8/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index ee9911b..9cb4b16 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -78,6 +78,7 @@ show_export_control = false
auth.method = local
# auth.login_url = /auth/
# auth.logout_url = /auth/logout
+# auth.login_fragment_url = /auth/login_fragment
auth.ldap.server = ldap://localhost
auth.ldap.suffix = ou=people,dc=localdomain
[3/3] git commit: [#6529] Added login overlay for project importers
Posted by br...@apache.org.
[#6529] Added login overlay for project importers
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/55a9de83
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/55a9de83
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/55a9de83
Branch: refs/heads/master
Commit: 55a9de83489358bb706b2f8caf6febf75b706635
Parents: 68c74e4
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Tue Sep 10 21:55:05 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Sep 16 22:34:13 2013 +0000
----------------------------------------------------------------------
Allura/allura/controllers/auth.py | 4 ++
Allura/allura/lib/app_globals.py | 7 +++
Allura/allura/lib/security.py | 10 +++-
Allura/allura/lib/widgets/forms.py | 3 +-
.../lib/widgets/resources/js/login_overlay.js | 27 +++++++++
Allura/allura/nf/allura/css/allura.css | 13 ++++-
.../allura/templates/jinja_master/master.html | 3 +
.../templates/jinja_master/theme_macros.html | 11 +++-
Allura/allura/templates/login_fragment.html | 60 ++++++++++++++++++++
Allura/allura/templates/widgets/forge_form.html | 1 +
ForgeImporters/forgeimporters/base.py | 3 +-
11 files changed, 135 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 4c1ee37..fa00208 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -105,6 +105,10 @@ class AuthController(BaseController):
c.form = F.login_form
return dict(oid_providers=OID_PROVIDERS, return_to=return_to)
+ @expose('jinja:allura:templates/login_fragment.html')
+ def login_fragment(self, *args, **kwargs):
+ return self.index(*args, **kwargs)
+
@expose('jinja:allura:templates/custom_login.html')
def login_verify_oid(self, provider, username, return_to=None):
if provider:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index c1c0b32..e684383 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -115,6 +115,7 @@ class Globals(object):
# Load login/logout urls; only used for SFX logins
self.login_url = config.get('auth.login_url', '/auth/')
self.logout_url = config.get('auth.logout_url', '/auth/logout')
+ self.login_fragment_url = config.get('auth.login_fragment_url', '/auth/login_fragment')
# Setup Gravatar
self.gravatar = gravatar.url
@@ -401,6 +402,12 @@ class Globals(object):
def resource_manager(self):
return ew_core.widget_context.resource_manager
+ def register_css(self, href, **kw):
+ self.resource_manager.register(ew.CSSLink(href, **kw))
+
+ def register_js(self, href, **kw):
+ self.resource_manager.register(ew.JSLink(href, **kw))
+
def register_forge_css(self, href, **kw):
self.resource_manager.register(ew.CSSLink('allura/' + href, **kw))
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/lib/security.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/security.py b/Allura/allura/lib/security.py
index a0497ca..4718e56 100644
--- a/Allura/allura/lib/security.py
+++ b/Allura/allura/lib/security.py
@@ -383,7 +383,7 @@ def all_allowed(obj, user_or_role=None, project=None):
return set([M.ALL_PERMISSIONS])
return perms
-def require(predicate, message=None):
+def require(predicate, message=None, login_overlay=False):
'''
Example: require(has_access(c.app, 'read'))
@@ -401,13 +401,17 @@ def require(predicate, message=None):
if c.user != M.User.anonymous():
request.environ['error_message'] = message
raise exc.HTTPForbidden(detail=message)
+ elif login_overlay:
+ c.show_login_overlay = True
else:
raise exc.HTTPUnauthorized()
-def require_access(obj, permission, **kwargs):
+def require_access(obj, permission, login_overlay=False, **kwargs):
if obj is not None:
predicate = has_access(obj, permission, **kwargs)
- return require(predicate, message='%s access required' % permission.capitalize())
+ return require(predicate,
+ message='%s access required' % permission.capitalize(),
+ login_overlay=login_overlay)
else:
raise exc.HTTPForbidden(detail="Could not verify permissions for this page.")
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index ae90b26..9d3f602 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -84,7 +84,8 @@ class ForgeForm(ew.SimpleForm):
submit_text='Save',
style='standard',
method='post',
- enctype=None)
+ enctype=None,
+ target=None)
def display_label(self, field, label_text=None):
ctx = super(ForgeForm, self).context_for(field)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/lib/widgets/resources/js/login_overlay.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/login_overlay.js b/Allura/allura/lib/widgets/resources/js/login_overlay.js
new file mode 100644
index 0000000..c852916
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/login_overlay.js
@@ -0,0 +1,27 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+/*global jQuery, $ */
+jQuery(function($) {
+ $('#login_overlay').draggable().lightbox_me({
+ closeClick: false,
+ closeEsc: false,
+ centered: true
+ });
+});
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/nf/allura/css/allura.css
----------------------------------------------------------------------
diff --git a/Allura/allura/nf/allura/css/allura.css b/Allura/allura/nf/allura/css/allura.css
index 1334b0c..38404f7 100644
--- a/Allura/allura/nf/allura/css/allura.css
+++ b/Allura/allura/nf/allura/css/allura.css
@@ -215,4 +215,15 @@ b.ico.ico-vote-down { background-image: url('../images/vote_down.png'); }
tr.rev div.markdown_content p {
padding: 0;
margin-bottom: 0;
-}
\ No newline at end of file
+}
+
+#login_overlay .title {
+ margin-bottom: 0;
+ padding-left: 10px;
+ border-top-left-radius: 4px;
+ border-top-right-radius: 4px;
+}
+
+#login_overlay iframe {
+ width: 400px;
+}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/templates/jinja_master/master.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/master.html b/Allura/allura/templates/jinja_master/master.html
index e3afa6a..8060240 100644
--- a/Allura/allura/templates/jinja_master/master.html
+++ b/Allura/allura/templates/jinja_master/master.html
@@ -132,6 +132,9 @@
</section>
{% endfor %}
</div>
+ {% if c.show_login_overlay %}
+ {{theme_macros.login_overlay()}}
+ {% endif %}
{% for blob in g.resource_manager.emit('body_js') %}
{{ blob }}
{% endfor %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/templates/jinja_master/theme_macros.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/theme_macros.html b/Allura/allura/templates/jinja_master/theme_macros.html
index 61f5e2f..7fc070c 100644
--- a/Allura/allura/templates/jinja_master/theme_macros.html
+++ b/Allura/allura/templates/jinja_master/theme_macros.html
@@ -112,4 +112,13 @@
{% endif %}
</div>
{% endif %}
-{%- endmacro %}
\ No newline at end of file
+{%- endmacro %}
+
+{%- macro login_overlay() %}
+ {% do g.register_js('js/jquery.lightbox_me.js') %}
+ {% do g.register_js('js/login_overlay.js') %}
+ <div id="login_overlay" class="ui-widget-content">
+ <h2 class="dark title">Login Required</h2>
+ <iframe src="{{g.login_fragment_url}}"></iframe>
+ </div>
+{%- endmacro %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/templates/login_fragment.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/login_fragment.html b/Allura/allura/templates/login_fragment.html
new file mode 100644
index 0000000..31fb26d
--- /dev/null
+++ b/Allura/allura/templates/login_fragment.html
@@ -0,0 +1,60 @@
+{#-
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+<!DOCTYPE html>
+<!-- Server: {{g.server_name}} -->
+{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
+{% if g.theme.jinja_macros %}
+ {% import g.theme.jinja_macros as theme_macros with context %}
+{% endif %}
+{% do g.register_forge_js('js/jquery-base.js') %}
+{% do g.register_forge_js('js/allura-base.js') %}
+{% do g.theme.require() %}
+{% do g.resource_manager.register_widgets(c) %}
+{# paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ #}
+<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
+<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
+<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
+<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
+<!--[if (gt IE 9)|!(IE)]>--> <html lang="en" class="no-js"> <!--<![endif]-->
+ <head>
+ {{theme_macros.extra_header(g.theme_href(''))}}
+ {% for blob in g.resource_manager.emit('head_css') %}
+ {{ blob }}
+ {% endfor %}
+ {% for blob in g.resource_manager.emit('head_js') %}
+ {{ blob }}
+ {% endfor %}
+ <style type="text/css">
+ html {
+ overflow: hidden;
+ }
+ body {
+ padding-top: 1em;
+ width: 1000px;
+ }
+ </style>
+ </head>
+ <body>
+ {{ c.form.display(action='../do_login', target='_top', value=dict(return_to=return_to)) }}
+
+ {% for blob in g.resource_manager.emit('body_js_tail') %}
+ {{ blob }}
+ {% endfor %}
+ </body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/Allura/allura/templates/widgets/forge_form.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/forge_form.html b/Allura/allura/templates/widgets/forge_form.html
index 8adde73..adbc01c 100644
--- a/Allura/allura/templates/widgets/forge_form.html
+++ b/Allura/allura/templates/widgets/forge_form.html
@@ -18,6 +18,7 @@
-#}
<form method="{{method}}"
{% if enctype %}enctype="{{enctype}}"{% endif %}
+ {% if target %}target="{{target}}"{% endif %}
action="{{action}}">
{% set extra_width = 0 %}
{% if style == 'wide' %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/55a9de83/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index d7479b3..0b07c6d 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -190,7 +190,7 @@ class ProjectImporter(BaseController):
self.neighborhood = neighborhood
def _check_security(self):
- require_access(self.neighborhood, 'register')
+ require_access(self.neighborhood, 'register', login_overlay=True)
@LazyProperty
def tool_importers(self):
@@ -231,6 +231,7 @@ class ProjectImporter(BaseController):
tools installed and redirect to the new project, presumably with a
message indicating that some data will not be available immediately.
"""
+ require_access(self.neighborhood, 'register', login_overlay=False)
try:
c.project = self.neighborhood.register_project(kw['project_shortname'],
project_name=kw['project_name'])
[2/3] git commit: [#6529] Refactored login overlay logic out of
allura.lib.security and added tests
Posted by br...@apache.org.
[#6529] Refactored login overlay logic out of allura.lib.security and added tests
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/b930a634
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b930a634
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b930a634
Branch: refs/heads/master
Commit: b930a634aee55ac839b6f6941980164d36e90694
Parents: 55a9de8
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Thu Sep 12 20:10:19 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Sep 16 22:34:13 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/helpers.py | 13 ++++++++++
Allura/allura/lib/security.py | 10 +++-----
Allura/allura/tests/test_helpers.py | 14 ++++++++++-
ForgeImporters/forgeimporters/base.py | 5 ++--
.../tests/github/functional/test_github.py | 8 +++++++
.../forgeimporters/tests/test_base.py | 25 ++++++++++++++++++++
6 files changed, 65 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b930a634/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 9c3d9e4..0b92968 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -52,6 +52,7 @@ from jinja2 import Markup
from paste.deploy.converters import asbool, aslist
from webhelpers import date, feedgenerator, html, number, misc, text
+from webob.exc import HTTPUnauthorized
from allura.lib import exceptions as exc
# Reimport to make available to templates
@@ -1012,3 +1013,15 @@ def iter_entry_points(group, *a, **kw):
def daterange(start_date, end_date):
for n in range(int((end_date - start_date).days)):
yield start_date + timedelta(n)
+
+
+@contextmanager
+def login_overlay(exceptions=None):
+ try:
+ yield
+ except HTTPUnauthorized as e:
+ if exceptions:
+ for exception in exceptions:
+ if request.path.rstrip('/').endswith('/%s' % exception):
+ raise
+ c.show_login_overlay = True
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b930a634/Allura/allura/lib/security.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/security.py b/Allura/allura/lib/security.py
index 4718e56..a0497ca 100644
--- a/Allura/allura/lib/security.py
+++ b/Allura/allura/lib/security.py
@@ -383,7 +383,7 @@ def all_allowed(obj, user_or_role=None, project=None):
return set([M.ALL_PERMISSIONS])
return perms
-def require(predicate, message=None, login_overlay=False):
+def require(predicate, message=None):
'''
Example: require(has_access(c.app, 'read'))
@@ -401,17 +401,13 @@ def require(predicate, message=None, login_overlay=False):
if c.user != M.User.anonymous():
request.environ['error_message'] = message
raise exc.HTTPForbidden(detail=message)
- elif login_overlay:
- c.show_login_overlay = True
else:
raise exc.HTTPUnauthorized()
-def require_access(obj, permission, login_overlay=False, **kwargs):
+def require_access(obj, permission, **kwargs):
if obj is not None:
predicate = has_access(obj, permission, **kwargs)
- return require(predicate,
- message='%s access required' % permission.capitalize(),
- login_overlay=login_overlay)
+ return require(predicate, message='%s access required' % permission.capitalize())
else:
raise exc.HTTPForbidden(detail="Could not verify permissions for this page.")
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b930a634/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index d4e5a0c..38a67c5 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -27,6 +27,7 @@ from nose.tools import eq_, assert_equals
from IPython.testing.decorators import skipif, module_not_available
from datadiff import tools as dd
from webob import Request
+from webob.exc import HTTPUnauthorized
from ming.orm import ThreadLocalORMSession
from allura import model as M
@@ -432,4 +433,15 @@ def test_absurl_with_request():
def test_daterange():
assert_equals(list(h.daterange(datetime(2013, 1, 1), datetime(2013, 1, 4))),
- [datetime(2013, 1, 1), datetime(2013, 1, 2), datetime(2013, 1, 3)])
\ No newline at end of file
+ [datetime(2013, 1, 1), datetime(2013, 1, 2), datetime(2013, 1, 3)])
+
+@patch.object(h, 'request',
+ new=Request.blank('/p/test/foobar', base_url='https://www.mysite.com/p/test/foobar'))
+def test_login_overlay():
+ with h.login_overlay():
+ raise HTTPUnauthorized()
+ with h.login_overlay(exceptions=['foo']):
+ raise HTTPUnauthorized()
+ with td.raises(HTTPUnauthorized):
+ with h.login_overlay(exceptions=['foobar']):
+ raise HTTPUnauthorized()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b930a634/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 0b07c6d..8c01b62 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -26,6 +26,7 @@ from tg import expose, validate, flash, redirect, config
from tg.decorators import with_trailing_slash
from pylons import app_globals as g
from pylons import tmpl_context as c
+from pylons import request
from formencode import validators as fev, schema
from webob import exc
@@ -190,7 +191,8 @@ class ProjectImporter(BaseController):
self.neighborhood = neighborhood
def _check_security(self):
- require_access(self.neighborhood, 'register', login_overlay=True)
+ with h.login_overlay(exceptions=['process']):
+ require_access(self.neighborhood, 'register')
@LazyProperty
def tool_importers(self):
@@ -231,7 +233,6 @@ class ProjectImporter(BaseController):
tools installed and redirect to the new project, presumably with a
message indicating that some data will not be available immediately.
"""
- require_access(self.neighborhood, 'register', login_overlay=False)
try:
c.project = self.neighborhood.register_project(kw['project_shortname'],
project_name=kw['project_name'])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b930a634/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
index 3c05a2d..cee88c0 100644
--- a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
+++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
@@ -26,3 +26,11 @@ class TestGitHubImportController(TestController, TestCase):
assert '<input id="user_name" name="user_name" value="" autofocus/>' in r
assert '<input id="project_name" name="project_name" value="" />' in r
assert '<input id="project_shortname" name="project_shortname" value=""/>' in r
+
+ def test_login_overlay(self):
+ r = self.app.get('/p/import_project/github/', extra_environ=dict(username='*anonymous'))
+ self.assertIn('GitHub Project Importer', r)
+ self.assertIn('Login Required', r)
+
+ r = self.app.post('/p/import_project/github/process', extra_environ=dict(username='*anonymous'), status=302)
+ self.assertIn('/auth/', r.location)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b930a634/ForgeImporters/forgeimporters/tests/test_base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index 4aefc35..d4b403d 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -21,8 +21,10 @@ from formencode import Invalid
import mock
from tg import expose
from nose.tools import assert_equal, assert_raises
+from webob.exc import HTTPUnauthorized
from alluratest.controller import TestController
+from allura.tests import decorators as td
from .. import base
@@ -123,6 +125,29 @@ class TestProjectImporter(TestCase):
self.assertEqual(flash.call_count, 1)
redirect.assert_called_once_with('script_name/admin/overview')
+ @mock.patch.object(base.h, 'request')
+ @mock.patch.object(base, 'require_access')
+ @mock.patch.object(base.h, 'c')
+ def test_login_overlay(self, c, require_access, request):
+ pi = base.ProjectImporter(mock.Mock())
+ require_access.side_effect = HTTPUnauthorized
+
+ c.show_login_overlay = False
+ request.path = '/test-importer/'
+ pi._check_security()
+ self.assertEqual(c.show_login_overlay, True)
+
+ c.show_login_overlay = False
+ request.path = '/test-importer/check_names/'
+ pi._check_security()
+ self.assertEqual(c.show_login_overlay, True)
+
+ c.show_login_overlay = False
+ request.path = '/test-importer/process/'
+ with td.raises(HTTPUnauthorized):
+ pi._check_security()
+ self.assertEqual(c.show_login_overlay, False)
+
TA1 = mock.Mock(tool_label='foo', tool_description='foo_desc')