##// END OF EJS Templates
commit less models...
marcink -
r1749:8ecc6b82 beta
parent child Browse files
Show More
@@ -102,7 +102,7 b' class PermissionsController(BaseControll'
102 102 form_result = _form.to_python(dict(request.POST))
103 103 form_result.update({'perm_user_name': id})
104 104 permission_model.update(form_result)
105 Session().commit()
105 Session.commit()
106 106 h.flash(_('Default permissions updated successfully'),
107 107 category='success')
108 108
@@ -150,7 +150,7 b' class ReposController(BaseController):'
150 150 else:
151 151 action_logger(self.rhodecode_user, 'admin_created_repo',
152 152 form_result['repo_name_full'], '', self.sa)
153 Session().commit()
153 Session.commit()
154 154 except formencode.Invalid, errors:
155 155
156 156 c.new_repo = errors.value['repo_name']
@@ -208,7 +208,7 b' class ReposController(BaseController):'
208 208 changed_name = repo.repo_name
209 209 action_logger(self.rhodecode_user, 'admin_updated_repo',
210 210 changed_name, '', self.sa)
211 Session().commit()
211 Session.commit()
212 212 except formencode.Invalid, errors:
213 213 defaults = self.__load_data(repo_name)
214 214 defaults.update(errors.value)
@@ -252,7 +252,7 b' class ReposController(BaseController):'
252 252 repo_model.delete(repo)
253 253 invalidate_cache('get_repo_cached_%s' % repo_name)
254 254 h.flash(_('deleted repository %s') % repo_name, category='success')
255 Session().commit()
255 Session.commit()
256 256 except IntegrityError, e:
257 257 if e.message.find('repositories_fork_id_fkey'):
258 258 log.error(traceback.format_exc())
@@ -71,7 +71,7 b' class ReposGroupsController(BaseControll'
71 71 try:
72 72 form_result = repos_group_form.to_python(dict(request.POST))
73 73 ReposGroupModel().create(form_result)
74 Session().commit()
74 Session.commit()
75 75 h.flash(_('created repos group %s') \
76 76 % form_result['group_name'], category='success')
77 77 #TODO: in futureaction_logger(, '', '', '', self.sa)
@@ -118,7 +118,7 b' class ReposGroupsController(BaseControll'
118 118 try:
119 119 form_result = repos_group_form.to_python(dict(request.POST))
120 120 ReposGroupModel().update(id, form_result)
121 Session().commit()
121 Session.commit()
122 122 h.flash(_('updated repos group %s') \
123 123 % form_result['group_name'], category='success')
124 124 #TODO: in futureaction_logger(, '', '', '', self.sa)
@@ -158,7 +158,7 b' class ReposGroupsController(BaseControll'
158 158
159 159 try:
160 160 ReposGroupModel().delete(id)
161 Session().commit()
161 Session.commit()
162 162 h.flash(_('removed repos group %s' % gr.group_name), category='success')
163 163 #TODO: in future action_logger(, '', '', '', self.sa)
164 164 except IntegrityError, e:
@@ -48,6 +48,7 b' from rhodecode.model.scm import ScmModel'
48 48 from rhodecode.model.user import UserModel
49 49 from rhodecode.model.db import User
50 50 from rhodecode.model.notification import EmailNotificationModel
51 from rhodecode.model.meta import Session
51 52
52 53 log = logging.getLogger(__name__)
53 54
@@ -247,7 +248,7 b' class SettingsController(BaseController)'
247 248
248 249 if update:
249 250 h.flash(_('Updated hooks'), category='success')
250
251 Session.commit()
251 252 except:
252 253 log.error(traceback.format_exc())
253 254 h.flash(_('error occurred during hook creation'),
@@ -353,7 +354,7 b' class SettingsController(BaseController)'
353 354 user_model.update_my_account(uid, form_result)
354 355 h.flash(_('Your account was updated successfully'),
355 356 category='success')
356
357 Session.commit()
357 358 except formencode.Invalid, errors:
358 359 c.user = User.get(self.rhodecode_user.user_id)
359 360 all_repos = self.sa.query(Repository)\
@@ -41,6 +41,7 b' from rhodecode.lib.base import BaseContr'
41 41 from rhodecode.model.db import User, UserRepoToPerm, UserToPerm, Permission
42 42 from rhodecode.model.forms import UserForm
43 43 from rhodecode.model.user import UserModel
44 from rhodecode.model.meta import Session
44 45
45 46 log = logging.getLogger(__name__)
46 47
@@ -77,6 +78,7 b' class UsersController(BaseController):'
77 78 user_model.create(form_result)
78 79 h.flash(_('created user %s') % form_result['username'],
79 80 category='success')
81 Session.commit()
80 82 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
81 83 except formencode.Invalid, errors:
82 84 return htmlfill.render(
@@ -114,11 +116,11 b' class UsersController(BaseController):'
114 116 form_result = _form.to_python(dict(request.POST))
115 117 user_model.update(id, form_result)
116 118 h.flash(_('User updated successfully'), category='success')
117
119 Session.commit()
118 120 except formencode.Invalid, errors:
119 121 e = errors.error_dict or {}
120 122 perm = Permission.get_by_key('hg.create.repository')
121 e.update({'create_repo_perm': UserToPerm.has_perm(id, perm)})
123 e.update({'create_repo_perm': user_model.has_perm(id, perm)})
122 124 return htmlfill.render(
123 125 render('admin/users/user_edit.html'),
124 126 defaults=errors.value,
@@ -144,6 +146,7 b' class UsersController(BaseController):'
144 146 try:
145 147 user_model.delete(id)
146 148 h.flash(_('successfully deleted user'), category='success')
149 Session.commit()
147 150 except (UserOwnsReposException, DefaultUserException), e:
148 151 h.flash(str(e), category='warning')
149 152 except Exception:
@@ -158,20 +161,19 b' class UsersController(BaseController):'
158 161 def edit(self, id, format='html'):
159 162 """GET /users/id/edit: Form to edit an existing item"""
160 163 # url('edit_user', id=ID)
161 user_model = UserModel()
162 c.user = user_model.get(id)
164 c.user = User.get(id)
163 165 if not c.user:
164 166 return redirect(url('users'))
165 167 if c.user.username == 'default':
166 168 h.flash(_("You can't edit this user"), category='warning')
167 169 return redirect(url('users'))
168 170 c.user.permissions = {}
169 c.granted_permissions = user_model.fill_perms(c.user)\
171 c.granted_permissions = UserModel().fill_perms(c.user)\
170 172 .permissions['global']
171 173
172 174 defaults = c.user.get_dict()
173 175 perm = Permission.get_by_key('hg.create.repository')
174 defaults.update({'create_repo_perm': UserToPerm.has_perm(id, perm)})
176 defaults.update({'create_repo_perm': UserModel().has_perm(id, perm)})
175 177
176 178 return htmlfill.render(
177 179 render('admin/users/user_edit.html'),
@@ -185,22 +187,23 b' class UsersController(BaseController):'
185 187 # url('user_perm', id=ID, method='put')
186 188
187 189 grant_perm = request.POST.get('create_repo_perm', False)
188
190 user_model = UserModel()
191
189 192 if grant_perm:
190 193 perm = Permission.get_by_key('hg.create.none')
191 UserToPerm.revoke_perm(id, perm)
194 user_model.revoke_perm(id, perm)
192 195
193 196 perm = Permission.get_by_key('hg.create.repository')
194 UserToPerm.grant_perm(id, perm)
197 user_model.grant_perm(id, perm)
195 198 h.flash(_("Granted 'repository create' permission to user"),
196 199 category='success')
197 200
198 201 else:
199 202 perm = Permission.get_by_key('hg.create.repository')
200 UserToPerm.revoke_perm(id, perm)
203 user_model.revoke_perm(id, perm)
201 204
202 205 perm = Permission.get_by_key('hg.create.none')
203 UserToPerm.grant_perm(id, perm)
206 user_model.grant_perm(id, perm)
204 207 h.flash(_("Revoked 'repository create' permission to user"),
205 208 category='success')
206 209
@@ -33,12 +33,15 b' from pylons.controllers.util import abor'
33 33 from pylons.i18n.translation import _
34 34
35 35 from rhodecode.lib.exceptions import UsersGroupsAssignedException
36 from rhodecode.lib import helpers as h
36 from rhodecode.lib import helpers as h, safe_unicode
37 37 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
38 38 from rhodecode.lib.base import BaseController, render
39 39
40 from rhodecode.model.users_group import UsersGroupModel
41
40 42 from rhodecode.model.db import User, UsersGroup, Permission, UsersGroupToPerm
41 from rhodecode.model.forms import UserForm, UsersGroupForm
43 from rhodecode.model.forms import UsersGroupForm
44 from rhodecode.model.meta import Session
42 45
43 46 log = logging.getLogger(__name__)
44 47
@@ -70,10 +73,12 b' class UsersGroupsController(BaseControll'
70 73 users_group_form = UsersGroupForm()()
71 74 try:
72 75 form_result = users_group_form.to_python(dict(request.POST))
73 UsersGroup.create(form_result)
76 UsersGroupModel().create(name=form_result['users_group_name'],
77 active=form_result['users_group_active'])
74 78 h.flash(_('created users group %s') \
75 79 % form_result['users_group_name'], category='success')
76 80 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
81 Session.commit()
77 82 except formencode.Invalid, errors:
78 83 return htmlfill.render(
79 84 render('admin/users_groups/users_group_add.html'),
@@ -108,24 +113,27 b' class UsersGroupsController(BaseControll'
108 113
109 114 c.available_members = [(x.user_id, x.username) for x in
110 115 self.sa.query(User).all()]
116
117 available_members = [safe_unicode(x[0]) for x in c.available_members]
118
111 119 users_group_form = UsersGroupForm(edit=True,
112 120 old_data=c.users_group.get_dict(),
113 available_members=[str(x[0]) for x
114 in c.available_members])()
121 available_members=available_members)()
115 122
116 123 try:
117 124 form_result = users_group_form.to_python(request.POST)
118 UsersGroup.update(id, form_result)
125 UsersGroupModel().update(c.users_group, form_result)
119 126 h.flash(_('updated users group %s') \
120 127 % form_result['users_group_name'],
121 128 category='success')
122 129 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
130 Session.commit()
123 131 except formencode.Invalid, errors:
124 132 e = errors.error_dict or {}
125 133
126 134 perm = Permission.get_by_key('hg.create.repository')
127 135 e.update({'create_repo_perm':
128 UsersGroupToPerm.has_perm(id, perm)})
136 UsersGroupModel().has_perm(id, perm)})
129 137
130 138 return htmlfill.render(
131 139 render('admin/users_groups/users_group_edit.html'),
@@ -150,8 +158,9 b' class UsersGroupsController(BaseControll'
150 158 # url('users_group', id=ID)
151 159
152 160 try:
153 UsersGroup.delete(id)
161 UsersGroupModel().delete(id)
154 162 h.flash(_('successfully deleted users group'), category='success')
163 Session.commit()
155 164 except UsersGroupsAssignedException, e:
156 165 h.flash(e, category='error')
157 166 except Exception:
@@ -179,7 +188,7 b' class UsersGroupsController(BaseControll'
179 188 defaults = c.users_group.get_dict()
180 189 perm = Permission.get_by_key('hg.create.repository')
181 190 defaults.update({'create_repo_perm':
182 UsersGroupToPerm.has_perm(id, perm)})
191 UsersGroupModel().has_perm(c.users_group, perm)})
183 192 return htmlfill.render(
184 193 render('admin/users_groups/users_group_edit.html'),
185 194 defaults=defaults,
@@ -195,20 +204,21 b' class UsersGroupsController(BaseControll'
195 204
196 205 if grant_perm:
197 206 perm = Permission.get_by_key('hg.create.none')
198 UsersGroupToPerm.revoke_perm(id, perm)
207 UsersGroupModel().revoke_perm(id, perm)
199 208
200 209 perm = Permission.get_by_key('hg.create.repository')
201 UsersGroupToPerm.grant_perm(id, perm)
210 UsersGroupModel().grant_perm(id, perm)
202 211 h.flash(_("Granted 'repository create' permission to user"),
203 212 category='success')
204
213
214 Session.commit()
205 215 else:
206 216 perm = Permission.get_by_key('hg.create.repository')
207 UsersGroupToPerm.revoke_perm(id, perm)
217 UsersGroupModel().revoke_perm(id, perm)
208 218
209 219 perm = Permission.get_by_key('hg.create.none')
210 UsersGroupToPerm.grant_perm(id, perm)
220 UsersGroupModel().grant_perm(id, perm)
211 221 h.flash(_("Revoked 'repository create' permission to user"),
212 222 category='success')
213
223 Session.commit()
214 224 return redirect(url('edit_users_group', id=id))
@@ -120,7 +120,7 b' class ApiController(JSONRPCController):'
120 120 try:
121 121 UserModel().create_or_update(username, password, email, firstname,
122 122 lastname, active, admin, ldap_dn)
123 Session().commit()
123 Session.commit()
124 124 return dict(msg='created new user %s' % username)
125 125 except Exception:
126 126 log.error(traceback.format_exc())
@@ -198,7 +198,7 b' class ApiController(JSONRPCController):'
198 198
199 199 try:
200 200 ug = UsersGroupModel().create(name=name, active=active)
201 Session().commit()
201 Session.commit()
202 202 return dict(id=ug.users_group_id,
203 203 msg='created new users group %s' % name)
204 204 except Exception:
@@ -226,7 +226,7 b' class ApiController(JSONRPCController):'
226 226 raise JSONRPCError('unknown user %s' % user_name)
227 227
228 228 ugm = UsersGroupModel().add_user_to_group(users_group, user)
229 Session().commit()
229 Session.commit()
230 230 return dict(id=ugm.users_group_member_id,
231 231 msg='created new users group member')
232 232 except Exception:
@@ -242,10 +242,9 b' class ApiController(JSONRPCController):'
242 242 :param repo_name
243 243 """
244 244
245 try:
246 repo = Repository.get_by_repo_name(repo_name)
247 except NoResultFound:
248 return None
245 repo = Repository.get_by_repo_name(repo_name)
246 if repo is None:
247 raise JSONRPCError('unknown repository %s' % repo)
249 248
250 249 members = []
251 250 for user in repo.repo_to_perm:
@@ -334,7 +333,7 b' class ApiController(JSONRPCController):'
334 333 repo_type=repo_type,
335 334 repo_group=parent_id,
336 335 clone_uri=None), owner)
337 Session().commit()
336 Session.commit()
338 337 except Exception:
339 338 log.error(traceback.format_exc())
340 339 raise JSONRPCError('failed to create repository %s' % name)
@@ -351,10 +350,9 b' class ApiController(JSONRPCController):'
351 350 """
352 351
353 352 try:
354 try:
355 repo = Repository.get_by_repo_name(repo_name)
356 except NoResultFound:
357 raise JSONRPCError('unknown repository %s' % repo)
353 repo = Repository.get_by_repo_name(repo_name)
354 if repo is None:
355 raise JSONRPCError('unknown repository %s' % repo)
358 356
359 357 try:
360 358 user = User.get_by_username(user_name)
@@ -363,7 +361,7 b' class ApiController(JSONRPCController):'
363 361
364 362 RepositoryPermissionModel()\
365 363 .update_or_delete_user_permission(repo, user, perm)
366 Session().commit()
364 Session.commit()
367 365 except Exception:
368 366 log.error(traceback.format_exc())
369 367 raise JSONRPCError('failed to edit permission %(repo)s for %(user)s'
@@ -280,7 +280,7 b' class ChangesetController(BaseRepoContro'
280 280 revision=revision,
281 281 f_path=request.POST.get('f_path'),
282 282 line_no=request.POST.get('line'))
283 Session().commit()
283 Session.commit()
284 284 return redirect(h.url('changeset_home', repo_name=repo_name,
285 285 revision=revision))
286 286
@@ -290,7 +290,7 b' class ChangesetController(BaseRepoContro'
290 290 owner = lambda : co.author.user_id == c.rhodecode_user.user_id
291 291 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
292 292 ChangesetCommentsModel().delete(comment=co)
293 Session().commit()
293 Session.commit()
294 294 return True
295 295 else:
296 296 raise HTTPForbidden()
@@ -134,7 +134,7 b' class JournalController(BaseController):'
134 134 try:
135 135 self.scm_model.toggle_following_user(user_id,
136 136 self.rhodecode_user.user_id)
137 Session().commit()
137 Session.commit()
138 138 return 'ok'
139 139 except:
140 140 raise HTTPBadRequest()
@@ -144,7 +144,7 b' class JournalController(BaseController):'
144 144 try:
145 145 self.scm_model.toggle_following_repo(repo_id,
146 146 self.rhodecode_user.user_id)
147 Session().commit()
147 Session.commit()
148 148 return 'ok'
149 149 except:
150 150 raise HTTPBadRequest()
@@ -75,7 +75,8 b' class LoginController(BaseController):'
75 75 log.info('user %s is now authenticated and stored in '
76 76 'session, session attrs %s' % (username, cs))
77 77 user.update_lastlogin()
78
78 Session.commit()
79
79 80 if c.came_from:
80 81 return redirect(c.came_from)
81 82 else:
@@ -94,7 +95,6 b' class LoginController(BaseController):'
94 95 @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate',
95 96 'hg.register.manual_activate')
96 97 def register(self):
97 user_model = UserModel()
98 98 c.auto_active = False
99 99 for perm in User.get_by_username('default').user_perms:
100 100 if perm.permission.permission_name == 'hg.register.auto_activate':
@@ -107,10 +107,10 b' class LoginController(BaseController):'
107 107 try:
108 108 form_result = register_form.to_python(dict(request.POST))
109 109 form_result['active'] = c.auto_active
110 user_model.create_registration(form_result)
110 UserModel().create_registration(form_result)
111 111 h.flash(_('You have successfully registered into rhodecode'),
112 112 category='success')
113 Session().commit()
113 Session.commit()
114 114 return redirect(url('login_home'))
115 115
116 116 except formencode.Invalid, errors:
@@ -124,13 +124,11 b' class LoginController(BaseController):'
124 124 return render('/register.html')
125 125
126 126 def password_reset(self):
127 user_model = UserModel()
128 127 if request.POST:
129
130 128 password_reset_form = PasswordResetForm()()
131 129 try:
132 130 form_result = password_reset_form.to_python(dict(request.POST))
133 user_model.reset_password_link(form_result)
131 UserModel().reset_password_link(form_result)
134 132 h.flash(_('Your password reset link was sent'),
135 133 category='success')
136 134 return redirect(url('login_home'))
@@ -146,13 +144,11 b' class LoginController(BaseController):'
146 144 return render('/password_reset.html')
147 145
148 146 def password_reset_confirmation(self):
149
150 147 if request.GET and request.GET.get('key'):
151 148 try:
152 user_model = UserModel()
153 149 user = User.get_by_api_key(request.GET.get('key'))
154 150 data = dict(email=user.email)
155 user_model.reset_password(data)
151 UserModel().reset_password(data)
156 152 h.flash(_('Your password reset was successful, '
157 153 'new password has been sent to your email'),
158 154 category='success')
@@ -105,7 +105,7 b' class SettingsController(BaseRepoControl'
105 105 changed_name = form_result['repo_name_full']
106 106 action_logger(self.rhodecode_user, 'user_updated_repo',
107 107 changed_name, '', self.sa)
108 Session().commit()
108 Session.commit()
109 109 except formencode.Invalid, errors:
110 110 c.repo_info = repo_model.get_by_repo_name(repo_name)
111 111 c.users_array = repo_model.get_users_js()
@@ -149,7 +149,7 b' class SettingsController(BaseRepoControl'
149 149 repo_model.delete(repo)
150 150 invalidate_cache('get_repo_cached_%s' % repo_name)
151 151 h.flash(_('deleted repository %s') % repo_name, category='success')
152 Session().commit()
152 Session.commit()
153 153 except Exception:
154 154 log.error(traceback.format_exc())
155 155 h.flash(_('An error occurred during deletion of %s') % repo_name,
@@ -35,6 +35,7 b' from pylons.controllers.util import abor'
35 35 from pylons.i18n.translation import _
36 36
37 37 from rhodecode import __platform__, PLATFORM_WIN, PLATFORM_OTHERS
38 from rhodecode.model.meta import Session
38 39
39 40 if __platform__ in PLATFORM_WIN:
40 41 from hashlib import sha256
@@ -225,7 +226,8 b' def authenticate(username, password):'
225 226 if user_model.create_ldap(username, password, user_dn,
226 227 user_attrs):
227 228 log.info('created new ldap user %s', username)
228
229
230 Session.commit()
229 231 return True
230 232 except (LdapUsernameError, LdapPasswordError,):
231 233 pass
@@ -237,13 +239,12 b' def authenticate(username, password):'
237 239 def login_container_auth(username):
238 240 user = User.get_by_username(username)
239 241 if user is None:
240 user_model = UserModel()
241 242 user_attrs = {
242 243 'name': username,
243 244 'lastname': None,
244 245 'email': None,
245 246 }
246 user = user_model.create_for_container_auth(username, user_attrs)
247 user = UserModel().create_for_container_auth(username, user_attrs)
247 248 if not user:
248 249 return None
249 250 log.info('User %s was created by container authentication', username)
@@ -252,6 +253,8 b' def login_container_auth(username):'
252 253 return None
253 254
254 255 user.update_lastlogin()
256 Session.commit()
257
255 258 log.debug('User %s is now logged in by container authentication',
256 259 user.username)
257 260 return user
@@ -380,7 +383,7 b' def set_available_permissions(config):'
380 383 """
381 384 log.info('getting information about all available permissions')
382 385 try:
383 sa = meta.Session()
386 sa = meta.Session
384 387 all_perms = sa.query(Permission).all()
385 388 except:
386 389 pass
@@ -35,7 +35,7 b' class BaseController(WSGIController):'
35 35 .get_unread_cnt_for_user(c.rhodecode_user.user_id)
36 36 self.cut_off_limit = int(config.get('cut_off_limit'))
37 37
38 self.sa = meta.Session()
38 self.sa = meta.Session
39 39 self.scm_model = ScmModel(self.sa)
40 40
41 41 def __call__(self, environ, start_response):
@@ -64,7 +64,7 b' def get_session():'
64 64 if CELERY_ON:
65 65 engine = engine_from_config(config, 'sqlalchemy.db1.')
66 66 init_model(engine)
67 sa = meta.Session()
67 sa = meta.Session
68 68 return sa
69 69
70 70 def get_logger(cls):
@@ -109,7 +109,11 b' def get_commits_stats(repo_name, ts_min_'
109 109
110 110 co_day_auth_aggr = {}
111 111 commits_by_day_aggregate = {}
112 repo = Repository.get_by_repo_name(repo_name).scm_instance
112 repo = Repository.get_by_repo_name(repo_name)
113 if repo is None:
114 return True
115
116 repo = repo.scm_instance
113 117 repo_size = len(repo.revisions)
114 118 #return if repo have no revisions
115 119 if repo_size < 1:
@@ -57,7 +57,7 b' class DbManage(object):'
57 57 def init_db(self):
58 58 engine = create_engine(self.dburi, echo=self.log_sql)
59 59 init_model(engine)
60 self.sa = meta.Session()
60 self.sa = meta.Session
61 61
62 62 def create_tables(self, override=False):
63 63 """Create a auth database
@@ -1061,7 +1061,7 b' class CacheInvalidation(Base, BaseModel)'
1061 1061 """
1062 1062
1063 1063 log.debug('marking %s for invalidation' % key)
1064 inv_obj = Session().query(cls)\
1064 inv_obj = Session.query(cls)\
1065 1065 .filter(cls.cache_key == key).scalar()
1066 1066 if inv_obj:
1067 1067 inv_obj.cache_active = False
@@ -1083,7 +1083,7 b' class CacheInvalidation(Base, BaseModel)'
1083 1083
1084 1084 :param key:
1085 1085 """
1086 inv_obj = Session().query(CacheInvalidation)\
1086 inv_obj = Session.query(CacheInvalidation)\
1087 1087 .filter(CacheInvalidation.cache_key == key).scalar()
1088 1088 inv_obj.cache_active = True
1089 1089 Session.add(inv_obj)
@@ -110,7 +110,7 b' def action_logger(user, action, repo, ip'
110 110 """
111 111
112 112 if not sa:
113 sa = meta.Session()
113 sa = meta.Session
114 114
115 115 try:
116 116 if hasattr(user, 'user_id'):
@@ -271,7 +271,7 b" def make_ui(read_from='file', path=None,"
271 271 baseui.setconfig(section, k, v)
272 272
273 273 elif read_from == 'db':
274 sa = meta.Session()
274 sa = meta.Session
275 275 ret = sa.query(RhodeCodeUi)\
276 276 .options(FromCache("sql_cache_short",
277 277 "get_hg_ui_settings")).all()
@@ -362,7 +362,7 b' def map_groups(groups):'
362 362
363 363 :param groups: list of groups structure
364 364 """
365 sa = meta.Session()
365 sa = meta.Session
366 366
367 367 parent = None
368 368 group = None
@@ -392,7 +392,7 b' def repo2db_mapper(initial_repo_list, re'
392 392 :param remove_obsolete: check for obsolete entries in database
393 393 """
394 394 from rhodecode.model.repo import RepoModel
395 sa = meta.Session()
395 sa = meta.Session
396 396 rm = RepoModel()
397 397 user = sa.query(User).filter(User.admin == True).first()
398 398 if user is None:
@@ -510,7 +510,7 b' def create_test_env(repos_test_path, con'
510 510 dbmanage.admin_prompt()
511 511 dbmanage.create_permissions()
512 512 dbmanage.populate_default_permissions()
513 Session().commit()
513 Session.commit()
514 514 # PART TWO make test repo
515 515 log.debug('making test vcs repositories')
516 516
@@ -71,7 +71,7 b' class BaseModel(object):'
71 71 if sa is not None:
72 72 self.sa = sa
73 73 else:
74 self.sa = meta.Session()
74 self.sa = meta.Session
75 75
76 76 def _get_instance(self, cls, instance):
77 77 """
@@ -118,7 +118,7 b' class BaseModel(object):'
118 118
119 119 @classmethod
120 120 def query(cls):
121 return Session().query(cls)
121 return Session.query(cls)
122 122
123 123 @classmethod
124 124 def get(cls, id_):
@@ -132,7 +132,7 b' class BaseModel(object):'
132 132 @classmethod
133 133 def delete(cls, id_):
134 134 obj = cls.query().get(id_)
135 Session().delete(obj)
135 Session.delete(obj)
136 136
137 137
138 138 class RhodeCodeSetting(Base, BaseModel):
@@ -252,8 +252,7 b' class RhodeCodeUi(Base, BaseModel):'
252 252 new_ui.ui_key = key
253 253 new_ui.ui_value = val
254 254
255 Session().add(new_ui)
256 Session().commit()
255 Session.add(new_ui)
257 256
258 257
259 258 class User(Base, BaseModel):
@@ -335,10 +334,8 b' class User(Base, BaseModel):'
335 334
336 335 def update_lastlogin(self):
337 336 """Update user lastlogin"""
338
339 337 self.last_login = datetime.datetime.now()
340 Session().add(self)
341 Session().commit()
338 Session.add(self)
342 339 log.debug('updated user %s lastlogin', self.username)
343 340
344 341
@@ -386,7 +383,6 b' class UsersGroup(Base, BaseModel):'
386 383 "get_user_%s" % group_name))
387 384 return q.scalar()
388 385
389
390 386 @classmethod
391 387 def get(cls, users_group_id, cache=False):
392 388 users_group = cls.query()
@@ -395,68 +391,6 b' class UsersGroup(Base, BaseModel):'
395 391 "get_users_group_%s" % users_group_id))
396 392 return users_group.get(users_group_id)
397 393
398 @classmethod
399 def create(cls, form_data):
400 try:
401 new_users_group = cls()
402 for k, v in form_data.items():
403 setattr(new_users_group, k, v)
404
405 Session().add(new_users_group)
406 Session().commit()
407 return new_users_group
408 except:
409 log.error(traceback.format_exc())
410 Session().rollback()
411 raise
412
413 @classmethod
414 def update(cls, users_group_id, form_data):
415
416 try:
417 users_group = cls.get(users_group_id, cache=False)
418
419 for k, v in form_data.items():
420 if k == 'users_group_members':
421 users_group.members = []
422 Session().flush()
423 members_list = []
424 if v:
425 v = [v] if isinstance(v, basestring) else v
426 for u_id in set(v):
427 member = UsersGroupMember(users_group_id, u_id)
428 members_list.append(member)
429 setattr(users_group, 'members', members_list)
430 setattr(users_group, k, v)
431
432 Session().add(users_group)
433 Session().commit()
434 except:
435 log.error(traceback.format_exc())
436 Session().rollback()
437 raise
438
439 @classmethod
440 def delete(cls, users_group_id):
441 try:
442
443 # check if this group is not assigned to repo
444 assigned_groups = UsersGroupRepoToPerm.query()\
445 .filter(UsersGroupRepoToPerm.users_group_id ==
446 users_group_id).all()
447
448 if assigned_groups:
449 raise UsersGroupsAssignedException('RepoGroup assigned to %s' %
450 assigned_groups)
451
452 users_group = cls.get(users_group_id, cache=False)
453 Session().delete(users_group)
454 Session().commit()
455 except:
456 log.error(traceback.format_exc())
457 Session().rollback()
458 raise
459
460 394 class UsersGroupMember(Base, BaseModel):
461 395 __tablename__ = 'users_groups_members'
462 396 __table_args__ = {'extend_existing':True}
@@ -477,8 +411,8 b' class UsersGroupMember(Base, BaseModel):'
477 411 ugm = UsersGroupMember()
478 412 ugm.users_group = group
479 413 ugm.user = user
480 Session().add(ugm)
481 Session().commit()
414 Session.add(ugm)
415 Session.commit()
482 416 return ugm
483 417
484 418 class Repository(Base, BaseModel):
@@ -521,11 +455,11 b' class Repository(Base, BaseModel):'
521 455
522 456 @classmethod
523 457 def get_by_repo_name(cls, repo_name):
524 q = Session().query(cls).filter(cls.repo_name == repo_name)
458 q = Session.query(cls).filter(cls.repo_name == repo_name)
525 459 q = q.options(joinedload(Repository.fork))\
526 460 .options(joinedload(Repository.user))\
527 461 .options(joinedload(Repository.group))
528 return q.one()
462 return q.scalar()
529 463
530 464 @classmethod
531 465 def get_repo_forks(cls, repo_id):
@@ -538,7 +472,7 b' class Repository(Base, BaseModel):'
538 472
539 473 :param cls:
540 474 """
541 q = Session().query(RhodeCodeUi)\
475 q = Session.query(RhodeCodeUi)\
542 476 .filter(RhodeCodeUi.ui_key == cls.url_sep())
543 477 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
544 478 return q.one().ui_value
@@ -574,7 +508,7 b' class Repository(Base, BaseModel):'
574 508 Returns base full path for that repository means where it actually
575 509 exists on a filesystem
576 510 """
577 q = Session().query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
511 q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key ==
578 512 Repository.url_sep())
579 513 q = q.options(FromCache("sql_cache_short", "repository_repo_path"))
580 514 return q.one().ui_value
@@ -851,7 +785,7 b' class Permission(Base, BaseModel):'
851 785
852 786 @classmethod
853 787 def get_default_perms(cls, default_user_id):
854 q = Session().query(UserRepoToPerm, Repository, cls)\
788 q = Session.query(UserRepoToPerm, Repository, cls)\
855 789 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\
856 790 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\
857 791 .filter(UserRepoToPerm.user_id == default_user_id)
@@ -877,7 +811,7 b' class UserRepoToPerm(Base, BaseModel):'
877 811 n.user = user
878 812 n.repository = repository
879 813 n.permission = permission
880 Session().add(n)
814 Session.add(n)
881 815 return n
882 816
883 817 def __repr__(self):
@@ -893,41 +827,6 b' class UserToPerm(Base, BaseModel):'
893 827 user = relationship('User')
894 828 permission = relationship('Permission', lazy='joined')
895 829
896 @classmethod
897 def has_perm(cls, user_id, perm):
898 if not isinstance(perm, Permission):
899 raise Exception('perm needs to be an instance of Permission class')
900
901 return cls.query().filter(cls.user_id == user_id)\
902 .filter(cls.permission == perm).scalar() is not None
903
904 @classmethod
905 def grant_perm(cls, user_id, perm):
906 if not isinstance(perm, Permission):
907 raise Exception('perm needs to be an instance of Permission class')
908
909 new = cls()
910 new.user_id = user_id
911 new.permission = perm
912 try:
913 Session().add(new)
914 Session().commit()
915 except:
916 Session().rollback()
917
918
919 @classmethod
920 def revoke_perm(cls, user_id, perm):
921 if not isinstance(perm, Permission):
922 raise Exception('perm needs to be an instance of Permission class')
923
924 try:
925 obj = cls.query().filter(cls.user_id == user_id)\
926 .filter(cls.permission == perm).one()
927 Session().delete(obj)
928 Session().commit()
929 except:
930 Session().rollback()
931 830
932 831 class UsersGroupRepoToPerm(Base, BaseModel):
933 832 __tablename__ = 'users_group_repo_to_perm'
@@ -947,7 +846,7 b' class UsersGroupRepoToPerm(Base, BaseMod'
947 846 n.users_group = users_group
948 847 n.repository = repository
949 848 n.permission = permission
950 Session().add(n)
849 Session.add(n)
951 850 return n
952 851
953 852 def __repr__(self):
@@ -963,45 +862,6 b' class UsersGroupToPerm(Base, BaseModel):'
963 862 permission = relationship('Permission')
964 863
965 864
966 @classmethod
967 def has_perm(cls, users_group_id, perm):
968 if not isinstance(perm, Permission):
969 raise Exception('perm needs to be an instance of Permission class')
970
971 return cls.query().filter(cls.users_group_id ==
972 users_group_id)\
973 .filter(cls.permission == perm)\
974 .scalar() is not None
975
976 @classmethod
977 def grant_perm(cls, users_group_id, perm):
978 if not isinstance(perm, Permission):
979 raise Exception('perm needs to be an instance of Permission class')
980
981 new = cls()
982 new.users_group_id = users_group_id
983 new.permission = perm
984 try:
985 Session().add(new)
986 Session().commit()
987 except:
988 Session().rollback()
989
990
991 @classmethod
992 def revoke_perm(cls, users_group_id, perm):
993 if not isinstance(perm, Permission):
994 raise Exception('perm needs to be an instance of Permission class')
995
996 try:
997 obj = cls.query().filter(cls.users_group_id == users_group_id)\
998 .filter(cls.permission == perm).one()
999 Session().delete(obj)
1000 Session().commit()
1001 except:
1002 Session().rollback()
1003
1004
1005 865 class UserRepoGroupToPerm(Base, BaseModel):
1006 866 __tablename__ = 'group_to_perm'
1007 867 __table_args__ = (UniqueConstraint('group_id', 'permission_id'), {'extend_existing':True})
@@ -1103,7 +963,7 b' class CacheInvalidation(Base, BaseModel)'
1103 963 """
1104 964
1105 965 log.debug('marking %s for invalidation' % key)
1106 inv_obj = Session().query(cls)\
966 inv_obj = Session.query(cls)\
1107 967 .filter(cls.cache_key == key).scalar()
1108 968 if inv_obj:
1109 969 inv_obj.cache_active = False
@@ -1112,11 +972,11 b' class CacheInvalidation(Base, BaseModel)'
1112 972 inv_obj = CacheInvalidation(key)
1113 973
1114 974 try:
1115 Session().add(inv_obj)
1116 Session().commit()
975 Session.add(inv_obj)
976 Session.commit()
1117 977 except Exception:
1118 978 log.error(traceback.format_exc())
1119 Session().rollback()
979 Session.rollback()
1120 980
1121 981 @classmethod
1122 982 def set_valid(cls, key):
@@ -1128,8 +988,8 b' class CacheInvalidation(Base, BaseModel)'
1128 988 inv_obj = CacheInvalidation.query()\
1129 989 .filter(CacheInvalidation.cache_key == key).scalar()
1130 990 inv_obj.cache_active = True
1131 Session().add(inv_obj)
1132 Session().commit()
991 Session.add(inv_obj)
992 Session.commit()
1133 993
1134 994
1135 995 class ChangesetComment(Base, BaseModel):
@@ -1157,7 +1017,7 b' class ChangesetComment(Base, BaseModel):'
1157 1017 :param cls:
1158 1018 :param revision:
1159 1019 """
1160 return Session().query(User)\
1020 return Session.query(User)\
1161 1021 .filter(cls.revision == revision)\
1162 1022 .join(ChangesetComment.author).all()
1163 1023
@@ -1203,7 +1063,7 b' class Notification(Base, BaseModel):'
1203 1063 assoc = UserNotification()
1204 1064 assoc.notification = notification
1205 1065 u.notifications.append(assoc)
1206 Session().add(notification)
1066 Session.add(notification)
1207 1067 return notification
1208 1068
1209 1069 @property
@@ -1226,7 +1086,7 b' class UserNotification(Base, BaseModel):'
1226 1086
1227 1087 def mark_as_read(self):
1228 1088 self.read = True
1229 Session().add(self)
1089 Session.add(self)
1230 1090
1231 1091 class DbMigrateVersion(Base, BaseModel):
1232 1092 __tablename__ = 'db_migrate_version'
@@ -36,9 +36,7 b' from rhodecode.config.routing import ADM'
36 36 from rhodecode.lib.utils import repo_name_slug
37 37 from rhodecode.lib.auth import authenticate, get_crypt_password
38 38 from rhodecode.lib.exceptions import LdapImportError
39 from rhodecode.model.user import UserModel
40 from rhodecode.model.repo import RepoModel
41 from rhodecode.model.db import User, UsersGroup, RepoGroup
39 from rhodecode.model.db import User, UsersGroup, RepoGroup, Repository
42 40 from rhodecode import BACKENDS
43 41
44 42 log = logging.getLogger(__name__)
@@ -68,7 +66,7 b' def ValidUsername(edit, old_data):'
68 66 #check if user is unique
69 67 old_un = None
70 68 if edit:
71 old_un = UserModel().get(old_data.get('user_id')).username
69 old_un = User.get(old_data.get('user_id')).username
72 70
73 71 if old_un != value or not edit:
74 72 if User.get_by_username(value, case_insensitive=True):
@@ -268,7 +266,7 b' def ValidRepoName(edit, old_data):'
268 266 if rename or create:
269 267
270 268 if group_path != '':
271 if RepoModel().get_by_repo_name(repo_name_full,):
269 if Repository.get_by_repo_name(repo_name_full):
272 270 e_dict = {'repo_name':_('This repository already '
273 271 'exists in a group "%s"') %
274 272 gr.group_name}
@@ -281,7 +279,7 b' def ValidRepoName(edit, old_data):'
281 279 raise formencode.Invalid('', value, state,
282 280 error_dict=e_dict)
283 281
284 elif RepoModel().get_by_repo_name(repo_name_full):
282 elif Repository.get_by_repo_name(repo_name_full):
285 283 e_dict = {'repo_name':_('This repository '
286 284 'already exists')}
287 285 raise formencode.Invalid('', value, state,
@@ -204,11 +204,9 b' class RepoModel(BaseModel):'
204 204 # rename repository
205 205 self.__rename_repo(old=repo_name, new=new_name)
206 206
207 self.sa.commit()
208 207 return cur_repo
209 208 except:
210 209 log.error(traceback.format_exc())
211 self.sa.rollback()
212 210 raise
213 211
214 212 def create(self, form_data, cur_user, just_db=False, fork=False):
@@ -312,10 +310,8 b' class RepoModel(BaseModel):'
312 310 try:
313 311 self.sa.delete(repo)
314 312 self.__delete_repo(repo)
315 self.sa.commit()
316 313 except:
317 314 log.error(traceback.format_exc())
318 self.sa.rollback()
319 315 raise
320 316
321 317 def delete_perm_user(self, form_data, repo_name):
@@ -325,10 +321,8 b' class RepoModel(BaseModel):'
325 321 == self.get_by_repo_name(repo_name))\
326 322 .filter(UserRepoToPerm.user_id == form_data['user_id']).one()
327 323 self.sa.delete(obj)
328 self.sa.commit()
329 324 except:
330 325 log.error(traceback.format_exc())
331 self.sa.rollback()
332 326 raise
333 327
334 328 def delete_perm_users_group(self, form_data, repo_name):
@@ -339,10 +333,8 b' class RepoModel(BaseModel):'
339 333 .filter(UsersGroupRepoToPerm.users_group_id
340 334 == form_data['users_group_id']).one()
341 335 self.sa.delete(obj)
342 self.sa.commit()
343 336 except:
344 337 log.error(traceback.format_exc())
345 self.sa.rollback()
346 338 raise
347 339
348 340 def delete_stats(self, repo_name):
@@ -356,10 +348,8 b' class RepoModel(BaseModel):'
356 348 .filter(Statistics.repository == \
357 349 self.get_by_repo_name(repo_name)).one()
358 350 self.sa.delete(obj)
359 self.sa.commit()
360 351 except:
361 352 log.error(traceback.format_exc())
362 self.sa.rollback()
363 353 raise
364 354
365 355 def __create_repo(self, repo_name, alias, new_parent_id, clone_uri=False):
@@ -428,11 +418,11 b' class RepoModel(BaseModel):'
428 418 """
429 419 rm_path = os.path.join(self.repos_path, repo.repo_name)
430 420 log.info("Removing %s", rm_path)
431 #disable hg/git
421 # disable hg/git
432 422 alias = repo.repo_type
433 423 shutil.move(os.path.join(rm_path, '.%s' % alias),
434 424 os.path.join(rm_path, 'rm__.%s' % alias))
435 #disable repo
425 # disable repo
436 426 shutil.move(rm_path, os.path.join(self.repos_path, 'rm__%s__%s' \
437 427 % (datetime.today()\
438 428 .strftime('%Y%m%d_%H%M%S_%f'),
@@ -54,6 +54,9 b" PERM_WEIGHTS = {'repository.none': 0,"
54 54
55 55 class UserModel(BaseModel):
56 56
57 def __get_user(self, user):
58 return self._get_instance(User, user)
59
57 60 def get(self, user_id, cache=False):
58 61 user = self.sa.query(User)
59 62 if cache:
@@ -84,11 +87,9 b' class UserModel(BaseModel):'
84 87
85 88 new_user.api_key = generate_api_key(form_data['username'])
86 89 self.sa.add(new_user)
87 self.sa.commit()
88 90 return new_user
89 91 except:
90 92 log.error(traceback.format_exc())
91 self.sa.rollback()
92 93 raise
93 94
94 95
@@ -159,7 +160,6 b' class UserModel(BaseModel):'
159 160 new_user.lastname = attrs['lastname']
160 161
161 162 self.sa.add(new_user)
162 self.sa.commit()
163 163 return new_user
164 164 except (DatabaseError,):
165 165 log.error(traceback.format_exc())
@@ -200,7 +200,6 b' class UserModel(BaseModel):'
200 200 new_user.lastname = attrs['lastname']
201 201
202 202 self.sa.add(new_user)
203 self.sa.commit()
204 203 return new_user
205 204 except (DatabaseError,):
206 205 log.error(traceback.format_exc())
@@ -258,10 +257,8 b' class UserModel(BaseModel):'
258 257 setattr(user, k, v)
259 258
260 259 self.sa.add(user)
261 self.sa.commit()
262 260 except:
263 261 log.error(traceback.format_exc())
264 self.sa.rollback()
265 262 raise
266 263
267 264 def update_my_account(self, user_id, form_data):
@@ -280,10 +277,8 b' class UserModel(BaseModel):'
280 277 setattr(user, k, v)
281 278
282 279 self.sa.add(user)
283 self.sa.commit()
284 280 except:
285 281 log.error(traceback.format_exc())
286 self.sa.rollback()
287 282 raise
288 283
289 284 def delete(self, user_id):
@@ -300,10 +295,8 b' class UserModel(BaseModel):'
300 295 'remove those repositories') \
301 296 % user.repositories)
302 297 self.sa.delete(user)
303 self.sa.commit()
304 298 except:
305 299 log.error(traceback.format_exc())
306 self.sa.rollback()
307 300 raise
308 301
309 302 def reset_password_link(self, data):
@@ -477,3 +470,35 b' class UserModel(BaseModel):'
477 470
478 471 return user
479 472
473
474
475 def has_perm(self, user, perm):
476 if not isinstance(perm, Permission):
477 raise Exception('perm needs to be an instance of Permission class')
478
479 user = self.__get_user(user)
480
481 return UserToPerm.query().filter(UserToPerm.user == user.user)\
482 .filter(UserToPerm.permission == perm).scalar() is not None
483
484 def grant_perm(self, user, perm):
485 if not isinstance(perm, Permission):
486 raise Exception('perm needs to be an instance of Permission class')
487
488 user = self.__get_user(user)
489
490 new = UserToPerm()
491 new.user = user.user
492 new.permission = perm
493 self.sa.add(new)
494
495
496 def revoke_perm(self, user, perm):
497 if not isinstance(perm, Permission):
498 raise Exception('perm needs to be an instance of Permission class')
499
500 user = self.__get_user(user)
501
502 obj = UserToPerm.query().filter(UserToPerm.user == user.user)\
503 .filter(UserToPerm.permission == perm).one()
504 self.sa.delete(obj)
@@ -27,7 +27,9 b' import logging'
27 27 import traceback
28 28
29 29 from rhodecode.model import BaseModel
30 from rhodecode.model.db import UsersGroupMember, UsersGroup
30 from rhodecode.model.db import UsersGroupMember, UsersGroup,\
31 UsersGroupRepoToPerm, Permission, UsersGroupToPerm
32 from rhodecode.lib.exceptions import UsersGroupsAssignedException
31 33
32 34 log = logging.getLogger(__name__)
33 35
@@ -44,15 +46,55 b' class UsersGroupModel(BaseModel):'
44 46 return UsersGroup.get_by_group_name(name, cache, case_insensitive)
45 47
46 48 def create(self, name, active=True):
47 new = UsersGroup()
48 new.users_group_name = name
49 new.users_group_active = active
50 self.sa.add(new)
51 return new
49 try:
50 new = UsersGroup()
51 new.users_group_name = name
52 new.users_group_active = active
53 self.sa.add(new)
54 return new
55 except:
56 log.error(traceback.format_exc())
57 raise
58
59 def update(self, users_group, form_data):
60
61 try:
62 users_group = self.__get_users_group(users_group)
63
64 for k, v in form_data.items():
65 if k == 'users_group_members':
66 users_group.members = []
67 self.sa.flush()
68 members_list = []
69 if v:
70 v = [v] if isinstance(v, basestring) else v
71 for u_id in set(v):
72 member = UsersGroupMember(users_group.users_group_id, u_id)
73 members_list.append(member)
74 setattr(users_group, 'members', members_list)
75 setattr(users_group, k, v)
76
77 self.sa.add(users_group)
78 except:
79 log.error(traceback.format_exc())
80 raise
52 81
53 82 def delete(self, users_group):
54 obj = self.__get_users_group(users_group)
55 self.sa.delete(obj)
83 try:
84 users_group = self.__get_users_group(users_group)
85
86 # check if this group is not assigned to repo
87 assigned_groups = UsersGroupRepoToPerm.query()\
88 .filter(UsersGroupRepoToPerm.users_group == users_group).all()
89
90 if assigned_groups:
91 raise UsersGroupsAssignedException('RepoGroup assigned to %s' %
92 assigned_groups)
93
94 self.sa.delete(users_group)
95 except:
96 log.error(traceback.format_exc())
97 raise
56 98
57 99 def add_user_to_group(self, users_group, user):
58 100 for m in users_group.members:
@@ -73,3 +115,38 b' class UsersGroupModel(BaseModel):'
73 115 except:
74 116 log.error(traceback.format_exc())
75 117 raise
118
119 def has_perm(self, users_group, perm):
120 if not isinstance(perm, Permission):
121 raise Exception('perm needs to be an instance of Permission class')
122
123 users_group = self.__get_users_group(users_group)
124
125 return UsersGroupToPerm.query()\
126 .filter(UsersGroupToPerm.users_group == users_group)\
127 .filter(UsersGroupToPerm.permission == perm).scalar() is not None
128
129 def grant_perm(self, users_group, perm):
130 if not isinstance(perm, Permission):
131 raise Exception('perm needs to be an instance of Permission class')
132
133 users_group = self.__get_users_group(users_group)
134
135 new = UsersGroupToPerm()
136 new.users_group = users_group
137 new.permission = perm
138 self.sa.add(new)
139
140
141 def revoke_perm(self, users_group, perm):
142 if not isinstance(perm, Permission):
143 raise Exception('perm needs to be an instance of Permission class')
144
145 users_group = self.__get_users_group(users_group)
146
147 obj = UsersGroupToPerm.query()\
148 .filter(UsersGroupToPerm.users_group == users_group)\
149 .filter(UsersGroupToPerm.permission == perm).one()
150 self.sa.delete(obj)
151
152
@@ -39,7 +39,7 b''
39 39 <script type="text/javascript">
40 40 var YPJAX_TITLE = "${c.repo_name} ${_('Files')} - ${c.rhodecode_name}";
41 41 var current_url = "${h.url.current()}";
42 var node_list_url = '${h.url("files_home",repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.file.path)}';
42 var node_list_url = '${h.url("files_home",repo_name=c.repo_name,revision=c.changeset.raw_id,f_path='__FPATH__')}';
43 43 var url_base = '${h.url("files_nodelist_home",repo_name=c.repo_name,revision=c.changeset.raw_id,f_path=c.file.path)}';
44 44 var truncated_lbl = "${_('search truncated')}";
45 45 var nomatch_lbl = "${_('no matching files')}";
@@ -81,7 +81,7 b' class Command(object):'
81 81 def get_session():
82 82 engine = engine_from_config(conf, 'sqlalchemy.db1.')
83 83 init_model(engine)
84 sa = meta.Session()
84 sa = meta.Session
85 85 return sa
86 86
87 87
@@ -11,8 +11,8 b' class TestNotificationsController(TestCo'
11 11 def tearDown(self):
12 12 for n in Notification.query().all():
13 13 inst = Notification.get(n.notification_id)
14 Session().delete(inst)
15 Session().commit()
14 Session.delete(inst)
15 Session.commit()
16 16
17 17 def test_index(self):
18 18 self.log_user()
@@ -30,7 +30,7 b' class TestNotificationsController(TestCo'
30 30 NotificationModel().create(created_by=u1, subject=u'test_notification_1',
31 31 body=u'notification_1',
32 32 recipients=[cur_user])
33 Session().commit()
33 Session.commit()
34 34 response = self.app.get(url('notifications'))
35 35 self.assertTrue(u'test_notification_1' in response.body)
36 36
@@ -68,7 +68,7 b' class TestNotificationsController(TestCo'
68 68 subject=u'test',
69 69 body=u'hi there',
70 70 recipients=[cur_user, u1, u2])
71 Session().commit()
71 Session.commit()
72 72 u1 = User.get(u1.user_id)
73 73 u2 = User.get(u2.user_id)
74 74
@@ -32,11 +32,10 b' class TestAdminReposController(TestContr'
32 32 'repo_group':'',
33 33 'description':description,
34 34 'private':private})
35
36 35 self.checkSessionFlash(response, 'created repository %s' % (repo_name))
37 36
38 37 #test if the repo was created in the database
39 new_repo = self.Session().query(Repository).filter(Repository.repo_name ==
38 new_repo = self.Session.query(Repository).filter(Repository.repo_name ==
40 39 repo_name).one()
41 40
42 41 self.assertEqual(new_repo.repo_name, repo_name)
@@ -73,7 +72,7 b' class TestAdminReposController(TestContr'
73 72 'created repository %s' % (repo_name_unicode))
74 73
75 74 #test if the repo was created in the database
76 new_repo = self.Session().query(Repository).filter(Repository.repo_name ==
75 new_repo = self.Session.query(Repository).filter(Repository.repo_name ==
77 76 repo_name_unicode).one()
78 77
79 78 self.assertEqual(new_repo.repo_name, repo_name_unicode)
@@ -113,7 +112,7 b' class TestAdminReposController(TestContr'
113 112 assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo'
114 113
115 114 #test if the fork was created in the database
116 new_repo = self.Session().query(Repository).filter(Repository.repo_name == repo_name).one()
115 new_repo = self.Session.query(Repository).filter(Repository.repo_name == repo_name).one()
117 116
118 117 assert new_repo.repo_name == repo_name, 'wrong name of repo name in db'
119 118 assert new_repo.description == description, 'wrong description'
@@ -162,7 +161,7 b' class TestAdminReposController(TestContr'
162 161 response.session['flash'][0])
163 162
164 163 #test if the repo was created in the database
165 new_repo = self.Session().query(Repository).filter(Repository.repo_name ==
164 new_repo = self.Session.query(Repository).filter(Repository.repo_name ==
166 165 repo_name).one()
167 166
168 167 self.assertEqual(new_repo.repo_name, repo_name)
@@ -182,7 +181,7 b' class TestAdminReposController(TestContr'
182 181 response.follow()
183 182
184 183 #check if repo was deleted from db
185 deleted_repo = self.Session().query(Repository).filter(Repository.repo_name
184 deleted_repo = self.Session.query(Repository).filter(Repository.repo_name
186 185 == repo_name).scalar()
187 186
188 187 self.assertEqual(deleted_repo, None)
@@ -145,7 +145,7 b' class TestAdminSettingsController(TestCo'
145 145 response.follow()
146 146
147 147 assert 'Your account was updated successfully' in response.session['flash'][0][1], 'no flash message about success of change'
148 user = self.Session().query(User).filter(User.username == 'test_admin').one()
148 user = self.Session.query(User).filter(User.username == 'test_admin').one()
149 149 assert user.email == new_email , 'incorrect user email after update got %s vs %s' % (user.email, new_email)
150 150 assert user.name == new_name, 'updated field mismatch %s vs %s' % (user.name, new_name)
151 151 assert user.lastname == new_lastname, 'updated field mismatch %s vs %s' % (user.lastname, new_lastname)
@@ -171,7 +171,7 b' class TestAdminSettingsController(TestCo'
171 171 self.checkSessionFlash(response,
172 172 'Your account was updated successfully')
173 173
174 user = self.Session().query(User).filter(User.username == 'test_admin').one()
174 user = self.Session.query(User).filter(User.username == 'test_admin').one()
175 175 assert user.email == old_email , 'incorrect user email after update got %s vs %s' % (user.email, old_email)
176 176
177 177 assert user.email == old_email , 'incorrect user email after update got %s vs %s' % (user.email, old_email)
@@ -32,7 +32,7 b' class TestAdminUsersController(TestContr'
32 32
33 33 assert '''created user %s''' % (username) in response.session['flash'][0], 'No flash message about new user'
34 34
35 new_user = self.Session().query(User).filter(User.username == username).one()
35 new_user = self.Session.query(User).filter(User.username == username).one()
36 36
37 37
38 38 assert new_user.username == username, 'wrong info about username'
@@ -66,7 +66,7 b' class TestAdminUsersController(TestContr'
66 66 assert """<span class="error-message">An email address must contain a single @</span>""" in response.body
67 67
68 68 def get_user():
69 self.Session().query(User).filter(User.username == username).one()
69 self.Session.query(User).filter(User.username == username).one()
70 70
71 71 self.assertRaises(NoResultFound, get_user), 'found user in database'
72 72
@@ -100,7 +100,7 b' class TestAdminUsersController(TestContr'
100 100
101 101 response = response.follow()
102 102
103 new_user = self.Session().query(User).filter(User.username == username).one()
103 new_user = self.Session.query(User).filter(User.username == username).one()
104 104 response = self.app.delete(url('user', id=new_user.user_id))
105 105
106 106 assert """successfully deleted user""" in response.session['flash'][0], 'No info about user deletion'
@@ -23,10 +23,6 b' class TestAdminUsersGroupsController(Tes'
23 23 self.checkSessionFlash(response,
24 24 'created users group %s' % TEST_USERS_GROUP)
25 25
26
27
28
29
30 26 def test_new(self):
31 27 response = self.app.get(url('new_users_group'))
32 28
@@ -52,13 +48,13 b' class TestAdminUsersGroupsController(Tes'
52 48 'created users group %s' % users_group_name)
53 49
54 50
55 gr = self.Session().query(UsersGroup)\
51 gr = self.Session.query(UsersGroup)\
56 52 .filter(UsersGroup.users_group_name ==
57 53 users_group_name).one()
58 54
59 55 response = self.app.delete(url('users_group', id=gr.users_group_id))
60 56
61 gr = self.Session().query(UsersGroup)\
57 gr = self.Session.query(UsersGroup)\
62 58 .filter(UsersGroup.users_group_name ==
63 59 users_group_name).scalar()
64 60
@@ -6,21 +6,21 b' class TestChangeSetCommentrController(Te'
6 6
7 7 def setUp(self):
8 8 for x in ChangesetComment.query().all():
9 self.Session().delete(x)
10 self.Session().commit()
9 self.Session.delete(x)
10 self.Session.commit()
11 11
12 12 for x in Notification.query().all():
13 self.Session().delete(x)
14 self.Session().commit()
13 self.Session.delete(x)
14 self.Session.commit()
15 15
16 16 def tearDown(self):
17 17 for x in ChangesetComment.query().all():
18 self.Session().delete(x)
19 self.Session().commit()
18 self.Session.delete(x)
19 self.Session.commit()
20 20
21 21 for x in Notification.query().all():
22 self.Session().delete(x)
23 self.Session().commit()
22 self.Session.delete(x)
23 self.Session.commit()
24 24
25 25 def test_create(self):
26 26 self.log_user()
@@ -311,3 +311,16 b' removed extra unicode conversion in diff'
311 311 f_path=f_path))
312 312
313 313 assert "There is no file nor directory at the given path: %r at revision %r" % (f_path, rev[:12]) in response.session['flash'][0][1], 'No flash message'
314
315 def test_ajaxed_files_list(self):
316 self.log_user()
317 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
318 response = self.app.get(url('files_nodelist_home',repo_name=HG_REPO,
319 f_path='/',
320 revision=rev),
321 extra_environ={'HTTP_X_PARTIAL_XHR':'1'},
322 )
323 self.assertTrue("vcs/web/simplevcs/views/repository.py" in response.body)
324
325
326
@@ -65,7 +65,7 b' class TestForksController(TestController'
65 65 % (repo_name, fork_name) in response.session['flash'][0])
66 66
67 67 #test if the fork was created in the database
68 fork_repo = self.Session().query(Repository)\
68 fork_repo = self.Session.query(Repository)\
69 69 .filter(Repository.repo_name == fork_name).one()
70 70
71 71 self.assertEqual(fork_repo.repo_name, fork_name)
@@ -16,10 +16,10 b' class TestJournalController(TestControll'
16 16
17 17 def test_stop_following_repository(self):
18 18 session = self.log_user()
19 # usr = self.Session().query(User).filter(User.username == 'test_admin').one()
20 # repo = self.Session().query(Repository).filter(Repository.repo_name == HG_REPO).one()
19 # usr = self.Session.query(User).filter(User.username == 'test_admin').one()
20 # repo = self.Session.query(Repository).filter(Repository.repo_name == HG_REPO).one()
21 21 #
22 # followings = self.Session().query(UserFollowing)\
22 # followings = self.Session.query(UserFollowing)\
23 23 # .filter(UserFollowing.user == usr)\
24 24 # .filter(UserFollowing.follows_repository == repo).all()
25 25 #
@@ -9,9 +9,9 b' class TestLoginController(TestController'
9 9
10 10 def tearDown(self):
11 11 for n in Notification.query().all():
12 Session().delete(n)
12 Session.delete(n)
13 13
14 Session().commit()
14 Session.commit()
15 15 self.assertEqual(Notification.query().all(), [])
16 16
17 17 def test_index(self):
@@ -199,7 +199,7 b' class TestLoginController(TestController'
199 199 self.assertEqual(response.status , '302 Found')
200 200 assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
201 201
202 ret = self.Session().query(User).filter(User.username == 'test_regular4').one()
202 ret = self.Session.query(User).filter(User.username == 'test_regular4').one()
203 203 assert ret.username == username , 'field mismatch %s %s' % (ret.username, username)
204 204 assert check_password(password, ret.password) == True , 'password mismatch'
205 205 assert ret.email == email , 'field mismatch %s %s' % (ret.email, email)
@@ -231,8 +231,8 b' class TestLoginController(TestController'
231 231 new.name = name
232 232 new.lastname = lastname
233 233 new.api_key = generate_api_key(username)
234 self.Session().add(new)
235 self.Session().commit()
234 self.Session.add(new)
235 self.Session.commit()
236 236
237 237 response = self.app.post(url(controller='login',
238 238 action='password_reset'),
@@ -37,11 +37,11 b' class TestSummaryController(TestControll'
37 37 in response.body)
38 38
39 39 # clone url...
40 self.assertTrue("""<input type="text" id="clone_url" readonly="readonly" value="hg clone http://test_admin@localhost:80/%s" size="70"/>""" % HG_REPO in response.body)
40 self.assertTrue("""<input type="text" id="clone_url" readonly="readonly" value="http://test_admin@localhost:80/%s" size="70"/>""" % HG_REPO in response.body)
41 41
42 42
43 43 def _enable_stats(self):
44 44 r = Repository.get_by_repo_name(HG_REPO)
45 45 r.enable_statistics = True
46 self.Session().add(r)
47 self.Session().commit()
46 self.Session.add(r)
47 self.Session.commit()
@@ -66,7 +66,7 b' class TestReposGroups(unittest.TestCase)'
66 66
67 67 def test_create_same_name_group(self):
68 68 self.assertRaises(IntegrityError, lambda:self.__make_group('newGroup'))
69 Session().rollback()
69 Session.rollback()
70 70
71 71 def test_same_subgroup(self):
72 72 sg1 = self.__make_group('sub1', parent_id=self.g1.group_id)
@@ -163,20 +163,20 b' class TestUser(unittest.TestCase):'
163 163 usr = UserModel().create_or_update(username=u'test_user', password=u'qweqwe',
164 164 email=u'u232@rhodecode.org',
165 165 name=u'u1', lastname=u'u1')
166 Session().commit()
166 Session.commit()
167 167 self.assertEqual(User.get_by_username(u'test_user'), usr)
168 168
169 169 # make users group
170 170 users_group = UsersGroupModel().create('some_example_group')
171 Session().commit()
171 Session.commit()
172 172
173 173 UsersGroupModel().add_user_to_group(users_group, usr)
174 Session().commit()
174 Session.commit()
175 175
176 176 self.assertEqual(UsersGroup.get(users_group.users_group_id), users_group)
177 177 self.assertEqual(UsersGroupMember.query().count(), 1)
178 178 UserModel().delete(usr.user_id)
179 Session().commit()
179 Session.commit()
180 180
181 181 self.assertEqual(UsersGroupMember.query().all(), [])
182 182
@@ -209,9 +209,9 b' class TestNotifications(unittest.TestCas'
209 209
210 210 def _clean_notifications(self):
211 211 for n in Notification.query().all():
212 Session().delete(n)
212 Session.delete(n)
213 213
214 Session().commit()
214 Session.commit()
215 215 self.assertEqual(Notification.query().all(), [])
216 216
217 217
@@ -223,7 +223,7 b' class TestNotifications(unittest.TestCas'
223 223 notification = NotificationModel().create(created_by=self.u1,
224 224 subject=u'subj', body=u'hi there',
225 225 recipients=usrs)
226 Session().commit()
226 Session.commit()
227 227 u1 = User.get(self.u1)
228 228 u2 = User.get(self.u2)
229 229 u3 = User.get(self.u3)
@@ -248,12 +248,12 b' class TestNotifications(unittest.TestCas'
248 248 notification1 = NotificationModel().create(created_by=self.u1,
249 249 subject=u'subj', body=u'hi there1',
250 250 recipients=[self.u3])
251 Session().commit()
251 Session.commit()
252 252 notification2 = NotificationModel().create(created_by=self.u1,
253 253 subject=u'subj', body=u'hi there2',
254 254 recipients=[self.u3])
255 Session().commit()
256 u3 = Session().query(User).get(self.u3)
255 Session.commit()
256 u3 = Session.query(User).get(self.u3)
257 257
258 258 self.assertEqual(sorted([x.notification for x in u3.notifications]),
259 259 sorted([notification2, notification1]))
@@ -266,12 +266,12 b' class TestNotifications(unittest.TestCas'
266 266 notification = NotificationModel().create(created_by=self.u1,
267 267 subject=u'title', body=u'hi there3',
268 268 recipients=[self.u3, self.u1, self.u2])
269 Session().commit()
269 Session.commit()
270 270 notifications = Notification.query().all()
271 271 self.assertTrue(notification in notifications)
272 272
273 273 Notification.delete(notification.notification_id)
274 Session().commit()
274 Session.commit()
275 275
276 276 notifications = Notification.query().all()
277 277 self.assertFalse(notification in notifications)
@@ -290,7 +290,7 b' class TestNotifications(unittest.TestCas'
290 290 notification = NotificationModel().create(created_by=self.u1,
291 291 subject=u'title', body=u'hi there3',
292 292 recipients=[self.u3, self.u1, self.u2])
293 Session().commit()
293 Session.commit()
294 294
295 295 unotification = UserNotification.query()\
296 296 .filter(UserNotification.notification ==
@@ -302,7 +302,7 b' class TestNotifications(unittest.TestCas'
302 302
303 303 NotificationModel().delete(self.u3,
304 304 notification.notification_id)
305 Session().commit()
305 Session.commit()
306 306
307 307 u3notification = UserNotification.query()\
308 308 .filter(UserNotification.notification ==
@@ -339,7 +339,7 b' class TestNotifications(unittest.TestCas'
339 339 NotificationModel().create(created_by=self.u1,
340 340 subject=u'title', body=u'hi there_delete',
341 341 recipients=[self.u3, self.u1])
342 Session().commit()
342 Session.commit()
343 343
344 344 self.assertEqual(NotificationModel()
345 345 .get_unread_cnt_for_user(self.u1), 1)
@@ -351,7 +351,7 b' class TestNotifications(unittest.TestCas'
351 351 notification = NotificationModel().create(created_by=self.u1,
352 352 subject=u'title', body=u'hi there3',
353 353 recipients=[self.u3, self.u1, self.u2])
354 Session().commit()
354 Session.commit()
355 355
356 356 self.assertEqual(NotificationModel()
357 357 .get_unread_cnt_for_user(self.u1), 2)
@@ -46,5 +46,5 b' def setup_app(command, conf, vars):'
46 46 dbmanage.admin_prompt()
47 47 dbmanage.create_permissions()
48 48 dbmanage.populate_default_permissions()
49 Session().commit()
49 Session.commit()
50 50 load_environment(conf.global_conf, conf.local_conf, initial=True)
General Comments 0
You need to be logged in to leave comments. Login now