Public user group profile Task #5326
This commit is contained in:
parent
a1a6ad26bc
commit
40434929a5
12 changed files with 309 additions and 6 deletions
27
rhodecode/apps/user_group_profile/__init__.py
Normal file
27
rhodecode/apps/user_group_profile/__init__.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2016-2018 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/
|
||||
|
||||
|
||||
def includeme(config):
|
||||
config.add_route(
|
||||
name='user_group_profile',
|
||||
pattern='/_profile_user_group/{user_group_name}')
|
||||
# Scan module for configuration decorators.
|
||||
config.scan('.views', ignore='.tests')
|
||||
19
rhodecode/apps/user_group_profile/tests/__init__.py
Normal file
19
rhodecode/apps/user_group_profile/tests/__init__.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2016-2018 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/
|
||||
76
rhodecode/apps/user_group_profile/tests/test_user_group.py
Normal file
76
rhodecode/apps/user_group_profile/tests/test_user_group.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2010-2018 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/
|
||||
from rhodecode.model.user_group import UserGroupModel
|
||||
from rhodecode.tests import (
|
||||
TestController, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
|
||||
from rhodecode.tests.fixture import Fixture
|
||||
from rhodecode.tests.utils import AssertResponse
|
||||
|
||||
fixture = Fixture()
|
||||
|
||||
|
||||
def route_path(name, **kwargs):
|
||||
return '/_profile_user_group/{user_group_name}'.format(**kwargs)
|
||||
|
||||
|
||||
class TestUsersController(TestController):
|
||||
|
||||
def test_user_group_profile(self, user_util):
|
||||
self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
|
||||
user, usergroup = user_util.create_user_with_group()
|
||||
|
||||
response = self.app.get(route_path('profile_user_group', user_group_name=usergroup.users_group_name))
|
||||
response.mustcontain(usergroup.users_group_name)
|
||||
response.mustcontain(user.username)
|
||||
|
||||
def test_user_can_check_own_group(self, user_util):
|
||||
user = user_util.create_user(
|
||||
TEST_USER_REGULAR_LOGIN, password=TEST_USER_REGULAR_PASS, email='testme@rhodecode.org')
|
||||
self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
|
||||
usergroup = user_util.create_user_group(owner=user)
|
||||
response = self.app.get(route_path('profile_user_group', user_group_name=usergroup.users_group_name))
|
||||
response.mustcontain(usergroup.users_group_name)
|
||||
response.mustcontain(user.username)
|
||||
|
||||
def test_user_can_not_check_other_group(self, user_util):
|
||||
self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
|
||||
user_group = user_util.create_user_group()
|
||||
UserGroupModel().grant_user_permission(user_group, self._get_logged_user(), 'usergroup.none')
|
||||
response = self.app.get(route_path('profile_user_group', user_group_name=user_group.users_group_name), status=404)
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_another_user_can_check_if_he_is_in_group(self, user_util):
|
||||
self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
|
||||
user = user_util.create_user(
|
||||
'test-my-user', password='qweqwe', email='testme@rhodecode.org')
|
||||
user_group = user_util.create_user_group()
|
||||
UserGroupModel().add_user_to_group(user_group, user)
|
||||
UserGroupModel().grant_user_permission(user_group, self._get_logged_user(), 'usergroup.read')
|
||||
response = self.app.get(route_path('profile_user_group', user_group_name=user_group.users_group_name))
|
||||
response.mustcontain(user_group.users_group_name)
|
||||
response.mustcontain(user.username)
|
||||
|
||||
def test_with_anonymous_user(self, user_util):
|
||||
user = user_util.create_user(
|
||||
'test-my-user', password='qweqwe', email='testme@rhodecode.org')
|
||||
user_group = user_util.create_user_group()
|
||||
UserGroupModel().add_user_to_group(user_group, user)
|
||||
response = self.app.get(route_path('profile_user_group', user_group_name=user_group.users_group_name), status=302)
|
||||
assert response.status_code == 302
|
||||
53
rhodecode/apps/user_group_profile/views.py
Normal file
53
rhodecode/apps/user_group_profile/views.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2016-2018 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 logging
|
||||
|
||||
from pyramid.httpexceptions import HTTPNotFound
|
||||
from pyramid.view import view_config
|
||||
|
||||
from rhodecode.apps._base import BaseAppView
|
||||
from rhodecode.lib.auth import HasUserGroupPermissionAnyDecorator, LoginRequired, NotAnonymous
|
||||
from rhodecode.model.db import UserGroup, User
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class UserGroupProfileView(BaseAppView):
|
||||
|
||||
@LoginRequired()
|
||||
@NotAnonymous()
|
||||
@HasUserGroupPermissionAnyDecorator('usergroup.read', 'usergroup.write', 'usergroup.admin',)
|
||||
@view_config(
|
||||
route_name='user_group_profile', request_method='GET',
|
||||
renderer='rhodecode:templates/user_group/user_group.mako')
|
||||
def user_group_profile(self):
|
||||
c = self._get_local_tmpl_context()
|
||||
c.active = 'profile'
|
||||
self.db_user_group_name = self.request.matchdict.get('user_group_name')
|
||||
c.user_group = UserGroup().get_by_group_name(self.db_user_group_name)
|
||||
if not c.user_group:
|
||||
raise HTTPNotFound()
|
||||
group_members_obj = sorted((x.user for x in c.user_group.members),
|
||||
key=lambda u: u.username.lower())
|
||||
c.group_members = group_members_obj
|
||||
c.anonymous = self._rhodecode_user.username == User.DEFAULT_USER
|
||||
return self._get_template_context(c)
|
||||
Loading…
Add table
Add a link
Reference in a new issue