Changeset - 88d13c1c6a55
[Not reviewed]
beta
1 5 0
Marcin Kuzminski - 14 years ago 2011-07-20 01:47:56
marcin@python-works.com
removed users_group controller in replace for model methods,
fixed tests
6 files changed with 148 insertions and 141 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/users_groups.py
Show inline comments
 
@@ -39,7 +39,6 @@ from rhodecode.lib.base import BaseContr
 

	
 
from rhodecode.model.db import User, UsersGroup, Permission, UsersGroupToPerm
 
from rhodecode.model.forms import UserForm, UsersGroupForm
 
from rhodecode.model.users_group import UsersGroupModel
 

	
 
log = logging.getLogger(__name__)
 

	
 
@@ -67,11 +66,11 @@ class UsersGroupsController(BaseControll
 
    def create(self):
 
        """POST /users_groups: Create a new item"""
 
        # url('users_groups')
 
        users_group_model = UsersGroupModel()
 

	
 
        users_group_form = UsersGroupForm()()
 
        try:
 
            form_result = users_group_form.to_python(dict(request.POST))
 
            users_group_model.create(form_result)
 
            UsersGroup.create(form_result)
 
            h.flash(_('created users group %s') \
 
                    % form_result['users_group_name'], category='success')
 
            #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
 
@@ -103,8 +102,7 @@ class UsersGroupsController(BaseControll
 
        #           method='put')
 
        # url('users_group', id=ID)
 

	
 
        users_group_model = UsersGroupModel()
 
        c.users_group = users_group_model.get(id)
 
        c.users_group = UsersGroup.get(id)
 
        c.group_members = [(x.user_id, x.user.username) for x in
 
                           c.users_group.members]
 

	
 
@@ -117,7 +115,7 @@ class UsersGroupsController(BaseControll
 

	
 
        try:
 
            form_result = users_group_form.to_python(request.POST)
 
            users_group_model.update(id, form_result)
 
            UsersGroup.update(id, form_result)
 
            h.flash(_('updated users group %s') \
 
                        % form_result['users_group_name'],
 
                    category='success')
 
@@ -150,9 +148,9 @@ class UsersGroupsController(BaseControll
 
        #    h.form(url('users_group', id=ID),
 
        #           method='delete')
 
        # url('users_group', id=ID)
 
        users_group_model = UsersGroupModel()
 

	
 
        try:
 
            users_group_model.delete(id)
 
            UsersGroup.delete(id)
 
            h.flash(_('successfully deleted users group'), category='success')
 
        except UsersGroupsAssignedException, e:
 
            h.flash(e, category='error')
rhodecode/model/db.py
Show inline comments
 
@@ -42,6 +42,7 @@ from vcs.exceptions import RepositoryErr
 
from vcs.utils.lazy import LazyProperty
 
from vcs.nodes import FileNode
 

	
 
from rhodecode.lib.exceptions import UsersGroupsAssignedException
 
from rhodecode.lib import str2bool, json, safe_str
 
from rhodecode.model.meta import Base, Session
 
from rhodecode.model.caching_query import FromCache
 
@@ -302,6 +303,77 @@ class UsersGroup(Base, BaseModel):
 
                                          "get_user_%s" % group_name))
 
        return gr.scalar()
 

	
 

	
 
    @classmethod
 
    def get(cls, users_group_id, cache=False):
 
        users_group = Session.query(cls)
 
        if cache:
 
            users_group = users_group.options(FromCache("sql_cache_short",
 
                                    "get_users_group_%s" % users_group_id))
 
        return users_group.get(users_group_id)
 

	
 
    @classmethod
 
    def create(cls, form_data):
 
        try:
 
            new_users_group = cls()
 
            for k, v in form_data.items():
 
                setattr(new_users_group, k, v)
 

	
 
            Session.add(new_users_group)
 
            Session.commit()
 
        except:
 
            log.error(traceback.format_exc())
 
            Session.rollback()
 
            raise
 

	
 
    @classmethod
 
    def update(cls, users_group_id, form_data):
 

	
 
        try:
 
            users_group = cls.get(users_group_id, cache=False)
 

	
 
            for k, v in form_data.items():
 
                if k == 'users_group_members':
 
                    users_group.members = []
 
                    Session.flush()
 
                    members_list = []
 
                    if v:
 
                        for u_id in set(v):
 
                            members_list.append(UsersGroupMember(
 
                                                            users_group_id,
 
                                                            u_id))
 
                    setattr(users_group, 'members', members_list)
 
                setattr(users_group, k, v)
 

	
 
            Session.add(users_group)
 
            Session.commit()
 
        except:
 
            log.error(traceback.format_exc())
 
            Session.rollback()
 
            raise
 

	
 
    @classmethod
 
    def delete(cls, users_group_id):
 
        try:
 

	
 
            # check if this group is not assigned to repo
 
            assigned_groups = UsersGroupRepoToPerm.query()\
 
                .filter(UsersGroupRepoToPerm.users_group_id ==
 
                        users_group_id).all()
 

	
 
            if assigned_groups:
 
                raise UsersGroupsAssignedException('Group assigned to %s' %
 
                                                   assigned_groups)
 

	
 
            users_group = cls.get(users_group_id, cache=False)
 
            Session.delete(users_group)
 
            Session.commit()
 
        except:
 
            log.error(traceback.format_exc())
 
            Session.rollback()
 
            raise
 

	
 

	
 
class UsersGroupMember(Base, BaseModel):
 
    __tablename__ = 'users_groups_members'
 
    __table_args__ = {'extend_existing':True}
rhodecode/model/users_group.py
Show inline comments
 
deleted file
rhodecode/templates/changelog/changelog.html
Show inline comments
 
@@ -60,10 +60,7 @@ ${c.repo_name} ${_('Changelog')} - ${c.r
 
						</div>	
 
						<div class="right">
 
									<div id="${cs.raw_id}_changes_info" class="changes">
 
                                        <span id="${cs.raw_id}" class="changed_total tooltip" 
 
                                        title="${_('Affected number of files, click to show more details')}">
 
                                        ${len(cs.affected_files)}
 
                                        </span>
 
                                        <span id="${cs.raw_id}" class="changed_total tooltip" title="${_('Affected number of files, click to show more details')}">${len(cs.affected_files)}</span>
 
									</div>					
 
										%if len(cs.parents)>1:
 
										<div class="merge">
rhodecode/tests/functional/test_admin_users_groups.py
Show inline comments
 
from rhodecode.tests import *
 
from rhodecode.model.db import UsersGroup
 

	
 
TEST_USERS_GROUP = 'admins_test'
 

	
 
@@ -36,13 +37,37 @@ class TestAdminUsersGroupsController(Tes
 
        response = self.app.put(url('users_group', id=1))
 

	
 
    def test_update_browser_fakeout(self):
 
        response = self.app.post(url('users_group', id=1), params=dict(_method='put'))
 
        response = self.app.post(url('users_group', id=1),
 
                                 params=dict(_method='put'))
 

	
 
    def test_delete(self):
 
        response = self.app.delete(url('users_group', id=1))
 
        self.log_user()
 
        users_group_name = TEST_USERS_GROUP + 'another'
 
        response = self.app.post(url('users_groups'),
 
                                 {'users_group_name':users_group_name,
 
                                  'active':True})
 
        response.follow()
 

	
 
        self.checkSessionFlash(response,
 
                               'created users group %s' % users_group_name)
 

	
 

	
 
        gr = self.sa.query(UsersGroup)\
 
                           .filter(UsersGroup.users_group_name ==
 
                                   users_group_name).one()
 

	
 
        response = self.app.delete(url('users_group', id=gr.users_group_id))
 

	
 
        gr = self.sa.query(UsersGroup)\
 
                           .filter(UsersGroup.users_group_name ==
 
                                   users_group_name).scalar()
 

	
 
        self.assertEqual(gr, None)
 

	
 

	
 
    def test_delete_browser_fakeout(self):
 
        response = self.app.post(url('users_group', id=1), params=dict(_method='delete'))
 
        response = self.app.post(url('users_group', id=1),
 
                                 params=dict(_method='delete'))
 

	
 
    def test_show(self):
 
        response = self.app.get(url('users_group', id=1))
rhodecode/tests/functional/test_changelog.py
Show inline comments
 
@@ -4,35 +4,55 @@ class TestChangelogController(TestContro
 

	
 
    def test_index_hg(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO))
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=HG_REPO))
 

	
 
        assert """<div id="chg_20" class="container">""" in response.body, 'wrong info about number of changes'
 
        assert """<input class="changeset_range" id="5e204e7583b9" name="5e204e7583b9" type="checkbox" value="1" />""" in response.body, 'no checkbox for this commit'
 
        assert """<span>commit 154: 5e204e7583b9@2010-08-10 01:18:46</span>""" in response.body , 'no info on this commit'
 
        assert """Small update at simplevcs app""" in response.body, 'missing info about commit message'
 
        self.assertTrue("""<div id="chg_20" class="container">"""
 
                        in response.body)
 
        self.assertTrue("""<input class="changeset_range" id="5e204e7583b9" """
 
                        """name="5e204e7583b9" type="checkbox" value="1" />"""
 
                        in response.body)
 
        self.assertTrue("""<span>commit 154: 5e204e7583b9@2010-08-10 """
 
                        """01:18:46</span>""" in response.body)
 
        self.assertTrue("""Small update at simplevcs app""" in response.body)
 

	
 
        assert """<span class="removed tooltip" title="<b>removed</b>: No Files">0</span>""" in response.body, 'wrong info about removed nodes'
 
        assert """<span class="changed tooltip" title="<b>changed</b>: <br/> vcs/backends/hg.py<br/> vcs/web/simplevcs/models.py">2</span>""" in response.body, 'wrong info about changed nodes'
 
        assert """<span class="added tooltip" title="<b>added</b>: <br/> vcs/web/simplevcs/managers.py">1</span>""" in response.body, 'wrong info about added nodes'
 

	
 
        self.assertTrue("""<span id="5e204e7583b9c8e7b93a020bd036564b1e"""
 
                        """731dae" class="changed_total tooltip" """
 
                        """title="Affected number of files, click to """
 
                        """show more details">3</span>""" in response.body)
 

	
 
        #pagination
 

	
 
        response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':1})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':2})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':3})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':4})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':5})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':6})
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=HG_REPO), {'page':1})
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=HG_REPO), {'page':2})
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=HG_REPO), {'page':3})
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=HG_REPO), {'page':4})
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=HG_REPO), {'page':5})
 
        response = self.app.get(url(controller='changelog', action='index',
 
                                    repo_name=HG_REPO), {'page':6})
 

	
 

	
 
        # Test response after pagination...
 
        print response.body
 
        assert """<input class="changeset_range" id="46ad32a4f974" name="46ad32a4f974" type="checkbox" value="1" />""" in response.body, 'no checkbox for this commit'
 
        assert """<span>commit 64: 46ad32a4f974@2010-04-20 00:33:21</span>"""in response.body, 'wrong info about commit 64'
 
        assert """<span class="removed tooltip" title="<b>removed</b>: <br/> docs/api.rst">1</span>"""in response.body, 'wrong info about number of removed'
 
        assert """<span class="changed tooltip" title="<b>changed</b>: <br/> .hgignore<br/> README.rst<br/> docs/conf.py<br/> docs/index.rst<br/> setup.py<br/> tests/test_hg.py<br/> tests/test_nodes.py<br/> vcs/__init__.py<br/> vcs/backends/__init__.py<br/> vcs/backends/base.py<br/> vcs/backends/hg.py<br/> vcs/nodes.py<br/> vcs/utils/__init__.py">13</span>"""in response.body, 'wrong info about number of changes'
 
        assert """<span class="added tooltip" title="<b>added</b>: <br/> docs/api/backends/hg.rst<br/> docs/api/backends/index.rst<br/> docs/api/index.rst<br/> docs/api/nodes.rst<br/> docs/api/web/index.rst<br/> docs/api/web/simplevcs.rst<br/> docs/installation.rst<br/> docs/quickstart.rst<br/> setup.cfg<br/> vcs/utils/baseui_config.py<br/> vcs/utils/web.py<br/> vcs/web/__init__.py<br/> vcs/web/exceptions.py<br/> vcs/web/simplevcs/__init__.py<br/> vcs/web/simplevcs/exceptions.py<br/> vcs/web/simplevcs/middleware.py<br/> vcs/web/simplevcs/models.py<br/> vcs/web/simplevcs/settings.py<br/> vcs/web/simplevcs/utils.py<br/> vcs/web/simplevcs/views.py">20</span>"""in response.body, 'wrong info about number of added'
 
        assert """<div class="message"><a href="/%s/changeset/46ad32a4f974e45472a898c6b0acb600320579b1">Merge with 2e6a2bf9356ca56df08807f4ad86d480da72a8f4</a></div>""" % HG_REPO in response.body, 'wrong info about commit 64 is a merge'
 
        self.assertTrue("""<input class="changeset_range" id="46ad32a4f974" """
 
                        """name="46ad32a4f974" type="checkbox" value="1" />"""
 
                        in response.body)
 
        self.assertTrue("""<span>commit 64: 46ad32a4f974@2010-04-20"""
 
                        """ 00:33:21</span>"""in response.body)
 

	
 
        self.assertTrue("""<span id="46ad32a4f974e45472a898c6b0acb600320"""
 
                        """579b1" class="changed_total tooltip" """
 
                        """title="Affected number of files, click to """
 
                        """show more details">21</span>"""in response.body)
 
        self.assertTrue("""<div class="message"><a href="/%s/changeset/"""
 
                        """46ad32a4f974e45472a898c6b0acb600320579b1">"""
 
                        """Merge with 2e6a2bf9356ca56df08807f4ad86d48"""
 
                        """0da72a8f4</a></div>""" % HG_REPO in response.body)
 

	
 

	
 

	
0 comments (0 inline, 0 general)