diff --git a/rhodecode/apps/admin/tests/test_admin_repos.py b/rhodecode/apps/admin/tests/test_admin_repos.py
--- a/rhodecode/apps/admin/tests/test_admin_repos.py
+++ b/rhodecode/apps/admin/tests/test_admin_repos.py
@@ -47,6 +47,7 @@ def route_path(name, params=None, **kwar
base_url = {
'repos': ADMIN_PREFIX + '/repos',
+ 'repos_data': ADMIN_PREFIX + '/repos_data',
'repo_new': ADMIN_PREFIX + '/repos/new',
'repo_create': ADMIN_PREFIX + '/repos/create',
@@ -70,11 +71,12 @@ def _get_permission_for_user(user, repo)
@pytest.mark.usefixtures("app")
class TestAdminRepos(object):
- def test_repo_list(self, autologin_user, user_util):
+ def test_repo_list(self, autologin_user, user_util, xhr_header):
repo = user_util.create_repo()
repo_name = repo.repo_name
response = self.app.get(
- route_path('repos'), status=200)
+ route_path('repos_data'), status=200,
+ extra_environ=xhr_header)
response.mustcontain(repo_name)
diff --git a/rhodecode/apps/admin/tests/test_admin_repository_groups.py b/rhodecode/apps/admin/tests/test_admin_repository_groups.py
--- a/rhodecode/apps/admin/tests/test_admin_repository_groups.py
+++ b/rhodecode/apps/admin/tests/test_admin_repository_groups.py
@@ -84,7 +84,7 @@ class TestAdminRepositoryGroups(object):
fixture.create_repo_group('test_repo_group')
response = self.app.get(route_path(
'repo_groups_data'), extra_environ=xhr_header)
- response.mustcontain('"name_raw": "test_repo_group"')
+ response.mustcontain('Edit'.format('test_repo_group'))
fixture.destroy_repo_group('test_repo_group')
def test_new(self, autologin_user):
diff --git a/rhodecode/apps/admin/tests/test_admin_users.py b/rhodecode/apps/admin/tests/test_admin_users.py
--- a/rhodecode/apps/admin/tests/test_admin_users.py
+++ b/rhodecode/apps/admin/tests/test_admin_users.py
@@ -546,6 +546,7 @@ class TestAdminUsersView(TestController)
usr = user_util.create_user(auto_cleanup=False)
username = usr.username
fixture.create_repo(obj_name, cur_user=usr.username)
+ Session().commit()
new_user = Session().query(User)\
.filter(User.username == username).one()
diff --git a/rhodecode/apps/home/tests/test_home.py b/rhodecode/apps/home/tests/test_home.py
--- a/rhodecode/apps/home/tests/test_home.py
+++ b/rhodecode/apps/home/tests/test_home.py
@@ -22,7 +22,7 @@
import pytest
import rhodecode
-from rhodecode.model.db import Repository
+from rhodecode.model.db import Repository, RepoGroup, User
from rhodecode.model.meta import Session
from rhodecode.model.repo import RepoModel
from rhodecode.model.repo_group import RepoGroupModel
@@ -37,6 +37,8 @@ fixture = Fixture()
def route_path(name, **kwargs):
return {
'home': '/',
+ 'main_page_repos_data': '/_home_repos',
+ 'main_page_repo_groups_data': '/_home_repo_groups',
'repo_group_home': '/{repo_group_name}'
}[name].format(**kwargs)
@@ -49,9 +51,40 @@ class TestHomeController(TestController)
# if global permission is set
response.mustcontain('New Repository')
+ def test_index_grid_repos(self, xhr_header):
+ self.log_user()
+ response = self.app.get(route_path('main_page_repos_data'), extra_environ=xhr_header)
# search for objects inside the JavaScript JSON
- for repo in Repository.getAll():
- response.mustcontain('"name_raw": "%s"' % repo.repo_name)
+ for obj in Repository.getAll():
+ response.mustcontain(''.format(obj.repo_name))
+
+ def test_index_grid_repo_groups(self, xhr_header):
+ self.log_user()
+ response = self.app.get(route_path('main_page_repo_groups_data'),
+ extra_environ=xhr_header,)
+
+ # search for objects inside the JavaScript JSON
+ for obj in RepoGroup.getAll():
+ response.mustcontain(''.format(obj.group_name))
+
+ def test_index_grid_repo_groups_without_access(self, xhr_header, user_util):
+ user = user_util.create_user(password='qweqwe')
+ group_ok = user_util.create_repo_group(owner=user)
+ group_id_ok = group_ok.group_id
+
+ group_forbidden = user_util.create_repo_group(owner=User.get_first_super_admin())
+ group_id_forbidden = group_forbidden.group_id
+
+ user_util.grant_user_permission_to_repo_group(group_forbidden, user, 'group.none')
+ self.log_user(user.username, 'qweqwe')
+
+ self.app.get(route_path('main_page_repo_groups_data'),
+ extra_environ=xhr_header,
+ params={'repo_group_id': group_id_ok}, status=200)
+
+ self.app.get(route_path('main_page_repo_groups_data'),
+ extra_environ=xhr_header,
+ params={'repo_group_id': group_id_forbidden}, status=404)
def test_index_contains_statics_with_ver(self):
from rhodecode.lib.base import calculate_version_hash
@@ -64,9 +97,9 @@ class TestHomeController(TestController)
response.mustcontain('style.css?ver={0}'.format(rhodecode_version_hash))
response.mustcontain('scripts.min.js?ver={0}'.format(rhodecode_version_hash))
- def test_index_contains_backend_specific_details(self, backend):
+ def test_index_contains_backend_specific_details(self, backend, xhr_header):
self.log_user()
- response = self.app.get(route_path('home'))
+ response = self.app.get(route_path('main_page_repos_data'), extra_environ=xhr_header)
tip = backend.repo.get_commit().raw_id
# html in javascript variable:
@@ -81,25 +114,44 @@ class TestHomeController(TestController)
response = self.app.get(route_path('home'), status=302)
assert 'login' in response.location
- def test_index_page_on_groups(self, autologin_user, repo_group):
- response = self.app.get(route_path('repo_group_home', repo_group_name='gr1'))
- response.mustcontain("gr1/repo_in_group")
+ def test_index_page_on_groups_with_wrong_group_id(self, autologin_user, xhr_header):
+ group_id = 918123
+ self.app.get(
+ route_path('main_page_repo_groups_data'),
+ params={'repo_group_id': group_id},
+ status=404, extra_environ=xhr_header)
- def test_index_page_on_group_with_trailing_slash(
- self, autologin_user, repo_group):
- response = self.app.get(route_path('repo_group_home', repo_group_name='gr1') + '/')
- response.mustcontain("gr1/repo_in_group")
+ def test_index_page_on_groups(self, autologin_user, user_util, xhr_header):
+ gr = user_util.create_repo_group()
+ repo = user_util.create_repo(parent=gr)
+ repo_name = repo.repo_name
+ group_id = gr.group_id
+
+ response = self.app.get(route_path(
+ 'repo_group_home', repo_group_name=gr.group_name))
+ response.mustcontain('d.repo_group_id = {}'.format(group_id))
- @pytest.fixture(scope='class')
- def repo_group(self, request):
- gr = fixture.create_repo_group('gr1')
- fixture.create_repo(name='gr1/repo_in_group', repo_group=gr)
+ response = self.app.get(
+ route_path('main_page_repos_data'),
+ params={'repo_group_id': group_id},
+ extra_environ=xhr_header,)
+ response.mustcontain(repo_name)
- @request.addfinalizer
- def cleanup():
- RepoModel().delete('gr1/repo_in_group')
- RepoGroupModel().delete(repo_group='gr1', force_delete=True)
- Session().commit()
+ def test_index_page_on_group_with_trailing_slash(self, autologin_user, user_util, xhr_header):
+ gr = user_util.create_repo_group()
+ repo = user_util.create_repo(parent=gr)
+ repo_name = repo.repo_name
+ group_id = gr.group_id
+
+ response = self.app.get(route_path(
+ 'repo_group_home', repo_group_name=gr.group_name+'/'))
+ response.mustcontain('d.repo_group_id = {}'.format(group_id))
+
+ response = self.app.get(
+ route_path('main_page_repos_data'),
+ params={'repo_group_id': group_id},
+ extra_environ=xhr_header, )
+ response.mustcontain(repo_name)
@pytest.mark.parametrize("name, state", [
('Disabled', False),
diff --git a/rhodecode/apps/home/views.py b/rhodecode/apps/home/views.py
--- a/rhodecode/apps/home/views.py
+++ b/rhodecode/apps/home/views.py
@@ -29,7 +29,7 @@ from rhodecode.apps._base import BaseApp
from rhodecode.lib import helpers as h
from rhodecode.lib.auth import (
LoginRequired, NotAnonymous, HasRepoGroupPermissionAnyDecorator, CSRFRequired,
- HasRepoGroupPermissionAny)
+ HasRepoGroupPermissionAny, AuthUser)
from rhodecode.lib.codeblocks import filenode_as_lines_tokens
from rhodecode.lib.index import searcher_from_config
from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int
@@ -723,7 +723,7 @@ class HomeView(BaseAppView, DataGridAppV
if repo_group_id:
group = RepoGroup.get_or_404(repo_group_id)
- _perms = ['group.read', 'group.write', 'group.admin']
+ _perms = AuthUser.repo_group_read_perms
if not HasRepoGroupPermissionAny(*_perms)(
group.group_name, 'user is allowed to list repo group children'):
raise HTTPNotFound()
@@ -740,7 +740,7 @@ class HomeView(BaseAppView, DataGridAppV
if repo_group_id:
group = RepoGroup.get_or_404(repo_group_id)
- _perms = ['group.read', 'group.write', 'group.admin']
+ _perms = AuthUser.repo_group_read_perms
if not HasRepoGroupPermissionAny(*_perms)(
group.group_name, 'user is allowed to list repo group children'):
raise HTTPNotFound()
@@ -748,8 +748,7 @@ class HomeView(BaseAppView, DataGridAppV
return self._main_page_repos_data(repo_group_id)
@LoginRequired()
- @HasRepoGroupPermissionAnyDecorator(
- 'group.read', 'group.write', 'group.admin')
+ @HasRepoGroupPermissionAnyDecorator(*AuthUser.repo_group_read_perms)
@view_config(
route_name='repo_group_home', request_method='GET',
renderer='rhodecode:templates/index_repo_group.mako')
diff --git a/rhodecode/apps/login/tests/test_login.py b/rhodecode/apps/login/tests/test_login.py
--- a/rhodecode/apps/login/tests/test_login.py
+++ b/rhodecode/apps/login/tests/test_login.py
@@ -93,7 +93,7 @@ class TestLoginController(object):
session = response.get_session_from_response()
username = session['rhodecode_user'].get('username')
assert username == 'test_admin'
- response.mustcontain('/%s' % HG_REPO)
+ response.mustcontain('logout')
def test_login_regular_ok(self):
response = self.app.post(route_path('login'),
@@ -104,8 +104,7 @@ class TestLoginController(object):
session = response.get_session_from_response()
username = session['rhodecode_user'].get('username')
assert username == 'test_regular'
-
- response.mustcontain('/%s' % HG_REPO)
+ response.mustcontain('logout')
def test_login_regular_forbidden_when_super_admin_restriction(self):
from rhodecode.authentication.plugins.auth_rhodecode import RhodeCodeAuthPlugin
@@ -225,7 +224,7 @@ class TestLoginController(object):
session = response.get_session_from_response()
username = session['rhodecode_user'].get('username')
assert username == temp_user
- response.mustcontain('/%s' % HG_REPO)
+ response.mustcontain('logout')
# new password should be bcrypted, after log-in and transfer
user = User.get_by_username(temp_user)
diff --git a/rhodecode/tests/functional/test_delegated_admin.py b/rhodecode/tests/functional/test_delegated_admin.py
--- a/rhodecode/tests/functional/test_delegated_admin.py
+++ b/rhodecode/tests/functional/test_delegated_admin.py
@@ -33,6 +33,8 @@ def route_path(name, params=None, **kwar
'admin_home': ADMIN_PREFIX,
'repos':
ADMIN_PREFIX + '/repos',
+ 'repos_data':
+ ADMIN_PREFIX + '/repos_data',
'repo_groups':
ADMIN_PREFIX + '/repo_groups',
'repo_groups_data':
@@ -62,8 +64,9 @@ class TestAdminDelegatedUser(TestControl
# user doesn't have any access to resources so main admin page should 404
self.app.get(route_path('admin_home'), status=404)
- response = self.app.get(route_path('repos'), status=200)
- response.mustcontain('data: []')
+ response = self.app.get(route_path('repos_data'),
+ status=200, extra_environ=xhr_header)
+ assert response.json['data'] == []
response = self.app.get(route_path('repo_groups_data'),
status=200, extra_environ=xhr_header)
@@ -97,16 +100,17 @@ class TestAdminDelegatedUser(TestControl
assert_response.element_contains('td.delegated-admin-user-groups', '1')
# admin interfaces have visible elements
- response = self.app.get(route_path('repos'), status=200)
- response.mustcontain('"name_raw": "{}"'.format(repo_name))
+ response = self.app.get(route_path('repos_data'),
+ extra_environ=xhr_header, status=200)
+ response.mustcontain(''.format(repo_name))
response = self.app.get(route_path('repo_groups_data'),
extra_environ=xhr_header, status=200)
- response.mustcontain('"name_raw": "{}"'.format(repo_group_name))
+ response.mustcontain(''.format(repo_group_name))
response = self.app.get(route_path('user_groups_data'),
extra_environ=xhr_header, status=200)
- response.mustcontain('"name_raw": "{}"'.format(user_group_name))
+ response.mustcontain(''.format(user_group_name))
def test_regular_user_can_see_admin_interfaces_if_admin_perm(
self, user_util, xhr_header):
@@ -140,13 +144,14 @@ class TestAdminDelegatedUser(TestControl
assert_response.element_contains('td.delegated-admin-user-groups', '1')
# admin interfaces have visible elements
- response = self.app.get(route_path('repos'), status=200)
- response.mustcontain('"name_raw": "{}"'.format(repo_name))
+ response = self.app.get(route_path('repos_data'),
+ extra_environ=xhr_header, status=200)
+ response.mustcontain(''.format(repo_name))
response = self.app.get(route_path('repo_groups_data'),
extra_environ=xhr_header, status=200)
- response.mustcontain('"name_raw": "{}"'.format(repo_group_name))
+ response.mustcontain(''.format(repo_group_name))
response = self.app.get(route_path('user_groups_data'),
extra_environ=xhr_header, status=200)
- response.mustcontain('"name_raw": "{}"'.format(user_group_name))
+ response.mustcontain(''.format(user_group_name))