##// END OF EJS Templates
removed users_group controller in replace for model methods,...
marcink -
r1436:88d13c1c beta
parent child Browse files
Show More
@@ -39,7 +39,6 b' from rhodecode.lib.base import BaseContr'
39 39
40 40 from rhodecode.model.db import User, UsersGroup, Permission, UsersGroupToPerm
41 41 from rhodecode.model.forms import UserForm, UsersGroupForm
42 from rhodecode.model.users_group import UsersGroupModel
43 42
44 43 log = logging.getLogger(__name__)
45 44
@@ -67,11 +66,11 b' class UsersGroupsController(BaseControll'
67 66 def create(self):
68 67 """POST /users_groups: Create a new item"""
69 68 # url('users_groups')
70 users_group_model = UsersGroupModel()
69
71 70 users_group_form = UsersGroupForm()()
72 71 try:
73 72 form_result = users_group_form.to_python(dict(request.POST))
74 users_group_model.create(form_result)
73 UsersGroup.create(form_result)
75 74 h.flash(_('created users group %s') \
76 75 % form_result['users_group_name'], category='success')
77 76 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
@@ -103,8 +102,7 b' class UsersGroupsController(BaseControll'
103 102 # method='put')
104 103 # url('users_group', id=ID)
105 104
106 users_group_model = UsersGroupModel()
107 c.users_group = users_group_model.get(id)
105 c.users_group = UsersGroup.get(id)
108 106 c.group_members = [(x.user_id, x.user.username) for x in
109 107 c.users_group.members]
110 108
@@ -117,7 +115,7 b' class UsersGroupsController(BaseControll'
117 115
118 116 try:
119 117 form_result = users_group_form.to_python(request.POST)
120 users_group_model.update(id, form_result)
118 UsersGroup.update(id, form_result)
121 119 h.flash(_('updated users group %s') \
122 120 % form_result['users_group_name'],
123 121 category='success')
@@ -150,9 +148,9 b' class UsersGroupsController(BaseControll'
150 148 # h.form(url('users_group', id=ID),
151 149 # method='delete')
152 150 # url('users_group', id=ID)
153 users_group_model = UsersGroupModel()
151
154 152 try:
155 users_group_model.delete(id)
153 UsersGroup.delete(id)
156 154 h.flash(_('successfully deleted users group'), category='success')
157 155 except UsersGroupsAssignedException, e:
158 156 h.flash(e, category='error')
@@ -42,6 +42,7 b' from vcs.exceptions import RepositoryErr'
42 42 from vcs.utils.lazy import LazyProperty
43 43 from vcs.nodes import FileNode
44 44
45 from rhodecode.lib.exceptions import UsersGroupsAssignedException
45 46 from rhodecode.lib import str2bool, json, safe_str
46 47 from rhodecode.model.meta import Base, Session
47 48 from rhodecode.model.caching_query import FromCache
@@ -302,6 +303,77 b' class UsersGroup(Base, BaseModel):'
302 303 "get_user_%s" % group_name))
303 304 return gr.scalar()
304 305
306
307 @classmethod
308 def get(cls, users_group_id, cache=False):
309 users_group = Session.query(cls)
310 if cache:
311 users_group = users_group.options(FromCache("sql_cache_short",
312 "get_users_group_%s" % users_group_id))
313 return users_group.get(users_group_id)
314
315 @classmethod
316 def create(cls, form_data):
317 try:
318 new_users_group = cls()
319 for k, v in form_data.items():
320 setattr(new_users_group, k, v)
321
322 Session.add(new_users_group)
323 Session.commit()
324 except:
325 log.error(traceback.format_exc())
326 Session.rollback()
327 raise
328
329 @classmethod
330 def update(cls, users_group_id, form_data):
331
332 try:
333 users_group = cls.get(users_group_id, cache=False)
334
335 for k, v in form_data.items():
336 if k == 'users_group_members':
337 users_group.members = []
338 Session.flush()
339 members_list = []
340 if v:
341 for u_id in set(v):
342 members_list.append(UsersGroupMember(
343 users_group_id,
344 u_id))
345 setattr(users_group, 'members', members_list)
346 setattr(users_group, k, v)
347
348 Session.add(users_group)
349 Session.commit()
350 except:
351 log.error(traceback.format_exc())
352 Session.rollback()
353 raise
354
355 @classmethod
356 def delete(cls, users_group_id):
357 try:
358
359 # check if this group is not assigned to repo
360 assigned_groups = UsersGroupRepoToPerm.query()\
361 .filter(UsersGroupRepoToPerm.users_group_id ==
362 users_group_id).all()
363
364 if assigned_groups:
365 raise UsersGroupsAssignedException('Group assigned to %s' %
366 assigned_groups)
367
368 users_group = cls.get(users_group_id, cache=False)
369 Session.delete(users_group)
370 Session.commit()
371 except:
372 log.error(traceback.format_exc())
373 Session.rollback()
374 raise
375
376
305 377 class UsersGroupMember(Base, BaseModel):
306 378 __tablename__ = 'users_groups_members'
307 379 __table_args__ = {'extend_existing':True}
@@ -60,10 +60,7 b''
60 60 </div>
61 61 <div class="right">
62 62 <div id="${cs.raw_id}_changes_info" class="changes">
63 <span id="${cs.raw_id}" class="changed_total tooltip"
64 title="${_('Affected number of files, click to show more details')}">
65 ${len(cs.affected_files)}
66 </span>
63 <span id="${cs.raw_id}" class="changed_total tooltip" title="${_('Affected number of files, click to show more details')}">${len(cs.affected_files)}</span>
67 64 </div>
68 65 %if len(cs.parents)>1:
69 66 <div class="merge">
@@ -1,4 +1,5 b''
1 1 from rhodecode.tests import *
2 from rhodecode.model.db import UsersGroup
2 3
3 4 TEST_USERS_GROUP = 'admins_test'
4 5
@@ -36,13 +37,37 b' class TestAdminUsersGroupsController(Tes'
36 37 response = self.app.put(url('users_group', id=1))
37 38
38 39 def test_update_browser_fakeout(self):
39 response = self.app.post(url('users_group', id=1), params=dict(_method='put'))
40 response = self.app.post(url('users_group', id=1),
41 params=dict(_method='put'))
40 42
41 43 def test_delete(self):
42 response = self.app.delete(url('users_group', id=1))
44 self.log_user()
45 users_group_name = TEST_USERS_GROUP + 'another'
46 response = self.app.post(url('users_groups'),
47 {'users_group_name':users_group_name,
48 'active':True})
49 response.follow()
50
51 self.checkSessionFlash(response,
52 'created users group %s' % users_group_name)
53
54
55 gr = self.sa.query(UsersGroup)\
56 .filter(UsersGroup.users_group_name ==
57 users_group_name).one()
58
59 response = self.app.delete(url('users_group', id=gr.users_group_id))
60
61 gr = self.sa.query(UsersGroup)\
62 .filter(UsersGroup.users_group_name ==
63 users_group_name).scalar()
64
65 self.assertEqual(gr, None)
66
43 67
44 68 def test_delete_browser_fakeout(self):
45 response = self.app.post(url('users_group', id=1), params=dict(_method='delete'))
69 response = self.app.post(url('users_group', id=1),
70 params=dict(_method='delete'))
46 71
47 72 def test_show(self):
48 73 response = self.app.get(url('users_group', id=1))
@@ -4,35 +4,55 b' class TestChangelogController(TestContro'
4 4
5 5 def test_index_hg(self):
6 6 self.log_user()
7 response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO))
7 response = self.app.get(url(controller='changelog', action='index',
8 repo_name=HG_REPO))
8 9
9 assert """<div id="chg_20" class="container">""" in response.body, 'wrong info about number of changes'
10 assert """<input class="changeset_range" id="5e204e7583b9" name="5e204e7583b9" type="checkbox" value="1" />""" in response.body, 'no checkbox for this commit'
11 assert """<span>commit 154: 5e204e7583b9@2010-08-10 01:18:46</span>""" in response.body , 'no info on this commit'
12 assert """Small update at simplevcs app""" in response.body, 'missing info about commit message'
10 self.assertTrue("""<div id="chg_20" class="container">"""
11 in response.body)
12 self.assertTrue("""<input class="changeset_range" id="5e204e7583b9" """
13 """name="5e204e7583b9" type="checkbox" value="1" />"""
14 in response.body)
15 self.assertTrue("""<span>commit 154: 5e204e7583b9@2010-08-10 """
16 """01:18:46</span>""" in response.body)
17 self.assertTrue("""Small update at simplevcs app""" in response.body)
13 18
14 assert """<span class="removed tooltip" title="<b>removed</b>: No Files">0</span>""" in response.body, 'wrong info about removed nodes'
15 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'
16 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'
19
20 self.assertTrue("""<span id="5e204e7583b9c8e7b93a020bd036564b1e"""
21 """731dae" class="changed_total tooltip" """
22 """title="Affected number of files, click to """
23 """show more details">3</span>""" in response.body)
17 24
18 25 #pagination
19 26
20 response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':1})
21 response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':2})
22 response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':3})
23 response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':4})
24 response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':5})
25 response = self.app.get(url(controller='changelog', action='index', repo_name=HG_REPO), {'page':6})
27 response = self.app.get(url(controller='changelog', action='index',
28 repo_name=HG_REPO), {'page':1})
29 response = self.app.get(url(controller='changelog', action='index',
30 repo_name=HG_REPO), {'page':2})
31 response = self.app.get(url(controller='changelog', action='index',
32 repo_name=HG_REPO), {'page':3})
33 response = self.app.get(url(controller='changelog', action='index',
34 repo_name=HG_REPO), {'page':4})
35 response = self.app.get(url(controller='changelog', action='index',
36 repo_name=HG_REPO), {'page':5})
37 response = self.app.get(url(controller='changelog', action='index',
38 repo_name=HG_REPO), {'page':6})
26 39
27 40
28 41 # Test response after pagination...
29 print response.body
30 assert """<input class="changeset_range" id="46ad32a4f974" name="46ad32a4f974" type="checkbox" value="1" />""" in response.body, 'no checkbox for this commit'
31 assert """<span>commit 64: 46ad32a4f974@2010-04-20 00:33:21</span>"""in response.body, 'wrong info about commit 64'
32 assert """<span class="removed tooltip" title="<b>removed</b>: <br/> docs/api.rst">1</span>"""in response.body, 'wrong info about number of removed'
33 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'
34 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'
35 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'
42 self.assertTrue("""<input class="changeset_range" id="46ad32a4f974" """
43 """name="46ad32a4f974" type="checkbox" value="1" />"""
44 in response.body)
45 self.assertTrue("""<span>commit 64: 46ad32a4f974@2010-04-20"""
46 """ 00:33:21</span>"""in response.body)
47
48 self.assertTrue("""<span id="46ad32a4f974e45472a898c6b0acb600320"""
49 """579b1" class="changed_total tooltip" """
50 """title="Affected number of files, click to """
51 """show more details">21</span>"""in response.body)
52 self.assertTrue("""<div class="message"><a href="/%s/changeset/"""
53 """46ad32a4f974e45472a898c6b0acb600320579b1">"""
54 """Merge with 2e6a2bf9356ca56df08807f4ad86d48"""
55 """0da72a8f4</a></div>""" % HG_REPO in response.body)
36 56
37 57
38 58
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now