diff --git a/ckan/controllers/home.py b/ckan/controllers/home.py index 83f268d2858..f297f06655f 100644 --- a/ckan/controllers/home.py +++ b/ckan/controllers/home.py @@ -74,30 +74,14 @@ def index(self): except search.SearchError: c.package_count = 0 - if c.userobj is not None: - msg = None + if c.userobj and not c.userobj.email: url = h.url_for(controller='user', action='edit') - is_google_id = \ - c.userobj.name.startswith( - 'https://www.google.com/accounts/o8/id') - if not c.userobj.email and (is_google_id and - not c.userobj.fullname): - msg = _(u'Please update your profile' - u' and add your email address and your full name. ' - u'{site} uses your email address' - u' if you need to reset your password.'.format( - link=url, site=g.site_title)) - elif not c.userobj.email: - msg = _('Please update your profile' - ' and add your email address. ') % url + \ - _('%s uses your email address' - ' if you need to reset your password.') \ - % g.site_title - elif is_google_id and not c.userobj.fullname: - msg = _('Please update your profile' - ' and add your full name.') % (url) - if msg: - h.flash_notice(msg, allow_html=True) + msg = _('Please update your profile' + ' and add your email address. ') % url + \ + _('%s uses your email address' + ' if you need to reset your password.') \ + % g.site_title + h.flash_notice(msg, allow_html=True) return base.render('home/index.html', cache_force=True) diff --git a/ckan/tests/controllers/test_home.py b/ckan/tests/controllers/test_home.py new file mode 100644 index 00000000000..f345cf48914 --- /dev/null +++ b/ckan/tests/controllers/test_home.py @@ -0,0 +1,53 @@ +from routes import url_for + +from ckan.tests import factories +import ckan.tests.helpers as helpers + + +class TestHome(helpers.FunctionalTestBase): + + def test_home_renders(self): + app = self._get_test_app() + response = app.get(url_for('home')) + assert 'Welcome to CKAN' in response.body + + def test_template_head_end(self): + app = self._get_test_app() + # test-core.ini sets ckan.template_head_end to this: + test_link = '' + response = app.get(url_for('home')) + assert test_link in response.body + + def test_template_footer_end(self): + app = self._get_test_app() + # test-core.ini sets ckan.template_footer_end to this: + test_html = 'TEST TEMPLATE_FOOTER_END TEST' + response = app.get(url_for('home')) + assert test_html in response.body + + def test_email_address_nag(self): + # before CKAN 1.6, users were allowed to have no email addresses + app = self._get_test_app() + # can't use factory to create user as without email it fails validation + from ckan import model + model.repo.new_revision() + user = model.user.User(name='has-no-email') + model.Session.add(user) + model.Session.commit() + env = {'REMOTE_USER': user.name.encode('ascii')} + + response = app.get(url=url_for('home'), extra_environ=env) + + assert 'update your profile' in response.body + assert url_for(controller='user', action='edit') in response.body + assert ' and add your email address.' in response.body + + def test_email_address_no_nag(self): + app = self._get_test_app() + user = factories.User(email='filled_in@nicely.com') + env = {'REMOTE_USER': user['name'].encode('ascii')} + + response = app.get(url=url_for('home'), extra_environ=env) + + assert 'add your email address' not in response diff --git a/ckan/tests/legacy/functional/test_home.py b/ckan/tests/legacy/functional/test_home.py deleted file mode 100644 index 1c7769a5540..00000000000 --- a/ckan/tests/legacy/functional/test_home.py +++ /dev/null @@ -1,138 +0,0 @@ -from pylons.i18n import set_lang - -from ckan.lib.create_test_data import CreateTestData -from ckan.controllers.home import HomeController -import ckan.model as model - -from ckan.tests.legacy import * -from ckan.tests.legacy.html_check import HtmlCheckMethods -from ckan.tests.legacy.pylons_controller import PylonsTestCase -from ckan.tests.legacy import search_related, setup_test_search_index - -from ckan.common import c, session - -class TestHomeController(TestController, PylonsTestCase, HtmlCheckMethods): - @classmethod - def setup_class(cls): - setup_test_search_index() - PylonsTestCase.setup_class() - model.repo.init_db() - CreateTestData.create() - - @classmethod - def teardown_class(self): - model.repo.rebuild_db() - - def test_template_head_end(self): - offset = url_for('home') - res = self.app.get(offset) - assert 'ckan.template_head_end = ' - - def test_template_footer_end(self): - offset = url_for('home') - res = self.app.get(offset) - assert 'TEST TEMPLATE_FOOTER_END TEST' - - - def test_update_profile_notice(self): - edit_url = url_for(controller='user', action='edit') - email_notice = 'Please update your profile' \ - ' and add your email address.' % (edit_url) - fullname_notice = 'Please update your profile' \ - ' and add your full name' % (edit_url) - email_and_fullname_notice ='Please update your' \ - ' profile and add your email address and your full name.' \ - % (edit_url) - url = url_for('home') - - # No update profile notices should be flashed if no one is logged in. - response = self.app.get(url) - assert email_notice not in response - assert fullname_notice not in response - assert email_and_fullname_notice not in response - - # Make some test users. - user1 = model.user.User(name='user1', fullname="user 1's full name", - email='user1@testusers.org') - user2 = model.user.User(name='user2', fullname="user 2's full name") - user3 = model.user.User(name='user3', email='user3@testusers.org') - user4 = model.user.User(name='user4') - - # Some test users with Google OpenIDs. - user5 = model.user.User( - name='https://www.google.com/accounts/o8/id/id=ACyQatixLeL' - 'ODscWvwqsCXWQ2sa3RRaBhaKTkcsvUElI6tNHIQ1_egX_wt1x3fA' - 'Y983DpW4UQV_U', - fullname="user 5's full name", email="user5@testusers.org") - user6 = model.user.User( - name='https://www.google.com/accounts/o8/id/id=ACyQatixLeL' - 'ODscWvwqsCXWQ2sa3RRaBhaKTkcsvUElI6tNHIQ1_egX_wt1x3fA' - 'Y983DpW4UQV_J', - fullname="user 6's full name") - user7 = model.user.User( - name='https://www.google.com/accounts/o8/id/id=AItOawl27F2' - 'M92ry4jTdjiVx06tuFNA', - email='user7@testusers.org') - user8 = model.user.User( - name='https://www.google.com/accounts/o8/id/id=AItOawl27F2' - 'M92ry4jTdjiVx06tuFNs' - ) - - users = (user1, user2, user3, user4, user5, user6, user7, user8) - google_users = (user5, user6, user7, user8) - - for user in users: - model.repo.new_revision() - model.Session.add(user) - model.Session.commit() - - response = self.app.get(url, extra_environ={'REMOTE_USER': - user.name.encode('utf-8')}) - - model.repo.new_revision() - model.Session.add(user) - - if user in google_users: - # Users with Google OpenIDs are asked to give their email if - # they don't have one and to enter a full name if they don't - # have one. - if not user.email and not user.fullname: - assert email_and_fullname_notice in response - assert email_notice not in response - assert fullname_notice not in response - elif user.email and not user.fullname: - assert email_notice not in response - assert fullname_notice in response - assert email_and_fullname_notice not in response - elif not user.email and user.fullname: - assert email_notice in response - assert fullname_notice not in response - assert email_and_fullname_notice not in response - elif user.email and user.fullname: - assert email_notice not in response - assert fullname_notice not in response - assert email_and_fullname_notice not in response - else: - # Users without Google OpenIDs are just asked to give their - # email if they don't have one. - if not user.email: - assert email_notice in response - assert email_and_fullname_notice not in response - assert fullname_notice not in response - elif user.email: - assert email_notice not in response - assert fullname_notice not in response - assert email_and_fullname_notice not in response - - if not user.email: - user.email = "mr_tusks@tusk_family.org" - if not user.fullname: - user.fullname = "Mr. Tusks" - model.Session.commit() - - response = self.app.get(url, extra_environ={'REMOTE_USER': - user.name.encode('utf-8')}) - assert email_notice not in response - assert fullname_notice not in response - assert email_and_fullname_notice not in response -