Show More
@@ -0,0 +1,55 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | # Copyright (C) 2010-2017 RhodeCode GmbH | |||
|
4 | # | |||
|
5 | # This program is free software: you can redistribute it and/or modify | |||
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |||
|
7 | # (only), as published by the Free Software Foundation. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU Affero General Public License | |||
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
|
16 | # | |||
|
17 | # This program is dual-licensed. If you wish to learn more about the | |||
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |||
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |||
|
20 | ||||
|
21 | import pytest | |||
|
22 | ||||
|
23 | from rhodecode.apps._base import ADMIN_PREFIX | |||
|
24 | from rhodecode.tests import ( | |||
|
25 | TestController, TEST_USER_ADMIN_LOGIN, | |||
|
26 | TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) | |||
|
27 | from rhodecode.tests.fixture import Fixture | |||
|
28 | ||||
|
29 | fixture = Fixture() | |||
|
30 | ||||
|
31 | ||||
|
32 | def route_path(name, **kwargs): | |||
|
33 | return { | |||
|
34 | 'my_account': | |||
|
35 | ADMIN_PREFIX + '/my_account/profile', | |||
|
36 | }[name].format(**kwargs) | |||
|
37 | ||||
|
38 | ||||
|
39 | class TestMyAccountProfile(TestController): | |||
|
40 | ||||
|
41 | def test_my_account(self): | |||
|
42 | self.log_user() | |||
|
43 | response = self.app.get(route_path('my_account')) | |||
|
44 | ||||
|
45 | response.mustcontain(TEST_USER_ADMIN_LOGIN) | |||
|
46 | response.mustcontain('href="/_admin/my_account/edit"') | |||
|
47 | response.mustcontain('Photo') | |||
|
48 | ||||
|
49 | def test_my_account_regular_user(self): | |||
|
50 | self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) | |||
|
51 | response = self.app.get(route_path('my_account')) | |||
|
52 | ||||
|
53 | response.mustcontain(TEST_USER_REGULAR_LOGIN) | |||
|
54 | response.mustcontain('href="/_admin/my_account/edit"') | |||
|
55 | response.mustcontain('Photo') |
@@ -25,6 +25,10 b' from rhodecode.apps._base import ADMIN_P' | |||||
25 | def includeme(config): |
|
25 | def includeme(config): | |
26 |
|
26 | |||
27 | config.add_route( |
|
27 | config.add_route( | |
|
28 | name='my_account_profile', | |||
|
29 | pattern=ADMIN_PREFIX + '/my_account/profile') | |||
|
30 | ||||
|
31 | config.add_route( | |||
28 | name='my_account_password', |
|
32 | name='my_account_password', | |
29 | pattern=ADMIN_PREFIX + '/my_account/password') |
|
33 | pattern=ADMIN_PREFIX + '/my_account/password') | |
30 |
|
34 |
@@ -53,6 +53,16 b' class MyAccountView(BaseAppView):' | |||||
53 | @LoginRequired() |
|
53 | @LoginRequired() | |
54 | @NotAnonymous() |
|
54 | @NotAnonymous() | |
55 | @view_config( |
|
55 | @view_config( | |
|
56 | route_name='my_account_profile', request_method='GET', | |||
|
57 | renderer='rhodecode:templates/admin/my_account/my_account.mako') | |||
|
58 | def my_account_profile(self): | |||
|
59 | c = self.load_default_context() | |||
|
60 | c.active = 'profile' | |||
|
61 | return self._get_template_context(c) | |||
|
62 | ||||
|
63 | @LoginRequired() | |||
|
64 | @NotAnonymous() | |||
|
65 | @view_config( | |||
56 | route_name='my_account_password', request_method='GET', |
|
66 | route_name='my_account_password', request_method='GET', | |
57 | renderer='rhodecode:templates/admin/my_account/my_account.mako') |
|
67 | renderer='rhodecode:templates/admin/my_account/my_account.mako') | |
58 | def my_account_password(self): |
|
68 | def my_account_password(self): |
@@ -505,11 +505,9 b' def make_map(config):' | |||||
505 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
505 | with rmap.submapper(path_prefix=ADMIN_PREFIX, | |
506 | controller='admin/my_account') as m: |
|
506 | controller='admin/my_account') as m: | |
507 |
|
507 | |||
508 | m.connect('my_account', '/my_account', |
|
|||
509 | action='my_account', conditions={'method': ['GET']}) |
|
|||
510 | m.connect('my_account_edit', '/my_account/edit', |
|
508 | m.connect('my_account_edit', '/my_account/edit', | |
511 | action='my_account_edit', conditions={'method': ['GET']}) |
|
509 | action='my_account_edit', conditions={'method': ['GET']}) | |
512 | m.connect('my_account', '/my_account', |
|
510 | m.connect('my_account', '/my_account/update', | |
513 | action='my_account_update', conditions={'method': ['POST']}) |
|
511 | action='my_account_update', conditions={'method': ['POST']}) | |
514 |
|
512 | |||
515 | # NOTE(marcink): this needs to be kept for password force flag to be |
|
513 | # NOTE(marcink): this needs to be kept for password force flag to be |
@@ -29,7 +29,9 b' import datetime' | |||||
29 | import formencode |
|
29 | import formencode | |
30 | from formencode import htmlfill |
|
30 | from formencode import htmlfill | |
31 | from pyramid.threadlocal import get_current_registry |
|
31 | from pyramid.threadlocal import get_current_registry | |
32 | from pylons import request, tmpl_context as c, url, session |
|
32 | from pyramid.httpexceptions import HTTPFound | |
|
33 | ||||
|
34 | from pylons import request, tmpl_context as c, url | |||
33 | from pylons.controllers.util import redirect |
|
35 | from pylons.controllers.util import redirect | |
34 | from pylons.i18n.translation import _ |
|
36 | from pylons.i18n.translation import _ | |
35 | from sqlalchemy.orm import joinedload |
|
37 | from sqlalchemy.orm import joinedload | |
@@ -152,7 +154,7 b' class MyAccountController(BaseController' | |||||
152 | % form_result.get('username'), category='error') |
|
154 | % form_result.get('username'), category='error') | |
153 |
|
155 | |||
154 | if update: |
|
156 | if update: | |
155 | return redirect('my_account') |
|
157 | raise HTTPFound(h.route_path('my_account_profile')) | |
156 |
|
158 | |||
157 | return htmlfill.render( |
|
159 | return htmlfill.render( | |
158 | render('admin/my_account/my_account.mako'), |
|
160 | render('admin/my_account/my_account.mako'), | |
@@ -161,19 +163,6 b' class MyAccountController(BaseController' | |||||
161 | force_defaults=False |
|
163 | force_defaults=False | |
162 | ) |
|
164 | ) | |
163 |
|
165 | |||
164 | def my_account(self): |
|
|||
165 | """ |
|
|||
166 | GET /_admin/my_account Displays info about my account |
|
|||
167 | """ |
|
|||
168 | # url('my_account') |
|
|||
169 | c.active = 'profile' |
|
|||
170 | self.__load_data() |
|
|||
171 |
|
||||
172 | defaults = c.user.get_dict() |
|
|||
173 | return htmlfill.render( |
|
|||
174 | render('admin/my_account/my_account.mako'), |
|
|||
175 | defaults=defaults, encoding="UTF-8", force_defaults=False) |
|
|||
176 |
|
||||
177 | def my_account_edit(self): |
|
166 | def my_account_edit(self): | |
178 | """ |
|
167 | """ | |
179 | GET /_admin/my_account/edit Displays edit form of my account |
|
168 | GET /_admin/my_account/edit Displays edit form of my account |
@@ -26,7 +26,7 b'' | |||||
26 | ##main |
|
26 | ##main | |
27 | <div class="sidebar"> |
|
27 | <div class="sidebar"> | |
28 | <ul class="nav nav-pills nav-stacked"> |
|
28 | <ul class="nav nav-pills nav-stacked"> | |
29 |
<li class="${'active' if c.active=='profile' or c.active=='profile_edit' else ''}"><a href="${h. |
|
29 | <li class="${'active' if c.active=='profile' or c.active=='profile_edit' else ''}"><a href="${h.route_path('my_account_profile')}">${_('Profile')}</a></li> | |
30 | <li class="${'active' if c.active=='password' else ''}"><a href="${h.route_path('my_account_password')}">${_('Password')}</a></li> |
|
30 | <li class="${'active' if c.active=='password' else ''}"><a href="${h.route_path('my_account_password')}">${_('Password')}</a></li> | |
31 | <li class="${'active' if c.active=='auth_tokens' else ''}"><a href="${h.route_path('my_account_auth_tokens')}">${_('Auth Tokens')}</a></li> |
|
31 | <li class="${'active' if c.active=='auth_tokens' else ''}"><a href="${h.route_path('my_account_auth_tokens')}">${_('Auth Tokens')}</a></li> | |
32 | ## TODO: Find a better integration of oauth views into navigation. |
|
32 | ## TODO: Find a better integration of oauth views into navigation. |
@@ -2,7 +2,7 b'' | |||||
2 | <div class="panel panel-default user-profile"> |
|
2 | <div class="panel panel-default user-profile"> | |
3 | <div class="panel-heading"> |
|
3 | <div class="panel-heading"> | |
4 | <h3 class="panel-title">${_('My Profile')}</h3> |
|
4 | <h3 class="panel-title">${_('My Profile')}</h3> | |
5 |
<a href="${ |
|
5 | <a href="${h.route_path('my_account_profile')}" class="panel-edit">Close</a> | |
6 | </div> |
|
6 | </div> | |
7 |
|
7 | |||
8 | <div class="panel-body"> |
|
8 | <div class="panel-body"> |
@@ -340,7 +340,7 b'' | |||||
340 | </div> |
|
340 | </div> | |
341 | <div class=""> |
|
341 | <div class=""> | |
342 | <ol class="links"> |
|
342 | <ol class="links"> | |
343 |
<li>${h.link_to(_(u'My account'),h. |
|
343 | <li>${h.link_to(_(u'My account'),h.route_path('my_account_profile'))}</li> | |
344 | % if c.rhodecode_user.personal_repo_group: |
|
344 | % if c.rhodecode_user.personal_repo_group: | |
345 | <li>${h.link_to(_(u'My personal group'), h.url('repo_group_home', group_name=c.rhodecode_user.personal_repo_group.group_name))}</li> |
|
345 | <li>${h.link_to(_(u'My personal group'), h.url('repo_group_home', group_name=c.rhodecode_user.personal_repo_group.group_name))}</li> | |
346 | % endif |
|
346 | % endif |
@@ -40,15 +40,8 b' class TestMyAccountController(TestContro' | |||||
40 | def teardown_class(cls): |
|
40 | def teardown_class(cls): | |
41 | fixture.destroy_users(cls.destroy_users) |
|
41 | fixture.destroy_users(cls.destroy_users) | |
42 |
|
42 | |||
43 | def test_my_account(self): |
|
|||
44 | self.log_user() |
|
|||
45 | response = self.app.get(url('my_account')) |
|
|||
46 |
|
||||
47 | response.mustcontain('test_admin') |
|
|||
48 | response.mustcontain('href="/_admin/my_account/edit"') |
|
|||
49 |
|
||||
50 | def test_logout_form_contains_csrf(self, autologin_user, csrf_token): |
|
43 | def test_logout_form_contains_csrf(self, autologin_user, csrf_token): | |
51 |
response = self.app.get(url(' |
|
44 | response = self.app.get(url('home')) | |
52 | assert_response = AssertResponse(response) |
|
45 | assert_response = AssertResponse(response) | |
53 | element = assert_response.get_element('.logout #csrf_token') |
|
46 | element = assert_response.get_element('.logout #csrf_token') | |
54 | assert element.value == csrf_token |
|
47 | assert element.value == csrf_token |
General Comments 0
You need to be logged in to leave comments.
Login now