my-account: moved profile page into pyramid.

This commit is contained in:
Marcin Kuzminski 2017-03-14 12:54:06 +01:00
parent 4845dc40af
commit 3f64f3f41f
9 changed files with 78 additions and 29 deletions

View file

@ -24,6 +24,10 @@ from rhodecode.apps._base import ADMIN_PREFIX
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')

View file

@ -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 <http://www.gnu.org/licenses/>.
#
# 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')

View file

@ -50,6 +50,16 @@ class MyAccountView(BaseAppView):
self._register_global_c(c)
return c
@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(

View file

@ -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

View file

@ -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

View file

@ -26,7 +26,7 @@
##main
<div class="sidebar">
<ul class="nav nav-pills nav-stacked">
<li class="${'active' if c.active=='profile' or c.active=='profile_edit' else ''}"><a href="${h.url('my_account')}">${_('Profile')}</a></li>
<li class="${'active' if c.active=='profile' or c.active=='profile_edit' else ''}"><a href="${h.route_path('my_account_profile')}">${_('Profile')}</a></li>
<li class="${'active' if c.active=='password' else ''}"><a href="${h.route_path('my_account_password')}">${_('Password')}</a></li>
<li class="${'active' if c.active=='auth_tokens' else ''}"><a href="${h.route_path('my_account_auth_tokens')}">${_('Auth Tokens')}</a></li>
## TODO: Find a better integration of oauth views into navigation.

View file

@ -2,7 +2,7 @@
<div class="panel panel-default user-profile">
<div class="panel-heading">
<h3 class="panel-title">${_('My Profile')}</h3>
<a href="${url('my_account')}" class="panel-edit">Close</a>
<a href="${h.route_path('my_account_profile')}" class="panel-edit">Close</a>
</div>
<div class="panel-body">

View file

@ -340,7 +340,7 @@
</div>
<div class="">
<ol class="links">
<li>${h.link_to(_(u'My account'),h.url('my_account'))}</li>
<li>${h.link_to(_(u'My account'),h.route_path('my_account_profile'))}</li>
% if c.rhodecode_user.personal_repo_group:
<li>${h.link_to(_(u'My personal group'), h.url('repo_group_home', group_name=c.rhodecode_user.personal_repo_group.group_name))}</li>
% endif

View file

@ -40,15 +40,8 @@ class TestMyAccountController(TestController):
def teardown_class(cls):
fixture.destroy_users(cls.destroy_users)
def test_my_account(self):
self.log_user()
response = self.app.get(url('my_account'))
response.mustcontain('test_admin')
response.mustcontain('href="/_admin/my_account/edit"')
def test_logout_form_contains_csrf(self, autologin_user, csrf_token):
response = self.app.get(url('my_account'))
response = self.app.get(url('home'))
assert_response = AssertResponse(response)
element = assert_response.get_element('.logout #csrf_token')
assert element.value == csrf_token