diff --git a/rhodecode/apps/my_account/__init__.py b/rhodecode/apps/my_account/__init__.py --- a/rhodecode/apps/my_account/__init__.py +++ b/rhodecode/apps/my_account/__init__.py @@ -25,6 +25,10 @@ from rhodecode.apps._base import ADMIN_P def includeme(config): config.add_route( + name='my_account_profile', + pattern=ADMIN_PREFIX + '/my_account/profile') + + config.add_route( name='my_account_password', pattern=ADMIN_PREFIX + '/my_account/password') diff --git a/rhodecode/apps/my_account/tests/test_my_account_profile.py b/rhodecode/apps/my_account/tests/test_my_account_profile.py new file mode 100644 --- /dev/null +++ b/rhodecode/apps/my_account/tests/test_my_account_profile.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2010-2017 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + +import pytest + +from rhodecode.apps._base import ADMIN_PREFIX +from rhodecode.tests import ( + TestController, TEST_USER_ADMIN_LOGIN, + TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) +from rhodecode.tests.fixture import Fixture + +fixture = Fixture() + + +def route_path(name, **kwargs): + return { + 'my_account': + ADMIN_PREFIX + '/my_account/profile', + }[name].format(**kwargs) + + +class TestMyAccountProfile(TestController): + + def test_my_account(self): + self.log_user() + response = self.app.get(route_path('my_account')) + + response.mustcontain(TEST_USER_ADMIN_LOGIN) + response.mustcontain('href="/_admin/my_account/edit"') + response.mustcontain('Photo') + + def test_my_account_regular_user(self): + self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) + response = self.app.get(route_path('my_account')) + + response.mustcontain(TEST_USER_REGULAR_LOGIN) + response.mustcontain('href="/_admin/my_account/edit"') + response.mustcontain('Photo') diff --git a/rhodecode/apps/my_account/views.py b/rhodecode/apps/my_account/views.py --- a/rhodecode/apps/my_account/views.py +++ b/rhodecode/apps/my_account/views.py @@ -53,6 +53,16 @@ class MyAccountView(BaseAppView): @LoginRequired() @NotAnonymous() @view_config( + route_name='my_account_profile', request_method='GET', + renderer='rhodecode:templates/admin/my_account/my_account.mako') + def my_account_profile(self): + c = self.load_default_context() + c.active = 'profile' + return self._get_template_context(c) + + @LoginRequired() + @NotAnonymous() + @view_config( route_name='my_account_password', request_method='GET', renderer='rhodecode:templates/admin/my_account/my_account.mako') def my_account_password(self): diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -505,11 +505,9 @@ def make_map(config): with rmap.submapper(path_prefix=ADMIN_PREFIX, controller='admin/my_account') as m: - m.connect('my_account', '/my_account', - action='my_account', conditions={'method': ['GET']}) m.connect('my_account_edit', '/my_account/edit', action='my_account_edit', conditions={'method': ['GET']}) - m.connect('my_account', '/my_account', + m.connect('my_account', '/my_account/update', action='my_account_update', conditions={'method': ['POST']}) # NOTE(marcink): this needs to be kept for password force flag to be diff --git a/rhodecode/controllers/admin/my_account.py b/rhodecode/controllers/admin/my_account.py --- a/rhodecode/controllers/admin/my_account.py +++ b/rhodecode/controllers/admin/my_account.py @@ -29,7 +29,9 @@ import datetime import formencode from formencode import htmlfill from pyramid.threadlocal import get_current_registry -from pylons import request, tmpl_context as c, url, session +from pyramid.httpexceptions import HTTPFound + +from pylons import request, tmpl_context as c, url from pylons.controllers.util import redirect from pylons.i18n.translation import _ from sqlalchemy.orm import joinedload @@ -152,7 +154,7 @@ class MyAccountController(BaseController % form_result.get('username'), category='error') if update: - return redirect('my_account') + raise HTTPFound(h.route_path('my_account_profile')) return htmlfill.render( render('admin/my_account/my_account.mako'), @@ -161,19 +163,6 @@ class MyAccountController(BaseController force_defaults=False ) - def my_account(self): - """ - GET /_admin/my_account Displays info about my account - """ - # url('my_account') - c.active = 'profile' - self.__load_data() - - defaults = c.user.get_dict() - return htmlfill.render( - render('admin/my_account/my_account.mako'), - defaults=defaults, encoding="UTF-8", force_defaults=False) - def my_account_edit(self): """ GET /_admin/my_account/edit Displays edit form of my account diff --git a/rhodecode/templates/admin/my_account/my_account.mako b/rhodecode/templates/admin/my_account/my_account.mako --- a/rhodecode/templates/admin/my_account/my_account.mako +++ b/rhodecode/templates/admin/my_account/my_account.mako @@ -26,7 +26,7 @@ ##main