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