Show More
@@ -33,7 +33,7 b' from kallithea.config.routing import mak' | |||||
33 |
|
33 | |||
34 | from kallithea.lib import helpers |
|
34 | from kallithea.lib import helpers | |
35 | from kallithea.lib.auth import set_available_permissions |
|
35 | from kallithea.lib.auth import set_available_permissions | |
36 | from kallithea.lib.utils import repo2db_mapper, make_ui, set_app_settings,\ |
|
36 | from kallithea.lib.utils import repo2db_mapper, make_ui, set_app_settings, \ | |
37 | load_rcextensions, check_git_version, set_vcs_config, set_indexer_config |
|
37 | load_rcextensions, check_git_version, set_vcs_config, set_indexer_config | |
38 | from kallithea.lib.utils2 import engine_from_config, str2bool |
|
38 | from kallithea.lib.utils2 import engine_from_config, str2bool | |
39 | from kallithea.lib.db_manage import DbManage |
|
39 | from kallithea.lib.db_manage import DbManage |
@@ -125,8 +125,8 b' class AdminController(BaseController):' | |||||
125 |
|
125 | |||
126 | @HasPermissionAllDecorator('hg.admin') |
|
126 | @HasPermissionAllDecorator('hg.admin') | |
127 | def index(self): |
|
127 | def index(self): | |
128 | users_log = UserLog.query()\ |
|
128 | users_log = UserLog.query() \ | |
129 | .options(joinedload(UserLog.user))\ |
|
129 | .options(joinedload(UserLog.user)) \ | |
130 | .options(joinedload(UserLog.repository)) |
|
130 | .options(joinedload(UserLog.repository)) | |
131 |
|
131 | |||
132 | #FILTERING |
|
132 | #FILTERING |
@@ -73,23 +73,23 b' class GistsController(BaseController):' | |||||
73 | c.show_private = request.GET.get('private') and not_default_user |
|
73 | c.show_private = request.GET.get('private') and not_default_user | |
74 | c.show_public = request.GET.get('public') and not_default_user |
|
74 | c.show_public = request.GET.get('public') and not_default_user | |
75 |
|
75 | |||
76 | gists = Gist().query()\ |
|
76 | gists = Gist().query() \ | |
77 | .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))\ |
|
77 | .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time())) \ | |
78 | .order_by(Gist.created_on.desc()) |
|
78 | .order_by(Gist.created_on.desc()) | |
79 |
|
79 | |||
80 | # MY private |
|
80 | # MY private | |
81 | if c.show_private and not c.show_public: |
|
81 | if c.show_private and not c.show_public: | |
82 | gists = gists.filter(Gist.gist_type == Gist.GIST_PRIVATE)\ |
|
82 | gists = gists.filter(Gist.gist_type == Gist.GIST_PRIVATE) \ | |
83 | .filter(Gist.gist_owner == c.authuser.user_id) |
|
83 | .filter(Gist.gist_owner == c.authuser.user_id) | |
84 | # MY public |
|
84 | # MY public | |
85 | elif c.show_public and not c.show_private: |
|
85 | elif c.show_public and not c.show_private: | |
86 | gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC)\ |
|
86 | gists = gists.filter(Gist.gist_type == Gist.GIST_PUBLIC) \ | |
87 | .filter(Gist.gist_owner == c.authuser.user_id) |
|
87 | .filter(Gist.gist_owner == c.authuser.user_id) | |
88 |
|
88 | |||
89 | # MY public+private |
|
89 | # MY public+private | |
90 | elif c.show_private and c.show_public: |
|
90 | elif c.show_private and c.show_public: | |
91 | gists = gists.filter(or_(Gist.gist_type == Gist.GIST_PUBLIC, |
|
91 | gists = gists.filter(or_(Gist.gist_type == Gist.GIST_PUBLIC, | |
92 | Gist.gist_type == Gist.GIST_PRIVATE))\ |
|
92 | Gist.gist_type == Gist.GIST_PRIVATE)) \ | |
93 | .filter(Gist.gist_owner == c.authuser.user_id) |
|
93 | .filter(Gist.gist_owner == c.authuser.user_id) | |
94 |
|
94 | |||
95 | # default show ALL public gists |
|
95 | # default show ALL public gists |
@@ -81,9 +81,9 b' class MyAccountController(BaseController' | |||||
81 | self.authuser.user_id).all()] |
|
81 | self.authuser.user_id).all()] | |
82 | else: |
|
82 | else: | |
83 | admin = True |
|
83 | admin = True | |
84 | repos_list = Session().query(Repository)\ |
|
84 | repos_list = Session().query(Repository) \ | |
85 | .filter(Repository.user_id == |
|
85 | .filter(Repository.user_id == | |
86 | self.authuser.user_id)\ |
|
86 | self.authuser.user_id) \ | |
87 | .order_by(func.lower(Repository.repo_name)).all() |
|
87 | .order_by(func.lower(Repository.repo_name)).all() | |
88 |
|
88 | |||
89 | repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list, |
|
89 | repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list, | |
@@ -207,7 +207,7 b' class MyAccountController(BaseController' | |||||
207 | c.active = 'emails' |
|
207 | c.active = 'emails' | |
208 | self.__load_data() |
|
208 | self.__load_data() | |
209 |
|
209 | |||
210 | c.user_email_map = UserEmailMap.query()\ |
|
210 | c.user_email_map = UserEmailMap.query() \ | |
211 | .filter(UserEmailMap.user == c.user).all() |
|
211 | .filter(UserEmailMap.user == c.user).all() | |
212 | return render('admin/my_account/my_account.html') |
|
212 | return render('admin/my_account/my_account.html') | |
213 |
|
213 |
@@ -154,7 +154,7 b' class NotificationsController(BaseContro' | |||||
154 | for un in no.notifications_to_users) |
|
154 | for un in no.notifications_to_users) | |
155 | repo_admin = h.HasRepoPermissionAny('repository.admin') |
|
155 | repo_admin = h.HasRepoPermissionAny('repository.admin') | |
156 | if no and (h.HasPermissionAny('hg.admin')() or repo_admin or owner): |
|
156 | if no and (h.HasPermissionAny('hg.admin')() or repo_admin or owner): | |
157 | unotification = NotificationModel()\ |
|
157 | unotification = NotificationModel() \ | |
158 | .get_user_notification(c.user.user_id, no) |
|
158 | .get_user_notification(c.user.user_id, no) | |
159 |
|
159 | |||
160 | # if this association to user is not valid, we don't want to show |
|
160 | # if this association to user is not valid, we don't want to show |
@@ -184,7 +184,7 b' class PermissionsController(BaseControll' | |||||
184 | def permission_ips(self): |
|
184 | def permission_ips(self): | |
185 | c.active = 'ips' |
|
185 | c.active = 'ips' | |
186 | c.user = User.get_default_user() |
|
186 | c.user = User.get_default_user() | |
187 | c.user_ip_map = UserIpMap.query()\ |
|
187 | c.user_ip_map = UserIpMap.query() \ | |
188 | .filter(UserIpMap.user == c.user).all() |
|
188 | .filter(UserIpMap.user == c.user).all() | |
189 |
|
189 | |||
190 | return render('admin/permissions/permissions.html') |
|
190 | return render('admin/permissions/permissions.html') |
@@ -110,8 +110,8 b' class RepoGroupsController(BaseControlle' | |||||
110 | def index(self, format='html'): |
|
110 | def index(self, format='html'): | |
111 | """GET /repo_groups: All items in the collection""" |
|
111 | """GET /repo_groups: All items in the collection""" | |
112 | # url('repos_groups') |
|
112 | # url('repos_groups') | |
113 | _list = RepoGroup.query()\ |
|
113 | _list = RepoGroup.query() \ | |
114 | .order_by(func.lower(RepoGroup.group_name))\ |
|
114 | .order_by(func.lower(RepoGroup.group_name)) \ | |
115 | .all() |
|
115 | .all() | |
116 | group_iter = RepoGroupList(_list, perm_set=['group.admin']) |
|
116 | group_iter = RepoGroupList(_list, perm_set=['group.admin']) | |
117 | repo_groups_data = [] |
|
117 | repo_groups_data = [] | |
@@ -329,13 +329,13 b' class RepoGroupsController(BaseControlle' | |||||
329 | #overwrite our cached list with current filter |
|
329 | #overwrite our cached list with current filter | |
330 | c.repo_cnt = 0 |
|
330 | c.repo_cnt = 0 | |
331 |
|
331 | |||
332 | groups = RepoGroup.query().order_by(RepoGroup.group_name)\ |
|
332 | groups = RepoGroup.query().order_by(RepoGroup.group_name) \ | |
333 | .filter(RepoGroup.group_parent_id == c.group.group_id).all() |
|
333 | .filter(RepoGroup.group_parent_id == c.group.group_id).all() | |
334 | c.groups = self.scm_model.get_repo_groups(groups) |
|
334 | c.groups = self.scm_model.get_repo_groups(groups) | |
335 |
|
335 | |||
336 | c.repos_list = Repository.query()\ |
|
336 | c.repos_list = Repository.query() \ | |
337 | .filter(Repository.group_id == c.group.group_id)\ |
|
337 | .filter(Repository.group_id == c.group.group_id) \ | |
338 | .order_by(func.lower(Repository.repo_name))\ |
|
338 | .order_by(func.lower(Repository.repo_name)) \ | |
339 | .all() |
|
339 | .all() | |
340 |
|
340 | |||
341 | repos_data = RepoModel().get_repos_as_dict(repos_list=c.repos_list, |
|
341 | repos_data = RepoModel().get_repos_as_dict(repos_list=c.repos_list, |
@@ -42,7 +42,7 b' from kallithea.lib.base import BaseRepoC' | |||||
42 | from kallithea.lib.utils import action_logger, jsonify |
|
42 | from kallithea.lib.utils import action_logger, jsonify | |
43 | from kallithea.lib.vcs import RepositoryError |
|
43 | from kallithea.lib.vcs import RepositoryError | |
44 | from kallithea.model.meta import Session |
|
44 | from kallithea.model.meta import Session | |
45 | from kallithea.model.db import User, Repository, UserFollowing, RepoGroup,\ |
|
45 | from kallithea.model.db import User, Repository, UserFollowing, RepoGroup, \ | |
46 | Setting, RepositoryField |
|
46 | Setting, RepositoryField | |
47 | from kallithea.model.forms import RepoForm, RepoFieldForm, RepoPermsForm |
|
47 | from kallithea.model.forms import RepoForm, RepoFieldForm, RepoPermsForm | |
48 | from kallithea.model.scm import ScmModel, AvailableRepoGroupChoices, RepoList |
|
48 | from kallithea.model.scm import ScmModel, AvailableRepoGroupChoices, RepoList | |
@@ -102,8 +102,8 b' class ReposController(BaseRepoController' | |||||
102 | def index(self, format='html'): |
|
102 | def index(self, format='html'): | |
103 | """GET /repos: All items in the collection""" |
|
103 | """GET /repos: All items in the collection""" | |
104 | # url('repos') |
|
104 | # url('repos') | |
105 | _list = Repository.query()\ |
|
105 | _list = Repository.query() \ | |
106 | .order_by(func.lower(Repository.repo_name))\ |
|
106 | .order_by(func.lower(Repository.repo_name)) \ | |
107 | .all() |
|
107 | .all() | |
108 |
|
108 | |||
109 | c.repos_list = RepoList(_list, perm_set=['repository.admin']) |
|
109 | c.repos_list = RepoList(_list, perm_set=['repository.admin']) | |
@@ -127,7 +127,7 b' class ReposController(BaseRepoController' | |||||
127 | try: |
|
127 | try: | |
128 | # CanWriteGroup validators checks permissions of this POST |
|
128 | # CanWriteGroup validators checks permissions of this POST | |
129 | form_result = RepoForm(repo_groups=c.repo_groups, |
|
129 | form_result = RepoForm(repo_groups=c.repo_groups, | |
130 | landing_revs=c.landing_revs_choices)()\ |
|
130 | landing_revs=c.landing_revs_choices)() \ | |
131 | .to_python(dict(request.POST)) |
|
131 | .to_python(dict(request.POST)) | |
132 |
|
132 | |||
133 | # create is done sometimes async on celery, db transaction |
|
133 | # create is done sometimes async on celery, db transaction | |
@@ -239,7 +239,7 b' class ReposController(BaseRepoController' | |||||
239 | c.repo_info = self._load_repo(repo_name) |
|
239 | c.repo_info = self._load_repo(repo_name) | |
240 | self.__load_defaults(c.repo_info) |
|
240 | self.__load_defaults(c.repo_info) | |
241 | c.active = 'settings' |
|
241 | c.active = 'settings' | |
242 | c.repo_fields = RepositoryField.query()\ |
|
242 | c.repo_fields = RepositoryField.query() \ | |
243 | .filter(RepositoryField.repository == c.repo_info).all() |
|
243 | .filter(RepositoryField.repository == c.repo_info).all() | |
244 |
|
244 | |||
245 | repo_model = RepoModel() |
|
245 | repo_model = RepoModel() | |
@@ -334,7 +334,7 b' class ReposController(BaseRepoController' | |||||
334 | """GET /repo_name/settings: Form to edit an existing item""" |
|
334 | """GET /repo_name/settings: Form to edit an existing item""" | |
335 | # url('edit_repo', repo_name=ID) |
|
335 | # url('edit_repo', repo_name=ID) | |
336 | defaults = self.__load_data(repo_name) |
|
336 | defaults = self.__load_data(repo_name) | |
337 | c.repo_fields = RepositoryField.query()\ |
|
337 | c.repo_fields = RepositoryField.query() \ | |
338 | .filter(RepositoryField.repository == c.repo_info).all() |
|
338 | .filter(RepositoryField.repository == c.repo_info).all() | |
339 | repo_model = RepoModel() |
|
339 | repo_model = RepoModel() | |
340 | c.users_array = repo_model.get_users_js() |
|
340 | c.users_array = repo_model.get_users_js() | |
@@ -403,7 +403,7 b' class ReposController(BaseRepoController' | |||||
403 | """GET /repo_name/settings: Form to edit an existing item""" |
|
403 | """GET /repo_name/settings: Form to edit an existing item""" | |
404 | # url('edit_repo', repo_name=ID) |
|
404 | # url('edit_repo', repo_name=ID) | |
405 | c.repo_info = self._load_repo(repo_name) |
|
405 | c.repo_info = self._load_repo(repo_name) | |
406 | c.repo_fields = RepositoryField.query()\ |
|
406 | c.repo_fields = RepositoryField.query() \ | |
407 | .filter(RepositoryField.repository == c.repo_info).all() |
|
407 | .filter(RepositoryField.repository == c.repo_info).all() | |
408 | c.active = 'fields' |
|
408 | c.active = 'fields' | |
409 | if request.POST: |
|
409 | if request.POST: | |
@@ -450,8 +450,8 b' class ReposController(BaseRepoController' | |||||
450 | # url('edit_repo', repo_name=ID) |
|
450 | # url('edit_repo', repo_name=ID) | |
451 | c.repo_info = self._load_repo(repo_name) |
|
451 | c.repo_info = self._load_repo(repo_name) | |
452 | c.default_user_id = User.get_default_user().user_id |
|
452 | c.default_user_id = User.get_default_user().user_id | |
453 | c.in_public_journal = UserFollowing.query()\ |
|
453 | c.in_public_journal = UserFollowing.query() \ | |
454 | .filter(UserFollowing.user_id == c.default_user_id)\ |
|
454 | .filter(UserFollowing.user_id == c.default_user_id) \ | |
455 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() |
|
455 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() | |
456 |
|
456 | |||
457 | _repos = Repository.query().order_by(Repository.repo_name).all() |
|
457 | _repos = Repository.query().order_by(Repository.repo_name).all() |
@@ -361,10 +361,10 b' class SettingsController(BaseController)' | |||||
361 | h.flash(_('Please enter email address'), category='error') |
|
361 | h.flash(_('Please enter email address'), category='error') | |
362 | raise HTTPFound(location=url('admin_settings_email')) |
|
362 | raise HTTPFound(location=url('admin_settings_email')) | |
363 |
|
363 | |||
364 | test_email_txt_body = EmailNotificationModel()\ |
|
364 | test_email_txt_body = EmailNotificationModel() \ | |
365 | .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT, |
|
365 | .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT, | |
366 | 'txt', body=test_body) |
|
366 | 'txt', body=test_body) | |
367 | test_email_html_body = EmailNotificationModel()\ |
|
367 | test_email_html_body = EmailNotificationModel() \ | |
368 | .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT, |
|
368 | .get_email_tmpl(EmailNotificationModel.TYPE_DEFAULT, | |
369 | 'html', body=test_body) |
|
369 | 'html', body=test_body) | |
370 |
|
370 |
@@ -90,8 +90,8 b' class UserGroupsController(BaseControlle' | |||||
90 | def index(self, format='html'): |
|
90 | def index(self, format='html'): | |
91 | """GET /users_groups: All items in the collection""" |
|
91 | """GET /users_groups: All items in the collection""" | |
92 | # url('users_groups') |
|
92 | # url('users_groups') | |
93 | _list = UserGroup.query()\ |
|
93 | _list = UserGroup.query() \ | |
94 | .order_by(func.lower(UserGroup.users_group_name))\ |
|
94 | .order_by(func.lower(UserGroup.users_group_name)) \ | |
95 | .all() |
|
95 | .all() | |
96 | group_iter = UserGroupList(_list, perm_set=['usergroup.admin']) |
|
96 | group_iter = UserGroupList(_list, perm_set=['usergroup.admin']) | |
97 | user_groups_data = [] |
|
97 | user_groups_data = [] | |
@@ -362,20 +362,20 b' class UserGroupsController(BaseControlle' | |||||
362 | 'repositories': {}, |
|
362 | 'repositories': {}, | |
363 | 'repositories_groups': {} |
|
363 | 'repositories_groups': {} | |
364 | } |
|
364 | } | |
365 | ugroup_repo_perms = UserGroupRepoToPerm.query()\ |
|
365 | ugroup_repo_perms = UserGroupRepoToPerm.query() \ | |
366 | .options(joinedload(UserGroupRepoToPerm.permission))\ |
|
366 | .options(joinedload(UserGroupRepoToPerm.permission)) \ | |
367 | .options(joinedload(UserGroupRepoToPerm.repository))\ |
|
367 | .options(joinedload(UserGroupRepoToPerm.repository)) \ | |
368 | .filter(UserGroupRepoToPerm.users_group_id == id)\ |
|
368 | .filter(UserGroupRepoToPerm.users_group_id == id) \ | |
369 | .all() |
|
369 | .all() | |
370 |
|
370 | |||
371 | for gr in ugroup_repo_perms: |
|
371 | for gr in ugroup_repo_perms: | |
372 | permissions['repositories'][gr.repository.repo_name] \ |
|
372 | permissions['repositories'][gr.repository.repo_name] \ | |
373 | = gr.permission.permission_name |
|
373 | = gr.permission.permission_name | |
374 |
|
374 | |||
375 | ugroup_group_perms = UserGroupRepoGroupToPerm.query()\ |
|
375 | ugroup_group_perms = UserGroupRepoGroupToPerm.query() \ | |
376 | .options(joinedload(UserGroupRepoGroupToPerm.permission))\ |
|
376 | .options(joinedload(UserGroupRepoGroupToPerm.permission)) \ | |
377 | .options(joinedload(UserGroupRepoGroupToPerm.group))\ |
|
377 | .options(joinedload(UserGroupRepoGroupToPerm.group)) \ | |
378 | .filter(UserGroupRepoGroupToPerm.users_group_id == id)\ |
|
378 | .filter(UserGroupRepoGroupToPerm.users_group_id == id) \ | |
379 | .all() |
|
379 | .all() | |
380 |
|
380 | |||
381 | for gr in ugroup_group_perms: |
|
381 | for gr in ugroup_group_perms: | |
@@ -418,8 +418,8 b' class UserGroupsController(BaseControlle' | |||||
418 | Session().add(user_group) |
|
418 | Session().add(user_group) | |
419 | usergroup_model = UserGroupModel() |
|
419 | usergroup_model = UserGroupModel() | |
420 |
|
420 | |||
421 | defs = UserGroupToPerm.query()\ |
|
421 | defs = UserGroupToPerm.query() \ | |
422 | .filter(UserGroupToPerm.users_group == user_group)\ |
|
422 | .filter(UserGroupToPerm.users_group == user_group) \ | |
423 | .all() |
|
423 | .all() | |
424 | for ug in defs: |
|
424 | for ug in defs: | |
425 | Session().delete(ug) |
|
425 | Session().delete(ug) |
@@ -71,9 +71,9 b' class UsersController(BaseController):' | |||||
71 | """GET /users: All items in the collection""" |
|
71 | """GET /users: All items in the collection""" | |
72 | # url('users') |
|
72 | # url('users') | |
73 |
|
73 | |||
74 | c.users_list = User.query().order_by(User.username)\ |
|
74 | c.users_list = User.query().order_by(User.username) \ | |
75 | .filter(User.username != User.DEFAULT_USER)\ |
|
75 | .filter(User.username != User.DEFAULT_USER) \ | |
76 | .order_by(func.lower(User.username))\ |
|
76 | .order_by(func.lower(User.username)) \ | |
77 | .all() |
|
77 | .all() | |
78 |
|
78 | |||
79 | users_data = [] |
|
79 | users_data = [] | |
@@ -362,8 +362,8 b' class UsersController(BaseController):' | |||||
362 | Session().add(user) |
|
362 | Session().add(user) | |
363 | user_model = UserModel() |
|
363 | user_model = UserModel() | |
364 |
|
364 | |||
365 | defs = UserToPerm.query()\ |
|
365 | defs = UserToPerm.query() \ | |
366 | .filter(UserToPerm.user == user)\ |
|
366 | .filter(UserToPerm.user == user) \ | |
367 | .all() |
|
367 | .all() | |
368 | for ug in defs: |
|
368 | for ug in defs: | |
369 | Session().delete(ug) |
|
369 | Session().delete(ug) | |
@@ -391,7 +391,7 b' class UsersController(BaseController):' | |||||
391 | def edit_emails(self, id): |
|
391 | def edit_emails(self, id): | |
392 | c.user = self._get_user_or_raise_if_default(id) |
|
392 | c.user = self._get_user_or_raise_if_default(id) | |
393 | c.active = 'emails' |
|
393 | c.active = 'emails' | |
394 | c.user_email_map = UserEmailMap.query()\ |
|
394 | c.user_email_map = UserEmailMap.query() \ | |
395 | .filter(UserEmailMap.user == c.user).all() |
|
395 | .filter(UserEmailMap.user == c.user).all() | |
396 |
|
396 | |||
397 | defaults = c.user.get_dict() |
|
397 | defaults = c.user.get_dict() | |
@@ -435,11 +435,11 b' class UsersController(BaseController):' | |||||
435 | def edit_ips(self, id): |
|
435 | def edit_ips(self, id): | |
436 | c.user = self._get_user_or_raise_if_default(id) |
|
436 | c.user = self._get_user_or_raise_if_default(id) | |
437 | c.active = 'ips' |
|
437 | c.active = 'ips' | |
438 | c.user_ip_map = UserIpMap.query()\ |
|
438 | c.user_ip_map = UserIpMap.query() \ | |
439 | .filter(UserIpMap.user == c.user).all() |
|
439 | .filter(UserIpMap.user == c.user).all() | |
440 |
|
440 | |||
441 | c.inherit_default_ips = c.user.inherit_default_permissions |
|
441 | c.inherit_default_ips = c.user.inherit_default_permissions | |
442 | c.default_user_ip_map = UserIpMap.query()\ |
|
442 | c.default_user_ip_map = UserIpMap.query() \ | |
443 | .filter(UserIpMap.user == User.get_default_user()).all() |
|
443 | .filter(UserIpMap.user == User.get_default_user()).all() | |
444 |
|
444 | |||
445 | defaults = c.user.get_dict() |
|
445 | defaults = c.user.get_dict() |
@@ -2508,9 +2508,9 b' class ApiController(JSONRPCController):' | |||||
2508 | user_id = get_user_or_error(userid).user_id |
|
2508 | user_id = get_user_or_error(userid).user_id | |
2509 |
|
2509 | |||
2510 | gists = [] |
|
2510 | gists = [] | |
2511 | _gists = Gist().query()\ |
|
2511 | _gists = Gist().query() \ | |
2512 | .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))\ |
|
2512 | .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time())) \ | |
2513 | .filter(Gist.gist_owner == user_id)\ |
|
2513 | .filter(Gist.gist_owner == user_id) \ | |
2514 | .order_by(Gist.created_on.desc()) |
|
2514 | .order_by(Gist.created_on.desc()) | |
2515 | for gist in _gists: |
|
2515 | for gist in _gists: | |
2516 | gists.append(gist.get_api_data()) |
|
2516 | gists.append(gist.get_api_data()) |
@@ -38,7 +38,7 b' from kallithea.lib.base import BaseRepoC' | |||||
38 | from kallithea.lib.helpers import RepoPage |
|
38 | from kallithea.lib.helpers import RepoPage | |
39 | from kallithea.lib.compat import json |
|
39 | from kallithea.lib.compat import json | |
40 | from kallithea.lib.graphmod import graph_data |
|
40 | from kallithea.lib.graphmod import graph_data | |
41 | from kallithea.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\ |
|
41 | from kallithea.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError, \ | |
42 | ChangesetError, NodeDoesNotExistError, EmptyRepositoryError |
|
42 | ChangesetError, NodeDoesNotExistError, EmptyRepositoryError | |
43 | from kallithea.lib.utils2 import safe_int, safe_str |
|
43 | from kallithea.lib.utils2 import safe_int, safe_str | |
44 |
|
44 |
@@ -40,7 +40,7 b' from kallithea.lib.vcs.exceptions import' | |||||
40 |
|
40 | |||
41 | from kallithea.lib.compat import json |
|
41 | from kallithea.lib.compat import json | |
42 | import kallithea.lib.helpers as h |
|
42 | import kallithea.lib.helpers as h | |
43 | from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator,\ |
|
43 | from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \ | |
44 | NotAnonymous |
|
44 | NotAnonymous | |
45 | from kallithea.lib.base import BaseRepoController, render |
|
45 | from kallithea.lib.base import BaseRepoController, render | |
46 | from kallithea.lib.utils import action_logger |
|
46 | from kallithea.lib.utils import action_logger | |
@@ -242,7 +242,7 b' class ChangesetController(BaseRepoContro' | |||||
242 | changeset.raw_id, with_revisions=True) |
|
242 | changeset.raw_id, with_revisions=True) | |
243 | if st.changeset_comment_id is not None) |
|
243 | if st.changeset_comment_id is not None) | |
244 |
|
244 | |||
245 | inlines = ChangesetCommentsModel()\ |
|
245 | inlines = ChangesetCommentsModel() \ | |
246 | .get_inline_comments(c.db_repo.repo_id, |
|
246 | .get_inline_comments(c.db_repo.repo_id, | |
247 | revision=changeset.raw_id) |
|
247 | revision=changeset.raw_id) | |
248 | c.inline_comments.extend(inlines) |
|
248 | c.inline_comments.extend(inlines) |
@@ -40,7 +40,7 b' from kallithea.lib import diffs' | |||||
40 | from kallithea.lib import helpers as h |
|
40 | from kallithea.lib import helpers as h | |
41 |
|
41 | |||
42 | from kallithea.lib.compat import OrderedDict |
|
42 | from kallithea.lib.compat import OrderedDict | |
43 | from kallithea.lib.utils2 import convert_line_endings, detect_mode, safe_str,\ |
|
43 | from kallithea.lib.utils2 import convert_line_endings, detect_mode, safe_str, \ | |
44 | str2bool |
|
44 | str2bool | |
45 | from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
45 | from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
46 | from kallithea.lib.base import BaseRepoController, render |
|
46 | from kallithea.lib.base import BaseRepoController, render | |
@@ -48,7 +48,7 b' from kallithea.lib.vcs.backends.base imp' | |||||
48 | from kallithea.lib.vcs.conf import settings |
|
48 | from kallithea.lib.vcs.conf import settings | |
49 | from kallithea.lib.vcs.exceptions import RepositoryError, \ |
|
49 | from kallithea.lib.vcs.exceptions import RepositoryError, \ | |
50 | ChangesetDoesNotExistError, EmptyRepositoryError, \ |
|
50 | ChangesetDoesNotExistError, EmptyRepositoryError, \ | |
51 | ImproperArchiveTypeError, VCSError, NodeAlreadyExistsError,\ |
|
51 | ImproperArchiveTypeError, VCSError, NodeAlreadyExistsError, \ | |
52 | NodeDoesNotExistError, ChangesetError, NodeError |
|
52 | NodeDoesNotExistError, ChangesetError, NodeError | |
53 | from kallithea.lib.vcs.nodes import FileNode |
|
53 | from kallithea.lib.vcs.nodes import FileNode | |
54 |
|
54 | |||
@@ -56,7 +56,7 b' from kallithea.model.repo import RepoMod' | |||||
56 | from kallithea.model.scm import ScmModel |
|
56 | from kallithea.model.scm import ScmModel | |
57 | from kallithea.model.db import Repository |
|
57 | from kallithea.model.db import Repository | |
58 |
|
58 | |||
59 | from kallithea.controllers.changeset import anchor_url, _ignorews_url,\ |
|
59 | from kallithea.controllers.changeset import anchor_url, _ignorews_url, \ | |
60 | _context_url, get_line_ctx, get_ignore_ws |
|
60 | _context_url, get_line_ctx, get_ignore_ws | |
61 | from webob.exc import HTTPNotFound |
|
61 | from webob.exc import HTTPNotFound | |
62 | from kallithea.lib.exceptions import NonRelativePathError |
|
62 | from kallithea.lib.exceptions import NonRelativePathError |
@@ -49,7 +49,7 b' class FollowersController(BaseRepoContro' | |||||
49 | def followers(self, repo_name): |
|
49 | def followers(self, repo_name): | |
50 | p = safe_int(request.GET.get('page', 1), 1) |
|
50 | p = safe_int(request.GET.get('page', 1), 1) | |
51 | repo_id = c.db_repo.repo_id |
|
51 | repo_id = c.db_repo.repo_id | |
52 | d = UserFollowing.get_repo_followers(repo_id)\ |
|
52 | d = UserFollowing.get_repo_followers(repo_id) \ | |
53 | .order_by(UserFollowing.follows_from) |
|
53 | .order_by(UserFollowing.follows_from) | |
54 | c.followers_pager = Page(d, page=p, items_per_page=20) |
|
54 | c.followers_pager = Page(d, page=p, items_per_page=20) | |
55 |
|
55 |
@@ -80,8 +80,8 b' class ForksController(BaseRepoController' | |||||
80 | raise HTTPFound(location=url('repos')) |
|
80 | raise HTTPFound(location=url('repos')) | |
81 |
|
81 | |||
82 | c.default_user_id = User.get_default_user().user_id |
|
82 | c.default_user_id = User.get_default_user().user_id | |
83 | c.in_public_journal = UserFollowing.query()\ |
|
83 | c.in_public_journal = UserFollowing.query() \ | |
84 | .filter(UserFollowing.user_id == c.default_user_id)\ |
|
84 | .filter(UserFollowing.user_id == c.default_user_id) \ | |
85 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() |
|
85 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() | |
86 |
|
86 | |||
87 | if c.repo_info.stats: |
|
87 | if c.repo_info.stats: |
@@ -57,9 +57,9 b' class HomeController(BaseController):' | |||||
57 | c.groups = self.scm_model.get_repo_groups() |
|
57 | c.groups = self.scm_model.get_repo_groups() | |
58 | c.group = None |
|
58 | c.group = None | |
59 |
|
59 | |||
60 | c.repos_list = Repository.query()\ |
|
60 | c.repos_list = Repository.query() \ | |
61 | .filter(Repository.group_id == None)\ |
|
61 | .filter(Repository.group_id == None) \ | |
62 | .order_by(func.lower(Repository.repo_name))\ |
|
62 | .order_by(func.lower(Repository.repo_name)) \ | |
63 | .all() |
|
63 | .all() | |
64 |
|
64 | |||
65 | repos_data = RepoModel().get_repos_as_dict(repos_list=c.repos_list, |
|
65 | repos_data = RepoModel().get_repos_as_dict(repos_list=c.repos_list, |
@@ -92,12 +92,12 b' class JournalController(BaseController):' | |||||
92 | if not repo_ids and user_ids: |
|
92 | if not repo_ids and user_ids: | |
93 | filtering_criterion = UserLog.user_id.in_(user_ids) |
|
93 | filtering_criterion = UserLog.user_id.in_(user_ids) | |
94 | if filtering_criterion is not None: |
|
94 | if filtering_criterion is not None: | |
95 | journal = self.sa.query(UserLog)\ |
|
95 | journal = self.sa.query(UserLog) \ | |
96 | .options(joinedload(UserLog.user))\ |
|
96 | .options(joinedload(UserLog.user)) \ | |
97 | .options(joinedload(UserLog.repository)) |
|
97 | .options(joinedload(UserLog.repository)) | |
98 | #filter |
|
98 | #filter | |
99 | journal = _journal_filter(journal, c.search_term) |
|
99 | journal = _journal_filter(journal, c.search_term) | |
100 | journal = journal.filter(filtering_criterion)\ |
|
100 | journal = journal.filter(filtering_criterion) \ | |
101 | .order_by(UserLog.action_date.desc()) |
|
101 | .order_by(UserLog.action_date.desc()) | |
102 | else: |
|
102 | else: | |
103 | journal = [] |
|
103 | journal = [] | |
@@ -194,9 +194,9 b' class JournalController(BaseController):' | |||||
194 | # Return a rendered template |
|
194 | # Return a rendered template | |
195 | p = safe_int(request.GET.get('page', 1), 1) |
|
195 | p = safe_int(request.GET.get('page', 1), 1) | |
196 | c.user = User.get(self.authuser.user_id) |
|
196 | c.user = User.get(self.authuser.user_id) | |
197 | c.following = self.sa.query(UserFollowing)\ |
|
197 | c.following = self.sa.query(UserFollowing) \ | |
198 | .filter(UserFollowing.user_id == self.authuser.user_id)\ |
|
198 | .filter(UserFollowing.user_id == self.authuser.user_id) \ | |
199 | .options(joinedload(UserFollowing.follows_repository))\ |
|
199 | .options(joinedload(UserFollowing.follows_repository)) \ | |
200 | .all() |
|
200 | .all() | |
201 |
|
201 | |||
202 | journal = self._get_journal_data(c.following) |
|
202 | journal = self._get_journal_data(c.following) | |
@@ -210,9 +210,9 b' class JournalController(BaseController):' | |||||
210 | if request.environ.get('HTTP_X_PARTIAL_XHR'): |
|
210 | if request.environ.get('HTTP_X_PARTIAL_XHR'): | |
211 | return render('journal/journal_data.html') |
|
211 | return render('journal/journal_data.html') | |
212 |
|
212 | |||
213 | repos_list = Session().query(Repository)\ |
|
213 | repos_list = Session().query(Repository) \ | |
214 | .filter(Repository.user_id == |
|
214 | .filter(Repository.user_id == | |
215 | self.authuser.user_id)\ |
|
215 | self.authuser.user_id) \ | |
216 | .order_by(func.lower(Repository.repo_name)).all() |
|
216 | .order_by(func.lower(Repository.repo_name)).all() | |
217 |
|
217 | |||
218 | repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list, |
|
218 | repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list, | |
@@ -280,9 +280,9 b' class JournalController(BaseController):' | |||||
280 | """ |
|
280 | """ | |
281 | Produce an atom-1.0 feed via feedgenerator module |
|
281 | Produce an atom-1.0 feed via feedgenerator module | |
282 | """ |
|
282 | """ | |
283 | following = self.sa.query(UserFollowing)\ |
|
283 | following = self.sa.query(UserFollowing) \ | |
284 | .filter(UserFollowing.user_id == self.authuser.user_id)\ |
|
284 | .filter(UserFollowing.user_id == self.authuser.user_id) \ | |
285 | .options(joinedload(UserFollowing.follows_repository))\ |
|
285 | .options(joinedload(UserFollowing.follows_repository)) \ | |
286 | .all() |
|
286 | .all() | |
287 | return self._atom_feed(following, public=False) |
|
287 | return self._atom_feed(following, public=False) | |
288 |
|
288 | |||
@@ -292,9 +292,9 b' class JournalController(BaseController):' | |||||
292 | """ |
|
292 | """ | |
293 | Produce an rss feed via feedgenerator module |
|
293 | Produce an rss feed via feedgenerator module | |
294 | """ |
|
294 | """ | |
295 | following = self.sa.query(UserFollowing)\ |
|
295 | following = self.sa.query(UserFollowing) \ | |
296 | .filter(UserFollowing.user_id == self.authuser.user_id)\ |
|
296 | .filter(UserFollowing.user_id == self.authuser.user_id) \ | |
297 | .options(joinedload(UserFollowing.follows_repository))\ |
|
297 | .options(joinedload(UserFollowing.follows_repository)) \ | |
298 | .all() |
|
298 | .all() | |
299 | return self._rss_feed(following, public=False) |
|
299 | return self._rss_feed(following, public=False) | |
300 |
|
300 | |||
@@ -330,9 +330,9 b' class JournalController(BaseController):' | |||||
330 | # Return a rendered template |
|
330 | # Return a rendered template | |
331 | p = safe_int(request.GET.get('page', 1), 1) |
|
331 | p = safe_int(request.GET.get('page', 1), 1) | |
332 |
|
332 | |||
333 | c.following = self.sa.query(UserFollowing)\ |
|
333 | c.following = self.sa.query(UserFollowing) \ | |
334 | .filter(UserFollowing.user_id == self.authuser.user_id)\ |
|
334 | .filter(UserFollowing.user_id == self.authuser.user_id) \ | |
335 | .options(joinedload(UserFollowing.follows_repository))\ |
|
335 | .options(joinedload(UserFollowing.follows_repository)) \ | |
336 | .all() |
|
336 | .all() | |
337 |
|
337 | |||
338 | journal = self._get_journal_data(c.following) |
|
338 | journal = self._get_journal_data(c.following) | |
@@ -351,9 +351,9 b' class JournalController(BaseController):' | |||||
351 | """ |
|
351 | """ | |
352 | Produce an atom-1.0 feed via feedgenerator module |
|
352 | Produce an atom-1.0 feed via feedgenerator module | |
353 | """ |
|
353 | """ | |
354 | c.following = self.sa.query(UserFollowing)\ |
|
354 | c.following = self.sa.query(UserFollowing) \ | |
355 | .filter(UserFollowing.user_id == self.authuser.user_id)\ |
|
355 | .filter(UserFollowing.user_id == self.authuser.user_id) \ | |
356 | .options(joinedload(UserFollowing.follows_repository))\ |
|
356 | .options(joinedload(UserFollowing.follows_repository)) \ | |
357 | .all() |
|
357 | .all() | |
358 |
|
358 | |||
359 | return self._atom_feed(c.following) |
|
359 | return self._atom_feed(c.following) | |
@@ -363,9 +363,9 b' class JournalController(BaseController):' | |||||
363 | """ |
|
363 | """ | |
364 | Produce an rss2 feed via feedgenerator module |
|
364 | Produce an rss2 feed via feedgenerator module | |
365 | """ |
|
365 | """ | |
366 | c.following = self.sa.query(UserFollowing)\ |
|
366 | c.following = self.sa.query(UserFollowing) \ | |
367 | .filter(UserFollowing.user_id == self.authuser.user_id)\ |
|
367 | .filter(UserFollowing.user_id == self.authuser.user_id) \ | |
368 | .options(joinedload(UserFollowing.follows_repository))\ |
|
368 | .options(joinedload(UserFollowing.follows_repository)) \ | |
369 | .all() |
|
369 | .all() | |
370 |
|
370 | |||
371 | return self._rss_feed(c.following) |
|
371 | return self._rss_feed(c.following) |
@@ -119,7 +119,7 b' class LoginController(BaseController):' | |||||
119 | @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate', |
|
119 | @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate', | |
120 | 'hg.register.manual_activate') |
|
120 | 'hg.register.manual_activate') | |
121 | def register(self): |
|
121 | def register(self): | |
122 | c.auto_active = 'hg.register.auto_activate' in User.get_default_user()\ |
|
122 | c.auto_active = 'hg.register.auto_activate' in User.get_default_user() \ | |
123 | .AuthUser.permissions['global'] |
|
123 | .AuthUser.permissions['global'] | |
124 |
|
124 | |||
125 | settings = Setting.get_app_settings() |
|
125 | settings = Setting.get_app_settings() |
@@ -37,7 +37,7 b' from webob.exc import HTTPFound, HTTPNot' | |||||
37 | from kallithea.lib.vcs.utils.hgcompat import unionrepo |
|
37 | from kallithea.lib.vcs.utils.hgcompat import unionrepo | |
38 | from kallithea.lib.compat import json |
|
38 | from kallithea.lib.compat import json | |
39 | from kallithea.lib.base import BaseRepoController, render |
|
39 | from kallithea.lib.base import BaseRepoController, render | |
40 | from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator,\ |
|
40 | from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \ | |
41 | NotAnonymous |
|
41 | NotAnonymous | |
42 | from kallithea.lib.helpers import Page |
|
42 | from kallithea.lib.helpers import Page | |
43 | from kallithea.lib import helpers as h |
|
43 | from kallithea.lib import helpers as h | |
@@ -47,7 +47,7 b' from kallithea.lib.utils import action_l' | |||||
47 | from kallithea.lib.vcs.utils import safe_str |
|
47 | from kallithea.lib.vcs.utils import safe_str | |
48 | from kallithea.lib.vcs.exceptions import EmptyRepositoryError |
|
48 | from kallithea.lib.vcs.exceptions import EmptyRepositoryError | |
49 | from kallithea.lib.diffs import LimitedDiffContainer |
|
49 | from kallithea.lib.diffs import LimitedDiffContainer | |
50 | from kallithea.model.db import PullRequest, ChangesetStatus, ChangesetComment,\ |
|
50 | from kallithea.model.db import PullRequest, ChangesetStatus, ChangesetComment, \ | |
51 | PullRequestReviewers, User |
|
51 | PullRequestReviewers, User | |
52 | from kallithea.model.pull_request import PullRequestModel |
|
52 | from kallithea.model.pull_request import PullRequestModel | |
53 | from kallithea.model.meta import Session |
|
53 | from kallithea.model.meta import Session | |
@@ -210,15 +210,15 b' class PullrequestsController(BaseRepoCon' | |||||
210 | s = filter(lambda p: p.status != PullRequest.STATUS_CLOSED, s) |
|
210 | s = filter(lambda p: p.status != PullRequest.STATUS_CLOSED, s) | |
211 | return s |
|
211 | return s | |
212 |
|
212 | |||
213 | c.my_pull_requests = _filter(PullRequest.query()\ |
|
213 | c.my_pull_requests = _filter(PullRequest.query() \ | |
214 | .filter(PullRequest.user_id == |
|
214 | .filter(PullRequest.user_id == | |
215 | self.authuser.user_id)\ |
|
215 | self.authuser.user_id) \ | |
216 | .all()) |
|
216 | .all()) | |
217 |
|
217 | |||
218 | c.participate_in_pull_requests = _filter(PullRequest.query()\ |
|
218 | c.participate_in_pull_requests = _filter(PullRequest.query() \ | |
219 | .join(PullRequestReviewers)\ |
|
219 | .join(PullRequestReviewers) \ | |
220 | .filter(PullRequestReviewers.user_id == |
|
220 | .filter(PullRequestReviewers.user_id == | |
221 | self.authuser.user_id)\ |
|
221 | self.authuser.user_id) \ | |
222 | ) |
|
222 | ) | |
223 |
|
223 | |||
224 | return render('/pullrequests/pullrequest_show_my.html') |
|
224 | return render('/pullrequests/pullrequest_show_my.html') |
@@ -44,7 +44,7 b' from kallithea.config.conf import ALL_RE' | |||||
44 | from kallithea.model.db import Statistics, CacheInvalidation, User |
|
44 | from kallithea.model.db import Statistics, CacheInvalidation, User | |
45 | from kallithea.lib.utils import jsonify |
|
45 | from kallithea.lib.utils import jsonify | |
46 | from kallithea.lib.utils2 import safe_str |
|
46 | from kallithea.lib.utils2 import safe_str | |
47 | from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator,\ |
|
47 | from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \ | |
48 | NotAnonymous |
|
48 | NotAnonymous | |
49 | from kallithea.lib.base import BaseRepoController, render |
|
49 | from kallithea.lib.base import BaseRepoController, render | |
50 | from kallithea.lib.vcs.backends.base import EmptyChangeset |
|
50 | from kallithea.lib.vcs.backends.base import EmptyChangeset | |
@@ -135,8 +135,8 b' class SummaryController(BaseRepoControll' | |||||
135 | else: |
|
135 | else: | |
136 | c.show_stats = False |
|
136 | c.show_stats = False | |
137 |
|
137 | |||
138 | stats = self.sa.query(Statistics)\ |
|
138 | stats = self.sa.query(Statistics) \ | |
139 | .filter(Statistics.repository == c.db_repo)\ |
|
139 | .filter(Statistics.repository == c.db_repo) \ | |
140 | .scalar() |
|
140 | .scalar() | |
141 |
|
141 | |||
142 | c.stats_percentage = 0 |
|
142 | c.stats_percentage = 0 | |
@@ -193,8 +193,8 b' class SummaryController(BaseRepoControll' | |||||
193 | c.ts_min = ts_min_m |
|
193 | c.ts_min = ts_min_m | |
194 | c.ts_max = ts_max_y |
|
194 | c.ts_max = ts_max_y | |
195 |
|
195 | |||
196 | stats = self.sa.query(Statistics)\ |
|
196 | stats = self.sa.query(Statistics) \ | |
197 | .filter(Statistics.repository == c.db_repo)\ |
|
197 | .filter(Statistics.repository == c.db_repo) \ | |
198 | .scalar() |
|
198 | .scalar() | |
199 | c.stats_percentage = 0 |
|
199 | c.stats_percentage = 0 | |
200 | if stats and stats.languages: |
|
200 | if stats and stats.languages: | |
@@ -211,7 +211,7 b' class SummaryController(BaseRepoControll' | |||||
211 | sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10] |
|
211 | sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10] | |
212 | ) |
|
212 | ) | |
213 | last_rev = stats.stat_on_revision + 1 |
|
213 | last_rev = stats.stat_on_revision + 1 | |
214 | c.repo_last_rev = c.db_repo_scm_instance.count()\ |
|
214 | c.repo_last_rev = c.db_repo_scm_instance.count() \ | |
215 | if c.db_repo_scm_instance.revisions else 0 |
|
215 | if c.db_repo_scm_instance.revisions else 0 | |
216 | if last_rev == 0 or c.repo_last_rev == 0: |
|
216 | if last_rev == 0 or c.repo_last_rev == 0: | |
217 | pass |
|
217 | pass |
@@ -68,7 +68,7 b' class AnnotateHtmlFormatter(HtmlFormatte' | |||||
68 | following function as ``annotate_from_changeset_func``:: |
|
68 | following function as ``annotate_from_changeset_func``:: | |
69 |
|
69 | |||
70 | def changeset_to_anchor(changeset): |
|
70 | def changeset_to_anchor(changeset): | |
71 | return '<a href="/changesets/%s/">%s</a>\n' %\ |
|
71 | return '<a href="/changesets/%s/">%s</a>\n' % \ | |
72 | (changeset.id, changeset.id) |
|
72 | (changeset.id, changeset.id) | |
73 |
|
73 | |||
74 | :param annotate_from_changeset_func: see above |
|
74 | :param annotate_from_changeset_func: see above |
@@ -204,8 +204,8 b' def _cached_perms_data(user_id, user_is_' | |||||
204 | #================================================================== |
|
204 | #================================================================== | |
205 |
|
205 | |||
206 | # default global permissions taken from the default user |
|
206 | # default global permissions taken from the default user | |
207 | default_global_perms = UserToPerm.query()\ |
|
207 | default_global_perms = UserToPerm.query() \ | |
208 | .filter(UserToPerm.user_id == default_user_id)\ |
|
208 | .filter(UserToPerm.user_id == default_user_id) \ | |
209 | .options(joinedload(UserToPerm.permission)) |
|
209 | .options(joinedload(UserToPerm.permission)) | |
210 |
|
210 | |||
211 | for perm in default_global_perms: |
|
211 | for perm in default_global_perms: | |
@@ -251,15 +251,15 b' def _cached_perms_data(user_id, user_is_' | |||||
251 |
|
251 | |||
252 | # USER GROUPS comes first |
|
252 | # USER GROUPS comes first | |
253 | # user group global permissions |
|
253 | # user group global permissions | |
254 | user_perms_from_users_groups = Session().query(UserGroupToPerm)\ |
|
254 | user_perms_from_users_groups = Session().query(UserGroupToPerm) \ | |
255 | .options(joinedload(UserGroupToPerm.permission))\ |
|
255 | .options(joinedload(UserGroupToPerm.permission)) \ | |
256 | .join((UserGroupMember, UserGroupToPerm.users_group_id == |
|
256 | .join((UserGroupMember, UserGroupToPerm.users_group_id == | |
257 | UserGroupMember.users_group_id))\ |
|
257 | UserGroupMember.users_group_id)) \ | |
258 | .filter(UserGroupMember.user_id == user_id)\ |
|
258 | .filter(UserGroupMember.user_id == user_id) \ | |
259 | .join((UserGroup, UserGroupMember.users_group_id == |
|
259 | .join((UserGroup, UserGroupMember.users_group_id == | |
260 | UserGroup.users_group_id))\ |
|
260 | UserGroup.users_group_id)) \ | |
261 | .filter(UserGroup.users_group_active == True)\ |
|
261 | .filter(UserGroup.users_group_active == True) \ | |
262 | .order_by(UserGroupToPerm.users_group_id)\ |
|
262 | .order_by(UserGroupToPerm.users_group_id) \ | |
263 | .all() |
|
263 | .all() | |
264 | # need to group here by groups since user can be in more than |
|
264 | # need to group here by groups since user can be in more than | |
265 | # one group |
|
265 | # one group | |
@@ -273,20 +273,20 b' def _cached_perms_data(user_id, user_is_' | |||||
273 | if not gr.inherit_default_permissions: |
|
273 | if not gr.inherit_default_permissions: | |
274 | # NEED TO IGNORE all configurable permissions and |
|
274 | # NEED TO IGNORE all configurable permissions and | |
275 | # replace them with explicitly set |
|
275 | # replace them with explicitly set | |
276 | permissions[GLOBAL] = permissions[GLOBAL]\ |
|
276 | permissions[GLOBAL] = permissions[GLOBAL] \ | |
277 | .difference(_configurable) |
|
277 | .difference(_configurable) | |
278 | for perm in perms: |
|
278 | for perm in perms: | |
279 | permissions[GLOBAL].add(perm.permission.permission_name) |
|
279 | permissions[GLOBAL].add(perm.permission.permission_name) | |
280 |
|
280 | |||
281 | # user specific global permissions |
|
281 | # user specific global permissions | |
282 | user_perms = Session().query(UserToPerm)\ |
|
282 | user_perms = Session().query(UserToPerm) \ | |
283 | .options(joinedload(UserToPerm.permission))\ |
|
283 | .options(joinedload(UserToPerm.permission)) \ | |
284 | .filter(UserToPerm.user_id == user_id).all() |
|
284 | .filter(UserToPerm.user_id == user_id).all() | |
285 |
|
285 | |||
286 | if not user_inherit_default_permissions: |
|
286 | if not user_inherit_default_permissions: | |
287 | # NEED TO IGNORE all configurable permissions and |
|
287 | # NEED TO IGNORE all configurable permissions and | |
288 | # replace them with explicitly set |
|
288 | # replace them with explicitly set | |
289 | permissions[GLOBAL] = permissions[GLOBAL]\ |
|
289 | permissions[GLOBAL] = permissions[GLOBAL] \ | |
290 | .difference(_configurable) |
|
290 | .difference(_configurable) | |
291 |
|
291 | |||
292 | for perm in user_perms: |
|
292 | for perm in user_perms: | |
@@ -304,17 +304,17 b' def _cached_perms_data(user_id, user_is_' | |||||
304 |
|
304 | |||
305 | # user group for repositories permissions |
|
305 | # user group for repositories permissions | |
306 | user_repo_perms_from_users_groups = \ |
|
306 | user_repo_perms_from_users_groups = \ | |
307 | Session().query(UserGroupRepoToPerm, Permission, Repository,)\ |
|
307 | Session().query(UserGroupRepoToPerm, Permission, Repository,) \ | |
308 | .join((Repository, UserGroupRepoToPerm.repository_id == |
|
308 | .join((Repository, UserGroupRepoToPerm.repository_id == | |
309 | Repository.repo_id))\ |
|
309 | Repository.repo_id)) \ | |
310 | .join((Permission, UserGroupRepoToPerm.permission_id == |
|
310 | .join((Permission, UserGroupRepoToPerm.permission_id == | |
311 | Permission.permission_id))\ |
|
311 | Permission.permission_id)) \ | |
312 | .join((UserGroup, UserGroupRepoToPerm.users_group_id == |
|
312 | .join((UserGroup, UserGroupRepoToPerm.users_group_id == | |
313 | UserGroup.users_group_id))\ |
|
313 | UserGroup.users_group_id)) \ | |
314 | .filter(UserGroup.users_group_active == True)\ |
|
314 | .filter(UserGroup.users_group_active == True) \ | |
315 | .join((UserGroupMember, UserGroupRepoToPerm.users_group_id == |
|
315 | .join((UserGroupMember, UserGroupRepoToPerm.users_group_id == | |
316 | UserGroupMember.users_group_id))\ |
|
316 | UserGroupMember.users_group_id)) \ | |
317 | .filter(UserGroupMember.user_id == user_id)\ |
|
317 | .filter(UserGroupMember.user_id == user_id) \ | |
318 | .all() |
|
318 | .all() | |
319 |
|
319 | |||
320 | multiple_counter = collections.defaultdict(int) |
|
320 | multiple_counter = collections.defaultdict(int) | |
@@ -357,16 +357,16 b' def _cached_perms_data(user_id, user_is_' | |||||
357 | #====================================================================== |
|
357 | #====================================================================== | |
358 | # user group for repo groups permissions |
|
358 | # user group for repo groups permissions | |
359 | user_repo_group_perms_from_users_groups = \ |
|
359 | user_repo_group_perms_from_users_groups = \ | |
360 | Session().query(UserGroupRepoGroupToPerm, Permission, RepoGroup)\ |
|
360 | Session().query(UserGroupRepoGroupToPerm, Permission, RepoGroup) \ | |
361 | .join((RepoGroup, UserGroupRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
361 | .join((RepoGroup, UserGroupRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
362 | .join((Permission, UserGroupRepoGroupToPerm.permission_id |
|
362 | .join((Permission, UserGroupRepoGroupToPerm.permission_id | |
363 | == Permission.permission_id))\ |
|
363 | == Permission.permission_id)) \ | |
364 | .join((UserGroup, UserGroupRepoGroupToPerm.users_group_id == |
|
364 | .join((UserGroup, UserGroupRepoGroupToPerm.users_group_id == | |
365 | UserGroup.users_group_id))\ |
|
365 | UserGroup.users_group_id)) \ | |
366 | .filter(UserGroup.users_group_active == True)\ |
|
366 | .filter(UserGroup.users_group_active == True) \ | |
367 | .join((UserGroupMember, UserGroupRepoGroupToPerm.users_group_id |
|
367 | .join((UserGroupMember, UserGroupRepoGroupToPerm.users_group_id | |
368 | == UserGroupMember.users_group_id))\ |
|
368 | == UserGroupMember.users_group_id)) \ | |
369 | .filter(UserGroupMember.user_id == user_id)\ |
|
369 | .filter(UserGroupMember.user_id == user_id) \ | |
370 | .all() |
|
370 | .all() | |
371 |
|
371 | |||
372 | multiple_counter = collections.defaultdict(int) |
|
372 | multiple_counter = collections.defaultdict(int) | |
@@ -394,17 +394,17 b' def _cached_perms_data(user_id, user_is_' | |||||
394 | #====================================================================== |
|
394 | #====================================================================== | |
395 | # user group for user group permissions |
|
395 | # user group for user group permissions | |
396 | user_group_user_groups_perms = \ |
|
396 | user_group_user_groups_perms = \ | |
397 | Session().query(UserGroupUserGroupToPerm, Permission, UserGroup)\ |
|
397 | Session().query(UserGroupUserGroupToPerm, Permission, UserGroup) \ | |
398 | .join((UserGroup, UserGroupUserGroupToPerm.target_user_group_id |
|
398 | .join((UserGroup, UserGroupUserGroupToPerm.target_user_group_id | |
399 | == UserGroup.users_group_id))\ |
|
399 | == UserGroup.users_group_id)) \ | |
400 | .join((Permission, UserGroupUserGroupToPerm.permission_id |
|
400 | .join((Permission, UserGroupUserGroupToPerm.permission_id | |
401 | == Permission.permission_id))\ |
|
401 | == Permission.permission_id)) \ | |
402 | .join((UserGroupMember, UserGroupUserGroupToPerm.user_group_id |
|
402 | .join((UserGroupMember, UserGroupUserGroupToPerm.user_group_id | |
403 | == UserGroupMember.users_group_id))\ |
|
403 | == UserGroupMember.users_group_id)) \ | |
404 | .filter(UserGroupMember.user_id == user_id)\ |
|
404 | .filter(UserGroupMember.user_id == user_id) \ | |
405 | .join((UserGroup, UserGroupMember.users_group_id == |
|
405 | .join((UserGroup, UserGroupMember.users_group_id == | |
406 | UserGroup.users_group_id), aliased=True, from_joinpoint=True)\ |
|
406 | UserGroup.users_group_id), aliased=True, from_joinpoint=True) \ | |
407 | .filter(UserGroup.users_group_active == True)\ |
|
407 | .filter(UserGroup.users_group_active == True) \ | |
408 | .all() |
|
408 | .all() | |
409 |
|
409 | |||
410 | multiple_counter = collections.defaultdict(int) |
|
410 | multiple_counter = collections.defaultdict(int) | |
@@ -566,8 +566,8 b' class AuthUser(object):' | |||||
566 |
|
566 | |||
567 | def _get_api_keys(self): |
|
567 | def _get_api_keys(self): | |
568 | api_keys = [self.api_key] |
|
568 | api_keys = [self.api_key] | |
569 | for api_key in UserApiKeys.query()\ |
|
569 | for api_key in UserApiKeys.query() \ | |
570 | .filter(UserApiKeys.user_id == self.user_id)\ |
|
570 | .filter(UserApiKeys.user_id == self.user_id) \ | |
571 | .filter(or_(UserApiKeys.expires == -1, |
|
571 | .filter(or_(UserApiKeys.expires == -1, | |
572 | UserApiKeys.expires >= time.time())).all(): |
|
572 | UserApiKeys.expires >= time.time())).all(): | |
573 | api_keys.append(api_key.api_key) |
|
573 | api_keys.append(api_key.api_key) | |
@@ -619,7 +619,7 b' class AuthUser(object):' | |||||
619 | return False |
|
619 | return False | |
620 |
|
620 | |||
621 | def __repr__(self): |
|
621 | def __repr__(self): | |
622 | return "<AuthUser('id:%s[%s] auth:%s')>"\ |
|
622 | return "<AuthUser('id:%s[%s] auth:%s')>" \ | |
623 | % (self.user_id, self.username, (self.is_authenticated or self.is_default_user)) |
|
623 | % (self.user_id, self.username, (self.is_authenticated or self.is_default_user)) | |
624 |
|
624 | |||
625 | def to_cookie(self): |
|
625 | def to_cookie(self): |
@@ -45,7 +45,7 b' from pylons.i18n.translation import _' | |||||
45 |
|
45 | |||
46 | from kallithea import __version__, BACKENDS |
|
46 | from kallithea import __version__, BACKENDS | |
47 |
|
47 | |||
48 | from kallithea.lib.utils2 import str2bool, safe_unicode, AttributeDict,\ |
|
48 | from kallithea.lib.utils2 import str2bool, safe_unicode, AttributeDict, \ | |
49 | safe_str, safe_int |
|
49 | safe_str, safe_int | |
50 | from kallithea.lib import auth_modules |
|
50 | from kallithea.lib import auth_modules | |
51 | from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware |
|
51 | from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware | |
@@ -367,7 +367,7 b' class BaseController(WSGIController):' | |||||
367 |
|
367 | |||
368 | c.repo_name = get_repo_slug(request) # can be empty |
|
368 | c.repo_name = get_repo_slug(request) # can be empty | |
369 | c.backends = BACKENDS.keys() |
|
369 | c.backends = BACKENDS.keys() | |
370 | c.unread_notifications = NotificationModel()\ |
|
370 | c.unread_notifications = NotificationModel() \ | |
371 | .get_unread_cnt_for_user(c.authuser.user_id) |
|
371 | .get_unread_cnt_for_user(c.authuser.user_id) | |
372 |
|
372 | |||
373 | self.cut_off_limit = safe_int(config.get('cut_off_limit')) |
|
373 | self.cut_off_limit = safe_int(config.get('cut_off_limit')) |
@@ -76,7 +76,7 b' def whoosh_index(repo_location, full_ind' | |||||
76 |
|
76 | |||
77 | index_location = config['index_dir'] |
|
77 | index_location = config['index_dir'] | |
78 | WhooshIndexingDaemon(index_location=index_location, |
|
78 | WhooshIndexingDaemon(index_location=index_location, | |
79 | repo_location=repo_location, sa=DBS)\ |
|
79 | repo_location=repo_location, sa=DBS) \ | |
80 | .run(full_index=full_index) |
|
80 | .run(full_index=full_index) | |
81 |
|
81 | |||
82 |
|
82 | |||
@@ -116,9 +116,9 b' def get_commits_stats(repo_name, ts_min_' | |||||
116 | last_cs = None |
|
116 | last_cs = None | |
117 | timegetter = itemgetter('time') |
|
117 | timegetter = itemgetter('time') | |
118 |
|
118 | |||
119 | dbrepo = DBS.query(Repository)\ |
|
119 | dbrepo = DBS.query(Repository) \ | |
120 | .filter(Repository.repo_name == repo_name).scalar() |
|
120 | .filter(Repository.repo_name == repo_name).scalar() | |
121 | cur_stats = DBS.query(Statistics)\ |
|
121 | cur_stats = DBS.query(Statistics) \ | |
122 | .filter(Statistics.repository == dbrepo).scalar() |
|
122 | .filter(Statistics.repository == dbrepo).scalar() | |
123 |
|
123 | |||
124 | if cur_stats is not None: |
|
124 | if cur_stats is not None: | |
@@ -176,7 +176,7 b' def get_commits_stats(repo_name, ts_min_' | |||||
176 | "changed": len(cs.changed), |
|
176 | "changed": len(cs.changed), | |
177 | "removed": len(cs.removed), |
|
177 | "removed": len(cs.removed), | |
178 | } |
|
178 | } | |
179 | co_day_auth_aggr[akc(cs.author)]['data']\ |
|
179 | co_day_auth_aggr[akc(cs.author)]['data'] \ | |
180 | .append(datadict) |
|
180 | .append(datadict) | |
181 |
|
181 | |||
182 | else: |
|
182 | else: |
@@ -42,19 +42,19 b' def one_space_trim(s):' | |||||
42 | def format_sql(sql): |
|
42 | def format_sql(sql): | |
43 | sql = sql.replace('\n', '') |
|
43 | sql = sql.replace('\n', '') | |
44 | sql = one_space_trim(sql) |
|
44 | sql = one_space_trim(sql) | |
45 | sql = sql\ |
|
45 | sql = sql \ | |
46 | .replace(',', ',\n\t')\ |
|
46 | .replace(',', ',\n\t') \ | |
47 | .replace('SELECT', '\n\tSELECT \n\t')\ |
|
47 | .replace('SELECT', '\n\tSELECT \n\t') \ | |
48 | .replace('UPDATE', '\n\tUPDATE \n\t')\ |
|
48 | .replace('UPDATE', '\n\tUPDATE \n\t') \ | |
49 | .replace('DELETE', '\n\tDELETE \n\t')\ |
|
49 | .replace('DELETE', '\n\tDELETE \n\t') \ | |
50 | .replace('FROM', '\n\tFROM')\ |
|
50 | .replace('FROM', '\n\tFROM') \ | |
51 | .replace('ORDER BY', '\n\tORDER BY')\ |
|
51 | .replace('ORDER BY', '\n\tORDER BY') \ | |
52 | .replace('LIMIT', '\n\tLIMIT')\ |
|
52 | .replace('LIMIT', '\n\tLIMIT') \ | |
53 | .replace('WHERE', '\n\tWHERE')\ |
|
53 | .replace('WHERE', '\n\tWHERE') \ | |
54 | .replace('AND', '\n\tAND')\ |
|
54 | .replace('AND', '\n\tAND') \ | |
55 | .replace('LEFT', '\n\tLEFT')\ |
|
55 | .replace('LEFT', '\n\tLEFT') \ | |
56 | .replace('INNER', '\n\tINNER')\ |
|
56 | .replace('INNER', '\n\tINNER') \ | |
57 | .replace('INSERT', '\n\tINSERT')\ |
|
57 | .replace('INSERT', '\n\tINSERT') \ | |
58 | .replace('DELETE', '\n\tDELETE') |
|
58 | .replace('DELETE', '\n\tDELETE') | |
59 | return sql |
|
59 | return sql | |
60 |
|
60 |
@@ -184,8 +184,8 b' class DbManage(object):' | |||||
184 | Fixes a old kallithea version path into new one without a '*' |
|
184 | Fixes a old kallithea version path into new one without a '*' | |
185 | """ |
|
185 | """ | |
186 |
|
186 | |||
187 | paths = self.sa.query(Ui)\ |
|
187 | paths = self.sa.query(Ui) \ | |
188 | .filter(Ui.ui_key == '/')\ |
|
188 | .filter(Ui.ui_key == '/') \ | |
189 | .scalar() |
|
189 | .scalar() | |
190 |
|
190 | |||
191 | paths.ui_value = paths.ui_value.replace('*', '') |
|
191 | paths.ui_value = paths.ui_value.replace('*', '') | |
@@ -198,8 +198,8 b' class DbManage(object):' | |||||
198 | Fixes a old default user with some 'nicer' default values, |
|
198 | Fixes a old default user with some 'nicer' default values, | |
199 | used mostly for anonymous access |
|
199 | used mostly for anonymous access | |
200 | """ |
|
200 | """ | |
201 | def_user = self.sa.query(User)\ |
|
201 | def_user = self.sa.query(User) \ | |
202 | .filter(User.username == User.DEFAULT_USER)\ |
|
202 | .filter(User.username == User.DEFAULT_USER) \ | |
203 | .one() |
|
203 | .one() | |
204 |
|
204 | |||
205 | def_user.name = 'Anonymous' |
|
205 | def_user.name = 'Anonymous' | |
@@ -278,7 +278,7 b' class DbManage(object):' | |||||
278 |
|
278 | |||
279 | #HOOKS |
|
279 | #HOOKS | |
280 | hooks1_key = Ui.HOOK_UPDATE |
|
280 | hooks1_key = Ui.HOOK_UPDATE | |
281 | hooks1_ = self.sa.query(Ui)\ |
|
281 | hooks1_ = self.sa.query(Ui) \ | |
282 | .filter(Ui.ui_key == hooks1_key).scalar() |
|
282 | .filter(Ui.ui_key == hooks1_key).scalar() | |
283 |
|
283 | |||
284 | hooks1 = Ui() if hooks1_ is None else hooks1_ |
|
284 | hooks1 = Ui() if hooks1_ is None else hooks1_ | |
@@ -289,7 +289,7 b' class DbManage(object):' | |||||
289 | self.sa.add(hooks1) |
|
289 | self.sa.add(hooks1) | |
290 |
|
290 | |||
291 | hooks2_key = Ui.HOOK_REPO_SIZE |
|
291 | hooks2_key = Ui.HOOK_REPO_SIZE | |
292 | hooks2_ = self.sa.query(Ui)\ |
|
292 | hooks2_ = self.sa.query(Ui) \ | |
293 | .filter(Ui.ui_key == hooks2_key).scalar() |
|
293 | .filter(Ui.ui_key == hooks2_key).scalar() | |
294 | hooks2 = Ui() if hooks2_ is None else hooks2_ |
|
294 | hooks2 = Ui() if hooks2_ is None else hooks2_ | |
295 | hooks2.ui_section = 'hooks' |
|
295 | hooks2.ui_section = 'hooks' | |
@@ -390,9 +390,9 b' class DbManage(object):' | |||||
390 | g.group_name = g.get_new_name(g.name) |
|
390 | g.group_name = g.get_new_name(g.name) | |
391 | self.sa.add(g) |
|
391 | self.sa.add(g) | |
392 | # get default perm |
|
392 | # get default perm | |
393 | default = UserRepoGroupToPerm.query()\ |
|
393 | default = UserRepoGroupToPerm.query() \ | |
394 | .filter(UserRepoGroupToPerm.group == g)\ |
|
394 | .filter(UserRepoGroupToPerm.group == g) \ | |
395 | .filter(UserRepoGroupToPerm.user == def_usr)\ |
|
395 | .filter(UserRepoGroupToPerm.user == def_usr) \ | |
396 | .scalar() |
|
396 | .scalar() | |
397 |
|
397 | |||
398 | if default is None: |
|
398 | if default is None: | |
@@ -411,7 +411,7 b' class DbManage(object):' | |||||
411 | if not default_user: |
|
411 | if not default_user: | |
412 | return |
|
412 | return | |
413 |
|
413 | |||
414 | u2p = UserToPerm.query()\ |
|
414 | u2p = UserToPerm.query() \ | |
415 | .filter(UserToPerm.user == default_user).all() |
|
415 | .filter(UserToPerm.user == default_user).all() | |
416 | fixed = False |
|
416 | fixed = False | |
417 | if len(u2p) != len(Permission.DEFAULT_USER_PERMISSIONS): |
|
417 | if len(u2p) != len(Permission.DEFAULT_USER_PERMISSIONS): |
@@ -146,7 +146,7 b' class CheckConstraint(ConstraintChangese' | |||||
146 | Migrate's additional parameters: |
|
146 | Migrate's additional parameters: | |
147 |
|
147 | |||
148 | :param sqltext: Plain SQL text to check condition |
|
148 | :param sqltext: Plain SQL text to check condition | |
149 | :param columns: If not name is applied, you must supply this kw\ |
|
149 | :param columns: If not name is applied, you must supply this kw \ | |
150 | to autoname constraint |
|
150 | to autoname constraint | |
151 | :param table: If columns are passed as strings, this kw is required |
|
151 | :param table: If columns are passed as strings, this kw is required | |
152 | :type table: Table instance |
|
152 | :type table: Table instance |
@@ -180,7 +180,7 b' class ColumnDelta(DictMixin, sqlalchemy.' | |||||
180 | * **current_col_name, \*p, \*\*kw** |
|
180 | * **current_col_name, \*p, \*\*kw** | |
181 | Table kw must specified. |
|
181 | Table kw must specified. | |
182 |
|
182 | |||
183 | :param table: Table at which current Column should be bound to.\ |
|
183 | :param table: Table at which current Column should be bound to. \ | |
184 | If table name is given, reflection will be used. |
|
184 | If table name is given, reflection will be used. | |
185 | :type table: string or Table instance |
|
185 | :type table: string or Table instance | |
186 |
|
186 | |||
@@ -499,9 +499,9 b' class ChangesetColumn(object):' | |||||
499 |
|
499 | |||
500 | :param table: Table instance to create on. |
|
500 | :param table: Table instance to create on. | |
501 | :param index_name: Creates :class:`ChangesetIndex` on this column. |
|
501 | :param index_name: Creates :class:`ChangesetIndex` on this column. | |
502 | :param unique_name: Creates :class:\ |
|
502 | :param unique_name: Creates :class: \ | |
503 | `~migrate.changeset.constraint.UniqueConstraint` on this column. |
|
503 | `~migrate.changeset.constraint.UniqueConstraint` on this column. | |
504 | :param primary_key_name: Creates :class:\ |
|
504 | :param primary_key_name: Creates :class: \ | |
505 | `~migrate.changeset.constraint.PrimaryKeyConstraint` on this column. |
|
505 | `~migrate.changeset.constraint.PrimaryKeyConstraint` on this column. | |
506 | :param populate_default: If True, created column will be \ |
|
506 | :param populate_default: If True, created column will be \ | |
507 | populated with defaults |
|
507 | populated with defaults |
@@ -181,7 +181,7 b' def upgrade(url, repository, version=Non' | |||||
181 | You may preview the Python or SQL code to be executed, rather than |
|
181 | You may preview the Python or SQL code to be executed, rather than | |
182 | actually executing it, using the appropriate 'preview' option. |
|
182 | actually executing it, using the appropriate 'preview' option. | |
183 | """ |
|
183 | """ | |
184 | err = "Cannot upgrade a database of version %s to version %s. "\ |
|
184 | err = "Cannot upgrade a database of version %s to version %s. " \ | |
185 | "Try 'downgrade' instead." |
|
185 | "Try 'downgrade' instead." | |
186 | return _migrate(url, repository, version, upgrade=True, err=err, **opts) |
|
186 | return _migrate(url, repository, version, upgrade=True, err=err, **opts) | |
187 |
|
187 | |||
@@ -197,7 +197,7 b' def downgrade(url, repository, version, ' | |||||
197 | You may preview the Python or SQL code to be executed, rather than |
|
197 | You may preview the Python or SQL code to be executed, rather than | |
198 | actually executing it, using the appropriate 'preview' option. |
|
198 | actually executing it, using the appropriate 'preview' option. | |
199 | """ |
|
199 | """ | |
200 | err = "Cannot downgrade a database of version %s to version %s. "\ |
|
200 | err = "Cannot downgrade a database of version %s to version %s. " \ | |
201 | "Try 'upgrade' instead." |
|
201 | "Try 'upgrade' instead." | |
202 | return _migrate(url, repository, version, upgrade=False, err=err, **opts) |
|
202 | return _migrate(url, repository, version, upgrade=False, err=err, **opts) | |
203 |
|
203 |
@@ -238,7 +238,7 b' class Repository(pathed.Pathed):' | |||||
238 | :param file_: Destination file to be written |
|
238 | :param file_: Destination file to be written | |
239 | :param opts: Options that are passed to :func:`migrate.versioning.shell.main` |
|
239 | :param opts: Options that are passed to :func:`migrate.versioning.shell.main` | |
240 | """ |
|
240 | """ | |
241 | mng_file = Template(opts.pop('templates_path', None))\ |
|
241 | mng_file = Template(opts.pop('templates_path', None)) \ | |
242 | .get_manage(theme=opts.pop('templates_theme', None)) |
|
242 | .get_manage(theme=opts.pop('templates_theme', None)) | |
243 |
|
243 | |||
244 | tmpl = open(mng_file).read() |
|
244 | tmpl = open(mng_file).read() |
@@ -182,7 +182,7 b' class Setting(Base, BaseModel):' | |||||
182 |
|
182 | |||
183 | @classmethod |
|
183 | @classmethod | |
184 | def get_by_name(cls, ldap_key): |
|
184 | def get_by_name(cls, ldap_key): | |
185 | return cls.query()\ |
|
185 | return cls.query() \ | |
186 | .filter(cls.app_settings_name == ldap_key).scalar() |
|
186 | .filter(cls.app_settings_name == ldap_key).scalar() | |
187 |
|
187 | |||
188 | @classmethod |
|
188 | @classmethod | |
@@ -204,7 +204,7 b' class Setting(Base, BaseModel):' | |||||
204 |
|
204 | |||
205 | @classmethod |
|
205 | @classmethod | |
206 | def get_ldap_settings(cls, cache=False): |
|
206 | def get_ldap_settings(cls, cache=False): | |
207 | ret = cls.query()\ |
|
207 | ret = cls.query() \ | |
208 | .filter(cls.app_settings_name.startswith('ldap_')).all() |
|
208 | .filter(cls.app_settings_name.startswith('ldap_')).all() | |
209 | fd = {} |
|
209 | fd = {} | |
210 | for row in ret: |
|
210 | for row in ret: | |
@@ -380,10 +380,10 b' class UserGroup(Base, BaseModel):' | |||||
380 | @classmethod |
|
380 | @classmethod | |
381 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
381 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
382 | if case_insensitive: |
|
382 | if case_insensitive: | |
383 | gr = cls.query()\ |
|
383 | gr = cls.query() \ | |
384 | .filter(cls.users_group_name.ilike(group_name)) |
|
384 | .filter(cls.users_group_name.ilike(group_name)) | |
385 | else: |
|
385 | else: | |
386 | gr = cls.query()\ |
|
386 | gr = cls.query() \ | |
387 | .filter(cls.users_group_name == group_name) |
|
387 | .filter(cls.users_group_name == group_name) | |
388 | if cache: |
|
388 | if cache: | |
389 | gr = gr.options(FromCache("sql_cache_short", |
|
389 | gr = gr.options(FromCache("sql_cache_short", | |
@@ -445,7 +445,7 b' class UserGroup(Base, BaseModel):' | |||||
445 | try: |
|
445 | try: | |
446 |
|
446 | |||
447 | # check if this group is not assigned to repo |
|
447 | # check if this group is not assigned to repo | |
448 | assigned_groups = UserGroupRepoToPerm.query()\ |
|
448 | assigned_groups = UserGroupRepoToPerm.query() \ | |
449 | .filter(UserGroupRepoToPerm.users_group_id == |
|
449 | .filter(UserGroupRepoToPerm.users_group_id == | |
450 | users_group_id).all() |
|
450 | users_group_id).all() | |
451 |
|
451 | |||
@@ -526,8 +526,8 b' class Repository(Base, BaseModel):' | |||||
526 | @classmethod |
|
526 | @classmethod | |
527 | def get_by_repo_name(cls, repo_name): |
|
527 | def get_by_repo_name(cls, repo_name): | |
528 | q = Session.query(cls).filter(cls.repo_name == repo_name) |
|
528 | q = Session.query(cls).filter(cls.repo_name == repo_name) | |
529 | q = q.options(joinedload(Repository.fork))\ |
|
529 | q = q.options(joinedload(Repository.fork)) \ | |
530 | .options(joinedload(Repository.user))\ |
|
530 | .options(joinedload(Repository.user)) \ | |
531 | .options(joinedload(Repository.group)) |
|
531 | .options(joinedload(Repository.group)) | |
532 | return q.one() |
|
532 | return q.one() | |
533 |
|
533 | |||
@@ -616,7 +616,7 b' class Repository(Base, BaseModel):' | |||||
616 | baseui._tcfg = config.config() |
|
616 | baseui._tcfg = config.config() | |
617 |
|
617 | |||
618 |
|
618 | |||
619 | ret = Ui.query()\ |
|
619 | ret = Ui.query() \ | |
620 | .options(FromCache("sql_cache_short", "repository_repo_ui")).all() |
|
620 | .options(FromCache("sql_cache_short", "repository_repo_ui")).all() | |
621 |
|
621 | |||
622 | hg_ui = ret |
|
622 | hg_ui = ret | |
@@ -758,10 +758,10 b' class Group(Base, BaseModel):' | |||||
758 | @classmethod |
|
758 | @classmethod | |
759 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
759 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
760 | if case_insensitive: |
|
760 | if case_insensitive: | |
761 | gr = cls.query()\ |
|
761 | gr = cls.query() \ | |
762 | .filter(cls.group_name.ilike(group_name)) |
|
762 | .filter(cls.group_name.ilike(group_name)) | |
763 | else: |
|
763 | else: | |
764 | gr = cls.query()\ |
|
764 | gr = cls.query() \ | |
765 | .filter(cls.group_name == group_name) |
|
765 | .filter(cls.group_name == group_name) | |
766 | if cache: |
|
766 | if cache: | |
767 | gr = gr.options(FromCache("sql_cache_short", |
|
767 | gr = gr.options(FromCache("sql_cache_short", | |
@@ -879,7 +879,7 b' class UserToPerm(Base, BaseModel):' | |||||
879 | if not isinstance(perm, Permission): |
|
879 | if not isinstance(perm, Permission): | |
880 | raise Exception('perm needs to be an instance of Permission class') |
|
880 | raise Exception('perm needs to be an instance of Permission class') | |
881 |
|
881 | |||
882 | return cls.query().filter(cls.user_id == user_id)\ |
|
882 | return cls.query().filter(cls.user_id == user_id) \ | |
883 | .filter(cls.permission == perm).scalar() is not None |
|
883 | .filter(cls.permission == perm).scalar() is not None | |
884 |
|
884 | |||
885 | @classmethod |
|
885 | @classmethod | |
@@ -941,8 +941,8 b' class UserGroupToPerm(Base, BaseModel):' | |||||
941 | raise Exception('perm needs to be an instance of Permission class') |
|
941 | raise Exception('perm needs to be an instance of Permission class') | |
942 |
|
942 | |||
943 | return cls.query().filter(cls.users_group_id == |
|
943 | return cls.query().filter(cls.users_group_id == | |
944 | users_group_id)\ |
|
944 | users_group_id) \ | |
945 | .filter(cls.permission == perm)\ |
|
945 | .filter(cls.permission == perm) \ | |
946 | .scalar() is not None |
|
946 | .scalar() is not None | |
947 |
|
947 | |||
948 | @classmethod |
|
948 | @classmethod | |
@@ -1047,9 +1047,9 b' class CacheInvalidation(Base, BaseModel)' | |||||
1047 |
|
1047 | |||
1048 | :param key: |
|
1048 | :param key: | |
1049 | """ |
|
1049 | """ | |
1050 | return cls.query()\ |
|
1050 | return cls.query() \ | |
1051 | .filter(CacheInvalidation.cache_key == key)\ |
|
1051 | .filter(CacheInvalidation.cache_key == key) \ | |
1052 | .filter(CacheInvalidation.cache_active == False)\ |
|
1052 | .filter(CacheInvalidation.cache_active == False) \ | |
1053 | .scalar() |
|
1053 | .scalar() | |
1054 |
|
1054 | |||
1055 | @classmethod |
|
1055 | @classmethod | |
@@ -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.query(cls)\ |
|
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.query(CacheInvalidation)\ |
|
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) |
@@ -201,7 +201,7 b' class Setting(Base, BaseModel):' | |||||
201 |
|
201 | |||
202 | @classmethod |
|
202 | @classmethod | |
203 | def get_by_name(cls, ldap_key): |
|
203 | def get_by_name(cls, ldap_key): | |
204 | return cls.query()\ |
|
204 | return cls.query() \ | |
205 | .filter(cls.app_settings_name == ldap_key).scalar() |
|
205 | .filter(cls.app_settings_name == ldap_key).scalar() | |
206 |
|
206 | |||
207 | @classmethod |
|
207 | @classmethod | |
@@ -223,7 +223,7 b' class Setting(Base, BaseModel):' | |||||
223 |
|
223 | |||
224 | @classmethod |
|
224 | @classmethod | |
225 | def get_ldap_settings(cls, cache=False): |
|
225 | def get_ldap_settings(cls, cache=False): | |
226 | ret = cls.query()\ |
|
226 | ret = cls.query() \ | |
227 | .filter(cls.app_settings_name.startswith('ldap_')).all() |
|
227 | .filter(cls.app_settings_name.startswith('ldap_')).all() | |
228 | fd = {} |
|
228 | fd = {} | |
229 | for row in ret: |
|
229 | for row in ret: | |
@@ -533,8 +533,8 b' class Repository(Base, BaseModel):' | |||||
533 | @classmethod |
|
533 | @classmethod | |
534 | def get_by_repo_name(cls, repo_name): |
|
534 | def get_by_repo_name(cls, repo_name): | |
535 | q = Session.query(cls).filter(cls.repo_name == repo_name) |
|
535 | q = Session.query(cls).filter(cls.repo_name == repo_name) | |
536 | q = q.options(joinedload(Repository.fork))\ |
|
536 | q = q.options(joinedload(Repository.fork)) \ | |
537 | .options(joinedload(Repository.user))\ |
|
537 | .options(joinedload(Repository.user)) \ | |
538 | .options(joinedload(Repository.group)) |
|
538 | .options(joinedload(Repository.group)) | |
539 | return q.scalar() |
|
539 | return q.scalar() | |
540 |
|
540 | |||
@@ -549,7 +549,7 b' class Repository(Base, BaseModel):' | |||||
549 |
|
549 | |||
550 | :param cls: |
|
550 | :param cls: | |
551 | """ |
|
551 | """ | |
552 | q = Session.query(Ui)\ |
|
552 | q = Session.query(Ui) \ | |
553 | .filter(Ui.ui_key == cls.url_sep()) |
|
553 | .filter(Ui.ui_key == cls.url_sep()) | |
554 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
554 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
555 | return q.one().ui_value |
|
555 | return q.one().ui_value | |
@@ -622,7 +622,7 b' class Repository(Base, BaseModel):' | |||||
622 | baseui._ucfg = config.config() |
|
622 | baseui._ucfg = config.config() | |
623 | baseui._tcfg = config.config() |
|
623 | baseui._tcfg = config.config() | |
624 |
|
624 | |||
625 | ret = Ui.query()\ |
|
625 | ret = Ui.query() \ | |
626 | .options(FromCache("sql_cache_short", "repository_repo_ui")).all() |
|
626 | .options(FromCache("sql_cache_short", "repository_repo_ui")).all() | |
627 |
|
627 | |||
628 | hg_ui = ret |
|
628 | hg_ui = ret | |
@@ -671,7 +671,7 b' class Repository(Base, BaseModel):' | |||||
671 |
|
671 | |||
672 | :param revisions: filter query by revisions only |
|
672 | :param revisions: filter query by revisions only | |
673 | """ |
|
673 | """ | |
674 | cmts = ChangesetComment.query()\ |
|
674 | cmts = ChangesetComment.query() \ | |
675 | .filter(ChangesetComment.repo == self) |
|
675 | .filter(ChangesetComment.repo == self) | |
676 | if revisions: |
|
676 | if revisions: | |
677 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
677 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -783,10 +783,10 b' class RepoGroup(Base, BaseModel):' | |||||
783 | @classmethod |
|
783 | @classmethod | |
784 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
784 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
785 | if case_insensitive: |
|
785 | if case_insensitive: | |
786 | gr = cls.query()\ |
|
786 | gr = cls.query() \ | |
787 | .filter(cls.group_name.ilike(group_name)) |
|
787 | .filter(cls.group_name.ilike(group_name)) | |
788 | else: |
|
788 | else: | |
789 | gr = cls.query()\ |
|
789 | gr = cls.query() \ | |
790 | .filter(cls.group_name == group_name) |
|
790 | .filter(cls.group_name == group_name) | |
791 | if cache: |
|
791 | if cache: | |
792 | gr = gr.options(FromCache( |
|
792 | gr = gr.options(FromCache( | |
@@ -838,8 +838,8 b' class RepoGroup(Base, BaseModel):' | |||||
838 |
|
838 | |||
839 | @property |
|
839 | @property | |
840 | def repositories(self): |
|
840 | def repositories(self): | |
841 | return Repository.query()\ |
|
841 | return Repository.query() \ | |
842 | .filter(Repository.group == self)\ |
|
842 | .filter(Repository.group == self) \ | |
843 | .order_by(Repository.repo_name) |
|
843 | .order_by(Repository.repo_name) | |
844 |
|
844 | |||
845 | @property |
|
845 | @property | |
@@ -887,18 +887,18 b' class Permission(Base, BaseModel):' | |||||
887 |
|
887 | |||
888 | @classmethod |
|
888 | @classmethod | |
889 | def get_default_perms(cls, default_user_id): |
|
889 | def get_default_perms(cls, default_user_id): | |
890 | q = Session.query(UserRepoToPerm, Repository, cls)\ |
|
890 | q = Session.query(UserRepoToPerm, Repository, cls) \ | |
891 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
891 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
892 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
892 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
893 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
893 | .filter(UserRepoToPerm.user_id == default_user_id) | |
894 |
|
894 | |||
895 | return q.all() |
|
895 | return q.all() | |
896 |
|
896 | |||
897 | @classmethod |
|
897 | @classmethod | |
898 | def get_default_group_perms(cls, default_user_id): |
|
898 | def get_default_group_perms(cls, default_user_id): | |
899 | q = Session.query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
899 | q = Session.query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
900 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
900 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
901 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
901 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
902 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
902 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
903 |
|
903 | |||
904 | return q.all() |
|
904 | return q.all() | |
@@ -1204,8 +1204,8 b' class ChangesetComment(Base, BaseModel):' | |||||
1204 | :param cls: |
|
1204 | :param cls: | |
1205 | :param revision: |
|
1205 | :param revision: | |
1206 | """ |
|
1206 | """ | |
1207 | return Session.query(User)\ |
|
1207 | return Session.query(User) \ | |
1208 | .filter(cls.revision == revision)\ |
|
1208 | .filter(cls.revision == revision) \ | |
1209 | .join(ChangesetComment.author).all() |
|
1209 | .join(ChangesetComment.author).all() | |
1210 |
|
1210 | |||
1211 |
|
1211 | |||
@@ -1234,7 +1234,7 b' class Notification(Base, BaseModel):' | |||||
1234 |
|
1234 | |||
1235 | @property |
|
1235 | @property | |
1236 | def recipients(self): |
|
1236 | def recipients(self): | |
1237 | return [x.user for x in UserNotification.query()\ |
|
1237 | return [x.user for x in UserNotification.query() \ | |
1238 | .filter(UserNotification.notification == self).all()] |
|
1238 | .filter(UserNotification.notification == self).all()] | |
1239 |
|
1239 | |||
1240 | @classmethod |
|
1240 | @classmethod |
@@ -191,7 +191,7 b' class Setting(Base, BaseModel):' | |||||
191 |
|
191 | |||
192 | @classmethod |
|
192 | @classmethod | |
193 | def get_by_name(cls, key): |
|
193 | def get_by_name(cls, key): | |
194 | return cls.query()\ |
|
194 | return cls.query() \ | |
195 | .filter(cls.app_settings_name == key).scalar() |
|
195 | .filter(cls.app_settings_name == key).scalar() | |
196 |
|
196 | |||
197 | @classmethod |
|
197 | @classmethod | |
@@ -220,7 +220,7 b' class Setting(Base, BaseModel):' | |||||
220 |
|
220 | |||
221 | @classmethod |
|
221 | @classmethod | |
222 | def get_ldap_settings(cls, cache=False): |
|
222 | def get_ldap_settings(cls, cache=False): | |
223 | ret = cls.query()\ |
|
223 | ret = cls.query() \ | |
224 | .filter(cls.app_settings_name.startswith('ldap_')).all() |
|
224 | .filter(cls.app_settings_name.startswith('ldap_')).all() | |
225 | fd = {} |
|
225 | fd = {} | |
226 | for row in ret: |
|
226 | for row in ret: | |
@@ -672,8 +672,8 b' class Repository(Base, BaseModel):' | |||||
672 | @classmethod |
|
672 | @classmethod | |
673 | def get_by_repo_name(cls, repo_name): |
|
673 | def get_by_repo_name(cls, repo_name): | |
674 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
674 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
675 | q = q.options(joinedload(Repository.fork))\ |
|
675 | q = q.options(joinedload(Repository.fork)) \ | |
676 | .options(joinedload(Repository.user))\ |
|
676 | .options(joinedload(Repository.user)) \ | |
677 | .options(joinedload(Repository.group)) |
|
677 | .options(joinedload(Repository.group)) | |
678 | return q.scalar() |
|
678 | return q.scalar() | |
679 |
|
679 | |||
@@ -693,7 +693,7 b' class Repository(Base, BaseModel):' | |||||
693 |
|
693 | |||
694 | :param cls: |
|
694 | :param cls: | |
695 | """ |
|
695 | """ | |
696 | q = Session().query(Ui)\ |
|
696 | q = Session().query(Ui) \ | |
697 | .filter(Ui.ui_key == cls.url_sep()) |
|
697 | .filter(Ui.ui_key == cls.url_sep()) | |
698 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
698 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
699 | return q.one().ui_value |
|
699 | return q.one().ui_value | |
@@ -762,9 +762,9 b' class Repository(Base, BaseModel):' | |||||
762 | """ |
|
762 | """ | |
763 | Returns associated cache keys for that repo |
|
763 | Returns associated cache keys for that repo | |
764 | """ |
|
764 | """ | |
765 | return CacheInvalidation.query()\ |
|
765 | return CacheInvalidation.query() \ | |
766 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
766 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
767 | .order_by(CacheInvalidation.cache_key)\ |
|
767 | .order_by(CacheInvalidation.cache_key) \ | |
768 | .all() |
|
768 | .all() | |
769 |
|
769 | |||
770 | def get_new_name(self, repo_name): |
|
770 | def get_new_name(self, repo_name): | |
@@ -886,7 +886,7 b' class Repository(Base, BaseModel):' | |||||
886 |
|
886 | |||
887 | :param revisions: filter query by revisions only |
|
887 | :param revisions: filter query by revisions only | |
888 | """ |
|
888 | """ | |
889 | cmts = ChangesetComment.query()\ |
|
889 | cmts = ChangesetComment.query() \ | |
890 | .filter(ChangesetComment.repo == self) |
|
890 | .filter(ChangesetComment.repo == self) | |
891 | if revisions: |
|
891 | if revisions: | |
892 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
892 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -903,8 +903,8 b' class Repository(Base, BaseModel):' | |||||
903 | :type revisions: list |
|
903 | :type revisions: list | |
904 | """ |
|
904 | """ | |
905 |
|
905 | |||
906 | statuses = ChangesetStatus.query()\ |
|
906 | statuses = ChangesetStatus.query() \ | |
907 | .filter(ChangesetStatus.repo == self)\ |
|
907 | .filter(ChangesetStatus.repo == self) \ | |
908 | .filter(ChangesetStatus.version == 0) |
|
908 | .filter(ChangesetStatus.version == 0) | |
909 | if revisions: |
|
909 | if revisions: | |
910 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
910 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1051,10 +1051,10 b' class RepoGroup(Base, BaseModel):' | |||||
1051 | @classmethod |
|
1051 | @classmethod | |
1052 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1052 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1053 | if case_insensitive: |
|
1053 | if case_insensitive: | |
1054 | gr = cls.query()\ |
|
1054 | gr = cls.query() \ | |
1055 | .filter(cls.group_name.ilike(group_name)) |
|
1055 | .filter(cls.group_name.ilike(group_name)) | |
1056 | else: |
|
1056 | else: | |
1057 | gr = cls.query()\ |
|
1057 | gr = cls.query() \ | |
1058 | .filter(cls.group_name == group_name) |
|
1058 | .filter(cls.group_name == group_name) | |
1059 | if cache: |
|
1059 | if cache: | |
1060 | gr = gr.options(FromCache( |
|
1060 | gr = gr.options(FromCache( | |
@@ -1106,8 +1106,8 b' class RepoGroup(Base, BaseModel):' | |||||
1106 |
|
1106 | |||
1107 | @property |
|
1107 | @property | |
1108 | def repositories(self): |
|
1108 | def repositories(self): | |
1109 | return Repository.query()\ |
|
1109 | return Repository.query() \ | |
1110 | .filter(Repository.group == self)\ |
|
1110 | .filter(Repository.group == self) \ | |
1111 | .order_by(Repository.repo_name) |
|
1111 | .order_by(Repository.repo_name) | |
1112 |
|
1112 | |||
1113 | @property |
|
1113 | @property | |
@@ -1216,18 +1216,18 b' class Permission(Base, BaseModel):' | |||||
1216 |
|
1216 | |||
1217 | @classmethod |
|
1217 | @classmethod | |
1218 | def get_default_perms(cls, default_user_id): |
|
1218 | def get_default_perms(cls, default_user_id): | |
1219 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1219 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1220 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1220 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1221 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1221 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1222 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1222 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1223 |
|
1223 | |||
1224 | return q.all() |
|
1224 | return q.all() | |
1225 |
|
1225 | |||
1226 | @classmethod |
|
1226 | @classmethod | |
1227 | def get_default_group_perms(cls, default_user_id): |
|
1227 | def get_default_group_perms(cls, default_user_id): | |
1228 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1228 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1229 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1229 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1230 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1230 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1231 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1231 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1232 |
|
1232 | |||
1233 | return q.all() |
|
1233 | return q.all() | |
@@ -1596,7 +1596,7 b' class ChangesetComment(Base, BaseModel):' | |||||
1596 | :param cls: |
|
1596 | :param cls: | |
1597 | :param revision: |
|
1597 | :param revision: | |
1598 | """ |
|
1598 | """ | |
1599 | q = Session().query(User)\ |
|
1599 | q = Session().query(User) \ | |
1600 | .join(ChangesetComment.author) |
|
1600 | .join(ChangesetComment.author) | |
1601 | if revision: |
|
1601 | if revision: | |
1602 | q = q.filter(cls.revision == revision) |
|
1602 | q = q.filter(cls.revision == revision) | |
@@ -1753,8 +1753,8 b' class Notification(Base, BaseModel):' | |||||
1753 |
|
1753 | |||
1754 | @property |
|
1754 | @property | |
1755 | def recipients(self): |
|
1755 | def recipients(self): | |
1756 | return [x.user for x in UserNotification.query()\ |
|
1756 | return [x.user for x in UserNotification.query() \ | |
1757 | .filter(UserNotification.notification == self)\ |
|
1757 | .filter(UserNotification.notification == self) \ | |
1758 | .order_by(UserNotification.user_id.asc()).all()] |
|
1758 | .order_by(UserNotification.user_id.asc()).all()] | |
1759 |
|
1759 | |||
1760 | @classmethod |
|
1760 | @classmethod |
@@ -194,7 +194,7 b' class Setting(Base, BaseModel):' | |||||
194 |
|
194 | |||
195 | @classmethod |
|
195 | @classmethod | |
196 | def get_by_name(cls, key): |
|
196 | def get_by_name(cls, key): | |
197 | return cls.query()\ |
|
197 | return cls.query() \ | |
198 | .filter(cls.app_settings_name == key).scalar() |
|
198 | .filter(cls.app_settings_name == key).scalar() | |
199 |
|
199 | |||
200 | @classmethod |
|
200 | @classmethod | |
@@ -223,7 +223,7 b' class Setting(Base, BaseModel):' | |||||
223 |
|
223 | |||
224 | @classmethod |
|
224 | @classmethod | |
225 | def get_ldap_settings(cls, cache=False): |
|
225 | def get_ldap_settings(cls, cache=False): | |
226 | ret = cls.query()\ |
|
226 | ret = cls.query() \ | |
227 | .filter(cls.app_settings_name.startswith('ldap_')).all() |
|
227 | .filter(cls.app_settings_name.startswith('ldap_')).all() | |
228 | fd = {} |
|
228 | fd = {} | |
229 | for row in ret: |
|
229 | for row in ret: | |
@@ -233,7 +233,7 b' class Setting(Base, BaseModel):' | |||||
233 |
|
233 | |||
234 | @classmethod |
|
234 | @classmethod | |
235 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
235 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
236 | ret = cls.query()\ |
|
236 | ret = cls.query() \ | |
237 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
237 | .filter(cls.app_settings_name.startswith('default_')).all() | |
238 | fd = {} |
|
238 | fd = {} | |
239 | for row in ret: |
|
239 | for row in ret: | |
@@ -691,8 +691,8 b' class Repository(Base, BaseModel):' | |||||
691 | @classmethod |
|
691 | @classmethod | |
692 | def get_by_repo_name(cls, repo_name): |
|
692 | def get_by_repo_name(cls, repo_name): | |
693 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
693 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
694 | q = q.options(joinedload(Repository.fork))\ |
|
694 | q = q.options(joinedload(Repository.fork)) \ | |
695 | .options(joinedload(Repository.user))\ |
|
695 | .options(joinedload(Repository.user)) \ | |
696 | .options(joinedload(Repository.group)) |
|
696 | .options(joinedload(Repository.group)) | |
697 | return q.scalar() |
|
697 | return q.scalar() | |
698 |
|
698 | |||
@@ -712,7 +712,7 b' class Repository(Base, BaseModel):' | |||||
712 |
|
712 | |||
713 | :param cls: |
|
713 | :param cls: | |
714 | """ |
|
714 | """ | |
715 | q = Session().query(Ui)\ |
|
715 | q = Session().query(Ui) \ | |
716 | .filter(Ui.ui_key == cls.url_sep()) |
|
716 | .filter(Ui.ui_key == cls.url_sep()) | |
717 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
717 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
718 | return q.one().ui_value |
|
718 | return q.one().ui_value | |
@@ -781,9 +781,9 b' class Repository(Base, BaseModel):' | |||||
781 | """ |
|
781 | """ | |
782 | Returns associated cache keys for that repo |
|
782 | Returns associated cache keys for that repo | |
783 | """ |
|
783 | """ | |
784 | return CacheInvalidation.query()\ |
|
784 | return CacheInvalidation.query() \ | |
785 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
785 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
786 | .order_by(CacheInvalidation.cache_key)\ |
|
786 | .order_by(CacheInvalidation.cache_key) \ | |
787 | .all() |
|
787 | .all() | |
788 |
|
788 | |||
789 | def get_new_name(self, repo_name): |
|
789 | def get_new_name(self, repo_name): | |
@@ -905,7 +905,7 b' class Repository(Base, BaseModel):' | |||||
905 |
|
905 | |||
906 | :param revisions: filter query by revisions only |
|
906 | :param revisions: filter query by revisions only | |
907 | """ |
|
907 | """ | |
908 | cmts = ChangesetComment.query()\ |
|
908 | cmts = ChangesetComment.query() \ | |
909 | .filter(ChangesetComment.repo == self) |
|
909 | .filter(ChangesetComment.repo == self) | |
910 | if revisions: |
|
910 | if revisions: | |
911 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
911 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -922,8 +922,8 b' class Repository(Base, BaseModel):' | |||||
922 | :type revisions: list |
|
922 | :type revisions: list | |
923 | """ |
|
923 | """ | |
924 |
|
924 | |||
925 | statuses = ChangesetStatus.query()\ |
|
925 | statuses = ChangesetStatus.query() \ | |
926 | .filter(ChangesetStatus.repo == self)\ |
|
926 | .filter(ChangesetStatus.repo == self) \ | |
927 | .filter(ChangesetStatus.version == 0) |
|
927 | .filter(ChangesetStatus.version == 0) | |
928 | if revisions: |
|
928 | if revisions: | |
929 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
929 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1070,10 +1070,10 b' class RepoGroup(Base, BaseModel):' | |||||
1070 | @classmethod |
|
1070 | @classmethod | |
1071 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1071 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1072 | if case_insensitive: |
|
1072 | if case_insensitive: | |
1073 | gr = cls.query()\ |
|
1073 | gr = cls.query() \ | |
1074 | .filter(cls.group_name.ilike(group_name)) |
|
1074 | .filter(cls.group_name.ilike(group_name)) | |
1075 | else: |
|
1075 | else: | |
1076 | gr = cls.query()\ |
|
1076 | gr = cls.query() \ | |
1077 | .filter(cls.group_name == group_name) |
|
1077 | .filter(cls.group_name == group_name) | |
1078 | if cache: |
|
1078 | if cache: | |
1079 | gr = gr.options(FromCache( |
|
1079 | gr = gr.options(FromCache( | |
@@ -1125,8 +1125,8 b' class RepoGroup(Base, BaseModel):' | |||||
1125 |
|
1125 | |||
1126 | @property |
|
1126 | @property | |
1127 | def repositories(self): |
|
1127 | def repositories(self): | |
1128 | return Repository.query()\ |
|
1128 | return Repository.query() \ | |
1129 | .filter(Repository.group == self)\ |
|
1129 | .filter(Repository.group == self) \ | |
1130 | .order_by(Repository.repo_name) |
|
1130 | .order_by(Repository.repo_name) | |
1131 |
|
1131 | |||
1132 | @property |
|
1132 | @property | |
@@ -1243,18 +1243,18 b' class Permission(Base, BaseModel):' | |||||
1243 |
|
1243 | |||
1244 | @classmethod |
|
1244 | @classmethod | |
1245 | def get_default_perms(cls, default_user_id): |
|
1245 | def get_default_perms(cls, default_user_id): | |
1246 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1246 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1247 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1247 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1248 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1248 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1249 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1249 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1250 |
|
1250 | |||
1251 | return q.all() |
|
1251 | return q.all() | |
1252 |
|
1252 | |||
1253 | @classmethod |
|
1253 | @classmethod | |
1254 | def get_default_group_perms(cls, default_user_id): |
|
1254 | def get_default_group_perms(cls, default_user_id): | |
1255 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1255 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1256 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1256 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1257 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1257 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1258 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1258 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1259 |
|
1259 | |||
1260 | return q.all() |
|
1260 | return q.all() | |
@@ -1623,7 +1623,7 b' class ChangesetComment(Base, BaseModel):' | |||||
1623 | :param cls: |
|
1623 | :param cls: | |
1624 | :param revision: |
|
1624 | :param revision: | |
1625 | """ |
|
1625 | """ | |
1626 | q = Session().query(User)\ |
|
1626 | q = Session().query(User) \ | |
1627 | .join(ChangesetComment.author) |
|
1627 | .join(ChangesetComment.author) | |
1628 | if revision: |
|
1628 | if revision: | |
1629 | q = q.filter(cls.revision == revision) |
|
1629 | q = q.filter(cls.revision == revision) | |
@@ -1780,8 +1780,8 b' class Notification(Base, BaseModel):' | |||||
1780 |
|
1780 | |||
1781 | @property |
|
1781 | @property | |
1782 | def recipients(self): |
|
1782 | def recipients(self): | |
1783 | return [x.user for x in UserNotification.query()\ |
|
1783 | return [x.user for x in UserNotification.query() \ | |
1784 | .filter(UserNotification.notification == self)\ |
|
1784 | .filter(UserNotification.notification == self) \ | |
1785 | .order_by(UserNotification.user_id.asc()).all()] |
|
1785 | .order_by(UserNotification.user_id.asc()).all()] | |
1786 |
|
1786 | |||
1787 | @classmethod |
|
1787 | @classmethod |
@@ -196,7 +196,7 b' class Setting(Base, BaseModel):' | |||||
196 |
|
196 | |||
197 | @classmethod |
|
197 | @classmethod | |
198 | def get_by_name(cls, key): |
|
198 | def get_by_name(cls, key): | |
199 | return cls.query()\ |
|
199 | return cls.query() \ | |
200 | .filter(cls.app_settings_name == key).scalar() |
|
200 | .filter(cls.app_settings_name == key).scalar() | |
201 |
|
201 | |||
202 | @classmethod |
|
202 | @classmethod | |
@@ -225,7 +225,7 b' class Setting(Base, BaseModel):' | |||||
225 |
|
225 | |||
226 | @classmethod |
|
226 | @classmethod | |
227 | def get_ldap_settings(cls, cache=False): |
|
227 | def get_ldap_settings(cls, cache=False): | |
228 | ret = cls.query()\ |
|
228 | ret = cls.query() \ | |
229 | .filter(cls.app_settings_name.startswith('ldap_')).all() |
|
229 | .filter(cls.app_settings_name.startswith('ldap_')).all() | |
230 | fd = {} |
|
230 | fd = {} | |
231 | for row in ret: |
|
231 | for row in ret: | |
@@ -235,7 +235,7 b' class Setting(Base, BaseModel):' | |||||
235 |
|
235 | |||
236 | @classmethod |
|
236 | @classmethod | |
237 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
237 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
238 | ret = cls.query()\ |
|
238 | ret = cls.query() \ | |
239 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
239 | .filter(cls.app_settings_name.startswith('default_')).all() | |
240 | fd = {} |
|
240 | fd = {} | |
241 | for row in ret: |
|
241 | for row in ret: | |
@@ -757,8 +757,8 b' class Repository(Base, BaseModel):' | |||||
757 | @classmethod |
|
757 | @classmethod | |
758 | def get_by_repo_name(cls, repo_name): |
|
758 | def get_by_repo_name(cls, repo_name): | |
759 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
759 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
760 | q = q.options(joinedload(Repository.fork))\ |
|
760 | q = q.options(joinedload(Repository.fork)) \ | |
761 | .options(joinedload(Repository.user))\ |
|
761 | .options(joinedload(Repository.user)) \ | |
762 | .options(joinedload(Repository.group)) |
|
762 | .options(joinedload(Repository.group)) | |
763 | return q.scalar() |
|
763 | return q.scalar() | |
764 |
|
764 | |||
@@ -779,7 +779,7 b' class Repository(Base, BaseModel):' | |||||
779 |
|
779 | |||
780 | :param cls: |
|
780 | :param cls: | |
781 | """ |
|
781 | """ | |
782 | q = Session().query(Ui)\ |
|
782 | q = Session().query(Ui) \ | |
783 | .filter(Ui.ui_key == cls.url_sep()) |
|
783 | .filter(Ui.ui_key == cls.url_sep()) | |
784 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
784 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
785 | return q.one().ui_value |
|
785 | return q.one().ui_value | |
@@ -848,9 +848,9 b' class Repository(Base, BaseModel):' | |||||
848 | """ |
|
848 | """ | |
849 | Returns associated cache keys for that repo |
|
849 | Returns associated cache keys for that repo | |
850 | """ |
|
850 | """ | |
851 | return CacheInvalidation.query()\ |
|
851 | return CacheInvalidation.query() \ | |
852 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
852 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
853 | .order_by(CacheInvalidation.cache_key)\ |
|
853 | .order_by(CacheInvalidation.cache_key) \ | |
854 | .all() |
|
854 | .all() | |
855 |
|
855 | |||
856 | def get_new_name(self, repo_name): |
|
856 | def get_new_name(self, repo_name): | |
@@ -1023,7 +1023,7 b' class Repository(Base, BaseModel):' | |||||
1023 |
|
1023 | |||
1024 | :param revisions: filter query by revisions only |
|
1024 | :param revisions: filter query by revisions only | |
1025 | """ |
|
1025 | """ | |
1026 | cmts = ChangesetComment.query()\ |
|
1026 | cmts = ChangesetComment.query() \ | |
1027 | .filter(ChangesetComment.repo == self) |
|
1027 | .filter(ChangesetComment.repo == self) | |
1028 | if revisions: |
|
1028 | if revisions: | |
1029 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1029 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1040,8 +1040,8 b' class Repository(Base, BaseModel):' | |||||
1040 | :type revisions: list |
|
1040 | :type revisions: list | |
1041 | """ |
|
1041 | """ | |
1042 |
|
1042 | |||
1043 | statuses = ChangesetStatus.query()\ |
|
1043 | statuses = ChangesetStatus.query() \ | |
1044 | .filter(ChangesetStatus.repo == self)\ |
|
1044 | .filter(ChangesetStatus.repo == self) \ | |
1045 | .filter(ChangesetStatus.version == 0) |
|
1045 | .filter(ChangesetStatus.version == 0) | |
1046 | if revisions: |
|
1046 | if revisions: | |
1047 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1047 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1191,10 +1191,10 b' class RepoGroup(Base, BaseModel):' | |||||
1191 | @classmethod |
|
1191 | @classmethod | |
1192 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1192 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1193 | if case_insensitive: |
|
1193 | if case_insensitive: | |
1194 | gr = cls.query()\ |
|
1194 | gr = cls.query() \ | |
1195 | .filter(cls.group_name.ilike(group_name)) |
|
1195 | .filter(cls.group_name.ilike(group_name)) | |
1196 | else: |
|
1196 | else: | |
1197 | gr = cls.query()\ |
|
1197 | gr = cls.query() \ | |
1198 | .filter(cls.group_name == group_name) |
|
1198 | .filter(cls.group_name == group_name) | |
1199 | if cache: |
|
1199 | if cache: | |
1200 | gr = gr.options(FromCache( |
|
1200 | gr = gr.options(FromCache( | |
@@ -1246,8 +1246,8 b' class RepoGroup(Base, BaseModel):' | |||||
1246 |
|
1246 | |||
1247 | @property |
|
1247 | @property | |
1248 | def repositories(self): |
|
1248 | def repositories(self): | |
1249 | return Repository.query()\ |
|
1249 | return Repository.query() \ | |
1250 | .filter(Repository.group == self)\ |
|
1250 | .filter(Repository.group == self) \ | |
1251 | .order_by(Repository.repo_name) |
|
1251 | .order_by(Repository.repo_name) | |
1252 |
|
1252 | |||
1253 | @property |
|
1253 | @property | |
@@ -1356,18 +1356,18 b' class Permission(Base, BaseModel):' | |||||
1356 |
|
1356 | |||
1357 | @classmethod |
|
1357 | @classmethod | |
1358 | def get_default_perms(cls, default_user_id): |
|
1358 | def get_default_perms(cls, default_user_id): | |
1359 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1359 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1360 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1360 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1361 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1361 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1362 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1362 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1363 |
|
1363 | |||
1364 | return q.all() |
|
1364 | return q.all() | |
1365 |
|
1365 | |||
1366 | @classmethod |
|
1366 | @classmethod | |
1367 | def get_default_group_perms(cls, default_user_id): |
|
1367 | def get_default_group_perms(cls, default_user_id): | |
1368 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1368 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1369 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1369 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1370 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1370 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1371 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1371 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1372 |
|
1372 | |||
1373 | return q.all() |
|
1373 | return q.all() | |
@@ -1736,7 +1736,7 b' class ChangesetComment(Base, BaseModel):' | |||||
1736 | :param cls: |
|
1736 | :param cls: | |
1737 | :param revision: |
|
1737 | :param revision: | |
1738 | """ |
|
1738 | """ | |
1739 | q = Session().query(User)\ |
|
1739 | q = Session().query(User) \ | |
1740 | .join(ChangesetComment.author) |
|
1740 | .join(ChangesetComment.author) | |
1741 | if revision: |
|
1741 | if revision: | |
1742 | q = q.filter(cls.revision == revision) |
|
1742 | q = q.filter(cls.revision == revision) | |
@@ -1901,8 +1901,8 b' class Notification(Base, BaseModel):' | |||||
1901 |
|
1901 | |||
1902 | @property |
|
1902 | @property | |
1903 | def recipients(self): |
|
1903 | def recipients(self): | |
1904 | return [x.user for x in UserNotification.query()\ |
|
1904 | return [x.user for x in UserNotification.query() \ | |
1905 | .filter(UserNotification.notification == self)\ |
|
1905 | .filter(UserNotification.notification == self) \ | |
1906 | .order_by(UserNotification.user_id.asc()).all()] |
|
1906 | .order_by(UserNotification.user_id.asc()).all()] | |
1907 |
|
1907 | |||
1908 | @classmethod |
|
1908 | @classmethod |
@@ -196,7 +196,7 b' class Setting(Base, BaseModel):' | |||||
196 |
|
196 | |||
197 | @classmethod |
|
197 | @classmethod | |
198 | def get_by_name(cls, key): |
|
198 | def get_by_name(cls, key): | |
199 | return cls.query()\ |
|
199 | return cls.query() \ | |
200 | .filter(cls.app_settings_name == key).scalar() |
|
200 | .filter(cls.app_settings_name == key).scalar() | |
201 |
|
201 | |||
202 | @classmethod |
|
202 | @classmethod | |
@@ -225,7 +225,7 b' class Setting(Base, BaseModel):' | |||||
225 |
|
225 | |||
226 | @classmethod |
|
226 | @classmethod | |
227 | def get_ldap_settings(cls, cache=False): |
|
227 | def get_ldap_settings(cls, cache=False): | |
228 | ret = cls.query()\ |
|
228 | ret = cls.query() \ | |
229 | .filter(cls.app_settings_name.startswith('ldap_')).all() |
|
229 | .filter(cls.app_settings_name.startswith('ldap_')).all() | |
230 | fd = {} |
|
230 | fd = {} | |
231 | for row in ret: |
|
231 | for row in ret: | |
@@ -235,7 +235,7 b' class Setting(Base, BaseModel):' | |||||
235 |
|
235 | |||
236 | @classmethod |
|
236 | @classmethod | |
237 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
237 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
238 | ret = cls.query()\ |
|
238 | ret = cls.query() \ | |
239 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
239 | .filter(cls.app_settings_name.startswith('default_')).all() | |
240 | fd = {} |
|
240 | fd = {} | |
241 | for row in ret: |
|
241 | for row in ret: | |
@@ -713,8 +713,8 b' class RepositoryField(Base, BaseModel):' | |||||
713 |
|
713 | |||
714 | @classmethod |
|
714 | @classmethod | |
715 | def get_by_key_name(cls, key, repo): |
|
715 | def get_by_key_name(cls, key, repo): | |
716 | row = cls.query()\ |
|
716 | row = cls.query() \ | |
717 | .filter(cls.repository == repo)\ |
|
717 | .filter(cls.repository == repo) \ | |
718 | .filter(cls.field_key == key).scalar() |
|
718 | .filter(cls.field_key == key).scalar() | |
719 | return row |
|
719 | return row | |
720 |
|
720 | |||
@@ -826,8 +826,8 b' class Repository(Base, BaseModel):' | |||||
826 | @classmethod |
|
826 | @classmethod | |
827 | def get_by_repo_name(cls, repo_name): |
|
827 | def get_by_repo_name(cls, repo_name): | |
828 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
828 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
829 | q = q.options(joinedload(Repository.fork))\ |
|
829 | q = q.options(joinedload(Repository.fork)) \ | |
830 | .options(joinedload(Repository.user))\ |
|
830 | .options(joinedload(Repository.user)) \ | |
831 | .options(joinedload(Repository.group)) |
|
831 | .options(joinedload(Repository.group)) | |
832 | return q.scalar() |
|
832 | return q.scalar() | |
833 |
|
833 | |||
@@ -848,7 +848,7 b' class Repository(Base, BaseModel):' | |||||
848 |
|
848 | |||
849 | :param cls: |
|
849 | :param cls: | |
850 | """ |
|
850 | """ | |
851 | q = Session().query(Ui)\ |
|
851 | q = Session().query(Ui) \ | |
852 | .filter(Ui.ui_key == cls.url_sep()) |
|
852 | .filter(Ui.ui_key == cls.url_sep()) | |
853 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
853 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
854 | return q.one().ui_value |
|
854 | return q.one().ui_value | |
@@ -917,9 +917,9 b' class Repository(Base, BaseModel):' | |||||
917 | """ |
|
917 | """ | |
918 | Returns associated cache keys for that repo |
|
918 | Returns associated cache keys for that repo | |
919 | """ |
|
919 | """ | |
920 | return CacheInvalidation.query()\ |
|
920 | return CacheInvalidation.query() \ | |
921 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
921 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
922 | .order_by(CacheInvalidation.cache_key)\ |
|
922 | .order_by(CacheInvalidation.cache_key) \ | |
923 | .all() |
|
923 | .all() | |
924 |
|
924 | |||
925 | def get_new_name(self, repo_name): |
|
925 | def get_new_name(self, repo_name): | |
@@ -1093,7 +1093,7 b' class Repository(Base, BaseModel):' | |||||
1093 |
|
1093 | |||
1094 | :param revisions: filter query by revisions only |
|
1094 | :param revisions: filter query by revisions only | |
1095 | """ |
|
1095 | """ | |
1096 | cmts = ChangesetComment.query()\ |
|
1096 | cmts = ChangesetComment.query() \ | |
1097 | .filter(ChangesetComment.repo == self) |
|
1097 | .filter(ChangesetComment.repo == self) | |
1098 | if revisions: |
|
1098 | if revisions: | |
1099 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1099 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1110,8 +1110,8 b' class Repository(Base, BaseModel):' | |||||
1110 | :type revisions: list |
|
1110 | :type revisions: list | |
1111 | """ |
|
1111 | """ | |
1112 |
|
1112 | |||
1113 | statuses = ChangesetStatus.query()\ |
|
1113 | statuses = ChangesetStatus.query() \ | |
1114 | .filter(ChangesetStatus.repo == self)\ |
|
1114 | .filter(ChangesetStatus.repo == self) \ | |
1115 | .filter(ChangesetStatus.version == 0) |
|
1115 | .filter(ChangesetStatus.version == 0) | |
1116 | if revisions: |
|
1116 | if revisions: | |
1117 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1117 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1266,10 +1266,10 b' class RepoGroup(Base, BaseModel):' | |||||
1266 | @classmethod |
|
1266 | @classmethod | |
1267 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1267 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1268 | if case_insensitive: |
|
1268 | if case_insensitive: | |
1269 | gr = cls.query()\ |
|
1269 | gr = cls.query() \ | |
1270 | .filter(cls.group_name.ilike(group_name)) |
|
1270 | .filter(cls.group_name.ilike(group_name)) | |
1271 | else: |
|
1271 | else: | |
1272 | gr = cls.query()\ |
|
1272 | gr = cls.query() \ | |
1273 | .filter(cls.group_name == group_name) |
|
1273 | .filter(cls.group_name == group_name) | |
1274 | if cache: |
|
1274 | if cache: | |
1275 | gr = gr.options(FromCache( |
|
1275 | gr = gr.options(FromCache( | |
@@ -1321,8 +1321,8 b' class RepoGroup(Base, BaseModel):' | |||||
1321 |
|
1321 | |||
1322 | @property |
|
1322 | @property | |
1323 | def repositories(self): |
|
1323 | def repositories(self): | |
1324 | return Repository.query()\ |
|
1324 | return Repository.query() \ | |
1325 | .filter(Repository.group == self)\ |
|
1325 | .filter(Repository.group == self) \ | |
1326 | .order_by(Repository.repo_name) |
|
1326 | .order_by(Repository.repo_name) | |
1327 |
|
1327 | |||
1328 | @property |
|
1328 | @property | |
@@ -1441,18 +1441,18 b' class Permission(Base, BaseModel):' | |||||
1441 |
|
1441 | |||
1442 | @classmethod |
|
1442 | @classmethod | |
1443 | def get_default_perms(cls, default_user_id): |
|
1443 | def get_default_perms(cls, default_user_id): | |
1444 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1444 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1445 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1445 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1446 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1446 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1447 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1447 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1448 |
|
1448 | |||
1449 | return q.all() |
|
1449 | return q.all() | |
1450 |
|
1450 | |||
1451 | @classmethod |
|
1451 | @classmethod | |
1452 | def get_default_group_perms(cls, default_user_id): |
|
1452 | def get_default_group_perms(cls, default_user_id): | |
1453 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1453 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1454 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1454 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1455 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1455 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1456 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1456 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1457 |
|
1457 | |||
1458 | return q.all() |
|
1458 | return q.all() | |
@@ -1811,7 +1811,7 b' class ChangesetComment(Base, BaseModel):' | |||||
1811 | :param cls: |
|
1811 | :param cls: | |
1812 | :param revision: |
|
1812 | :param revision: | |
1813 | """ |
|
1813 | """ | |
1814 | q = Session().query(User)\ |
|
1814 | q = Session().query(User) \ | |
1815 | .join(ChangesetComment.author) |
|
1815 | .join(ChangesetComment.author) | |
1816 | if revision: |
|
1816 | if revision: | |
1817 | q = q.filter(cls.revision == revision) |
|
1817 | q = q.filter(cls.revision == revision) | |
@@ -1980,8 +1980,8 b' class Notification(Base, BaseModel):' | |||||
1980 |
|
1980 | |||
1981 | @property |
|
1981 | @property | |
1982 | def recipients(self): |
|
1982 | def recipients(self): | |
1983 | return [x.user for x in UserNotification.query()\ |
|
1983 | return [x.user for x in UserNotification.query() \ | |
1984 | .filter(UserNotification.notification == self)\ |
|
1984 | .filter(UserNotification.notification == self) \ | |
1985 | .order_by(UserNotification.user_id.asc()).all()] |
|
1985 | .order_by(UserNotification.user_id.asc()).all()] | |
1986 |
|
1986 | |||
1987 | @classmethod |
|
1987 | @classmethod |
@@ -201,7 +201,7 b' class Setting(Base, BaseModel):' | |||||
201 |
|
201 | |||
202 | @classmethod |
|
202 | @classmethod | |
203 | def get_by_name(cls, key): |
|
203 | def get_by_name(cls, key): | |
204 | return cls.query()\ |
|
204 | return cls.query() \ | |
205 | .filter(cls.app_settings_name == key).scalar() |
|
205 | .filter(cls.app_settings_name == key).scalar() | |
206 |
|
206 | |||
207 | @classmethod |
|
207 | @classmethod | |
@@ -230,7 +230,7 b' class Setting(Base, BaseModel):' | |||||
230 |
|
230 | |||
231 | @classmethod |
|
231 | @classmethod | |
232 | def get_ldap_settings(cls, cache=False): |
|
232 | def get_ldap_settings(cls, cache=False): | |
233 | ret = cls.query()\ |
|
233 | ret = cls.query() \ | |
234 | .filter(cls.app_settings_name.startswith('ldap_')).all() |
|
234 | .filter(cls.app_settings_name.startswith('ldap_')).all() | |
235 | fd = {} |
|
235 | fd = {} | |
236 | for row in ret: |
|
236 | for row in ret: | |
@@ -240,7 +240,7 b' class Setting(Base, BaseModel):' | |||||
240 |
|
240 | |||
241 | @classmethod |
|
241 | @classmethod | |
242 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
242 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
243 | ret = cls.query()\ |
|
243 | ret = cls.query() \ | |
244 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
244 | .filter(cls.app_settings_name.startswith('default_')).all() | |
245 | fd = {} |
|
245 | fd = {} | |
246 | for row in ret: |
|
246 | for row in ret: | |
@@ -742,8 +742,8 b' class RepositoryField(Base, BaseModel):' | |||||
742 |
|
742 | |||
743 | @classmethod |
|
743 | @classmethod | |
744 | def get_by_key_name(cls, key, repo): |
|
744 | def get_by_key_name(cls, key, repo): | |
745 | row = cls.query()\ |
|
745 | row = cls.query() \ | |
746 | .filter(cls.repository == repo)\ |
|
746 | .filter(cls.repository == repo) \ | |
747 | .filter(cls.field_key == key).scalar() |
|
747 | .filter(cls.field_key == key).scalar() | |
748 | return row |
|
748 | return row | |
749 |
|
749 | |||
@@ -855,8 +855,8 b' class Repository(Base, BaseModel):' | |||||
855 | @classmethod |
|
855 | @classmethod | |
856 | def get_by_repo_name(cls, repo_name): |
|
856 | def get_by_repo_name(cls, repo_name): | |
857 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
857 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
858 | q = q.options(joinedload(Repository.fork))\ |
|
858 | q = q.options(joinedload(Repository.fork)) \ | |
859 | .options(joinedload(Repository.user))\ |
|
859 | .options(joinedload(Repository.user)) \ | |
860 | .options(joinedload(Repository.group)) |
|
860 | .options(joinedload(Repository.group)) | |
861 | return q.scalar() |
|
861 | return q.scalar() | |
862 |
|
862 | |||
@@ -877,7 +877,7 b' class Repository(Base, BaseModel):' | |||||
877 |
|
877 | |||
878 | :param cls: |
|
878 | :param cls: | |
879 | """ |
|
879 | """ | |
880 | q = Session().query(Ui)\ |
|
880 | q = Session().query(Ui) \ | |
881 | .filter(Ui.ui_key == cls.url_sep()) |
|
881 | .filter(Ui.ui_key == cls.url_sep()) | |
882 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
882 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
883 | return q.one().ui_value |
|
883 | return q.one().ui_value | |
@@ -946,9 +946,9 b' class Repository(Base, BaseModel):' | |||||
946 | """ |
|
946 | """ | |
947 | Returns associated cache keys for that repo |
|
947 | Returns associated cache keys for that repo | |
948 | """ |
|
948 | """ | |
949 | return CacheInvalidation.query()\ |
|
949 | return CacheInvalidation.query() \ | |
950 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
950 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
951 | .order_by(CacheInvalidation.cache_key)\ |
|
951 | .order_by(CacheInvalidation.cache_key) \ | |
952 | .all() |
|
952 | .all() | |
953 |
|
953 | |||
954 | def get_new_name(self, repo_name): |
|
954 | def get_new_name(self, repo_name): | |
@@ -1124,7 +1124,7 b' class Repository(Base, BaseModel):' | |||||
1124 |
|
1124 | |||
1125 | :param revisions: filter query by revisions only |
|
1125 | :param revisions: filter query by revisions only | |
1126 | """ |
|
1126 | """ | |
1127 | cmts = ChangesetComment.query()\ |
|
1127 | cmts = ChangesetComment.query() \ | |
1128 | .filter(ChangesetComment.repo == self) |
|
1128 | .filter(ChangesetComment.repo == self) | |
1129 | if revisions: |
|
1129 | if revisions: | |
1130 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1130 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1140,8 +1140,8 b' class Repository(Base, BaseModel):' | |||||
1140 | :param revisions: list of revisions to get statuses for |
|
1140 | :param revisions: list of revisions to get statuses for | |
1141 | """ |
|
1141 | """ | |
1142 |
|
1142 | |||
1143 | statuses = ChangesetStatus.query()\ |
|
1143 | statuses = ChangesetStatus.query() \ | |
1144 | .filter(ChangesetStatus.repo == self)\ |
|
1144 | .filter(ChangesetStatus.repo == self) \ | |
1145 | .filter(ChangesetStatus.version == 0) |
|
1145 | .filter(ChangesetStatus.version == 0) | |
1146 | if revisions: |
|
1146 | if revisions: | |
1147 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1147 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1284,10 +1284,10 b' class RepoGroup(Base, BaseModel):' | |||||
1284 | @classmethod |
|
1284 | @classmethod | |
1285 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1285 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1286 | if case_insensitive: |
|
1286 | if case_insensitive: | |
1287 | gr = cls.query()\ |
|
1287 | gr = cls.query() \ | |
1288 | .filter(cls.group_name.ilike(group_name)) |
|
1288 | .filter(cls.group_name.ilike(group_name)) | |
1289 | else: |
|
1289 | else: | |
1290 | gr = cls.query()\ |
|
1290 | gr = cls.query() \ | |
1291 | .filter(cls.group_name == group_name) |
|
1291 | .filter(cls.group_name == group_name) | |
1292 | if cache: |
|
1292 | if cache: | |
1293 | gr = gr.options(FromCache( |
|
1293 | gr = gr.options(FromCache( | |
@@ -1339,8 +1339,8 b' class RepoGroup(Base, BaseModel):' | |||||
1339 |
|
1339 | |||
1340 | @property |
|
1340 | @property | |
1341 | def repositories(self): |
|
1341 | def repositories(self): | |
1342 | return Repository.query()\ |
|
1342 | return Repository.query() \ | |
1343 | .filter(Repository.group == self)\ |
|
1343 | .filter(Repository.group == self) \ | |
1344 | .order_by(Repository.repo_name) |
|
1344 | .order_by(Repository.repo_name) | |
1345 |
|
1345 | |||
1346 | @property |
|
1346 | @property | |
@@ -1497,27 +1497,27 b' class Permission(Base, BaseModel):' | |||||
1497 |
|
1497 | |||
1498 | @classmethod |
|
1498 | @classmethod | |
1499 | def get_default_perms(cls, default_user_id): |
|
1499 | def get_default_perms(cls, default_user_id): | |
1500 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1500 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1501 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1501 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1502 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1502 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1503 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1503 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1504 |
|
1504 | |||
1505 | return q.all() |
|
1505 | return q.all() | |
1506 |
|
1506 | |||
1507 | @classmethod |
|
1507 | @classmethod | |
1508 | def get_default_group_perms(cls, default_user_id): |
|
1508 | def get_default_group_perms(cls, default_user_id): | |
1509 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1509 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1510 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1510 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1511 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1511 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1512 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1512 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1513 |
|
1513 | |||
1514 | return q.all() |
|
1514 | return q.all() | |
1515 |
|
1515 | |||
1516 | @classmethod |
|
1516 | @classmethod | |
1517 | def get_default_user_group_perms(cls, default_user_id): |
|
1517 | def get_default_user_group_perms(cls, default_user_id): | |
1518 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1518 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1519 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1519 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1520 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1520 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1521 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1521 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1522 |
|
1522 | |||
1523 | return q.all() |
|
1523 | return q.all() | |
@@ -1907,7 +1907,7 b' class ChangesetComment(Base, BaseModel):' | |||||
1907 | :param cls: |
|
1907 | :param cls: | |
1908 | :param revision: |
|
1908 | :param revision: | |
1909 | """ |
|
1909 | """ | |
1910 | q = Session().query(User)\ |
|
1910 | q = Session().query(User) \ | |
1911 | .join(ChangesetComment.author) |
|
1911 | .join(ChangesetComment.author) | |
1912 | if revision: |
|
1912 | if revision: | |
1913 | q = q.filter(cls.revision == revision) |
|
1913 | q = q.filter(cls.revision == revision) | |
@@ -2076,8 +2076,8 b' class Notification(Base, BaseModel):' | |||||
2076 |
|
2076 | |||
2077 | @property |
|
2077 | @property | |
2078 | def recipients(self): |
|
2078 | def recipients(self): | |
2079 | return [x.user for x in UserNotification.query()\ |
|
2079 | return [x.user for x in UserNotification.query() \ | |
2080 | .filter(UserNotification.notification == self)\ |
|
2080 | .filter(UserNotification.notification == self) \ | |
2081 | .order_by(UserNotification.user_id.asc()).all()] |
|
2081 | .order_by(UserNotification.user_id.asc()).all()] | |
2082 |
|
2082 | |||
2083 | @classmethod |
|
2083 | @classmethod | |
@@ -2176,7 +2176,7 b' class Gist(Base, BaseModel):' | |||||
2176 | :param cls: |
|
2176 | :param cls: | |
2177 | """ |
|
2177 | """ | |
2178 | from kallithea.model.gist import GIST_STORE_LOC |
|
2178 | from kallithea.model.gist import GIST_STORE_LOC | |
2179 | q = Session().query(Ui)\ |
|
2179 | q = Session().query(Ui) \ | |
2180 | .filter(Ui.ui_key == URL_SEP) |
|
2180 | .filter(Ui.ui_key == URL_SEP) | |
2181 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2181 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2182 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2182 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -203,7 +203,7 b' class Setting(Base, BaseModel):' | |||||
203 |
|
203 | |||
204 | @classmethod |
|
204 | @classmethod | |
205 | def get_by_name(cls, key): |
|
205 | def get_by_name(cls, key): | |
206 | return cls.query()\ |
|
206 | return cls.query() \ | |
207 | .filter(cls.app_settings_name == key).scalar() |
|
207 | .filter(cls.app_settings_name == key).scalar() | |
208 |
|
208 | |||
209 | @classmethod |
|
209 | @classmethod | |
@@ -232,7 +232,7 b' class Setting(Base, BaseModel):' | |||||
232 |
|
232 | |||
233 | @classmethod |
|
233 | @classmethod | |
234 | def get_ldap_settings(cls, cache=False): |
|
234 | def get_ldap_settings(cls, cache=False): | |
235 | ret = cls.query()\ |
|
235 | ret = cls.query() \ | |
236 | .filter(cls.app_settings_name.startswith('ldap_')).all() |
|
236 | .filter(cls.app_settings_name.startswith('ldap_')).all() | |
237 | fd = {} |
|
237 | fd = {} | |
238 | for row in ret: |
|
238 | for row in ret: | |
@@ -242,7 +242,7 b' class Setting(Base, BaseModel):' | |||||
242 |
|
242 | |||
243 | @classmethod |
|
243 | @classmethod | |
244 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
244 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
245 | ret = cls.query()\ |
|
245 | ret = cls.query() \ | |
246 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
246 | .filter(cls.app_settings_name.startswith('default_')).all() | |
247 | fd = {} |
|
247 | fd = {} | |
248 | for row in ret: |
|
248 | for row in ret: | |
@@ -772,8 +772,8 b' class RepositoryField(Base, BaseModel):' | |||||
772 |
|
772 | |||
773 | @classmethod |
|
773 | @classmethod | |
774 | def get_by_key_name(cls, key, repo): |
|
774 | def get_by_key_name(cls, key, repo): | |
775 | row = cls.query()\ |
|
775 | row = cls.query() \ | |
776 | .filter(cls.repository == repo)\ |
|
776 | .filter(cls.repository == repo) \ | |
777 | .filter(cls.field_key == key).scalar() |
|
777 | .filter(cls.field_key == key).scalar() | |
778 | return row |
|
778 | return row | |
779 |
|
779 | |||
@@ -885,8 +885,8 b' class Repository(Base, BaseModel):' | |||||
885 | @classmethod |
|
885 | @classmethod | |
886 | def get_by_repo_name(cls, repo_name): |
|
886 | def get_by_repo_name(cls, repo_name): | |
887 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
887 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
888 | q = q.options(joinedload(Repository.fork))\ |
|
888 | q = q.options(joinedload(Repository.fork)) \ | |
889 | .options(joinedload(Repository.user))\ |
|
889 | .options(joinedload(Repository.user)) \ | |
890 | .options(joinedload(Repository.group)) |
|
890 | .options(joinedload(Repository.group)) | |
891 | return q.scalar() |
|
891 | return q.scalar() | |
892 |
|
892 | |||
@@ -907,7 +907,7 b' class Repository(Base, BaseModel):' | |||||
907 |
|
907 | |||
908 | :param cls: |
|
908 | :param cls: | |
909 | """ |
|
909 | """ | |
910 | q = Session().query(Ui)\ |
|
910 | q = Session().query(Ui) \ | |
911 | .filter(Ui.ui_key == cls.url_sep()) |
|
911 | .filter(Ui.ui_key == cls.url_sep()) | |
912 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
912 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
913 | return q.one().ui_value |
|
913 | return q.one().ui_value | |
@@ -976,9 +976,9 b' class Repository(Base, BaseModel):' | |||||
976 | """ |
|
976 | """ | |
977 | Returns associated cache keys for that repo |
|
977 | Returns associated cache keys for that repo | |
978 | """ |
|
978 | """ | |
979 | return CacheInvalidation.query()\ |
|
979 | return CacheInvalidation.query() \ | |
980 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
980 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
981 | .order_by(CacheInvalidation.cache_key)\ |
|
981 | .order_by(CacheInvalidation.cache_key) \ | |
982 | .all() |
|
982 | .all() | |
983 |
|
983 | |||
984 | def get_new_name(self, repo_name): |
|
984 | def get_new_name(self, repo_name): | |
@@ -1154,7 +1154,7 b' class Repository(Base, BaseModel):' | |||||
1154 |
|
1154 | |||
1155 | :param revisions: filter query by revisions only |
|
1155 | :param revisions: filter query by revisions only | |
1156 | """ |
|
1156 | """ | |
1157 | cmts = ChangesetComment.query()\ |
|
1157 | cmts = ChangesetComment.query() \ | |
1158 | .filter(ChangesetComment.repo == self) |
|
1158 | .filter(ChangesetComment.repo == self) | |
1159 | if revisions: |
|
1159 | if revisions: | |
1160 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1160 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1170,8 +1170,8 b' class Repository(Base, BaseModel):' | |||||
1170 | :param revisions: list of revisions to get statuses for |
|
1170 | :param revisions: list of revisions to get statuses for | |
1171 | """ |
|
1171 | """ | |
1172 |
|
1172 | |||
1173 | statuses = ChangesetStatus.query()\ |
|
1173 | statuses = ChangesetStatus.query() \ | |
1174 | .filter(ChangesetStatus.repo == self)\ |
|
1174 | .filter(ChangesetStatus.repo == self) \ | |
1175 | .filter(ChangesetStatus.version == 0) |
|
1175 | .filter(ChangesetStatus.version == 0) | |
1176 | if revisions: |
|
1176 | if revisions: | |
1177 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1177 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1314,10 +1314,10 b' class RepoGroup(Base, BaseModel):' | |||||
1314 | @classmethod |
|
1314 | @classmethod | |
1315 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1315 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1316 | if case_insensitive: |
|
1316 | if case_insensitive: | |
1317 | gr = cls.query()\ |
|
1317 | gr = cls.query() \ | |
1318 | .filter(cls.group_name.ilike(group_name)) |
|
1318 | .filter(cls.group_name.ilike(group_name)) | |
1319 | else: |
|
1319 | else: | |
1320 | gr = cls.query()\ |
|
1320 | gr = cls.query() \ | |
1321 | .filter(cls.group_name == group_name) |
|
1321 | .filter(cls.group_name == group_name) | |
1322 | if cache: |
|
1322 | if cache: | |
1323 | gr = gr.options(FromCache( |
|
1323 | gr = gr.options(FromCache( | |
@@ -1369,8 +1369,8 b' class RepoGroup(Base, BaseModel):' | |||||
1369 |
|
1369 | |||
1370 | @property |
|
1370 | @property | |
1371 | def repositories(self): |
|
1371 | def repositories(self): | |
1372 | return Repository.query()\ |
|
1372 | return Repository.query() \ | |
1373 | .filter(Repository.group == self)\ |
|
1373 | .filter(Repository.group == self) \ | |
1374 | .order_by(Repository.repo_name) |
|
1374 | .order_by(Repository.repo_name) | |
1375 |
|
1375 | |||
1376 | @property |
|
1376 | @property | |
@@ -1543,27 +1543,27 b' class Permission(Base, BaseModel):' | |||||
1543 |
|
1543 | |||
1544 | @classmethod |
|
1544 | @classmethod | |
1545 | def get_default_perms(cls, default_user_id): |
|
1545 | def get_default_perms(cls, default_user_id): | |
1546 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1546 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1547 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1547 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1548 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1548 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1549 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1549 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1550 |
|
1550 | |||
1551 | return q.all() |
|
1551 | return q.all() | |
1552 |
|
1552 | |||
1553 | @classmethod |
|
1553 | @classmethod | |
1554 | def get_default_group_perms(cls, default_user_id): |
|
1554 | def get_default_group_perms(cls, default_user_id): | |
1555 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1555 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1556 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1556 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1557 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1557 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1558 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1558 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1559 |
|
1559 | |||
1560 | return q.all() |
|
1560 | return q.all() | |
1561 |
|
1561 | |||
1562 | @classmethod |
|
1562 | @classmethod | |
1563 | def get_default_user_group_perms(cls, default_user_id): |
|
1563 | def get_default_user_group_perms(cls, default_user_id): | |
1564 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1564 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1565 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1565 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1566 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1566 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1567 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1567 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1568 |
|
1568 | |||
1569 | return q.all() |
|
1569 | return q.all() | |
@@ -1953,7 +1953,7 b' class ChangesetComment(Base, BaseModel):' | |||||
1953 | :param cls: |
|
1953 | :param cls: | |
1954 | :param revision: |
|
1954 | :param revision: | |
1955 | """ |
|
1955 | """ | |
1956 | q = Session().query(User)\ |
|
1956 | q = Session().query(User) \ | |
1957 | .join(ChangesetComment.author) |
|
1957 | .join(ChangesetComment.author) | |
1958 | if revision: |
|
1958 | if revision: | |
1959 | q = q.filter(cls.revision == revision) |
|
1959 | q = q.filter(cls.revision == revision) | |
@@ -2123,8 +2123,8 b' class Notification(Base, BaseModel):' | |||||
2123 |
|
2123 | |||
2124 | @property |
|
2124 | @property | |
2125 | def recipients(self): |
|
2125 | def recipients(self): | |
2126 | return [x.user for x in UserNotification.query()\ |
|
2126 | return [x.user for x in UserNotification.query() \ | |
2127 | .filter(UserNotification.notification == self)\ |
|
2127 | .filter(UserNotification.notification == self) \ | |
2128 | .order_by(UserNotification.user_id.asc()).all()] |
|
2128 | .order_by(UserNotification.user_id.asc()).all()] | |
2129 |
|
2129 | |||
2130 | @classmethod |
|
2130 | @classmethod | |
@@ -2223,7 +2223,7 b' class Gist(Base, BaseModel):' | |||||
2223 | :param cls: |
|
2223 | :param cls: | |
2224 | """ |
|
2224 | """ | |
2225 | from kallithea.model.gist import GIST_STORE_LOC |
|
2225 | from kallithea.model.gist import GIST_STORE_LOC | |
2226 | q = Session().query(Ui)\ |
|
2226 | q = Session().query(Ui) \ | |
2227 | .filter(Ui.ui_key == URL_SEP) |
|
2227 | .filter(Ui.ui_key == URL_SEP) | |
2228 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2228 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2229 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2229 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -218,7 +218,7 b' class Setting(Base, BaseModel):' | |||||
218 |
|
218 | |||
219 | @classmethod |
|
219 | @classmethod | |
220 | def get_by_name(cls, key): |
|
220 | def get_by_name(cls, key): | |
221 | return cls.query()\ |
|
221 | return cls.query() \ | |
222 | .filter(cls.app_settings_name == key).scalar() |
|
222 | .filter(cls.app_settings_name == key).scalar() | |
223 |
|
223 | |||
224 | @classmethod |
|
224 | @classmethod | |
@@ -278,7 +278,7 b' class Setting(Base, BaseModel):' | |||||
278 |
|
278 | |||
279 | @classmethod |
|
279 | @classmethod | |
280 | def get_auth_settings(cls, cache=False): |
|
280 | def get_auth_settings(cls, cache=False): | |
281 | ret = cls.query()\ |
|
281 | ret = cls.query() \ | |
282 | .filter(cls.app_settings_name.startswith('auth_')).all() |
|
282 | .filter(cls.app_settings_name.startswith('auth_')).all() | |
283 | fd = {} |
|
283 | fd = {} | |
284 | for row in ret: |
|
284 | for row in ret: | |
@@ -288,7 +288,7 b' class Setting(Base, BaseModel):' | |||||
288 |
|
288 | |||
289 | @classmethod |
|
289 | @classmethod | |
290 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
290 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
291 | ret = cls.query()\ |
|
291 | ret = cls.query() \ | |
292 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
292 | .filter(cls.app_settings_name.startswith('default_')).all() | |
293 | fd = {} |
|
293 | fd = {} | |
294 | for row in ret: |
|
294 | for row in ret: | |
@@ -829,8 +829,8 b' class RepositoryField(Base, BaseModel):' | |||||
829 |
|
829 | |||
830 | @classmethod |
|
830 | @classmethod | |
831 | def get_by_key_name(cls, key, repo): |
|
831 | def get_by_key_name(cls, key, repo): | |
832 | row = cls.query()\ |
|
832 | row = cls.query() \ | |
833 | .filter(cls.repository == repo)\ |
|
833 | .filter(cls.repository == repo) \ | |
834 | .filter(cls.field_key == key).scalar() |
|
834 | .filter(cls.field_key == key).scalar() | |
835 | return row |
|
835 | return row | |
836 |
|
836 | |||
@@ -942,8 +942,8 b' class Repository(Base, BaseModel):' | |||||
942 | @classmethod |
|
942 | @classmethod | |
943 | def get_by_repo_name(cls, repo_name): |
|
943 | def get_by_repo_name(cls, repo_name): | |
944 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
944 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
945 | q = q.options(joinedload(Repository.fork))\ |
|
945 | q = q.options(joinedload(Repository.fork)) \ | |
946 | .options(joinedload(Repository.user))\ |
|
946 | .options(joinedload(Repository.user)) \ | |
947 | .options(joinedload(Repository.group)) |
|
947 | .options(joinedload(Repository.group)) | |
948 | return q.scalar() |
|
948 | return q.scalar() | |
949 |
|
949 | |||
@@ -964,7 +964,7 b' class Repository(Base, BaseModel):' | |||||
964 |
|
964 | |||
965 | :param cls: |
|
965 | :param cls: | |
966 | """ |
|
966 | """ | |
967 | q = Session().query(Ui)\ |
|
967 | q = Session().query(Ui) \ | |
968 | .filter(Ui.ui_key == cls.url_sep()) |
|
968 | .filter(Ui.ui_key == cls.url_sep()) | |
969 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
969 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
970 | return q.one().ui_value |
|
970 | return q.one().ui_value | |
@@ -1033,9 +1033,9 b' class Repository(Base, BaseModel):' | |||||
1033 | """ |
|
1033 | """ | |
1034 | Returns associated cache keys for that repo |
|
1034 | Returns associated cache keys for that repo | |
1035 | """ |
|
1035 | """ | |
1036 | return CacheInvalidation.query()\ |
|
1036 | return CacheInvalidation.query() \ | |
1037 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
1037 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
1038 | .order_by(CacheInvalidation.cache_key)\ |
|
1038 | .order_by(CacheInvalidation.cache_key) \ | |
1039 | .all() |
|
1039 | .all() | |
1040 |
|
1040 | |||
1041 | def get_new_name(self, repo_name): |
|
1041 | def get_new_name(self, repo_name): | |
@@ -1211,7 +1211,7 b' class Repository(Base, BaseModel):' | |||||
1211 |
|
1211 | |||
1212 | :param revisions: filter query by revisions only |
|
1212 | :param revisions: filter query by revisions only | |
1213 | """ |
|
1213 | """ | |
1214 | cmts = ChangesetComment.query()\ |
|
1214 | cmts = ChangesetComment.query() \ | |
1215 | .filter(ChangesetComment.repo == self) |
|
1215 | .filter(ChangesetComment.repo == self) | |
1216 | if revisions: |
|
1216 | if revisions: | |
1217 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1217 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1227,8 +1227,8 b' class Repository(Base, BaseModel):' | |||||
1227 | :param revisions: list of revisions to get statuses for |
|
1227 | :param revisions: list of revisions to get statuses for | |
1228 | """ |
|
1228 | """ | |
1229 |
|
1229 | |||
1230 | statuses = ChangesetStatus.query()\ |
|
1230 | statuses = ChangesetStatus.query() \ | |
1231 | .filter(ChangesetStatus.repo == self)\ |
|
1231 | .filter(ChangesetStatus.repo == self) \ | |
1232 | .filter(ChangesetStatus.version == 0) |
|
1232 | .filter(ChangesetStatus.version == 0) | |
1233 | if revisions: |
|
1233 | if revisions: | |
1234 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1234 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1371,10 +1371,10 b' class RepoGroup(Base, BaseModel):' | |||||
1371 | @classmethod |
|
1371 | @classmethod | |
1372 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1372 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1373 | if case_insensitive: |
|
1373 | if case_insensitive: | |
1374 | gr = cls.query()\ |
|
1374 | gr = cls.query() \ | |
1375 | .filter(cls.group_name.ilike(group_name)) |
|
1375 | .filter(cls.group_name.ilike(group_name)) | |
1376 | else: |
|
1376 | else: | |
1377 | gr = cls.query()\ |
|
1377 | gr = cls.query() \ | |
1378 | .filter(cls.group_name == group_name) |
|
1378 | .filter(cls.group_name == group_name) | |
1379 | if cache: |
|
1379 | if cache: | |
1380 | gr = gr.options(FromCache( |
|
1380 | gr = gr.options(FromCache( | |
@@ -1426,8 +1426,8 b' class RepoGroup(Base, BaseModel):' | |||||
1426 |
|
1426 | |||
1427 | @property |
|
1427 | @property | |
1428 | def repositories(self): |
|
1428 | def repositories(self): | |
1429 | return Repository.query()\ |
|
1429 | return Repository.query() \ | |
1430 | .filter(Repository.group == self)\ |
|
1430 | .filter(Repository.group == self) \ | |
1431 | .order_by(Repository.repo_name) |
|
1431 | .order_by(Repository.repo_name) | |
1432 |
|
1432 | |||
1433 | @property |
|
1433 | @property | |
@@ -1600,27 +1600,27 b' class Permission(Base, BaseModel):' | |||||
1600 |
|
1600 | |||
1601 | @classmethod |
|
1601 | @classmethod | |
1602 | def get_default_perms(cls, default_user_id): |
|
1602 | def get_default_perms(cls, default_user_id): | |
1603 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1603 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1604 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1604 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1605 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1605 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1606 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1606 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1607 |
|
1607 | |||
1608 | return q.all() |
|
1608 | return q.all() | |
1609 |
|
1609 | |||
1610 | @classmethod |
|
1610 | @classmethod | |
1611 | def get_default_group_perms(cls, default_user_id): |
|
1611 | def get_default_group_perms(cls, default_user_id): | |
1612 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1612 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1613 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1613 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1614 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1614 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1615 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1615 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1616 |
|
1616 | |||
1617 | return q.all() |
|
1617 | return q.all() | |
1618 |
|
1618 | |||
1619 | @classmethod |
|
1619 | @classmethod | |
1620 | def get_default_user_group_perms(cls, default_user_id): |
|
1620 | def get_default_user_group_perms(cls, default_user_id): | |
1621 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1621 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1622 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1622 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1623 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1623 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1624 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1624 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1625 |
|
1625 | |||
1626 | return q.all() |
|
1626 | return q.all() | |
@@ -2013,7 +2013,7 b' class ChangesetComment(Base, BaseModel):' | |||||
2013 | :param cls: |
|
2013 | :param cls: | |
2014 | :param revision: |
|
2014 | :param revision: | |
2015 | """ |
|
2015 | """ | |
2016 | q = Session().query(User)\ |
|
2016 | q = Session().query(User) \ | |
2017 | .join(ChangesetComment.author) |
|
2017 | .join(ChangesetComment.author) | |
2018 | if revision: |
|
2018 | if revision: | |
2019 | q = q.filter(cls.revision == revision) |
|
2019 | q = q.filter(cls.revision == revision) | |
@@ -2183,8 +2183,8 b' class Notification(Base, BaseModel):' | |||||
2183 |
|
2183 | |||
2184 | @property |
|
2184 | @property | |
2185 | def recipients(self): |
|
2185 | def recipients(self): | |
2186 | return [x.user for x in UserNotification.query()\ |
|
2186 | return [x.user for x in UserNotification.query() \ | |
2187 | .filter(UserNotification.notification == self)\ |
|
2187 | .filter(UserNotification.notification == self) \ | |
2188 | .order_by(UserNotification.user_id.asc()).all()] |
|
2188 | .order_by(UserNotification.user_id.asc()).all()] | |
2189 |
|
2189 | |||
2190 | @classmethod |
|
2190 | @classmethod | |
@@ -2283,7 +2283,7 b' class Gist(Base, BaseModel):' | |||||
2283 | :param cls: |
|
2283 | :param cls: | |
2284 | """ |
|
2284 | """ | |
2285 | from kallithea.model.gist import GIST_STORE_LOC |
|
2285 | from kallithea.model.gist import GIST_STORE_LOC | |
2286 | q = Session().query(Ui)\ |
|
2286 | q = Session().query(Ui) \ | |
2287 | .filter(Ui.ui_key == URL_SEP) |
|
2287 | .filter(Ui.ui_key == URL_SEP) | |
2288 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2288 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2289 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2289 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -221,7 +221,7 b' class Setting(Base, BaseModel):' | |||||
221 |
|
221 | |||
222 | @classmethod |
|
222 | @classmethod | |
223 | def get_by_name(cls, key): |
|
223 | def get_by_name(cls, key): | |
224 | return cls.query()\ |
|
224 | return cls.query() \ | |
225 | .filter(cls.app_settings_name == key).scalar() |
|
225 | .filter(cls.app_settings_name == key).scalar() | |
226 |
|
226 | |||
227 | @classmethod |
|
227 | @classmethod | |
@@ -281,7 +281,7 b' class Setting(Base, BaseModel):' | |||||
281 |
|
281 | |||
282 | @classmethod |
|
282 | @classmethod | |
283 | def get_auth_settings(cls, cache=False): |
|
283 | def get_auth_settings(cls, cache=False): | |
284 | ret = cls.query()\ |
|
284 | ret = cls.query() \ | |
285 | .filter(cls.app_settings_name.startswith('auth_')).all() |
|
285 | .filter(cls.app_settings_name.startswith('auth_')).all() | |
286 | fd = {} |
|
286 | fd = {} | |
287 | for row in ret: |
|
287 | for row in ret: | |
@@ -291,7 +291,7 b' class Setting(Base, BaseModel):' | |||||
291 |
|
291 | |||
292 | @classmethod |
|
292 | @classmethod | |
293 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
293 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
294 | ret = cls.query()\ |
|
294 | ret = cls.query() \ | |
295 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
295 | .filter(cls.app_settings_name.startswith('default_')).all() | |
296 | fd = {} |
|
296 | fd = {} | |
297 | for row in ret: |
|
297 | for row in ret: | |
@@ -828,8 +828,8 b' class RepositoryField(Base, BaseModel):' | |||||
828 |
|
828 | |||
829 | @classmethod |
|
829 | @classmethod | |
830 | def get_by_key_name(cls, key, repo): |
|
830 | def get_by_key_name(cls, key, repo): | |
831 | row = cls.query()\ |
|
831 | row = cls.query() \ | |
832 | .filter(cls.repository == repo)\ |
|
832 | .filter(cls.repository == repo) \ | |
833 | .filter(cls.field_key == key).scalar() |
|
833 | .filter(cls.field_key == key).scalar() | |
834 | return row |
|
834 | return row | |
835 |
|
835 | |||
@@ -941,8 +941,8 b' class Repository(Base, BaseModel):' | |||||
941 | @classmethod |
|
941 | @classmethod | |
942 | def get_by_repo_name(cls, repo_name): |
|
942 | def get_by_repo_name(cls, repo_name): | |
943 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
943 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
944 | q = q.options(joinedload(Repository.fork))\ |
|
944 | q = q.options(joinedload(Repository.fork)) \ | |
945 | .options(joinedload(Repository.user))\ |
|
945 | .options(joinedload(Repository.user)) \ | |
946 | .options(joinedload(Repository.group)) |
|
946 | .options(joinedload(Repository.group)) | |
947 | return q.scalar() |
|
947 | return q.scalar() | |
948 |
|
948 | |||
@@ -963,7 +963,7 b' class Repository(Base, BaseModel):' | |||||
963 |
|
963 | |||
964 | :param cls: |
|
964 | :param cls: | |
965 | """ |
|
965 | """ | |
966 | q = Session().query(Ui)\ |
|
966 | q = Session().query(Ui) \ | |
967 | .filter(Ui.ui_key == cls.url_sep()) |
|
967 | .filter(Ui.ui_key == cls.url_sep()) | |
968 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
968 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
969 | return q.one().ui_value |
|
969 | return q.one().ui_value | |
@@ -1032,9 +1032,9 b' class Repository(Base, BaseModel):' | |||||
1032 | """ |
|
1032 | """ | |
1033 | Returns associated cache keys for that repo |
|
1033 | Returns associated cache keys for that repo | |
1034 | """ |
|
1034 | """ | |
1035 | return CacheInvalidation.query()\ |
|
1035 | return CacheInvalidation.query() \ | |
1036 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
1036 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
1037 | .order_by(CacheInvalidation.cache_key)\ |
|
1037 | .order_by(CacheInvalidation.cache_key) \ | |
1038 | .all() |
|
1038 | .all() | |
1039 |
|
1039 | |||
1040 | def get_new_name(self, repo_name): |
|
1040 | def get_new_name(self, repo_name): | |
@@ -1210,7 +1210,7 b' class Repository(Base, BaseModel):' | |||||
1210 |
|
1210 | |||
1211 | :param revisions: filter query by revisions only |
|
1211 | :param revisions: filter query by revisions only | |
1212 | """ |
|
1212 | """ | |
1213 | cmts = ChangesetComment.query()\ |
|
1213 | cmts = ChangesetComment.query() \ | |
1214 | .filter(ChangesetComment.repo == self) |
|
1214 | .filter(ChangesetComment.repo == self) | |
1215 | if revisions: |
|
1215 | if revisions: | |
1216 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1216 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1226,8 +1226,8 b' class Repository(Base, BaseModel):' | |||||
1226 | :param revisions: list of revisions to get statuses for |
|
1226 | :param revisions: list of revisions to get statuses for | |
1227 | """ |
|
1227 | """ | |
1228 |
|
1228 | |||
1229 | statuses = ChangesetStatus.query()\ |
|
1229 | statuses = ChangesetStatus.query() \ | |
1230 | .filter(ChangesetStatus.repo == self)\ |
|
1230 | .filter(ChangesetStatus.repo == self) \ | |
1231 | .filter(ChangesetStatus.version == 0) |
|
1231 | .filter(ChangesetStatus.version == 0) | |
1232 | if revisions: |
|
1232 | if revisions: | |
1233 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1233 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1372,10 +1372,10 b' class RepoGroup(Base, BaseModel):' | |||||
1372 | @classmethod |
|
1372 | @classmethod | |
1373 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1373 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1374 | if case_insensitive: |
|
1374 | if case_insensitive: | |
1375 | gr = cls.query()\ |
|
1375 | gr = cls.query() \ | |
1376 | .filter(cls.group_name.ilike(group_name)) |
|
1376 | .filter(cls.group_name.ilike(group_name)) | |
1377 | else: |
|
1377 | else: | |
1378 | gr = cls.query()\ |
|
1378 | gr = cls.query() \ | |
1379 | .filter(cls.group_name == group_name) |
|
1379 | .filter(cls.group_name == group_name) | |
1380 | if cache: |
|
1380 | if cache: | |
1381 | gr = gr.options(FromCache( |
|
1381 | gr = gr.options(FromCache( | |
@@ -1427,8 +1427,8 b' class RepoGroup(Base, BaseModel):' | |||||
1427 |
|
1427 | |||
1428 | @property |
|
1428 | @property | |
1429 | def repositories(self): |
|
1429 | def repositories(self): | |
1430 | return Repository.query()\ |
|
1430 | return Repository.query() \ | |
1431 | .filter(Repository.group == self)\ |
|
1431 | .filter(Repository.group == self) \ | |
1432 | .order_by(Repository.repo_name) |
|
1432 | .order_by(Repository.repo_name) | |
1433 |
|
1433 | |||
1434 | @property |
|
1434 | @property | |
@@ -1601,27 +1601,27 b' class Permission(Base, BaseModel):' | |||||
1601 |
|
1601 | |||
1602 | @classmethod |
|
1602 | @classmethod | |
1603 | def get_default_perms(cls, default_user_id): |
|
1603 | def get_default_perms(cls, default_user_id): | |
1604 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1604 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1605 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1605 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1606 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1606 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1607 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1607 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1608 |
|
1608 | |||
1609 | return q.all() |
|
1609 | return q.all() | |
1610 |
|
1610 | |||
1611 | @classmethod |
|
1611 | @classmethod | |
1612 | def get_default_group_perms(cls, default_user_id): |
|
1612 | def get_default_group_perms(cls, default_user_id): | |
1613 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1613 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1614 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1614 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1615 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1615 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1616 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1616 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1617 |
|
1617 | |||
1618 | return q.all() |
|
1618 | return q.all() | |
1619 |
|
1619 | |||
1620 | @classmethod |
|
1620 | @classmethod | |
1621 | def get_default_user_group_perms(cls, default_user_id): |
|
1621 | def get_default_user_group_perms(cls, default_user_id): | |
1622 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1622 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1623 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1623 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1624 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1624 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1625 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1625 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1626 |
|
1626 | |||
1627 | return q.all() |
|
1627 | return q.all() | |
@@ -2014,7 +2014,7 b' class ChangesetComment(Base, BaseModel):' | |||||
2014 | :param cls: |
|
2014 | :param cls: | |
2015 | :param revision: |
|
2015 | :param revision: | |
2016 | """ |
|
2016 | """ | |
2017 | q = Session().query(User)\ |
|
2017 | q = Session().query(User) \ | |
2018 | .join(ChangesetComment.author) |
|
2018 | .join(ChangesetComment.author) | |
2019 | if revision: |
|
2019 | if revision: | |
2020 | q = q.filter(cls.revision == revision) |
|
2020 | q = q.filter(cls.revision == revision) | |
@@ -2184,8 +2184,8 b' class Notification(Base, BaseModel):' | |||||
2184 |
|
2184 | |||
2185 | @property |
|
2185 | @property | |
2186 | def recipients(self): |
|
2186 | def recipients(self): | |
2187 | return [x.user for x in UserNotification.query()\ |
|
2187 | return [x.user for x in UserNotification.query() \ | |
2188 | .filter(UserNotification.notification == self)\ |
|
2188 | .filter(UserNotification.notification == self) \ | |
2189 | .order_by(UserNotification.user_id.asc()).all()] |
|
2189 | .order_by(UserNotification.user_id.asc()).all()] | |
2190 |
|
2190 | |||
2191 | @classmethod |
|
2191 | @classmethod | |
@@ -2284,7 +2284,7 b' class Gist(Base, BaseModel):' | |||||
2284 | :param cls: |
|
2284 | :param cls: | |
2285 | """ |
|
2285 | """ | |
2286 | from kallithea.model.gist import GIST_STORE_LOC |
|
2286 | from kallithea.model.gist import GIST_STORE_LOC | |
2287 | q = Session().query(Ui)\ |
|
2287 | q = Session().query(Ui) \ | |
2288 | .filter(Ui.ui_key == URL_SEP) |
|
2288 | .filter(Ui.ui_key == URL_SEP) | |
2289 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2289 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2290 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2290 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -221,7 +221,7 b' class Setting(Base, BaseModel):' | |||||
221 |
|
221 | |||
222 | @classmethod |
|
222 | @classmethod | |
223 | def get_by_name(cls, key): |
|
223 | def get_by_name(cls, key): | |
224 | return cls.query()\ |
|
224 | return cls.query() \ | |
225 | .filter(cls.app_settings_name == key).scalar() |
|
225 | .filter(cls.app_settings_name == key).scalar() | |
226 |
|
226 | |||
227 | @classmethod |
|
227 | @classmethod | |
@@ -281,7 +281,7 b' class Setting(Base, BaseModel):' | |||||
281 |
|
281 | |||
282 | @classmethod |
|
282 | @classmethod | |
283 | def get_auth_settings(cls, cache=False): |
|
283 | def get_auth_settings(cls, cache=False): | |
284 | ret = cls.query()\ |
|
284 | ret = cls.query() \ | |
285 | .filter(cls.app_settings_name.startswith('auth_')).all() |
|
285 | .filter(cls.app_settings_name.startswith('auth_')).all() | |
286 | fd = {} |
|
286 | fd = {} | |
287 | for row in ret: |
|
287 | for row in ret: | |
@@ -291,7 +291,7 b' class Setting(Base, BaseModel):' | |||||
291 |
|
291 | |||
292 | @classmethod |
|
292 | @classmethod | |
293 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
293 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
294 | ret = cls.query()\ |
|
294 | ret = cls.query() \ | |
295 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
295 | .filter(cls.app_settings_name.startswith('default_')).all() | |
296 | fd = {} |
|
296 | fd = {} | |
297 | for row in ret: |
|
297 | for row in ret: | |
@@ -828,8 +828,8 b' class RepositoryField(Base, BaseModel):' | |||||
828 |
|
828 | |||
829 | @classmethod |
|
829 | @classmethod | |
830 | def get_by_key_name(cls, key, repo): |
|
830 | def get_by_key_name(cls, key, repo): | |
831 | row = cls.query()\ |
|
831 | row = cls.query() \ | |
832 | .filter(cls.repository == repo)\ |
|
832 | .filter(cls.repository == repo) \ | |
833 | .filter(cls.field_key == key).scalar() |
|
833 | .filter(cls.field_key == key).scalar() | |
834 | return row |
|
834 | return row | |
835 |
|
835 | |||
@@ -958,8 +958,8 b' class Repository(Base, BaseModel):' | |||||
958 | @classmethod |
|
958 | @classmethod | |
959 | def get_by_repo_name(cls, repo_name): |
|
959 | def get_by_repo_name(cls, repo_name): | |
960 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
960 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
961 | q = q.options(joinedload(Repository.fork))\ |
|
961 | q = q.options(joinedload(Repository.fork)) \ | |
962 | .options(joinedload(Repository.user))\ |
|
962 | .options(joinedload(Repository.user)) \ | |
963 | .options(joinedload(Repository.group)) |
|
963 | .options(joinedload(Repository.group)) | |
964 | return q.scalar() |
|
964 | return q.scalar() | |
965 |
|
965 | |||
@@ -980,7 +980,7 b' class Repository(Base, BaseModel):' | |||||
980 |
|
980 | |||
981 | :param cls: |
|
981 | :param cls: | |
982 | """ |
|
982 | """ | |
983 | q = Session().query(Ui)\ |
|
983 | q = Session().query(Ui) \ | |
984 | .filter(Ui.ui_key == cls.url_sep()) |
|
984 | .filter(Ui.ui_key == cls.url_sep()) | |
985 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
985 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
986 | return q.one().ui_value |
|
986 | return q.one().ui_value | |
@@ -1049,9 +1049,9 b' class Repository(Base, BaseModel):' | |||||
1049 | """ |
|
1049 | """ | |
1050 | Returns associated cache keys for that repo |
|
1050 | Returns associated cache keys for that repo | |
1051 | """ |
|
1051 | """ | |
1052 | return CacheInvalidation.query()\ |
|
1052 | return CacheInvalidation.query() \ | |
1053 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
1053 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
1054 | .order_by(CacheInvalidation.cache_key)\ |
|
1054 | .order_by(CacheInvalidation.cache_key) \ | |
1055 | .all() |
|
1055 | .all() | |
1056 |
|
1056 | |||
1057 | def get_new_name(self, repo_name): |
|
1057 | def get_new_name(self, repo_name): | |
@@ -1230,7 +1230,7 b' class Repository(Base, BaseModel):' | |||||
1230 |
|
1230 | |||
1231 | :param revisions: filter query by revisions only |
|
1231 | :param revisions: filter query by revisions only | |
1232 | """ |
|
1232 | """ | |
1233 | cmts = ChangesetComment.query()\ |
|
1233 | cmts = ChangesetComment.query() \ | |
1234 | .filter(ChangesetComment.repo == self) |
|
1234 | .filter(ChangesetComment.repo == self) | |
1235 | if revisions: |
|
1235 | if revisions: | |
1236 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1236 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1246,8 +1246,8 b' class Repository(Base, BaseModel):' | |||||
1246 | :param revisions: list of revisions to get statuses for |
|
1246 | :param revisions: list of revisions to get statuses for | |
1247 | """ |
|
1247 | """ | |
1248 |
|
1248 | |||
1249 | statuses = ChangesetStatus.query()\ |
|
1249 | statuses = ChangesetStatus.query() \ | |
1250 | .filter(ChangesetStatus.repo == self)\ |
|
1250 | .filter(ChangesetStatus.repo == self) \ | |
1251 | .filter(ChangesetStatus.version == 0) |
|
1251 | .filter(ChangesetStatus.version == 0) | |
1252 | if revisions: |
|
1252 | if revisions: | |
1253 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1253 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1393,10 +1393,10 b' class RepoGroup(Base, BaseModel):' | |||||
1393 | @classmethod |
|
1393 | @classmethod | |
1394 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1394 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1395 | if case_insensitive: |
|
1395 | if case_insensitive: | |
1396 | gr = cls.query()\ |
|
1396 | gr = cls.query() \ | |
1397 | .filter(cls.group_name.ilike(group_name)) |
|
1397 | .filter(cls.group_name.ilike(group_name)) | |
1398 | else: |
|
1398 | else: | |
1399 | gr = cls.query()\ |
|
1399 | gr = cls.query() \ | |
1400 | .filter(cls.group_name == group_name) |
|
1400 | .filter(cls.group_name == group_name) | |
1401 | if cache: |
|
1401 | if cache: | |
1402 | gr = gr.options(FromCache( |
|
1402 | gr = gr.options(FromCache( | |
@@ -1448,8 +1448,8 b' class RepoGroup(Base, BaseModel):' | |||||
1448 |
|
1448 | |||
1449 | @property |
|
1449 | @property | |
1450 | def repositories(self): |
|
1450 | def repositories(self): | |
1451 | return Repository.query()\ |
|
1451 | return Repository.query() \ | |
1452 | .filter(Repository.group == self)\ |
|
1452 | .filter(Repository.group == self) \ | |
1453 | .order_by(Repository.repo_name) |
|
1453 | .order_by(Repository.repo_name) | |
1454 |
|
1454 | |||
1455 | @property |
|
1455 | @property | |
@@ -1622,27 +1622,27 b' class Permission(Base, BaseModel):' | |||||
1622 |
|
1622 | |||
1623 | @classmethod |
|
1623 | @classmethod | |
1624 | def get_default_perms(cls, default_user_id): |
|
1624 | def get_default_perms(cls, default_user_id): | |
1625 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1625 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1626 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1626 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1627 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1627 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1628 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1628 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1629 |
|
1629 | |||
1630 | return q.all() |
|
1630 | return q.all() | |
1631 |
|
1631 | |||
1632 | @classmethod |
|
1632 | @classmethod | |
1633 | def get_default_group_perms(cls, default_user_id): |
|
1633 | def get_default_group_perms(cls, default_user_id): | |
1634 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1634 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1635 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1635 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1636 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1636 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1637 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1637 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1638 |
|
1638 | |||
1639 | return q.all() |
|
1639 | return q.all() | |
1640 |
|
1640 | |||
1641 | @classmethod |
|
1641 | @classmethod | |
1642 | def get_default_user_group_perms(cls, default_user_id): |
|
1642 | def get_default_user_group_perms(cls, default_user_id): | |
1643 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1643 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1644 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1644 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1645 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1645 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1646 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1646 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1647 |
|
1647 | |||
1648 | return q.all() |
|
1648 | return q.all() | |
@@ -2035,7 +2035,7 b' class ChangesetComment(Base, BaseModel):' | |||||
2035 | :param cls: |
|
2035 | :param cls: | |
2036 | :param revision: |
|
2036 | :param revision: | |
2037 | """ |
|
2037 | """ | |
2038 | q = Session().query(User)\ |
|
2038 | q = Session().query(User) \ | |
2039 | .join(ChangesetComment.author) |
|
2039 | .join(ChangesetComment.author) | |
2040 | if revision: |
|
2040 | if revision: | |
2041 | q = q.filter(cls.revision == revision) |
|
2041 | q = q.filter(cls.revision == revision) | |
@@ -2205,8 +2205,8 b' class Notification(Base, BaseModel):' | |||||
2205 |
|
2205 | |||
2206 | @property |
|
2206 | @property | |
2207 | def recipients(self): |
|
2207 | def recipients(self): | |
2208 | return [x.user for x in UserNotification.query()\ |
|
2208 | return [x.user for x in UserNotification.query() \ | |
2209 | .filter(UserNotification.notification == self)\ |
|
2209 | .filter(UserNotification.notification == self) \ | |
2210 | .order_by(UserNotification.user_id.asc()).all()] |
|
2210 | .order_by(UserNotification.user_id.asc()).all()] | |
2211 |
|
2211 | |||
2212 | @classmethod |
|
2212 | @classmethod | |
@@ -2305,7 +2305,7 b' class Gist(Base, BaseModel):' | |||||
2305 | :param cls: |
|
2305 | :param cls: | |
2306 | """ |
|
2306 | """ | |
2307 | from kallithea.model.gist import GIST_STORE_LOC |
|
2307 | from kallithea.model.gist import GIST_STORE_LOC | |
2308 | q = Session().query(Ui)\ |
|
2308 | q = Session().query(Ui) \ | |
2309 | .filter(Ui.ui_key == URL_SEP) |
|
2309 | .filter(Ui.ui_key == URL_SEP) | |
2310 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2310 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2311 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2311 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -224,7 +224,7 b' class Setting(Base, BaseModel):' | |||||
224 |
|
224 | |||
225 | @classmethod |
|
225 | @classmethod | |
226 | def get_by_name(cls, key): |
|
226 | def get_by_name(cls, key): | |
227 | return cls.query()\ |
|
227 | return cls.query() \ | |
228 | .filter(cls.app_settings_name == key).scalar() |
|
228 | .filter(cls.app_settings_name == key).scalar() | |
229 |
|
229 | |||
230 | @classmethod |
|
230 | @classmethod | |
@@ -284,7 +284,7 b' class Setting(Base, BaseModel):' | |||||
284 |
|
284 | |||
285 | @classmethod |
|
285 | @classmethod | |
286 | def get_auth_settings(cls, cache=False): |
|
286 | def get_auth_settings(cls, cache=False): | |
287 | ret = cls.query()\ |
|
287 | ret = cls.query() \ | |
288 | .filter(cls.app_settings_name.startswith('auth_')).all() |
|
288 | .filter(cls.app_settings_name.startswith('auth_')).all() | |
289 | fd = {} |
|
289 | fd = {} | |
290 | for row in ret: |
|
290 | for row in ret: | |
@@ -294,7 +294,7 b' class Setting(Base, BaseModel):' | |||||
294 |
|
294 | |||
295 | @classmethod |
|
295 | @classmethod | |
296 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
296 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
297 | ret = cls.query()\ |
|
297 | ret = cls.query() \ | |
298 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
298 | .filter(cls.app_settings_name.startswith('default_')).all() | |
299 | fd = {} |
|
299 | fd = {} | |
300 | for row in ret: |
|
300 | for row in ret: | |
@@ -523,10 +523,10 b' class User(Base, BaseModel):' | |||||
523 |
|
523 | |||
524 | if fallback and not res: |
|
524 | if fallback and not res: | |
525 | #fallback to additional keys |
|
525 | #fallback to additional keys | |
526 | _res = UserApiKeys.query()\ |
|
526 | _res = UserApiKeys.query() \ | |
527 | .filter(UserApiKeys.api_key == api_key)\ |
|
527 | .filter(UserApiKeys.api_key == api_key) \ | |
528 | .filter(or_(UserApiKeys.expires == -1, |
|
528 | .filter(or_(UserApiKeys.expires == -1, | |
529 | UserApiKeys.expires >= time.time()))\ |
|
529 | UserApiKeys.expires >= time.time())) \ | |
530 | .first() |
|
530 | .first() | |
531 | if _res: |
|
531 | if _res: | |
532 | res = _res.user |
|
532 | res = _res.user | |
@@ -866,8 +866,8 b' class RepositoryField(Base, BaseModel):' | |||||
866 |
|
866 | |||
867 | @classmethod |
|
867 | @classmethod | |
868 | def get_by_key_name(cls, key, repo): |
|
868 | def get_by_key_name(cls, key, repo): | |
869 | row = cls.query()\ |
|
869 | row = cls.query() \ | |
870 | .filter(cls.repository == repo)\ |
|
870 | .filter(cls.repository == repo) \ | |
871 | .filter(cls.field_key == key).scalar() |
|
871 | .filter(cls.field_key == key).scalar() | |
872 | return row |
|
872 | return row | |
873 |
|
873 | |||
@@ -997,8 +997,8 b' class Repository(Base, BaseModel):' | |||||
997 | @classmethod |
|
997 | @classmethod | |
998 | def get_by_repo_name(cls, repo_name): |
|
998 | def get_by_repo_name(cls, repo_name): | |
999 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
999 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
1000 | q = q.options(joinedload(Repository.fork))\ |
|
1000 | q = q.options(joinedload(Repository.fork)) \ | |
1001 | .options(joinedload(Repository.user))\ |
|
1001 | .options(joinedload(Repository.user)) \ | |
1002 | .options(joinedload(Repository.group)) |
|
1002 | .options(joinedload(Repository.group)) | |
1003 | return q.scalar() |
|
1003 | return q.scalar() | |
1004 |
|
1004 | |||
@@ -1019,7 +1019,7 b' class Repository(Base, BaseModel):' | |||||
1019 |
|
1019 | |||
1020 | :param cls: |
|
1020 | :param cls: | |
1021 | """ |
|
1021 | """ | |
1022 | q = Session().query(Ui)\ |
|
1022 | q = Session().query(Ui) \ | |
1023 | .filter(Ui.ui_key == cls.url_sep()) |
|
1023 | .filter(Ui.ui_key == cls.url_sep()) | |
1024 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
1024 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
1025 | return q.one().ui_value |
|
1025 | return q.one().ui_value | |
@@ -1088,9 +1088,9 b' class Repository(Base, BaseModel):' | |||||
1088 | """ |
|
1088 | """ | |
1089 | Returns associated cache keys for that repo |
|
1089 | Returns associated cache keys for that repo | |
1090 | """ |
|
1090 | """ | |
1091 | return CacheInvalidation.query()\ |
|
1091 | return CacheInvalidation.query() \ | |
1092 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
1092 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
1093 | .order_by(CacheInvalidation.cache_key)\ |
|
1093 | .order_by(CacheInvalidation.cache_key) \ | |
1094 | .all() |
|
1094 | .all() | |
1095 |
|
1095 | |||
1096 | def get_new_name(self, repo_name): |
|
1096 | def get_new_name(self, repo_name): | |
@@ -1269,7 +1269,7 b' class Repository(Base, BaseModel):' | |||||
1269 |
|
1269 | |||
1270 | :param revisions: filter query by revisions only |
|
1270 | :param revisions: filter query by revisions only | |
1271 | """ |
|
1271 | """ | |
1272 | cmts = ChangesetComment.query()\ |
|
1272 | cmts = ChangesetComment.query() \ | |
1273 | .filter(ChangesetComment.repo == self) |
|
1273 | .filter(ChangesetComment.repo == self) | |
1274 | if revisions: |
|
1274 | if revisions: | |
1275 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1275 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1285,8 +1285,8 b' class Repository(Base, BaseModel):' | |||||
1285 | :param revisions: list of revisions to get statuses for |
|
1285 | :param revisions: list of revisions to get statuses for | |
1286 | """ |
|
1286 | """ | |
1287 |
|
1287 | |||
1288 | statuses = ChangesetStatus.query()\ |
|
1288 | statuses = ChangesetStatus.query() \ | |
1289 | .filter(ChangesetStatus.repo == self)\ |
|
1289 | .filter(ChangesetStatus.repo == self) \ | |
1290 | .filter(ChangesetStatus.version == 0) |
|
1290 | .filter(ChangesetStatus.version == 0) | |
1291 | if revisions: |
|
1291 | if revisions: | |
1292 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1292 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1432,10 +1432,10 b' class RepoGroup(Base, BaseModel):' | |||||
1432 | @classmethod |
|
1432 | @classmethod | |
1433 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1433 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1434 | if case_insensitive: |
|
1434 | if case_insensitive: | |
1435 | gr = cls.query()\ |
|
1435 | gr = cls.query() \ | |
1436 | .filter(cls.group_name.ilike(group_name)) |
|
1436 | .filter(cls.group_name.ilike(group_name)) | |
1437 | else: |
|
1437 | else: | |
1438 | gr = cls.query()\ |
|
1438 | gr = cls.query() \ | |
1439 | .filter(cls.group_name == group_name) |
|
1439 | .filter(cls.group_name == group_name) | |
1440 | if cache: |
|
1440 | if cache: | |
1441 | gr = gr.options(FromCache( |
|
1441 | gr = gr.options(FromCache( | |
@@ -1487,8 +1487,8 b' class RepoGroup(Base, BaseModel):' | |||||
1487 |
|
1487 | |||
1488 | @property |
|
1488 | @property | |
1489 | def repositories(self): |
|
1489 | def repositories(self): | |
1490 | return Repository.query()\ |
|
1490 | return Repository.query() \ | |
1491 | .filter(Repository.group == self)\ |
|
1491 | .filter(Repository.group == self) \ | |
1492 | .order_by(Repository.repo_name) |
|
1492 | .order_by(Repository.repo_name) | |
1493 |
|
1493 | |||
1494 | @property |
|
1494 | @property | |
@@ -1661,27 +1661,27 b' class Permission(Base, BaseModel):' | |||||
1661 |
|
1661 | |||
1662 | @classmethod |
|
1662 | @classmethod | |
1663 | def get_default_perms(cls, default_user_id): |
|
1663 | def get_default_perms(cls, default_user_id): | |
1664 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1664 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1665 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1665 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1666 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1666 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1667 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1667 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1668 |
|
1668 | |||
1669 | return q.all() |
|
1669 | return q.all() | |
1670 |
|
1670 | |||
1671 | @classmethod |
|
1671 | @classmethod | |
1672 | def get_default_group_perms(cls, default_user_id): |
|
1672 | def get_default_group_perms(cls, default_user_id): | |
1673 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1673 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1674 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1674 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1675 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1675 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1676 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1676 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1677 |
|
1677 | |||
1678 | return q.all() |
|
1678 | return q.all() | |
1679 |
|
1679 | |||
1680 | @classmethod |
|
1680 | @classmethod | |
1681 | def get_default_user_group_perms(cls, default_user_id): |
|
1681 | def get_default_user_group_perms(cls, default_user_id): | |
1682 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1682 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1683 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1683 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1684 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1684 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1685 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1685 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1686 |
|
1686 | |||
1687 | return q.all() |
|
1687 | return q.all() | |
@@ -2074,7 +2074,7 b' class ChangesetComment(Base, BaseModel):' | |||||
2074 | :param cls: |
|
2074 | :param cls: | |
2075 | :param revision: |
|
2075 | :param revision: | |
2076 | """ |
|
2076 | """ | |
2077 | q = Session().query(User)\ |
|
2077 | q = Session().query(User) \ | |
2078 | .join(ChangesetComment.author) |
|
2078 | .join(ChangesetComment.author) | |
2079 | if revision: |
|
2079 | if revision: | |
2080 | q = q.filter(cls.revision == revision) |
|
2080 | q = q.filter(cls.revision == revision) | |
@@ -2244,8 +2244,8 b' class Notification(Base, BaseModel):' | |||||
2244 |
|
2244 | |||
2245 | @property |
|
2245 | @property | |
2246 | def recipients(self): |
|
2246 | def recipients(self): | |
2247 | return [x.user for x in UserNotification.query()\ |
|
2247 | return [x.user for x in UserNotification.query() \ | |
2248 | .filter(UserNotification.notification == self)\ |
|
2248 | .filter(UserNotification.notification == self) \ | |
2249 | .order_by(UserNotification.user_id.asc()).all()] |
|
2249 | .order_by(UserNotification.user_id.asc()).all()] | |
2250 |
|
2250 | |||
2251 | @classmethod |
|
2251 | @classmethod | |
@@ -2344,7 +2344,7 b' class Gist(Base, BaseModel):' | |||||
2344 | :param cls: |
|
2344 | :param cls: | |
2345 | """ |
|
2345 | """ | |
2346 | from kallithea.model.gist import GIST_STORE_LOC |
|
2346 | from kallithea.model.gist import GIST_STORE_LOC | |
2347 | q = Session().query(Ui)\ |
|
2347 | q = Session().query(Ui) \ | |
2348 | .filter(Ui.ui_key == URL_SEP) |
|
2348 | .filter(Ui.ui_key == URL_SEP) | |
2349 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2349 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2350 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2350 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -225,7 +225,7 b' class Setting(Base, BaseModel):' | |||||
225 |
|
225 | |||
226 | @classmethod |
|
226 | @classmethod | |
227 | def get_by_name(cls, key): |
|
227 | def get_by_name(cls, key): | |
228 | return cls.query()\ |
|
228 | return cls.query() \ | |
229 | .filter(cls.app_settings_name == key).scalar() |
|
229 | .filter(cls.app_settings_name == key).scalar() | |
230 |
|
230 | |||
231 | @classmethod |
|
231 | @classmethod | |
@@ -285,7 +285,7 b' class Setting(Base, BaseModel):' | |||||
285 |
|
285 | |||
286 | @classmethod |
|
286 | @classmethod | |
287 | def get_auth_settings(cls, cache=False): |
|
287 | def get_auth_settings(cls, cache=False): | |
288 | ret = cls.query()\ |
|
288 | ret = cls.query() \ | |
289 | .filter(cls.app_settings_name.startswith('auth_')).all() |
|
289 | .filter(cls.app_settings_name.startswith('auth_')).all() | |
290 | fd = {} |
|
290 | fd = {} | |
291 | for row in ret: |
|
291 | for row in ret: | |
@@ -295,7 +295,7 b' class Setting(Base, BaseModel):' | |||||
295 |
|
295 | |||
296 | @classmethod |
|
296 | @classmethod | |
297 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
297 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
298 | ret = cls.query()\ |
|
298 | ret = cls.query() \ | |
299 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
299 | .filter(cls.app_settings_name.startswith('default_')).all() | |
300 | fd = {} |
|
300 | fd = {} | |
301 | for row in ret: |
|
301 | for row in ret: | |
@@ -550,10 +550,10 b' class User(Base, BaseModel):' | |||||
550 |
|
550 | |||
551 | if fallback and not res: |
|
551 | if fallback and not res: | |
552 | #fallback to additional keys |
|
552 | #fallback to additional keys | |
553 | _res = UserApiKeys.query()\ |
|
553 | _res = UserApiKeys.query() \ | |
554 | .filter(UserApiKeys.api_key == api_key)\ |
|
554 | .filter(UserApiKeys.api_key == api_key) \ | |
555 | .filter(or_(UserApiKeys.expires == -1, |
|
555 | .filter(or_(UserApiKeys.expires == -1, | |
556 | UserApiKeys.expires >= time.time()))\ |
|
556 | UserApiKeys.expires >= time.time())) \ | |
557 | .first() |
|
557 | .first() | |
558 | if _res: |
|
558 | if _res: | |
559 | res = _res.user |
|
559 | res = _res.user | |
@@ -901,8 +901,8 b' class RepositoryField(Base, BaseModel):' | |||||
901 |
|
901 | |||
902 | @classmethod |
|
902 | @classmethod | |
903 | def get_by_key_name(cls, key, repo): |
|
903 | def get_by_key_name(cls, key, repo): | |
904 | row = cls.query()\ |
|
904 | row = cls.query() \ | |
905 | .filter(cls.repository == repo)\ |
|
905 | .filter(cls.repository == repo) \ | |
906 | .filter(cls.field_key == key).scalar() |
|
906 | .filter(cls.field_key == key).scalar() | |
907 | return row |
|
907 | return row | |
908 |
|
908 | |||
@@ -1037,8 +1037,8 b' class Repository(Base, BaseModel):' | |||||
1037 | @classmethod |
|
1037 | @classmethod | |
1038 | def get_by_repo_name(cls, repo_name): |
|
1038 | def get_by_repo_name(cls, repo_name): | |
1039 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
1039 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
1040 | q = q.options(joinedload(Repository.fork))\ |
|
1040 | q = q.options(joinedload(Repository.fork)) \ | |
1041 | .options(joinedload(Repository.user))\ |
|
1041 | .options(joinedload(Repository.user)) \ | |
1042 | .options(joinedload(Repository.group)) |
|
1042 | .options(joinedload(Repository.group)) | |
1043 | return q.scalar() |
|
1043 | return q.scalar() | |
1044 |
|
1044 | |||
@@ -1059,7 +1059,7 b' class Repository(Base, BaseModel):' | |||||
1059 |
|
1059 | |||
1060 | :param cls: |
|
1060 | :param cls: | |
1061 | """ |
|
1061 | """ | |
1062 | q = Session().query(Ui)\ |
|
1062 | q = Session().query(Ui) \ | |
1063 | .filter(Ui.ui_key == cls.url_sep()) |
|
1063 | .filter(Ui.ui_key == cls.url_sep()) | |
1064 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
1064 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
1065 | return q.one().ui_value |
|
1065 | return q.one().ui_value | |
@@ -1128,9 +1128,9 b' class Repository(Base, BaseModel):' | |||||
1128 | """ |
|
1128 | """ | |
1129 | Returns associated cache keys for that repo |
|
1129 | Returns associated cache keys for that repo | |
1130 | """ |
|
1130 | """ | |
1131 | return CacheInvalidation.query()\ |
|
1131 | return CacheInvalidation.query() \ | |
1132 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
1132 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
1133 | .order_by(CacheInvalidation.cache_key)\ |
|
1133 | .order_by(CacheInvalidation.cache_key) \ | |
1134 | .all() |
|
1134 | .all() | |
1135 |
|
1135 | |||
1136 | def get_new_name(self, repo_name): |
|
1136 | def get_new_name(self, repo_name): | |
@@ -1315,7 +1315,7 b' class Repository(Base, BaseModel):' | |||||
1315 |
|
1315 | |||
1316 | :param revisions: filter query by revisions only |
|
1316 | :param revisions: filter query by revisions only | |
1317 | """ |
|
1317 | """ | |
1318 | cmts = ChangesetComment.query()\ |
|
1318 | cmts = ChangesetComment.query() \ | |
1319 | .filter(ChangesetComment.repo == self) |
|
1319 | .filter(ChangesetComment.repo == self) | |
1320 | if revisions: |
|
1320 | if revisions: | |
1321 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1321 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1331,8 +1331,8 b' class Repository(Base, BaseModel):' | |||||
1331 | :param revisions: list of revisions to get statuses for |
|
1331 | :param revisions: list of revisions to get statuses for | |
1332 | """ |
|
1332 | """ | |
1333 |
|
1333 | |||
1334 | statuses = ChangesetStatus.query()\ |
|
1334 | statuses = ChangesetStatus.query() \ | |
1335 | .filter(ChangesetStatus.repo == self)\ |
|
1335 | .filter(ChangesetStatus.repo == self) \ | |
1336 | .filter(ChangesetStatus.version == 0) |
|
1336 | .filter(ChangesetStatus.version == 0) | |
1337 | if revisions: |
|
1337 | if revisions: | |
1338 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1338 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1482,10 +1482,10 b' class RepoGroup(Base, BaseModel):' | |||||
1482 | @classmethod |
|
1482 | @classmethod | |
1483 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1483 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1484 | if case_insensitive: |
|
1484 | if case_insensitive: | |
1485 | gr = cls.query()\ |
|
1485 | gr = cls.query() \ | |
1486 | .filter(cls.group_name.ilike(group_name)) |
|
1486 | .filter(cls.group_name.ilike(group_name)) | |
1487 | else: |
|
1487 | else: | |
1488 | gr = cls.query()\ |
|
1488 | gr = cls.query() \ | |
1489 | .filter(cls.group_name == group_name) |
|
1489 | .filter(cls.group_name == group_name) | |
1490 | if cache: |
|
1490 | if cache: | |
1491 | gr = gr.options(FromCache( |
|
1491 | gr = gr.options(FromCache( | |
@@ -1537,8 +1537,8 b' class RepoGroup(Base, BaseModel):' | |||||
1537 |
|
1537 | |||
1538 | @property |
|
1538 | @property | |
1539 | def repositories(self): |
|
1539 | def repositories(self): | |
1540 | return Repository.query()\ |
|
1540 | return Repository.query() \ | |
1541 | .filter(Repository.group == self)\ |
|
1541 | .filter(Repository.group == self) \ | |
1542 | .order_by(Repository.repo_name) |
|
1542 | .order_by(Repository.repo_name) | |
1543 |
|
1543 | |||
1544 | @property |
|
1544 | @property | |
@@ -1714,27 +1714,27 b' class Permission(Base, BaseModel):' | |||||
1714 |
|
1714 | |||
1715 | @classmethod |
|
1715 | @classmethod | |
1716 | def get_default_perms(cls, default_user_id): |
|
1716 | def get_default_perms(cls, default_user_id): | |
1717 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1717 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1718 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1718 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1719 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1719 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1720 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1720 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1721 |
|
1721 | |||
1722 | return q.all() |
|
1722 | return q.all() | |
1723 |
|
1723 | |||
1724 | @classmethod |
|
1724 | @classmethod | |
1725 | def get_default_group_perms(cls, default_user_id): |
|
1725 | def get_default_group_perms(cls, default_user_id): | |
1726 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1726 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1727 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1727 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1728 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1728 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1729 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1729 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1730 |
|
1730 | |||
1731 | return q.all() |
|
1731 | return q.all() | |
1732 |
|
1732 | |||
1733 | @classmethod |
|
1733 | @classmethod | |
1734 | def get_default_user_group_perms(cls, default_user_id): |
|
1734 | def get_default_user_group_perms(cls, default_user_id): | |
1735 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1735 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1736 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1736 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1737 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1737 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1738 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1738 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1739 |
|
1739 | |||
1740 | return q.all() |
|
1740 | return q.all() | |
@@ -2127,7 +2127,7 b' class ChangesetComment(Base, BaseModel):' | |||||
2127 | :param cls: |
|
2127 | :param cls: | |
2128 | :param revision: |
|
2128 | :param revision: | |
2129 | """ |
|
2129 | """ | |
2130 | q = Session().query(User)\ |
|
2130 | q = Session().query(User) \ | |
2131 | .join(ChangesetComment.author) |
|
2131 | .join(ChangesetComment.author) | |
2132 | if revision: |
|
2132 | if revision: | |
2133 | q = q.filter(cls.revision == revision) |
|
2133 | q = q.filter(cls.revision == revision) | |
@@ -2297,8 +2297,8 b' class Notification(Base, BaseModel):' | |||||
2297 |
|
2297 | |||
2298 | @property |
|
2298 | @property | |
2299 | def recipients(self): |
|
2299 | def recipients(self): | |
2300 | return [x.user for x in UserNotification.query()\ |
|
2300 | return [x.user for x in UserNotification.query() \ | |
2301 | .filter(UserNotification.notification == self)\ |
|
2301 | .filter(UserNotification.notification == self) \ | |
2302 | .order_by(UserNotification.user_id.asc()).all()] |
|
2302 | .order_by(UserNotification.user_id.asc()).all()] | |
2303 |
|
2303 | |||
2304 | @classmethod |
|
2304 | @classmethod | |
@@ -2401,7 +2401,7 b' class Gist(Base, BaseModel):' | |||||
2401 | :param cls: |
|
2401 | :param cls: | |
2402 | """ |
|
2402 | """ | |
2403 | from kallithea.model.gist import GIST_STORE_LOC |
|
2403 | from kallithea.model.gist import GIST_STORE_LOC | |
2404 | q = Session().query(Ui)\ |
|
2404 | q = Session().query(Ui) \ | |
2405 | .filter(Ui.ui_key == URL_SEP) |
|
2405 | .filter(Ui.ui_key == URL_SEP) | |
2406 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2406 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2407 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2407 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -225,7 +225,7 b' class Setting(Base, BaseModel):' | |||||
225 |
|
225 | |||
226 | @classmethod |
|
226 | @classmethod | |
227 | def get_by_name(cls, key): |
|
227 | def get_by_name(cls, key): | |
228 | return cls.query()\ |
|
228 | return cls.query() \ | |
229 | .filter(cls.app_settings_name == key).scalar() |
|
229 | .filter(cls.app_settings_name == key).scalar() | |
230 |
|
230 | |||
231 | @classmethod |
|
231 | @classmethod | |
@@ -285,7 +285,7 b' class Setting(Base, BaseModel):' | |||||
285 |
|
285 | |||
286 | @classmethod |
|
286 | @classmethod | |
287 | def get_auth_settings(cls, cache=False): |
|
287 | def get_auth_settings(cls, cache=False): | |
288 | ret = cls.query()\ |
|
288 | ret = cls.query() \ | |
289 | .filter(cls.app_settings_name.startswith('auth_')).all() |
|
289 | .filter(cls.app_settings_name.startswith('auth_')).all() | |
290 | fd = {} |
|
290 | fd = {} | |
291 | for row in ret: |
|
291 | for row in ret: | |
@@ -295,7 +295,7 b' class Setting(Base, BaseModel):' | |||||
295 |
|
295 | |||
296 | @classmethod |
|
296 | @classmethod | |
297 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
297 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
298 | ret = cls.query()\ |
|
298 | ret = cls.query() \ | |
299 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
299 | .filter(cls.app_settings_name.startswith('default_')).all() | |
300 | fd = {} |
|
300 | fd = {} | |
301 | for row in ret: |
|
301 | for row in ret: | |
@@ -550,10 +550,10 b' class User(Base, BaseModel):' | |||||
550 |
|
550 | |||
551 | if fallback and not res: |
|
551 | if fallback and not res: | |
552 | #fallback to additional keys |
|
552 | #fallback to additional keys | |
553 | _res = UserApiKeys.query()\ |
|
553 | _res = UserApiKeys.query() \ | |
554 | .filter(UserApiKeys.api_key == api_key)\ |
|
554 | .filter(UserApiKeys.api_key == api_key) \ | |
555 | .filter(or_(UserApiKeys.expires == -1, |
|
555 | .filter(or_(UserApiKeys.expires == -1, | |
556 | UserApiKeys.expires >= time.time()))\ |
|
556 | UserApiKeys.expires >= time.time())) \ | |
557 | .first() |
|
557 | .first() | |
558 | if _res: |
|
558 | if _res: | |
559 | res = _res.user |
|
559 | res = _res.user | |
@@ -919,8 +919,8 b' class RepositoryField(Base, BaseModel):' | |||||
919 |
|
919 | |||
920 | @classmethod |
|
920 | @classmethod | |
921 | def get_by_key_name(cls, key, repo): |
|
921 | def get_by_key_name(cls, key, repo): | |
922 | row = cls.query()\ |
|
922 | row = cls.query() \ | |
923 | .filter(cls.repository == repo)\ |
|
923 | .filter(cls.repository == repo) \ | |
924 | .filter(cls.field_key == key).scalar() |
|
924 | .filter(cls.field_key == key).scalar() | |
925 | return row |
|
925 | return row | |
926 |
|
926 | |||
@@ -1057,8 +1057,8 b' class Repository(Base, BaseModel):' | |||||
1057 | @classmethod |
|
1057 | @classmethod | |
1058 | def get_by_repo_name(cls, repo_name): |
|
1058 | def get_by_repo_name(cls, repo_name): | |
1059 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
1059 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
1060 | q = q.options(joinedload(Repository.fork))\ |
|
1060 | q = q.options(joinedload(Repository.fork)) \ | |
1061 | .options(joinedload(Repository.user))\ |
|
1061 | .options(joinedload(Repository.user)) \ | |
1062 | .options(joinedload(Repository.group)) |
|
1062 | .options(joinedload(Repository.group)) | |
1063 | return q.scalar() |
|
1063 | return q.scalar() | |
1064 |
|
1064 | |||
@@ -1079,7 +1079,7 b' class Repository(Base, BaseModel):' | |||||
1079 |
|
1079 | |||
1080 | :param cls: |
|
1080 | :param cls: | |
1081 | """ |
|
1081 | """ | |
1082 | q = Session().query(Ui)\ |
|
1082 | q = Session().query(Ui) \ | |
1083 | .filter(Ui.ui_key == cls.url_sep()) |
|
1083 | .filter(Ui.ui_key == cls.url_sep()) | |
1084 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
1084 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
1085 | return q.one().ui_value |
|
1085 | return q.one().ui_value | |
@@ -1148,9 +1148,9 b' class Repository(Base, BaseModel):' | |||||
1148 | """ |
|
1148 | """ | |
1149 | Returns associated cache keys for that repo |
|
1149 | Returns associated cache keys for that repo | |
1150 | """ |
|
1150 | """ | |
1151 | return CacheInvalidation.query()\ |
|
1151 | return CacheInvalidation.query() \ | |
1152 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
1152 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
1153 | .order_by(CacheInvalidation.cache_key)\ |
|
1153 | .order_by(CacheInvalidation.cache_key) \ | |
1154 | .all() |
|
1154 | .all() | |
1155 |
|
1155 | |||
1156 | def get_new_name(self, repo_name): |
|
1156 | def get_new_name(self, repo_name): | |
@@ -1342,7 +1342,7 b' class Repository(Base, BaseModel):' | |||||
1342 |
|
1342 | |||
1343 | :param revisions: filter query by revisions only |
|
1343 | :param revisions: filter query by revisions only | |
1344 | """ |
|
1344 | """ | |
1345 | cmts = ChangesetComment.query()\ |
|
1345 | cmts = ChangesetComment.query() \ | |
1346 | .filter(ChangesetComment.repo == self) |
|
1346 | .filter(ChangesetComment.repo == self) | |
1347 | if revisions: |
|
1347 | if revisions: | |
1348 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) |
|
1348 | cmts = cmts.filter(ChangesetComment.revision.in_(revisions)) | |
@@ -1358,8 +1358,8 b' class Repository(Base, BaseModel):' | |||||
1358 | :param revisions: list of revisions to get statuses for |
|
1358 | :param revisions: list of revisions to get statuses for | |
1359 | """ |
|
1359 | """ | |
1360 |
|
1360 | |||
1361 | statuses = ChangesetStatus.query()\ |
|
1361 | statuses = ChangesetStatus.query() \ | |
1362 | .filter(ChangesetStatus.repo == self)\ |
|
1362 | .filter(ChangesetStatus.repo == self) \ | |
1363 | .filter(ChangesetStatus.version == 0) |
|
1363 | .filter(ChangesetStatus.version == 0) | |
1364 | if revisions: |
|
1364 | if revisions: | |
1365 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) |
|
1365 | statuses = statuses.filter(ChangesetStatus.revision.in_(revisions)) | |
@@ -1509,10 +1509,10 b' class RepoGroup(Base, BaseModel):' | |||||
1509 | @classmethod |
|
1509 | @classmethod | |
1510 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1510 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1511 | if case_insensitive: |
|
1511 | if case_insensitive: | |
1512 | gr = cls.query()\ |
|
1512 | gr = cls.query() \ | |
1513 | .filter(cls.group_name.ilike(group_name)) |
|
1513 | .filter(cls.group_name.ilike(group_name)) | |
1514 | else: |
|
1514 | else: | |
1515 | gr = cls.query()\ |
|
1515 | gr = cls.query() \ | |
1516 | .filter(cls.group_name == group_name) |
|
1516 | .filter(cls.group_name == group_name) | |
1517 | if cache: |
|
1517 | if cache: | |
1518 | gr = gr.options(FromCache( |
|
1518 | gr = gr.options(FromCache( | |
@@ -1564,8 +1564,8 b' class RepoGroup(Base, BaseModel):' | |||||
1564 |
|
1564 | |||
1565 | @property |
|
1565 | @property | |
1566 | def repositories(self): |
|
1566 | def repositories(self): | |
1567 | return Repository.query()\ |
|
1567 | return Repository.query() \ | |
1568 | .filter(Repository.group == self)\ |
|
1568 | .filter(Repository.group == self) \ | |
1569 | .order_by(Repository.repo_name) |
|
1569 | .order_by(Repository.repo_name) | |
1570 |
|
1570 | |||
1571 | @property |
|
1571 | @property | |
@@ -1741,27 +1741,27 b' class Permission(Base, BaseModel):' | |||||
1741 |
|
1741 | |||
1742 | @classmethod |
|
1742 | @classmethod | |
1743 | def get_default_perms(cls, default_user_id): |
|
1743 | def get_default_perms(cls, default_user_id): | |
1744 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1744 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1745 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1745 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1746 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1746 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1747 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1747 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1748 |
|
1748 | |||
1749 | return q.all() |
|
1749 | return q.all() | |
1750 |
|
1750 | |||
1751 | @classmethod |
|
1751 | @classmethod | |
1752 | def get_default_group_perms(cls, default_user_id): |
|
1752 | def get_default_group_perms(cls, default_user_id): | |
1753 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1753 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1754 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1754 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1755 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1755 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1756 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1756 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1757 |
|
1757 | |||
1758 | return q.all() |
|
1758 | return q.all() | |
1759 |
|
1759 | |||
1760 | @classmethod |
|
1760 | @classmethod | |
1761 | def get_default_user_group_perms(cls, default_user_id): |
|
1761 | def get_default_user_group_perms(cls, default_user_id): | |
1762 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1762 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1763 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1763 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1764 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1764 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1765 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1765 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1766 |
|
1766 | |||
1767 | return q.all() |
|
1767 | return q.all() | |
@@ -2173,7 +2173,7 b' class ChangesetComment(Base, BaseModel):' | |||||
2173 | :param cls: |
|
2173 | :param cls: | |
2174 | :param revision: |
|
2174 | :param revision: | |
2175 | """ |
|
2175 | """ | |
2176 | q = Session().query(User)\ |
|
2176 | q = Session().query(User) \ | |
2177 | .join(ChangesetComment.author) |
|
2177 | .join(ChangesetComment.author) | |
2178 | if revision: |
|
2178 | if revision: | |
2179 | q = q.filter(cls.revision == revision) |
|
2179 | q = q.filter(cls.revision == revision) | |
@@ -2343,8 +2343,8 b' class Notification(Base, BaseModel):' | |||||
2343 |
|
2343 | |||
2344 | @property |
|
2344 | @property | |
2345 | def recipients(self): |
|
2345 | def recipients(self): | |
2346 | return [x.user for x in UserNotification.query()\ |
|
2346 | return [x.user for x in UserNotification.query() \ | |
2347 | .filter(UserNotification.notification == self)\ |
|
2347 | .filter(UserNotification.notification == self) \ | |
2348 | .order_by(UserNotification.user_id.asc()).all()] |
|
2348 | .order_by(UserNotification.user_id.asc()).all()] | |
2349 |
|
2349 | |||
2350 | @classmethod |
|
2350 | @classmethod | |
@@ -2447,7 +2447,7 b' class Gist(Base, BaseModel):' | |||||
2447 | :param cls: |
|
2447 | :param cls: | |
2448 | """ |
|
2448 | """ | |
2449 | from kallithea.model.gist import GIST_STORE_LOC |
|
2449 | from kallithea.model.gist import GIST_STORE_LOC | |
2450 | q = Session().query(Ui)\ |
|
2450 | q = Session().query(Ui) \ | |
2451 | .filter(Ui.ui_key == URL_SEP) |
|
2451 | .filter(Ui.ui_key == URL_SEP) | |
2452 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2452 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2453 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2453 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -32,8 +32,8 b' def upgrade(migrate_engine):' | |||||
32 |
|
32 | |||
33 | _Session = meta.Session() |
|
33 | _Session = meta.Session() | |
34 | ## after adding that column fix all usernames |
|
34 | ## after adding that column fix all usernames | |
35 | users_log = _Session.query(db_1_5_0.UserLog)\ |
|
35 | users_log = _Session.query(db_1_5_0.UserLog) \ | |
36 | .options(joinedload(db_1_5_0.UserLog.user))\ |
|
36 | .options(joinedload(db_1_5_0.UserLog.user)) \ | |
37 | .options(joinedload(db_1_5_0.UserLog.repository)).all() |
|
37 | .options(joinedload(db_1_5_0.UserLog.repository)).all() | |
38 |
|
38 | |||
39 | for entry in users_log: |
|
39 | for entry in users_log: |
@@ -54,7 +54,7 b' from webhelpers.html.tags import _set_in' | |||||
54 | from kallithea.lib.annotate import annotate_highlight |
|
54 | from kallithea.lib.annotate import annotate_highlight | |
55 | from kallithea.lib.utils import repo_name_slug, get_custom_lexer |
|
55 | from kallithea.lib.utils import repo_name_slug, get_custom_lexer | |
56 | from kallithea.lib.utils2 import str2bool, safe_unicode, safe_str, \ |
|
56 | from kallithea.lib.utils2 import str2bool, safe_unicode, safe_str, \ | |
57 | get_changeset_safe, datetime_to_time, time_to_datetime, AttributeDict,\ |
|
57 | get_changeset_safe, datetime_to_time, time_to_datetime, AttributeDict, \ | |
58 | safe_int |
|
58 | safe_int | |
59 | from kallithea.lib.markup_renderer import MarkupRenderer, url_re |
|
59 | from kallithea.lib.markup_renderer import MarkupRenderer, url_re | |
60 | from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError |
|
60 | from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError | |
@@ -802,8 +802,8 b' def action_parser(user_log, feed=False, ' | |||||
802 | if feed: |
|
802 | if feed: | |
803 | action = action_str[0].replace('[', '').replace(']', '') |
|
803 | action = action_str[0].replace('[', '').replace(']', '') | |
804 | else: |
|
804 | else: | |
805 | action = action_str[0]\ |
|
805 | action = action_str[0] \ | |
806 | .replace('[', '<span class="journal_highlight">')\ |
|
806 | .replace('[', '<span class="journal_highlight">') \ | |
807 | .replace(']', '</span>') |
|
807 | .replace(']', '</span>') | |
808 |
|
808 | |||
809 | action_params_func = lambda: "" |
|
809 | action_params_func = lambda: "" | |
@@ -879,10 +879,10 b' def gravatar_url(email_address, size=30,' | |||||
879 |
|
879 | |||
880 | tmpl = _gravatar_url |
|
880 | tmpl = _gravatar_url | |
881 | parsed_url = urlparse.urlparse(url.current(qualified=True)) |
|
881 | parsed_url = urlparse.urlparse(url.current(qualified=True)) | |
882 | tmpl = tmpl.replace('{email}', email_address)\ |
|
882 | tmpl = tmpl.replace('{email}', email_address) \ | |
883 | .replace('{md5email}', _md5(safe_str(email_address).lower())) \ |
|
883 | .replace('{md5email}', _md5(safe_str(email_address).lower())) \ | |
884 | .replace('{netloc}', parsed_url.netloc)\ |
|
884 | .replace('{netloc}', parsed_url.netloc) \ | |
885 | .replace('{scheme}', parsed_url.scheme)\ |
|
885 | .replace('{scheme}', parsed_url.scheme) \ | |
886 | .replace('{size}', safe_str(size)) |
|
886 | .replace('{size}', safe_str(size)) | |
887 | return tmpl |
|
887 | return tmpl | |
888 |
|
888 |
@@ -38,7 +38,7 b' from webob.exc import HTTPNotFound, HTTP' | |||||
38 | HTTPNotAcceptable |
|
38 | HTTPNotAcceptable | |
39 | from kallithea.model.db import User, Ui |
|
39 | from kallithea.model.db import User, Ui | |
40 |
|
40 | |||
41 | from kallithea.lib.utils2 import safe_str, fix_PATH, get_server_url,\ |
|
41 | from kallithea.lib.utils2 import safe_str, fix_PATH, get_server_url, \ | |
42 | _set_extras |
|
42 | _set_extras | |
43 | from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback |
|
43 | from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback | |
44 | from kallithea.lib.utils import make_ui, is_valid_repo |
|
44 | from kallithea.lib.utils import make_ui, is_valid_repo |
@@ -37,7 +37,7 b' from webob.exc import HTTPNotFound, HTTP' | |||||
37 | HTTPNotAcceptable |
|
37 | HTTPNotAcceptable | |
38 | from kallithea.model.db import User |
|
38 | from kallithea.model.db import User | |
39 |
|
39 | |||
40 | from kallithea.lib.utils2 import safe_str, fix_PATH, get_server_url,\ |
|
40 | from kallithea.lib.utils2 import safe_str, fix_PATH, get_server_url, \ | |
41 | _set_extras |
|
41 | _set_extras | |
42 | from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback |
|
42 | from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback | |
43 | from kallithea.lib.utils import make_ui, is_valid_repo, ui_sections |
|
43 | from kallithea.lib.utils import make_ui, is_valid_repo, ui_sections |
@@ -76,7 +76,7 b' class Command(BasePasterCommand):' | |||||
76 | WhooshIndexingDaemon(index_location=index_location, |
|
76 | WhooshIndexingDaemon(index_location=index_location, | |
77 | repo_location=repo_location, |
|
77 | repo_location=repo_location, | |
78 | repo_list=repo_list, |
|
78 | repo_list=repo_list, | |
79 | repo_update_list=repo_update_list)\ |
|
79 | repo_update_list=repo_update_list) \ | |
80 | .run(full_index=self.options.full_index) |
|
80 | .run(full_index=self.options.full_index) | |
81 | l.release() |
|
81 | l.release() | |
82 | except LockHeld: |
|
82 | except LockHeld: |
@@ -41,11 +41,10 b' class Command(AbstractInstallCommand):' | |||||
41 | group_name = "Kallithea" |
|
41 | group_name = "Kallithea" | |
42 |
|
42 | |||
43 | description = """\ |
|
43 | description = """\ | |
44 |
|
44 | Setup Kallithea according to its configuration file. This is | ||
45 | Setup Kallithea according to its configuration file. This is |
|
45 | the second part of a two-phase web application installation | |
46 | the second part of a two-phase web application installation |
|
46 | process (the first phase is prepare-app). The setup process | |
47 | process (the first phase is prepare-app). The setup process |
|
47 | consist of things like setting up databases, creating super user | |
48 | consist of things like setting up databases, creating super user |
|
|||
49 | """ |
|
48 | """ | |
50 |
|
49 | |||
51 | parser = AbstractInstallCommand.standard_parser( |
|
50 | parser = AbstractInstallCommand.standard_parser( |
@@ -61,7 +61,7 b' class Command(BasePasterCommand):' | |||||
61 | if self.options.repo_update_list else None |
|
61 | if self.options.repo_update_list else None | |
62 |
|
62 | |||
63 | if repo_update_list is not None: |
|
63 | if repo_update_list is not None: | |
64 | repo_list = list(Repository.query()\ |
|
64 | repo_list = list(Repository.query() \ | |
65 | .filter(Repository.repo_name.in_(repo_update_list))) |
|
65 | .filter(Repository.repo_name.in_(repo_update_list))) | |
66 | else: |
|
66 | else: | |
67 | repo_list = Repository.getAll() |
|
67 | repo_list = Repository.getAll() |
@@ -654,7 +654,7 b' def create_test_index(repo_location, con' | |||||
654 | try: |
|
654 | try: | |
655 | l = DaemonLock(file_=jn(dn(index_location), 'make_index.lock')) |
|
655 | l = DaemonLock(file_=jn(dn(index_location), 'make_index.lock')) | |
656 | WhooshIndexingDaemon(index_location=index_location, |
|
656 | WhooshIndexingDaemon(index_location=index_location, | |
657 | repo_location=repo_location)\ |
|
657 | repo_location=repo_location) \ | |
658 | .run(full_index=full_index) |
|
658 | .run(full_index=full_index) | |
659 | l.release() |
|
659 | l.release() | |
660 | except LockHeld: |
|
660 | except LockHeld: |
@@ -40,7 +40,7 b' class GitInMemoryChangeset(BaseInMemoryC' | |||||
40 | ENCODING = "UTF-8" |
|
40 | ENCODING = "UTF-8" | |
41 |
|
41 | |||
42 | # Create tree and populates it with blobs |
|
42 | # Create tree and populates it with blobs | |
43 | commit_tree = self.parents[0] and repo[self.parents[0]._commit.tree] or\ |
|
43 | commit_tree = self.parents[0] and repo[self.parents[0]._commit.tree] or \ | |
44 | objects.Tree() |
|
44 | objects.Tree() | |
45 | for node in self.added + self.changed: |
|
45 | for node in self.added + self.changed: | |
46 | # Compute subdirs if needed |
|
46 | # Compute subdirs if needed |
@@ -361,10 +361,10 b' class MercurialRepository(BaseRepository' | |||||
361 | return localrepository(self.baseui, self.path, create=create) |
|
361 | return localrepository(self.baseui, self.path, create=create) | |
362 | except (Abort, RepoError) as err: |
|
362 | except (Abort, RepoError) as err: | |
363 | if create: |
|
363 | if create: | |
364 | msg = "Cannot create repository at %s. Original error was %s"\ |
|
364 | msg = "Cannot create repository at %s. Original error was %s" \ | |
365 | % (self.path, err) |
|
365 | % (self.path, err) | |
366 | else: |
|
366 | else: | |
367 | msg = "Not valid repository at %s. Original error was %s"\ |
|
367 | msg = "Not valid repository at %s. Original error was %s" \ | |
368 | % (self.path, err) |
|
368 | % (self.path, err) | |
369 | raise RepositoryError(msg) |
|
369 | raise RepositoryError(msg) | |
370 |
|
370 |
@@ -186,5 +186,5 b' def author_name(author):' | |||||
186 | return '' |
|
186 | return '' | |
187 | if not '@' in author: |
|
187 | if not '@' in author: | |
188 | return author |
|
188 | return author | |
189 | return author.replace(author_email(author), '').replace('<', '')\ |
|
189 | return author.replace(author_email(author), '').replace('<', '') \ | |
190 | .replace('>', '').strip() |
|
190 | .replace('>', '').strip() |
@@ -41,7 +41,7 b' class AnnotateHtmlFormatter(HtmlFormatte' | |||||
41 | following function as ``annotate_from_changeset_func``:: |
|
41 | following function as ``annotate_from_changeset_func``:: | |
42 |
|
42 | |||
43 | def changeset_to_anchor(changeset): |
|
43 | def changeset_to_anchor(changeset): | |
44 | return '<a href="/changesets/%s/">%s</a>\n' %\ |
|
44 | return '<a href="/changesets/%s/">%s</a>\n' % \ | |
45 | (changeset.id, changeset.id) |
|
45 | (changeset.id, changeset.id) | |
46 |
|
46 | |||
47 | :param annotate_from_changeset_func: see above |
|
47 | :param annotate_from_changeset_func: see above |
@@ -389,15 +389,15 b' class DiffProcessor(object):' | |||||
389 | diff_lines = self.prepare() |
|
389 | diff_lines = self.prepare() | |
390 | _html_empty = True |
|
390 | _html_empty = True | |
391 | _html = [] |
|
391 | _html = [] | |
392 |
_html.append('''<table class="%(table_class)s">\n''' |
|
392 | _html.append('''<table class="%(table_class)s">\n''' | |
393 |
|
|
393 | % {'table_class': table_class}) | |
394 | for diff in diff_lines: |
|
394 | for diff in diff_lines: | |
395 | for line in diff['chunks']: |
|
395 | for line in diff['chunks']: | |
396 | _html_empty = False |
|
396 | _html_empty = False | |
397 | for change in line: |
|
397 | for change in line: | |
398 |
_html.append('''<tr class="%(line_class)s %(action)s">\n''' |
|
398 | _html.append('''<tr class="%(line_class)s %(action)s">\n''' | |
399 | % {'line_class': line_class, |
|
399 | % {'line_class': line_class, | |
400 | 'action': change['action']}) |
|
400 | 'action': change['action']}) | |
401 | anchor_old_id = '' |
|
401 | anchor_old_id = '' | |
402 | anchor_new_id = '' |
|
402 | anchor_new_id = '' | |
403 | anchor_old = "%(filename)s_o%(oldline_no)s" % \ |
|
403 | anchor_old = "%(filename)s_o%(oldline_no)s" % \ | |
@@ -417,35 +417,32 b' class DiffProcessor(object):' | |||||
417 | ########################################################### |
|
417 | ########################################################### | |
418 | # OLD LINE NUMBER |
|
418 | # OLD LINE NUMBER | |
419 | ########################################################### |
|
419 | ########################################################### | |
420 |
_html.append('''\t<td %(a_id)s class="%(old_lineno_cls)s">''' |
|
420 | _html.append('''\t<td %(a_id)s class="%(old_lineno_cls)s">''' | |
421 |
|
|
421 | % {'a_id': anchor_old_id, | |
422 |
|
|
422 | 'old_lineno_cls': old_lineno_class}) | |
423 |
|
423 | |||
424 |
_html.append('''<pre>%(link)s</pre>''' |
|
424 | _html.append('''<pre>%(link)s</pre>''' | |
425 | % {'link': |
|
425 | % {'link': | |
426 |
_link_to_if(cond_old, change['old_lineno'], '#%s' |
|
426 | _link_to_if(cond_old, change['old_lineno'], '#%s' % anchor_old)}) | |
427 | % anchor_old)}) |
|
|||
428 | _html.append('''</td>\n''') |
|
427 | _html.append('''</td>\n''') | |
429 | ########################################################### |
|
428 | ########################################################### | |
430 | # NEW LINE NUMBER |
|
429 | # NEW LINE NUMBER | |
431 | ########################################################### |
|
430 | ########################################################### | |
432 |
|
431 | |||
433 |
_html.append('''\t<td %(a_id)s class="%(new_lineno_cls)s">''' |
|
432 | _html.append('''\t<td %(a_id)s class="%(new_lineno_cls)s">''' | |
434 |
|
|
433 | % {'a_id': anchor_new_id, | |
435 |
|
|
434 | 'new_lineno_cls': new_lineno_class}) | |
436 |
|
435 | |||
437 |
_html.append('''<pre>%(link)s</pre>''' |
|
436 | _html.append('''<pre>%(link)s</pre>''' | |
438 | % {'link': |
|
437 | % {'link': _link_to_if(cond_new, change['new_lineno'], '#%s' % anchor_new)}) | |
439 | _link_to_if(cond_new, change['new_lineno'], '#%s' \ |
|
|||
440 | % anchor_new)}) |
|
|||
441 | _html.append('''</td>\n''') |
|
438 | _html.append('''</td>\n''') | |
442 | ########################################################### |
|
439 | ########################################################### | |
443 | # CODE |
|
440 | # CODE | |
444 | ########################################################### |
|
441 | ########################################################### | |
445 |
_html.append('''\t<td class="%(code_class)s">''' |
|
442 | _html.append('''\t<td class="%(code_class)s">''' | |
446 |
|
|
443 | % {'code_class': code_class}) | |
447 |
_html.append('''\n\t\t<pre>%(code)s</pre>\n''' |
|
444 | _html.append('''\n\t\t<pre>%(code)s</pre>\n''' | |
448 |
|
|
445 | % {'code': change['line']}) | |
449 | _html.append('''\t</td>''') |
|
446 | _html.append('''\t</td>''') | |
450 | _html.append('''\n</tr>\n''') |
|
447 | _html.append('''\n</tr>\n''') | |
451 | _html.append('''</table>''') |
|
448 | _html.append('''</table>''') |
@@ -19,7 +19,7 b' def import_class(class_path):' | |||||
19 | try: |
|
19 | try: | |
20 | class_mod = __import__(mod_path, {}, {}, [class_name]) |
|
20 | class_mod = __import__(mod_path, {}, {}, [class_name]) | |
21 | except ImportError as err: |
|
21 | except ImportError as err: | |
22 | msg = "There was problem while trying to import backend class. "\ |
|
22 | msg = "There was problem while trying to import backend class. " \ | |
23 | "Original error was:\n%s" % err |
|
23 | "Original error was:\n%s" % err | |
24 | raise VCSError(msg) |
|
24 | raise VCSError(msg) | |
25 | cls = getattr(class_mod, class_name) |
|
25 | cls = getattr(class_mod, class_name) |
@@ -73,10 +73,10 b' class ApiKeyModel(BaseModel):' | |||||
73 |
|
73 | |||
74 | def get_api_keys(self, user, show_expired=True): |
|
74 | def get_api_keys(self, user, show_expired=True): | |
75 | user = self._get_user(user) |
|
75 | user = self._get_user(user) | |
76 | user_api_keys = UserApiKeys.query()\ |
|
76 | user_api_keys = UserApiKeys.query() \ | |
77 | .filter(UserApiKeys.user_id == user.user_id) |
|
77 | .filter(UserApiKeys.user_id == user.user_id) | |
78 | if not show_expired: |
|
78 | if not show_expired: | |
79 | user_api_keys = user_api_keys\ |
|
79 | user_api_keys = user_api_keys \ | |
80 | .filter(or_(UserApiKeys.expires == -1, |
|
80 | .filter(or_(UserApiKeys.expires == -1, | |
81 | UserApiKeys.expires >= time.time())) |
|
81 | UserApiKeys.expires >= time.time())) | |
82 | return user_api_keys |
|
82 | return user_api_keys |
@@ -49,7 +49,7 b' class ChangesetStatusModel(BaseModel):' | |||||
49 | with_revisions=False): |
|
49 | with_revisions=False): | |
50 | repo = self._get_repo(repo) |
|
50 | repo = self._get_repo(repo) | |
51 |
|
51 | |||
52 | q = ChangesetStatus.query()\ |
|
52 | q = ChangesetStatus.query() \ | |
53 | .filter(ChangesetStatus.repo == repo) |
|
53 | .filter(ChangesetStatus.repo == repo) | |
54 | if not with_revisions: |
|
54 | if not with_revisions: | |
55 | q = q.filter(ChangesetStatus.version == 0) |
|
55 | q = q.filter(ChangesetStatus.version == 0) |
@@ -210,7 +210,7 b' class ChangesetCommentsModel(BaseModel):' | |||||
210 | email_kwargs=email_kwargs, |
|
210 | email_kwargs=email_kwargs, | |
211 | ) |
|
211 | ) | |
212 |
|
212 | |||
213 | mention_recipients = set(self._extract_mentions(body))\ |
|
213 | mention_recipients = set(self._extract_mentions(body)) \ | |
214 | .difference(recipients) |
|
214 | .difference(recipients) | |
215 | if mention_recipients: |
|
215 | if mention_recipients: | |
216 | email_kwargs['is_mention'] = True |
|
216 | email_kwargs['is_mention'] = True | |
@@ -260,14 +260,14 b' class ChangesetCommentsModel(BaseModel):' | |||||
260 | q = Session().query(ChangesetComment) |
|
260 | q = Session().query(ChangesetComment) | |
261 |
|
261 | |||
262 | if inline: |
|
262 | if inline: | |
263 | q = q.filter(ChangesetComment.line_no != None)\ |
|
263 | q = q.filter(ChangesetComment.line_no != None) \ | |
264 | .filter(ChangesetComment.f_path != None) |
|
264 | .filter(ChangesetComment.f_path != None) | |
265 | else: |
|
265 | else: | |
266 | q = q.filter(ChangesetComment.line_no == None)\ |
|
266 | q = q.filter(ChangesetComment.line_no == None) \ | |
267 | .filter(ChangesetComment.f_path == None) |
|
267 | .filter(ChangesetComment.f_path == None) | |
268 |
|
268 | |||
269 | if revision is not None: |
|
269 | if revision is not None: | |
270 | q = q.filter(ChangesetComment.revision == revision)\ |
|
270 | q = q.filter(ChangesetComment.revision == revision) \ | |
271 | .filter(ChangesetComment.repo_id == repo_id) |
|
271 | .filter(ChangesetComment.repo_id == repo_id) | |
272 | elif pull_request is not None: |
|
272 | elif pull_request is not None: | |
273 | pull_request = self.__get_pull_request(pull_request) |
|
273 | pull_request = self.__get_pull_request(pull_request) |
@@ -225,7 +225,7 b' class Setting(Base, BaseModel):' | |||||
225 |
|
225 | |||
226 | @classmethod |
|
226 | @classmethod | |
227 | def get_by_name(cls, key): |
|
227 | def get_by_name(cls, key): | |
228 | return cls.query()\ |
|
228 | return cls.query() \ | |
229 | .filter(cls.app_settings_name == key).scalar() |
|
229 | .filter(cls.app_settings_name == key).scalar() | |
230 |
|
230 | |||
231 | @classmethod |
|
231 | @classmethod | |
@@ -285,7 +285,7 b' class Setting(Base, BaseModel):' | |||||
285 |
|
285 | |||
286 | @classmethod |
|
286 | @classmethod | |
287 | def get_auth_settings(cls, cache=False): |
|
287 | def get_auth_settings(cls, cache=False): | |
288 | ret = cls.query()\ |
|
288 | ret = cls.query() \ | |
289 | .filter(cls.app_settings_name.startswith('auth_')).all() |
|
289 | .filter(cls.app_settings_name.startswith('auth_')).all() | |
290 | fd = {} |
|
290 | fd = {} | |
291 | for row in ret: |
|
291 | for row in ret: | |
@@ -294,7 +294,7 b' class Setting(Base, BaseModel):' | |||||
294 |
|
294 | |||
295 | @classmethod |
|
295 | @classmethod | |
296 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): |
|
296 | def get_default_repo_settings(cls, cache=False, strip_prefix=False): | |
297 | ret = cls.query()\ |
|
297 | ret = cls.query() \ | |
298 | .filter(cls.app_settings_name.startswith('default_')).all() |
|
298 | .filter(cls.app_settings_name.startswith('default_')).all() | |
299 | fd = {} |
|
299 | fd = {} | |
300 | for row in ret: |
|
300 | for row in ret: | |
@@ -574,10 +574,10 b' class User(Base, BaseModel):' | |||||
574 |
|
574 | |||
575 | if fallback and not res: |
|
575 | if fallback and not res: | |
576 | #fallback to additional keys |
|
576 | #fallback to additional keys | |
577 | _res = UserApiKeys.query()\ |
|
577 | _res = UserApiKeys.query() \ | |
578 | .filter(UserApiKeys.api_key == api_key)\ |
|
578 | .filter(UserApiKeys.api_key == api_key) \ | |
579 | .filter(or_(UserApiKeys.expires == -1, |
|
579 | .filter(or_(UserApiKeys.expires == -1, | |
580 | UserApiKeys.expires >= time.time()))\ |
|
580 | UserApiKeys.expires >= time.time())) \ | |
581 | .first() |
|
581 | .first() | |
582 | if _res: |
|
582 | if _res: | |
583 | res = _res.user |
|
583 | res = _res.user | |
@@ -946,8 +946,8 b' class RepositoryField(Base, BaseModel):' | |||||
946 |
|
946 | |||
947 | @classmethod |
|
947 | @classmethod | |
948 | def get_by_key_name(cls, key, repo): |
|
948 | def get_by_key_name(cls, key, repo): | |
949 | row = cls.query()\ |
|
949 | row = cls.query() \ | |
950 | .filter(cls.repository == repo)\ |
|
950 | .filter(cls.repository == repo) \ | |
951 | .filter(cls.field_key == key).scalar() |
|
951 | .filter(cls.field_key == key).scalar() | |
952 | return row |
|
952 | return row | |
953 |
|
953 | |||
@@ -1082,8 +1082,8 b' class Repository(Base, BaseModel):' | |||||
1082 | @classmethod |
|
1082 | @classmethod | |
1083 | def get_by_repo_name(cls, repo_name): |
|
1083 | def get_by_repo_name(cls, repo_name): | |
1084 | q = Session().query(cls).filter(cls.repo_name == repo_name) |
|
1084 | q = Session().query(cls).filter(cls.repo_name == repo_name) | |
1085 | q = q.options(joinedload(Repository.fork))\ |
|
1085 | q = q.options(joinedload(Repository.fork)) \ | |
1086 | .options(joinedload(Repository.user))\ |
|
1086 | .options(joinedload(Repository.user)) \ | |
1087 | .options(joinedload(Repository.group)) |
|
1087 | .options(joinedload(Repository.group)) | |
1088 | return q.scalar() |
|
1088 | return q.scalar() | |
1089 |
|
1089 | |||
@@ -1104,7 +1104,7 b' class Repository(Base, BaseModel):' | |||||
1104 |
|
1104 | |||
1105 | :param cls: |
|
1105 | :param cls: | |
1106 | """ |
|
1106 | """ | |
1107 | q = Session().query(Ui)\ |
|
1107 | q = Session().query(Ui) \ | |
1108 | .filter(Ui.ui_key == cls.url_sep()) |
|
1108 | .filter(Ui.ui_key == cls.url_sep()) | |
1109 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
1109 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
1110 | return q.one().ui_value |
|
1110 | return q.one().ui_value | |
@@ -1173,9 +1173,9 b' class Repository(Base, BaseModel):' | |||||
1173 | """ |
|
1173 | """ | |
1174 | Returns associated cache keys for that repo |
|
1174 | Returns associated cache keys for that repo | |
1175 | """ |
|
1175 | """ | |
1176 | return CacheInvalidation.query()\ |
|
1176 | return CacheInvalidation.query() \ | |
1177 | .filter(CacheInvalidation.cache_args == self.repo_name)\ |
|
1177 | .filter(CacheInvalidation.cache_args == self.repo_name) \ | |
1178 | .order_by(CacheInvalidation.cache_key)\ |
|
1178 | .order_by(CacheInvalidation.cache_key) \ | |
1179 | .all() |
|
1179 | .all() | |
1180 |
|
1180 | |||
1181 | def get_new_name(self, repo_name): |
|
1181 | def get_new_name(self, repo_name): | |
@@ -1377,7 +1377,7 b' class Repository(Base, BaseModel):' | |||||
1377 |
|
1377 | |||
1378 | :param revisions: filter query by revisions only |
|
1378 | :param revisions: filter query by revisions only | |
1379 | """ |
|
1379 | """ | |
1380 | cmts = ChangesetComment.query()\ |
|
1380 | cmts = ChangesetComment.query() \ | |
1381 | .filter(ChangesetComment.repo == self) |
|
1381 | .filter(ChangesetComment.repo == self) | |
1382 | if revisions is not None: |
|
1382 | if revisions is not None: | |
1383 | if not revisions: |
|
1383 | if not revisions: | |
@@ -1398,9 +1398,9 b' class Repository(Base, BaseModel):' | |||||
1398 | if not revisions: |
|
1398 | if not revisions: | |
1399 | return {} |
|
1399 | return {} | |
1400 |
|
1400 | |||
1401 | statuses = ChangesetStatus.query()\ |
|
1401 | statuses = ChangesetStatus.query() \ | |
1402 | .filter(ChangesetStatus.repo == self)\ |
|
1402 | .filter(ChangesetStatus.repo == self) \ | |
1403 | .filter(ChangesetStatus.version == 0)\ |
|
1403 | .filter(ChangesetStatus.version == 0) \ | |
1404 | .filter(ChangesetStatus.revision.in_(revisions)) |
|
1404 | .filter(ChangesetStatus.revision.in_(revisions)) | |
1405 |
|
1405 | |||
1406 | grouped = {} |
|
1406 | grouped = {} | |
@@ -1527,10 +1527,10 b' class RepoGroup(Base, BaseModel):' | |||||
1527 | @classmethod |
|
1527 | @classmethod | |
1528 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): |
|
1528 | def get_by_group_name(cls, group_name, cache=False, case_insensitive=False): | |
1529 | if case_insensitive: |
|
1529 | if case_insensitive: | |
1530 | gr = cls.query()\ |
|
1530 | gr = cls.query() \ | |
1531 | .filter(cls.group_name.ilike(group_name)) |
|
1531 | .filter(cls.group_name.ilike(group_name)) | |
1532 | else: |
|
1532 | else: | |
1533 | gr = cls.query()\ |
|
1533 | gr = cls.query() \ | |
1534 | .filter(cls.group_name == group_name) |
|
1534 | .filter(cls.group_name == group_name) | |
1535 | if cache: |
|
1535 | if cache: | |
1536 | gr = gr.options(FromCache( |
|
1536 | gr = gr.options(FromCache( | |
@@ -1582,8 +1582,8 b' class RepoGroup(Base, BaseModel):' | |||||
1582 |
|
1582 | |||
1583 | @property |
|
1583 | @property | |
1584 | def repositories(self): |
|
1584 | def repositories(self): | |
1585 | return Repository.query()\ |
|
1585 | return Repository.query() \ | |
1586 | .filter(Repository.group == self)\ |
|
1586 | .filter(Repository.group == self) \ | |
1587 | .order_by(Repository.repo_name) |
|
1587 | .order_by(Repository.repo_name) | |
1588 |
|
1588 | |||
1589 | @property |
|
1589 | @property | |
@@ -1761,27 +1761,27 b' class Permission(Base, BaseModel):' | |||||
1761 |
|
1761 | |||
1762 | @classmethod |
|
1762 | @classmethod | |
1763 | def get_default_perms(cls, default_user_id): |
|
1763 | def get_default_perms(cls, default_user_id): | |
1764 | q = Session().query(UserRepoToPerm, Repository, cls)\ |
|
1764 | q = Session().query(UserRepoToPerm, Repository, cls) \ | |
1765 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
|
1765 | .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id)) \ | |
1766 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
|
1766 | .join((cls, UserRepoToPerm.permission_id == cls.permission_id)) \ | |
1767 | .filter(UserRepoToPerm.user_id == default_user_id) |
|
1767 | .filter(UserRepoToPerm.user_id == default_user_id) | |
1768 |
|
1768 | |||
1769 | return q.all() |
|
1769 | return q.all() | |
1770 |
|
1770 | |||
1771 | @classmethod |
|
1771 | @classmethod | |
1772 | def get_default_group_perms(cls, default_user_id): |
|
1772 | def get_default_group_perms(cls, default_user_id): | |
1773 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls)\ |
|
1773 | q = Session().query(UserRepoGroupToPerm, RepoGroup, cls) \ | |
1774 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id))\ |
|
1774 | .join((RepoGroup, UserRepoGroupToPerm.group_id == RepoGroup.group_id)) \ | |
1775 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id))\ |
|
1775 | .join((cls, UserRepoGroupToPerm.permission_id == cls.permission_id)) \ | |
1776 | .filter(UserRepoGroupToPerm.user_id == default_user_id) |
|
1776 | .filter(UserRepoGroupToPerm.user_id == default_user_id) | |
1777 |
|
1777 | |||
1778 | return q.all() |
|
1778 | return q.all() | |
1779 |
|
1779 | |||
1780 | @classmethod |
|
1780 | @classmethod | |
1781 | def get_default_user_group_perms(cls, default_user_id): |
|
1781 | def get_default_user_group_perms(cls, default_user_id): | |
1782 | q = Session().query(UserUserGroupToPerm, UserGroup, cls)\ |
|
1782 | q = Session().query(UserUserGroupToPerm, UserGroup, cls) \ | |
1783 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id))\ |
|
1783 | .join((UserGroup, UserUserGroupToPerm.user_group_id == UserGroup.users_group_id)) \ | |
1784 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id))\ |
|
1784 | .join((cls, UserUserGroupToPerm.permission_id == cls.permission_id)) \ | |
1785 | .filter(UserUserGroupToPerm.user_id == default_user_id) |
|
1785 | .filter(UserUserGroupToPerm.user_id == default_user_id) | |
1786 |
|
1786 | |||
1787 | return q.all() |
|
1787 | return q.all() | |
@@ -2187,7 +2187,7 b' class ChangesetComment(Base, BaseModel):' | |||||
2187 | :param cls: |
|
2187 | :param cls: | |
2188 | :param revision: |
|
2188 | :param revision: | |
2189 | """ |
|
2189 | """ | |
2190 | q = Session().query(User)\ |
|
2190 | q = Session().query(User) \ | |
2191 | .join(ChangesetComment.author) |
|
2191 | .join(ChangesetComment.author) | |
2192 | if revision is not None: |
|
2192 | if revision is not None: | |
2193 | q = q.filter(cls.revision == revision) |
|
2193 | q = q.filter(cls.revision == revision) | |
@@ -2314,10 +2314,10 b' class PullRequest(Base, BaseModel):' | |||||
2314 | def user_review_status(self, user_id): |
|
2314 | def user_review_status(self, user_id): | |
2315 | """Return the user's latest status votes on PR""" |
|
2315 | """Return the user's latest status votes on PR""" | |
2316 | # note: no filtering on repo - that would be redundant |
|
2316 | # note: no filtering on repo - that would be redundant | |
2317 | status = ChangesetStatus.query()\ |
|
2317 | status = ChangesetStatus.query() \ | |
2318 | .filter(ChangesetStatus.pull_request == self)\ |
|
2318 | .filter(ChangesetStatus.pull_request == self) \ | |
2319 | .filter(ChangesetStatus.user_id == user_id)\ |
|
2319 | .filter(ChangesetStatus.user_id == user_id) \ | |
2320 | .order_by(ChangesetStatus.version)\ |
|
2320 | .order_by(ChangesetStatus.version) \ | |
2321 | .first() |
|
2321 | .first() | |
2322 | return str(status.status) if status else '' |
|
2322 | return str(status.status) if status else '' | |
2323 |
|
2323 | |||
@@ -2505,7 +2505,7 b' class Gist(Base, BaseModel):' | |||||
2505 | :param cls: |
|
2505 | :param cls: | |
2506 | """ |
|
2506 | """ | |
2507 | from kallithea.model.gist import GIST_STORE_LOC |
|
2507 | from kallithea.model.gist import GIST_STORE_LOC | |
2508 | q = Session().query(Ui)\ |
|
2508 | q = Session().query(Ui) \ | |
2509 | .filter(Ui.ui_key == URL_SEP) |
|
2509 | .filter(Ui.ui_key == URL_SEP) | |
2510 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) |
|
2510 | q = q.options(FromCache("sql_cache_short", "repository_repo_path")) | |
2511 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
|
2511 | return os.path.join(q.one().ui_value, GIST_STORE_LOC) |
@@ -137,11 +137,11 b' class NotificationModel(BaseModel):' | |||||
137 |
|
137 | |||
138 | html_kwargs.update(email_kwargs) |
|
138 | html_kwargs.update(email_kwargs) | |
139 | txt_kwargs.update(email_kwargs) |
|
139 | txt_kwargs.update(email_kwargs) | |
140 | email_subject = EmailNotificationModel()\ |
|
140 | email_subject = EmailNotificationModel() \ | |
141 | .get_email_description(type_, **txt_kwargs) |
|
141 | .get_email_description(type_, **txt_kwargs) | |
142 | email_txt_body = EmailNotificationModel()\ |
|
142 | email_txt_body = EmailNotificationModel() \ | |
143 | .get_email_tmpl(type_, 'txt', **txt_kwargs) |
|
143 | .get_email_tmpl(type_, 'txt', **txt_kwargs) | |
144 | email_html_body = EmailNotificationModel()\ |
|
144 | email_html_body = EmailNotificationModel() \ | |
145 | .get_email_tmpl(type_, 'html', **html_kwargs) |
|
145 | .get_email_tmpl(type_, 'html', **html_kwargs) | |
146 |
|
146 | |||
147 | run_task(tasks.send_email, [rec.email], email_subject, email_txt_body, |
|
147 | run_task(tasks.send_email, [rec.email], email_subject, email_txt_body, | |
@@ -155,10 +155,10 b' class NotificationModel(BaseModel):' | |||||
155 | notification = self.__get_notification(notification) |
|
155 | notification = self.__get_notification(notification) | |
156 | user = self._get_user(user) |
|
156 | user = self._get_user(user) | |
157 | if notification and user: |
|
157 | if notification and user: | |
158 | obj = UserNotification.query()\ |
|
158 | obj = UserNotification.query() \ | |
159 | .filter(UserNotification.user == user)\ |
|
159 | .filter(UserNotification.user == user) \ | |
160 | .filter(UserNotification.notification |
|
160 | .filter(UserNotification.notification | |
161 | == notification)\ |
|
161 | == notification) \ | |
162 | .one() |
|
162 | .one() | |
163 | Session().delete(obj) |
|
163 | Session().delete(obj) | |
164 | return True |
|
164 | return True | |
@@ -175,12 +175,12 b' class NotificationModel(BaseModel):' | |||||
175 | """ |
|
175 | """ | |
176 | user = self._get_user(user) |
|
176 | user = self._get_user(user) | |
177 |
|
177 | |||
178 | q = UserNotification.query()\ |
|
178 | q = UserNotification.query() \ | |
179 | .filter(UserNotification.user == user)\ |
|
179 | .filter(UserNotification.user == user) \ | |
180 | .join((Notification, UserNotification.notification_id == |
|
180 | .join((Notification, UserNotification.notification_id == | |
181 | Notification.notification_id))\ |
|
181 | Notification.notification_id)) \ | |
182 | .options(joinedload('notification'))\ |
|
182 | .options(joinedload('notification')) \ | |
183 | .options(subqueryload('notification.created_by_user'))\ |
|
183 | .options(subqueryload('notification.created_by_user')) \ | |
184 | .order_by(Notification.created_on.desc()) |
|
184 | .order_by(Notification.created_on.desc()) | |
185 |
|
185 | |||
186 | if filter_: |
|
186 | if filter_: | |
@@ -193,10 +193,10 b' class NotificationModel(BaseModel):' | |||||
193 | notification = self.__get_notification(notification) |
|
193 | notification = self.__get_notification(notification) | |
194 | user = self._get_user(user) |
|
194 | user = self._get_user(user) | |
195 | if notification and user: |
|
195 | if notification and user: | |
196 | obj = UserNotification.query()\ |
|
196 | obj = UserNotification.query() \ | |
197 | .filter(UserNotification.user == user)\ |
|
197 | .filter(UserNotification.user == user) \ | |
198 | .filter(UserNotification.notification |
|
198 | .filter(UserNotification.notification | |
199 | == notification)\ |
|
199 | == notification) \ | |
200 | .one() |
|
200 | .one() | |
201 | obj.read = True |
|
201 | obj.read = True | |
202 | Session().add(obj) |
|
202 | Session().add(obj) | |
@@ -207,9 +207,9 b' class NotificationModel(BaseModel):' | |||||
207 |
|
207 | |||
208 | def mark_all_read_for_user(self, user, filter_=None): |
|
208 | def mark_all_read_for_user(self, user, filter_=None): | |
209 | user = self._get_user(user) |
|
209 | user = self._get_user(user) | |
210 | q = UserNotification.query()\ |
|
210 | q = UserNotification.query() \ | |
211 | .filter(UserNotification.user == user)\ |
|
211 | .filter(UserNotification.user == user) \ | |
212 | .filter(UserNotification.read == False)\ |
|
212 | .filter(UserNotification.read == False) \ | |
213 | .join((Notification, UserNotification.notification_id == |
|
213 | .join((Notification, UserNotification.notification_id == | |
214 | Notification.notification_id)) |
|
214 | Notification.notification_id)) | |
215 | if filter_: |
|
215 | if filter_: | |
@@ -223,22 +223,22 b' class NotificationModel(BaseModel):' | |||||
223 |
|
223 | |||
224 | def get_unread_cnt_for_user(self, user): |
|
224 | def get_unread_cnt_for_user(self, user): | |
225 | user = self._get_user(user) |
|
225 | user = self._get_user(user) | |
226 | return UserNotification.query()\ |
|
226 | return UserNotification.query() \ | |
227 | .filter(UserNotification.read == False)\ |
|
227 | .filter(UserNotification.read == False) \ | |
228 | .filter(UserNotification.user == user).count() |
|
228 | .filter(UserNotification.user == user).count() | |
229 |
|
229 | |||
230 | def get_unread_for_user(self, user): |
|
230 | def get_unread_for_user(self, user): | |
231 | user = self._get_user(user) |
|
231 | user = self._get_user(user) | |
232 | return [x.notification for x in UserNotification.query()\ |
|
232 | return [x.notification for x in UserNotification.query() \ | |
233 | .filter(UserNotification.read == False)\ |
|
233 | .filter(UserNotification.read == False) \ | |
234 | .filter(UserNotification.user == user).all()] |
|
234 | .filter(UserNotification.user == user).all()] | |
235 |
|
235 | |||
236 | def get_user_notification(self, user, notification): |
|
236 | def get_user_notification(self, user, notification): | |
237 | user = self._get_user(user) |
|
237 | user = self._get_user(user) | |
238 | notification = self.__get_notification(notification) |
|
238 | notification = self.__get_notification(notification) | |
239 |
|
239 | |||
240 | return UserNotification.query()\ |
|
240 | return UserNotification.query() \ | |
241 | .filter(UserNotification.notification == notification)\ |
|
241 | .filter(UserNotification.notification == notification) \ | |
242 | .filter(UserNotification.user == user).scalar() |
|
242 | .filter(UserNotification.user == user).scalar() | |
243 |
|
243 | |||
244 | def make_description(self, notification, show_age=True): |
|
244 | def make_description(self, notification, show_age=True): |
@@ -32,7 +32,7 b' import traceback' | |||||
32 | from sqlalchemy.exc import DatabaseError |
|
32 | from sqlalchemy.exc import DatabaseError | |
33 |
|
33 | |||
34 | from kallithea.model import BaseModel |
|
34 | from kallithea.model import BaseModel | |
35 | from kallithea.model.db import User, Permission, UserToPerm, UserRepoToPerm,\ |
|
35 | from kallithea.model.db import User, Permission, UserToPerm, UserRepoToPerm, \ | |
36 | UserRepoGroupToPerm, UserUserGroupToPerm |
|
36 | UserRepoGroupToPerm, UserUserGroupToPerm | |
37 | from kallithea.lib.utils2 import str2bool |
|
37 | from kallithea.lib.utils2 import str2bool | |
38 |
|
38 | |||
@@ -116,8 +116,8 b' class PermissionModel(BaseModel):' | |||||
116 | # clear current entries, to make this function idempotent |
|
116 | # clear current entries, to make this function idempotent | |
117 | # it will fix even if we define more permissions or permissions |
|
117 | # it will fix even if we define more permissions or permissions | |
118 | # are somehow missing |
|
118 | # are somehow missing | |
119 | u2p = self.sa.query(UserToPerm)\ |
|
119 | u2p = self.sa.query(UserToPerm) \ | |
120 | .filter(UserToPerm.user == perm_user)\ |
|
120 | .filter(UserToPerm.user == perm_user) \ | |
121 | .all() |
|
121 | .all() | |
122 | for p in u2p: |
|
122 | for p in u2p: | |
123 | self.sa.delete(p) |
|
123 | self.sa.delete(p) | |
@@ -140,8 +140,8 b' class PermissionModel(BaseModel):' | |||||
140 | _def_name = form_result['default_repo_perm'].split('repository.')[-1] |
|
140 | _def_name = form_result['default_repo_perm'].split('repository.')[-1] | |
141 | _def = Permission.get_by_key('repository.' + _def_name) |
|
141 | _def = Permission.get_by_key('repository.' + _def_name) | |
142 | # repos |
|
142 | # repos | |
143 | for r2p in self.sa.query(UserRepoToPerm)\ |
|
143 | for r2p in self.sa.query(UserRepoToPerm) \ | |
144 | .filter(UserRepoToPerm.user == perm_user)\ |
|
144 | .filter(UserRepoToPerm.user == perm_user) \ | |
145 | .all(): |
|
145 | .all(): | |
146 |
|
146 | |||
147 | #don't reset PRIVATE repositories |
|
147 | #don't reset PRIVATE repositories | |
@@ -153,8 +153,8 b' class PermissionModel(BaseModel):' | |||||
153 | _def_name = form_result['default_group_perm'].split('group.')[-1] |
|
153 | _def_name = form_result['default_group_perm'].split('group.')[-1] | |
154 | # groups |
|
154 | # groups | |
155 | _def = Permission.get_by_key('group.' + _def_name) |
|
155 | _def = Permission.get_by_key('group.' + _def_name) | |
156 | for g2p in self.sa.query(UserRepoGroupToPerm)\ |
|
156 | for g2p in self.sa.query(UserRepoGroupToPerm) \ | |
157 | .filter(UserRepoGroupToPerm.user == perm_user)\ |
|
157 | .filter(UserRepoGroupToPerm.user == perm_user) \ | |
158 | .all(): |
|
158 | .all(): | |
159 | g2p.permission = _def |
|
159 | g2p.permission = _def | |
160 | self.sa.add(g2p) |
|
160 | self.sa.add(g2p) | |
@@ -163,8 +163,8 b' class PermissionModel(BaseModel):' | |||||
163 | _def_name = form_result['default_user_group_perm'].split('usergroup.')[-1] |
|
163 | _def_name = form_result['default_user_group_perm'].split('usergroup.')[-1] | |
164 | # groups |
|
164 | # groups | |
165 | _def = Permission.get_by_key('usergroup.' + _def_name) |
|
165 | _def = Permission.get_by_key('usergroup.' + _def_name) | |
166 | for g2p in self.sa.query(UserUserGroupToPerm)\ |
|
166 | for g2p in self.sa.query(UserUserGroupToPerm) \ | |
167 | .filter(UserUserGroupToPerm.user == perm_user)\ |
|
167 | .filter(UserUserGroupToPerm.user == perm_user) \ | |
168 | .all(): |
|
168 | .all(): | |
169 | g2p.permission = _def |
|
169 | g2p.permission = _def | |
170 | self.sa.add(g2p) |
|
170 | self.sa.add(g2p) |
@@ -34,7 +34,7 b' from kallithea.model.meta import Session' | |||||
34 | from kallithea.lib import helpers as h |
|
34 | from kallithea.lib import helpers as h | |
35 | from kallithea.lib.exceptions import UserInvalidException |
|
35 | from kallithea.lib.exceptions import UserInvalidException | |
36 | from kallithea.model import BaseModel |
|
36 | from kallithea.model import BaseModel | |
37 | from kallithea.model.db import PullRequest, PullRequestReviewers, Notification,\ |
|
37 | from kallithea.model.db import PullRequest, PullRequestReviewers, Notification, \ | |
38 | ChangesetStatus, User |
|
38 | ChangesetStatus, User | |
39 | from kallithea.model.notification import NotificationModel |
|
39 | from kallithea.model.notification import NotificationModel | |
40 | from kallithea.lib.utils2 import extract_mentioned_users, safe_unicode |
|
40 | from kallithea.lib.utils2 import extract_mentioned_users, safe_unicode | |
@@ -51,10 +51,10 b' class PullRequestModel(BaseModel):' | |||||
51 | return self._get_instance(PullRequest, pull_request) |
|
51 | return self._get_instance(PullRequest, pull_request) | |
52 |
|
52 | |||
53 | def get_pullrequest_cnt_for_user(self, user): |
|
53 | def get_pullrequest_cnt_for_user(self, user): | |
54 | return PullRequest.query()\ |
|
54 | return PullRequest.query() \ | |
55 | .join(PullRequestReviewers)\ |
|
55 | .join(PullRequestReviewers) \ | |
56 | .filter(PullRequestReviewers.user_id == user)\ |
|
56 | .filter(PullRequestReviewers.user_id == user) \ | |
57 | .filter(PullRequest.status != PullRequest.STATUS_CLOSED)\ |
|
57 | .filter(PullRequest.status != PullRequest.STATUS_CLOSED) \ | |
58 | .count() |
|
58 | .count() | |
59 |
|
59 | |||
60 | def get_all(self, repo_name, from_=False, closed=False): |
|
60 | def get_all(self, repo_name, from_=False, closed=False): | |
@@ -184,9 +184,9 b' class PullRequestModel(BaseModel):' | |||||
184 | def update_reviewers(self, user, pull_request, reviewers_ids): |
|
184 | def update_reviewers(self, user, pull_request, reviewers_ids): | |
185 | reviewers_ids = set(reviewers_ids) |
|
185 | reviewers_ids = set(reviewers_ids) | |
186 | pull_request = self.__get_pull_request(pull_request) |
|
186 | pull_request = self.__get_pull_request(pull_request) | |
187 | current_reviewers = PullRequestReviewers.query()\ |
|
187 | current_reviewers = PullRequestReviewers.query() \ | |
188 | .filter(PullRequestReviewers.pull_request== |
|
188 | .filter(PullRequestReviewers.pull_request== | |
189 | pull_request)\ |
|
189 | pull_request) \ | |
190 | .all() |
|
190 | .all() | |
191 | current_reviewers_ids = set([x.user.user_id for x in current_reviewers]) |
|
191 | current_reviewers_ids = set([x.user.user_id for x in current_reviewers]) | |
192 |
|
192 | |||
@@ -198,9 +198,9 b' class PullRequestModel(BaseModel):' | |||||
198 |
|
198 | |||
199 | log.debug("Removing %s reviewers", to_remove) |
|
199 | log.debug("Removing %s reviewers", to_remove) | |
200 | for uid in to_remove: |
|
200 | for uid in to_remove: | |
201 | reviewer = PullRequestReviewers.query()\ |
|
201 | reviewer = PullRequestReviewers.query() \ | |
202 | .filter(PullRequestReviewers.user_id==uid, |
|
202 | .filter(PullRequestReviewers.user_id==uid, | |
203 | PullRequestReviewers.pull_request==pull_request)\ |
|
203 | PullRequestReviewers.pull_request==pull_request) \ | |
204 | .scalar() |
|
204 | .scalar() | |
205 | if reviewer: |
|
205 | if reviewer: | |
206 | Session().delete(reviewer) |
|
206 | Session().delete(reviewer) |
@@ -455,9 +455,9 b' class RepoGroupModel(BaseModel):' | |||||
455 | permission = self._get_perm(perm) |
|
455 | permission = self._get_perm(perm) | |
456 |
|
456 | |||
457 | # check if we have that permission already |
|
457 | # check if we have that permission already | |
458 | obj = self.sa.query(UserRepoGroupToPerm)\ |
|
458 | obj = self.sa.query(UserRepoGroupToPerm) \ | |
459 | .filter(UserRepoGroupToPerm.user == user)\ |
|
459 | .filter(UserRepoGroupToPerm.user == user) \ | |
460 | .filter(UserRepoGroupToPerm.group == repo_group)\ |
|
460 | .filter(UserRepoGroupToPerm.group == repo_group) \ | |
461 | .scalar() |
|
461 | .scalar() | |
462 | if obj is None: |
|
462 | if obj is None: | |
463 | # create new ! |
|
463 | # create new ! | |
@@ -481,9 +481,9 b' class RepoGroupModel(BaseModel):' | |||||
481 | repo_group = self._get_repo_group(repo_group) |
|
481 | repo_group = self._get_repo_group(repo_group) | |
482 | user = self._get_user(user) |
|
482 | user = self._get_user(user) | |
483 |
|
483 | |||
484 | obj = self.sa.query(UserRepoGroupToPerm)\ |
|
484 | obj = self.sa.query(UserRepoGroupToPerm) \ | |
485 | .filter(UserRepoGroupToPerm.user == user)\ |
|
485 | .filter(UserRepoGroupToPerm.user == user) \ | |
486 | .filter(UserRepoGroupToPerm.group == repo_group)\ |
|
486 | .filter(UserRepoGroupToPerm.group == repo_group) \ | |
487 | .scalar() |
|
487 | .scalar() | |
488 | if obj is not None: |
|
488 | if obj is not None: | |
489 | self.sa.delete(obj) |
|
489 | self.sa.delete(obj) | |
@@ -505,9 +505,9 b' class RepoGroupModel(BaseModel):' | |||||
505 | permission = self._get_perm(perm) |
|
505 | permission = self._get_perm(perm) | |
506 |
|
506 | |||
507 | # check if we have that permission already |
|
507 | # check if we have that permission already | |
508 | obj = self.sa.query(UserGroupRepoGroupToPerm)\ |
|
508 | obj = self.sa.query(UserGroupRepoGroupToPerm) \ | |
509 | .filter(UserGroupRepoGroupToPerm.group == repo_group)\ |
|
509 | .filter(UserGroupRepoGroupToPerm.group == repo_group) \ | |
510 | .filter(UserGroupRepoGroupToPerm.users_group == group_name)\ |
|
510 | .filter(UserGroupRepoGroupToPerm.users_group == group_name) \ | |
511 | .scalar() |
|
511 | .scalar() | |
512 |
|
512 | |||
513 | if obj is None: |
|
513 | if obj is None: | |
@@ -533,9 +533,9 b' class RepoGroupModel(BaseModel):' | |||||
533 | repo_group = self._get_repo_group(repo_group) |
|
533 | repo_group = self._get_repo_group(repo_group) | |
534 | group_name = self._get_user_group(group_name) |
|
534 | group_name = self._get_user_group(group_name) | |
535 |
|
535 | |||
536 | obj = self.sa.query(UserGroupRepoGroupToPerm)\ |
|
536 | obj = self.sa.query(UserGroupRepoGroupToPerm) \ | |
537 | .filter(UserGroupRepoGroupToPerm.group == repo_group)\ |
|
537 | .filter(UserGroupRepoGroupToPerm.group == repo_group) \ | |
538 | .filter(UserGroupRepoGroupToPerm.users_group == group_name)\ |
|
538 | .filter(UserGroupRepoGroupToPerm.users_group == group_name) \ | |
539 | .scalar() |
|
539 | .scalar() | |
540 | if obj is not None: |
|
540 | if obj is not None: | |
541 | self.sa.delete(obj) |
|
541 | self.sa.delete(obj) |
@@ -46,9 +46,9 b' from kallithea.lib.vcs.backends.base imp' | |||||
46 |
|
46 | |||
47 | from kallithea import BACKENDS |
|
47 | from kallithea import BACKENDS | |
48 | from kallithea.lib import helpers as h |
|
48 | from kallithea.lib import helpers as h | |
49 | from kallithea.lib.utils2 import safe_str, safe_unicode, get_server_url,\ |
|
49 | from kallithea.lib.utils2 import safe_str, safe_unicode, get_server_url, \ | |
50 | _set_extras |
|
50 | _set_extras | |
51 | from kallithea.lib.auth import HasRepoPermissionAny, HasRepoGroupPermissionAny,\ |
|
51 | from kallithea.lib.auth import HasRepoPermissionAny, HasRepoGroupPermissionAny, \ | |
52 | HasUserGroupPermissionAny, HasPermissionAny, HasPermissionAll |
|
52 | HasUserGroupPermissionAny, HasPermissionAny, HasPermissionAll | |
53 | from kallithea.lib.utils import get_filesystem_repos, make_ui, \ |
|
53 | from kallithea.lib.utils import get_filesystem_repos, make_ui, \ | |
54 | action_logger |
|
54 | action_logger | |
@@ -311,8 +311,8 b' class ScmModel(BaseModel):' | |||||
311 | :param simple: use SimpleCachedList - one without the SCM info |
|
311 | :param simple: use SimpleCachedList - one without the SCM info | |
312 | """ |
|
312 | """ | |
313 | if all_repos is None: |
|
313 | if all_repos is None: | |
314 | all_repos = self.sa.query(Repository)\ |
|
314 | all_repos = self.sa.query(Repository) \ | |
315 | .filter(Repository.group_id == None)\ |
|
315 | .filter(Repository.group_id == None) \ | |
316 | .order_by(func.lower(Repository.repo_name)).all() |
|
316 | .order_by(func.lower(Repository.repo_name)).all() | |
317 | if simple: |
|
317 | if simple: | |
318 | repo_iter = SimpleCachedRepoList(all_repos, |
|
318 | repo_iter = SimpleCachedRepoList(all_repos, | |
@@ -327,7 +327,7 b' class ScmModel(BaseModel):' | |||||
327 |
|
327 | |||
328 | def get_repo_groups(self, all_groups=None): |
|
328 | def get_repo_groups(self, all_groups=None): | |
329 | if all_groups is None: |
|
329 | if all_groups is None: | |
330 | all_groups = RepoGroup.query()\ |
|
330 | all_groups = RepoGroup.query() \ | |
331 | .filter(RepoGroup.group_parent_id == None).all() |
|
331 | .filter(RepoGroup.group_parent_id == None).all() | |
332 | return [x for x in RepoGroupList(all_groups)] |
|
332 | return [x for x in RepoGroupList(all_groups)] | |
333 |
|
333 | |||
@@ -344,8 +344,8 b' class ScmModel(BaseModel):' | |||||
344 |
|
344 | |||
345 | def toggle_following_repo(self, follow_repo_id, user_id): |
|
345 | def toggle_following_repo(self, follow_repo_id, user_id): | |
346 |
|
346 | |||
347 | f = self.sa.query(UserFollowing)\ |
|
347 | f = self.sa.query(UserFollowing) \ | |
348 | .filter(UserFollowing.follows_repo_id == follow_repo_id)\ |
|
348 | .filter(UserFollowing.follows_repo_id == follow_repo_id) \ | |
349 | .filter(UserFollowing.user_id == user_id).scalar() |
|
349 | .filter(UserFollowing.user_id == user_id).scalar() | |
350 |
|
350 | |||
351 | if f is not None: |
|
351 | if f is not None: | |
@@ -373,8 +373,8 b' class ScmModel(BaseModel):' | |||||
373 | raise |
|
373 | raise | |
374 |
|
374 | |||
375 | def toggle_following_user(self, follow_user_id, user_id): |
|
375 | def toggle_following_user(self, follow_user_id, user_id): | |
376 | f = self.sa.query(UserFollowing)\ |
|
376 | f = self.sa.query(UserFollowing) \ | |
377 | .filter(UserFollowing.follows_user_id == follow_user_id)\ |
|
377 | .filter(UserFollowing.follows_user_id == follow_user_id) \ | |
378 | .filter(UserFollowing.user_id == user_id).scalar() |
|
378 | .filter(UserFollowing.user_id == user_id).scalar() | |
379 |
|
379 | |||
380 | if f is not None: |
|
380 | if f is not None: | |
@@ -395,11 +395,11 b' class ScmModel(BaseModel):' | |||||
395 | raise |
|
395 | raise | |
396 |
|
396 | |||
397 | def is_following_repo(self, repo_name, user_id, cache=False): |
|
397 | def is_following_repo(self, repo_name, user_id, cache=False): | |
398 | r = self.sa.query(Repository)\ |
|
398 | r = self.sa.query(Repository) \ | |
399 | .filter(Repository.repo_name == repo_name).scalar() |
|
399 | .filter(Repository.repo_name == repo_name).scalar() | |
400 |
|
400 | |||
401 | f = self.sa.query(UserFollowing)\ |
|
401 | f = self.sa.query(UserFollowing) \ | |
402 | .filter(UserFollowing.follows_repository == r)\ |
|
402 | .filter(UserFollowing.follows_repository == r) \ | |
403 | .filter(UserFollowing.user_id == user_id).scalar() |
|
403 | .filter(UserFollowing.user_id == user_id).scalar() | |
404 |
|
404 | |||
405 | return f is not None |
|
405 | return f is not None | |
@@ -407,8 +407,8 b' class ScmModel(BaseModel):' | |||||
407 | def is_following_user(self, username, user_id, cache=False): |
|
407 | def is_following_user(self, username, user_id, cache=False): | |
408 | u = User.get_by_username(username) |
|
408 | u = User.get_by_username(username) | |
409 |
|
409 | |||
410 | f = self.sa.query(UserFollowing)\ |
|
410 | f = self.sa.query(UserFollowing) \ | |
411 | .filter(UserFollowing.follows_user == u)\ |
|
411 | .filter(UserFollowing.follows_user == u) \ | |
412 | .filter(UserFollowing.user_id == user_id).scalar() |
|
412 | .filter(UserFollowing.user_id == user_id).scalar() | |
413 |
|
413 | |||
414 | return f is not None |
|
414 | return f is not None | |
@@ -416,18 +416,18 b' class ScmModel(BaseModel):' | |||||
416 | def get_followers(self, repo): |
|
416 | def get_followers(self, repo): | |
417 | repo = self._get_repo(repo) |
|
417 | repo = self._get_repo(repo) | |
418 |
|
418 | |||
419 | return self.sa.query(UserFollowing)\ |
|
419 | return self.sa.query(UserFollowing) \ | |
420 | .filter(UserFollowing.follows_repository == repo).count() |
|
420 | .filter(UserFollowing.follows_repository == repo).count() | |
421 |
|
421 | |||
422 | def get_forks(self, repo): |
|
422 | def get_forks(self, repo): | |
423 | repo = self._get_repo(repo) |
|
423 | repo = self._get_repo(repo) | |
424 | return self.sa.query(Repository)\ |
|
424 | return self.sa.query(Repository) \ | |
425 | .filter(Repository.fork == repo).count() |
|
425 | .filter(Repository.fork == repo).count() | |
426 |
|
426 | |||
427 | def get_pull_requests(self, repo): |
|
427 | def get_pull_requests(self, repo): | |
428 | repo = self._get_repo(repo) |
|
428 | repo = self._get_repo(repo) | |
429 | return self.sa.query(PullRequest)\ |
|
429 | return self.sa.query(PullRequest) \ | |
430 | .filter(PullRequest.other_repo == repo)\ |
|
430 | .filter(PullRequest.other_repo == repo) \ | |
431 | .filter(PullRequest.status != PullRequest.STATUS_CLOSED).count() |
|
431 | .filter(PullRequest.status != PullRequest.STATUS_CLOSED).count() | |
432 |
|
432 | |||
433 | def mark_as_fork(self, repo, fork, user): |
|
433 | def mark_as_fork(self, repo, fork, user): |
@@ -425,7 +425,7 b' class UserModel(BaseModel):' | |||||
425 | perm = self._get_perm(perm) |
|
425 | perm = self._get_perm(perm) | |
426 | user = self._get_user(user) |
|
426 | user = self._get_user(user) | |
427 |
|
427 | |||
428 | return UserToPerm.query().filter(UserToPerm.user == user)\ |
|
428 | return UserToPerm.query().filter(UserToPerm.user == user) \ | |
429 | .filter(UserToPerm.permission == perm).scalar() is not None |
|
429 | .filter(UserToPerm.permission == perm).scalar() is not None | |
430 |
|
430 | |||
431 | def grant_perm(self, user, perm): |
|
431 | def grant_perm(self, user, perm): | |
@@ -438,9 +438,9 b' class UserModel(BaseModel):' | |||||
438 | user = self._get_user(user) |
|
438 | user = self._get_user(user) | |
439 | perm = self._get_perm(perm) |
|
439 | perm = self._get_perm(perm) | |
440 | # if this permission is already granted skip it |
|
440 | # if this permission is already granted skip it | |
441 | _perm = UserToPerm.query()\ |
|
441 | _perm = UserToPerm.query() \ | |
442 | .filter(UserToPerm.user == user)\ |
|
442 | .filter(UserToPerm.user == user) \ | |
443 | .filter(UserToPerm.permission == perm)\ |
|
443 | .filter(UserToPerm.permission == perm) \ | |
444 | .scalar() |
|
444 | .scalar() | |
445 | if _perm: |
|
445 | if _perm: | |
446 | return |
|
446 | return |
@@ -28,10 +28,10 b' import logging' | |||||
28 | import traceback |
|
28 | import traceback | |
29 |
|
29 | |||
30 | from kallithea.model import BaseModel |
|
30 | from kallithea.model import BaseModel | |
31 | from kallithea.model.db import UserGroupMember, UserGroup,\ |
|
31 | from kallithea.model.db import UserGroupMember, UserGroup, \ | |
32 | UserGroupRepoToPerm, Permission, UserGroupToPerm, User, UserUserGroupToPerm,\ |
|
32 | UserGroupRepoToPerm, Permission, UserGroupToPerm, User, UserUserGroupToPerm, \ | |
33 | UserGroupUserGroupToPerm |
|
33 | UserGroupUserGroupToPerm | |
34 | from kallithea.lib.exceptions import UserGroupsAssignedException,\ |
|
34 | from kallithea.lib.exceptions import UserGroupsAssignedException, \ | |
35 | RepoGroupAssignmentError |
|
35 | RepoGroupAssignmentError | |
36 |
|
36 | |||
37 | log = logging.getLogger(__name__) |
|
37 | log = logging.getLogger(__name__) | |
@@ -162,7 +162,7 b' class UserGroupModel(BaseModel):' | |||||
162 | user_group = self._get_user_group(user_group) |
|
162 | user_group = self._get_user_group(user_group) | |
163 | try: |
|
163 | try: | |
164 | # check if this group is not assigned to repo |
|
164 | # check if this group is not assigned to repo | |
165 | assigned_groups = UserGroupRepoToPerm.query()\ |
|
165 | assigned_groups = UserGroupRepoToPerm.query() \ | |
166 | .filter(UserGroupRepoToPerm.users_group == user_group).all() |
|
166 | .filter(UserGroupRepoToPerm.users_group == user_group).all() | |
167 | assigned_groups = [x.repository.repo_name for x in assigned_groups] |
|
167 | assigned_groups = [x.repository.repo_name for x in assigned_groups] | |
168 |
|
168 | |||
@@ -224,8 +224,8 b' class UserGroupModel(BaseModel):' | |||||
224 | user_group = self._get_user_group(user_group) |
|
224 | user_group = self._get_user_group(user_group) | |
225 | perm = self._get_perm(perm) |
|
225 | perm = self._get_perm(perm) | |
226 |
|
226 | |||
227 | return UserGroupToPerm.query()\ |
|
227 | return UserGroupToPerm.query() \ | |
228 | .filter(UserGroupToPerm.users_group == user_group)\ |
|
228 | .filter(UserGroupToPerm.users_group == user_group) \ | |
229 | .filter(UserGroupToPerm.permission == perm).scalar() is not None |
|
229 | .filter(UserGroupToPerm.permission == perm).scalar() is not None | |
230 |
|
230 | |||
231 | def grant_perm(self, user_group, perm): |
|
231 | def grant_perm(self, user_group, perm): | |
@@ -233,9 +233,9 b' class UserGroupModel(BaseModel):' | |||||
233 | perm = self._get_perm(perm) |
|
233 | perm = self._get_perm(perm) | |
234 |
|
234 | |||
235 | # if this permission is already granted skip it |
|
235 | # if this permission is already granted skip it | |
236 | _perm = UserGroupToPerm.query()\ |
|
236 | _perm = UserGroupToPerm.query() \ | |
237 | .filter(UserGroupToPerm.users_group == user_group)\ |
|
237 | .filter(UserGroupToPerm.users_group == user_group) \ | |
238 | .filter(UserGroupToPerm.permission == perm)\ |
|
238 | .filter(UserGroupToPerm.permission == perm) \ | |
239 | .scalar() |
|
239 | .scalar() | |
240 | if _perm: |
|
240 | if _perm: | |
241 | return |
|
241 | return | |
@@ -250,8 +250,8 b' class UserGroupModel(BaseModel):' | |||||
250 | user_group = self._get_user_group(user_group) |
|
250 | user_group = self._get_user_group(user_group) | |
251 | perm = self._get_perm(perm) |
|
251 | perm = self._get_perm(perm) | |
252 |
|
252 | |||
253 | obj = UserGroupToPerm.query()\ |
|
253 | obj = UserGroupToPerm.query() \ | |
254 | .filter(UserGroupToPerm.users_group == user_group)\ |
|
254 | .filter(UserGroupToPerm.users_group == user_group) \ | |
255 | .filter(UserGroupToPerm.permission == perm).scalar() |
|
255 | .filter(UserGroupToPerm.permission == perm).scalar() | |
256 | if obj is not None: |
|
256 | if obj is not None: | |
257 | self.sa.delete(obj) |
|
257 | self.sa.delete(obj) | |
@@ -272,9 +272,9 b' class UserGroupModel(BaseModel):' | |||||
272 | permission = self._get_perm(perm) |
|
272 | permission = self._get_perm(perm) | |
273 |
|
273 | |||
274 | # check if we have that permission already |
|
274 | # check if we have that permission already | |
275 | obj = self.sa.query(UserUserGroupToPerm)\ |
|
275 | obj = self.sa.query(UserUserGroupToPerm) \ | |
276 | .filter(UserUserGroupToPerm.user == user)\ |
|
276 | .filter(UserUserGroupToPerm.user == user) \ | |
277 | .filter(UserUserGroupToPerm.user_group == user_group)\ |
|
277 | .filter(UserUserGroupToPerm.user_group == user_group) \ | |
278 | .scalar() |
|
278 | .scalar() | |
279 | if obj is None: |
|
279 | if obj is None: | |
280 | # create new ! |
|
280 | # create new ! | |
@@ -298,9 +298,9 b' class UserGroupModel(BaseModel):' | |||||
298 | user_group = self._get_user_group(user_group) |
|
298 | user_group = self._get_user_group(user_group) | |
299 | user = self._get_user(user) |
|
299 | user = self._get_user(user) | |
300 |
|
300 | |||
301 | obj = self.sa.query(UserUserGroupToPerm)\ |
|
301 | obj = self.sa.query(UserUserGroupToPerm) \ | |
302 | .filter(UserUserGroupToPerm.user == user)\ |
|
302 | .filter(UserUserGroupToPerm.user == user) \ | |
303 | .filter(UserUserGroupToPerm.user_group == user_group)\ |
|
303 | .filter(UserUserGroupToPerm.user_group == user_group) \ | |
304 | .scalar() |
|
304 | .scalar() | |
305 | if obj is not None: |
|
305 | if obj is not None: | |
306 | self.sa.delete(obj) |
|
306 | self.sa.delete(obj) | |
@@ -323,9 +323,9 b' class UserGroupModel(BaseModel):' | |||||
323 | 'assigned to itself' % target_user_group) |
|
323 | 'assigned to itself' % target_user_group) | |
324 |
|
324 | |||
325 | # check if we have that permission already |
|
325 | # check if we have that permission already | |
326 | obj = self.sa.query(UserGroupUserGroupToPerm)\ |
|
326 | obj = self.sa.query(UserGroupUserGroupToPerm) \ | |
327 | .filter(UserGroupUserGroupToPerm.target_user_group == target_user_group)\ |
|
327 | .filter(UserGroupUserGroupToPerm.target_user_group == target_user_group) \ | |
328 | .filter(UserGroupUserGroupToPerm.user_group == user_group)\ |
|
328 | .filter(UserGroupUserGroupToPerm.user_group == user_group) \ | |
329 | .scalar() |
|
329 | .scalar() | |
330 | if obj is None: |
|
330 | if obj is None: | |
331 | # create new ! |
|
331 | # create new ! | |
@@ -347,9 +347,9 b' class UserGroupModel(BaseModel):' | |||||
347 | target_user_group = self._get_user_group(target_user_group) |
|
347 | target_user_group = self._get_user_group(target_user_group) | |
348 | user_group = self._get_user_group(user_group) |
|
348 | user_group = self._get_user_group(user_group) | |
349 |
|
349 | |||
350 | obj = self.sa.query(UserGroupUserGroupToPerm)\ |
|
350 | obj = self.sa.query(UserGroupUserGroupToPerm) \ | |
351 | .filter(UserGroupUserGroupToPerm.target_user_group == target_user_group)\ |
|
351 | .filter(UserGroupUserGroupToPerm.target_user_group == target_user_group) \ | |
352 | .filter(UserGroupUserGroupToPerm.user_group == user_group)\ |
|
352 | .filter(UserGroupUserGroupToPerm.user_group == user_group) \ | |
353 | .scalar() |
|
353 | .scalar() | |
354 | if obj is not None: |
|
354 | if obj is not None: | |
355 | self.sa.delete(obj) |
|
355 | self.sa.delete(obj) |
@@ -136,7 +136,7 b' def ValidRepoUser():' | |||||
136 |
|
136 | |||
137 | def validate_python(self, value, state): |
|
137 | def validate_python(self, value, state): | |
138 | try: |
|
138 | try: | |
139 | User.query().filter(User.active == True)\ |
|
139 | User.query().filter(User.active == True) \ | |
140 | .filter(User.username == value).one() |
|
140 | .filter(User.username == value).one() | |
141 | except sqlalchemy.exc.InvalidRequestError: # NoResultFound/MultipleResultsFound |
|
141 | except sqlalchemy.exc.InvalidRequestError: # NoResultFound/MultipleResultsFound | |
142 | msg = M(self, 'invalid_username', state, username=value) |
|
142 | msg = M(self, 'invalid_username', state, username=value) | |
@@ -226,9 +226,9 b' def ValidRepoGroup(edit=False, old_data=' | |||||
226 | if old_gname != group_name or not edit: |
|
226 | if old_gname != group_name or not edit: | |
227 |
|
227 | |||
228 | # check group |
|
228 | # check group | |
229 | gr = RepoGroup.query()\ |
|
229 | gr = RepoGroup.query() \ | |
230 | .filter(RepoGroup.group_name == slug)\ |
|
230 | .filter(RepoGroup.group_name == slug) \ | |
231 | .filter(RepoGroup.group_parent_id == group_parent_id)\ |
|
231 | .filter(RepoGroup.group_parent_id == group_parent_id) \ | |
232 | .scalar() |
|
232 | .scalar() | |
233 |
|
233 | |||
234 | if gr is not None: |
|
234 | if gr is not None: | |
@@ -238,8 +238,8 b' def ValidRepoGroup(edit=False, old_data=' | |||||
238 | ) |
|
238 | ) | |
239 |
|
239 | |||
240 | # check for same repo |
|
240 | # check for same repo | |
241 | repo = Repository.query()\ |
|
241 | repo = Repository.query() \ | |
242 | .filter(Repository.repo_name == slug)\ |
|
242 | .filter(Repository.repo_name == slug) \ | |
243 | .scalar() |
|
243 | .scalar() | |
244 |
|
244 | |||
245 | if repo is not None: |
|
245 | if repo is not None: | |
@@ -651,12 +651,12 b" def ValidPerms(type_='repo'):" | |||||
651 | for k, v, t in perms_new: |
|
651 | for k, v, t in perms_new: | |
652 | try: |
|
652 | try: | |
653 | if t is 'user': |
|
653 | if t is 'user': | |
654 | self.user_db = User.query()\ |
|
654 | self.user_db = User.query() \ | |
655 | .filter(User.active == True)\ |
|
655 | .filter(User.active == True) \ | |
656 | .filter(User.username == k).one() |
|
656 | .filter(User.username == k).one() | |
657 | if t is 'users_group': |
|
657 | if t is 'users_group': | |
658 | self.user_db = UserGroup.query()\ |
|
658 | self.user_db = UserGroup.query() \ | |
659 | .filter(UserGroup.users_group_active == True)\ |
|
659 | .filter(UserGroup.users_group_active == True) \ | |
660 | .filter(UserGroup.users_group_name == k).one() |
|
660 | .filter(UserGroup.users_group_name == k).one() | |
661 |
|
661 | |||
662 | except Exception: |
|
662 | except Exception: |
@@ -75,7 +75,7 b'' | |||||
75 | %endfor |
|
75 | %endfor | |
76 |
|
76 | |||
77 | <% |
|
77 | <% | |
78 |
_tmpl = h.literal("""' |
|
78 | _tmpl = h.literal("""'\ | |
79 | <td><input type="radio" value="group.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
79 | <td><input type="radio" value="group.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ | |
80 | <td><input type="radio" value="group.read" checked="checked" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
80 | <td><input type="radio" value="group.read" checked="checked" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ | |
81 | <td><input type="radio" value="group.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
81 | <td><input type="radio" value="group.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
@@ -72,7 +72,7 b'' | |||||
72 | %endfor |
|
72 | %endfor | |
73 |
|
73 | |||
74 | <% |
|
74 | <% | |
75 |
_tmpl = h.literal("""' |
|
75 | _tmpl = h.literal("""'\ | |
76 | <td><input type="radio" value="repository.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
76 | <td><input type="radio" value="repository.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ | |
77 | <td><input type="radio" value="repository.read" checked="checked" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
77 | <td><input type="radio" value="repository.read" checked="checked" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ | |
78 | <td><input type="radio" value="repository.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
78 | <td><input type="radio" value="repository.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
@@ -75,7 +75,7 b'' | |||||
75 | %endfor |
|
75 | %endfor | |
76 |
|
76 | |||
77 | <% |
|
77 | <% | |
78 |
_tmpl = h.literal("""' |
|
78 | _tmpl = h.literal("""'\ | |
79 | <td><input type="radio" value="usergroup.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
79 | <td><input type="radio" value="usergroup.none" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ | |
80 | <td><input type="radio" value="usergroup.read" checked="checked" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
80 | <td><input type="radio" value="usergroup.read" checked="checked" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ | |
81 | <td><input type="radio" value="usergroup.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
|
81 | <td><input type="radio" value="usergroup.write" name="perm_new_member_{0}" id="perm_new_member_{0}"></td> \ |
@@ -5,7 +5,7 b' import mock' | |||||
5 | import urllib |
|
5 | import urllib | |
6 |
|
6 | |||
7 | from kallithea.lib import vcs |
|
7 | from kallithea.lib import vcs | |
8 | from kallithea.model.db import Repository, RepoGroup, UserRepoToPerm, User,\ |
|
8 | from kallithea.model.db import Repository, RepoGroup, UserRepoToPerm, User, \ | |
9 | Permission |
|
9 | Permission | |
10 | from kallithea.model.user import UserModel |
|
10 | from kallithea.model.user import UserModel | |
11 | from kallithea.tests import * |
|
11 | from kallithea.tests import * | |
@@ -18,10 +18,10 b' fixture = Fixture()' | |||||
18 |
|
18 | |||
19 |
|
19 | |||
20 | def _get_permission_for_user(user, repo): |
|
20 | def _get_permission_for_user(user, repo): | |
21 | perm = UserRepoToPerm.query()\ |
|
21 | perm = UserRepoToPerm.query() \ | |
22 | .filter(UserRepoToPerm.repository == |
|
22 | .filter(UserRepoToPerm.repository == | |
23 | Repository.get_by_repo_name(repo))\ |
|
23 | Repository.get_by_repo_name(repo)) \ | |
24 | .filter(UserRepoToPerm.user == User.get_by_username(user))\ |
|
24 | .filter(UserRepoToPerm.user == User.get_by_username(user)) \ | |
25 | .all() |
|
25 | .all() | |
26 | return perm |
|
26 | return perm | |
27 |
|
27 | |||
@@ -66,7 +66,7 b' class _BaseTest(object):' | |||||
66 | % (repo_name, repo_name)) |
|
66 | % (repo_name, repo_name)) | |
67 |
|
67 | |||
68 | # test if the repo was created in the database |
|
68 | # test if the repo was created in the database | |
69 | new_repo = Session().query(Repository)\ |
|
69 | new_repo = Session().query(Repository) \ | |
70 | .filter(Repository.repo_name == repo_name).one() |
|
70 | .filter(Repository.repo_name == repo_name).one() | |
71 |
|
71 | |||
72 | self.assertEqual(new_repo.repo_name, repo_name) |
|
72 | self.assertEqual(new_repo.repo_name, repo_name) | |
@@ -106,7 +106,7 b' class _BaseTest(object):' | |||||
106 | u'Created repository <a href="/%s">%s</a>' |
|
106 | u'Created repository <a href="/%s">%s</a>' | |
107 | % (urllib.quote(repo_name), repo_name_unicode)) |
|
107 | % (urllib.quote(repo_name), repo_name_unicode)) | |
108 | # test if the repo was created in the database |
|
108 | # test if the repo was created in the database | |
109 | new_repo = Session().query(Repository)\ |
|
109 | new_repo = Session().query(Repository) \ | |
110 | .filter(Repository.repo_name == repo_name_unicode).one() |
|
110 | .filter(Repository.repo_name == repo_name_unicode).one() | |
111 |
|
111 | |||
112 | self.assertEqual(new_repo.repo_name, repo_name_unicode) |
|
112 | self.assertEqual(new_repo.repo_name, repo_name_unicode) | |
@@ -150,7 +150,7 b' class _BaseTest(object):' | |||||
150 | 'Created repository <a href="/%s">%s</a>' |
|
150 | 'Created repository <a href="/%s">%s</a>' | |
151 | % (repo_name_full, repo_name_full)) |
|
151 | % (repo_name_full, repo_name_full)) | |
152 | # test if the repo was created in the database |
|
152 | # test if the repo was created in the database | |
153 | new_repo = Session().query(Repository)\ |
|
153 | new_repo = Session().query(Repository) \ | |
154 | .filter(Repository.repo_name == repo_name_full).one() |
|
154 | .filter(Repository.repo_name == repo_name_full).one() | |
155 | new_repo_id = new_repo.repo_id |
|
155 | new_repo_id = new_repo.repo_id | |
156 |
|
156 | |||
@@ -162,7 +162,7 b' class _BaseTest(object):' | |||||
162 | response.mustcontain(repo_name_full) |
|
162 | response.mustcontain(repo_name_full) | |
163 | response.mustcontain(self.REPO_TYPE) |
|
163 | response.mustcontain(self.REPO_TYPE) | |
164 |
|
164 | |||
165 | inherited_perms = UserRepoToPerm.query()\ |
|
165 | inherited_perms = UserRepoToPerm.query() \ | |
166 | .filter(UserRepoToPerm.repository_id == new_repo_id).all() |
|
166 | .filter(UserRepoToPerm.repository_id == new_repo_id).all() | |
167 | self.assertEqual(len(inherited_perms), 1) |
|
167 | self.assertEqual(len(inherited_perms), 1) | |
168 |
|
168 | |||
@@ -242,7 +242,7 b' class _BaseTest(object):' | |||||
242 | 'Created repository <a href="/%s">%s</a>' |
|
242 | 'Created repository <a href="/%s">%s</a>' | |
243 | % (repo_name_full, repo_name_full)) |
|
243 | % (repo_name_full, repo_name_full)) | |
244 | # test if the repo was created in the database |
|
244 | # test if the repo was created in the database | |
245 | new_repo = Session().query(Repository)\ |
|
245 | new_repo = Session().query(Repository) \ | |
246 | .filter(Repository.repo_name == repo_name_full).one() |
|
246 | .filter(Repository.repo_name == repo_name_full).one() | |
247 | new_repo_id = new_repo.repo_id |
|
247 | new_repo_id = new_repo.repo_id | |
248 |
|
248 | |||
@@ -254,7 +254,7 b' class _BaseTest(object):' | |||||
254 | response.mustcontain(repo_name_full) |
|
254 | response.mustcontain(repo_name_full) | |
255 | response.mustcontain(self.REPO_TYPE) |
|
255 | response.mustcontain(self.REPO_TYPE) | |
256 |
|
256 | |||
257 | inherited_perms = UserRepoToPerm.query()\ |
|
257 | inherited_perms = UserRepoToPerm.query() \ | |
258 | .filter(UserRepoToPerm.repository_id == new_repo_id).all() |
|
258 | .filter(UserRepoToPerm.repository_id == new_repo_id).all() | |
259 | self.assertEqual(len(inherited_perms), 1) |
|
259 | self.assertEqual(len(inherited_perms), 1) | |
260 |
|
260 | |||
@@ -303,7 +303,7 b' class _BaseTest(object):' | |||||
303 | 'Created repository <a href="/%s">%s</a>' |
|
303 | 'Created repository <a href="/%s">%s</a>' | |
304 | % (repo_name_full, repo_name_full)) |
|
304 | % (repo_name_full, repo_name_full)) | |
305 | # test if the repo was created in the database |
|
305 | # test if the repo was created in the database | |
306 | new_repo = Session().query(Repository)\ |
|
306 | new_repo = Session().query(Repository) \ | |
307 | .filter(Repository.repo_name == repo_name_full).one() |
|
307 | .filter(Repository.repo_name == repo_name_full).one() | |
308 | new_repo_id = new_repo.repo_id |
|
308 | new_repo_id = new_repo.repo_id | |
309 |
|
309 | |||
@@ -324,7 +324,7 b' class _BaseTest(object):' | |||||
324 | self.fail('no repo %s in filesystem' % repo_name) |
|
324 | self.fail('no repo %s in filesystem' % repo_name) | |
325 |
|
325 | |||
326 | #check if inherited permissiona are applied |
|
326 | #check if inherited permissiona are applied | |
327 | inherited_perms = UserRepoToPerm.query()\ |
|
327 | inherited_perms = UserRepoToPerm.query() \ | |
328 | .filter(UserRepoToPerm.repository_id == new_repo_id).all() |
|
328 | .filter(UserRepoToPerm.repository_id == new_repo_id).all() | |
329 | self.assertEqual(len(inherited_perms), 2) |
|
329 | self.assertEqual(len(inherited_perms), 2) | |
330 |
|
330 | |||
@@ -381,7 +381,7 b' class _BaseTest(object):' | |||||
381 | 'Created repository <a href="/%s">%s</a>' |
|
381 | 'Created repository <a href="/%s">%s</a>' | |
382 | % (repo_name, repo_name)) |
|
382 | % (repo_name, repo_name)) | |
383 | # test if the repo was created in the database |
|
383 | # test if the repo was created in the database | |
384 | new_repo = Session().query(Repository)\ |
|
384 | new_repo = Session().query(Repository) \ | |
385 | .filter(Repository.repo_name == repo_name).one() |
|
385 | .filter(Repository.repo_name == repo_name).one() | |
386 |
|
386 | |||
387 | self.assertEqual(new_repo.repo_name, repo_name) |
|
387 | self.assertEqual(new_repo.repo_name, repo_name) | |
@@ -406,7 +406,7 b' class _BaseTest(object):' | |||||
406 | response.follow() |
|
406 | response.follow() | |
407 |
|
407 | |||
408 | #check if repo was deleted from db |
|
408 | #check if repo was deleted from db | |
409 | deleted_repo = Session().query(Repository)\ |
|
409 | deleted_repo = Session().query(Repository) \ | |
410 | .filter(Repository.repo_name == repo_name).scalar() |
|
410 | .filter(Repository.repo_name == repo_name).scalar() | |
411 |
|
411 | |||
412 | self.assertEqual(deleted_repo, None) |
|
412 | self.assertEqual(deleted_repo, None) | |
@@ -434,7 +434,7 b' class _BaseTest(object):' | |||||
434 | u'Created repository <a href="/%s">%s</a>' |
|
434 | u'Created repository <a href="/%s">%s</a>' | |
435 | % (urllib.quote(repo_name), repo_name_unicode)) |
|
435 | % (urllib.quote(repo_name), repo_name_unicode)) | |
436 | # test if the repo was created in the database |
|
436 | # test if the repo was created in the database | |
437 | new_repo = Session().query(Repository)\ |
|
437 | new_repo = Session().query(Repository) \ | |
438 | .filter(Repository.repo_name == repo_name_unicode).one() |
|
438 | .filter(Repository.repo_name == repo_name_unicode).one() | |
439 |
|
439 | |||
440 | self.assertEqual(new_repo.repo_name, repo_name_unicode) |
|
440 | self.assertEqual(new_repo.repo_name, repo_name_unicode) | |
@@ -457,7 +457,7 b' class _BaseTest(object):' | |||||
457 | response.follow() |
|
457 | response.follow() | |
458 |
|
458 | |||
459 | #check if repo was deleted from db |
|
459 | #check if repo was deleted from db | |
460 | deleted_repo = Session().query(Repository)\ |
|
460 | deleted_repo = Session().query(Repository) \ | |
461 | .filter(Repository.repo_name == repo_name_unicode).scalar() |
|
461 | .filter(Repository.repo_name == repo_name_unicode).scalar() | |
462 |
|
462 | |||
463 | self.assertEqual(deleted_repo, None) |
|
463 | self.assertEqual(deleted_repo, None) |
@@ -51,13 +51,13 b' class TestAdminUsersGroupsController(Tes' | |||||
51 | self.checkSessionFlash(response, |
|
51 | self.checkSessionFlash(response, | |
52 | 'Created user group ') |
|
52 | 'Created user group ') | |
53 |
|
53 | |||
54 | gr = Session().query(UserGroup)\ |
|
54 | gr = Session().query(UserGroup) \ | |
55 | .filter(UserGroup.users_group_name == users_group_name).one() |
|
55 | .filter(UserGroup.users_group_name == users_group_name).one() | |
56 |
|
56 | |||
57 | response = self.app.post(url('users_group', id=gr.users_group_id), |
|
57 | response = self.app.post(url('users_group', id=gr.users_group_id), | |
58 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) |
|
58 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) | |
59 |
|
59 | |||
60 | gr = Session().query(UserGroup)\ |
|
60 | gr = Session().query(UserGroup) \ | |
61 | .filter(UserGroup.users_group_name == users_group_name).scalar() |
|
61 | .filter(UserGroup.users_group_name == users_group_name).scalar() | |
62 |
|
62 | |||
63 | self.assertEqual(gr, None) |
|
63 | self.assertEqual(gr, None) | |
@@ -87,7 +87,7 b' class TestAdminUsersGroupsController(Tes' | |||||
87 | p3 = Permission.get_by_key('hg.fork.none') |
|
87 | p3 = Permission.get_by_key('hg.fork.none') | |
88 | # check if user has this perms, they should be here since |
|
88 | # check if user has this perms, they should be here since | |
89 | # defaults are on |
|
89 | # defaults are on | |
90 | perms = UserGroupToPerm.query()\ |
|
90 | perms = UserGroupToPerm.query() \ | |
91 | .filter(UserGroupToPerm.users_group == ug).all() |
|
91 | .filter(UserGroupToPerm.users_group == ug).all() | |
92 |
|
92 | |||
93 | self.assertEqual( |
|
93 | self.assertEqual( | |
@@ -109,7 +109,7 b' class TestAdminUsersGroupsController(Tes' | |||||
109 |
|
109 | |||
110 | # check if user has this perms, they should be here since |
|
110 | # check if user has this perms, they should be here since | |
111 | # defaults are on |
|
111 | # defaults are on | |
112 | perms = UserGroupToPerm.query()\ |
|
112 | perms = UserGroupToPerm.query() \ | |
113 | .filter(UserGroupToPerm.users_group == ug).all() |
|
113 | .filter(UserGroupToPerm.users_group == ug).all() | |
114 |
|
114 | |||
115 | self.assertEqual( |
|
115 | self.assertEqual( | |
@@ -124,12 +124,12 b' class TestAdminUsersGroupsController(Tes' | |||||
124 | response = self.app.post(url('users_group', id=ug.users_group_id), |
|
124 | response = self.app.post(url('users_group', id=ug.users_group_id), | |
125 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) |
|
125 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) | |
126 | response = response.follow() |
|
126 | response = response.follow() | |
127 | gr = Session().query(UserGroup)\ |
|
127 | gr = Session().query(UserGroup) \ | |
128 | .filter(UserGroup.users_group_name == users_group_name).scalar() |
|
128 | .filter(UserGroup.users_group_name == users_group_name).scalar() | |
129 |
|
129 | |||
130 | self.assertEqual(gr, None) |
|
130 | self.assertEqual(gr, None) | |
131 | p = Permission.get_by_key('hg.create.repository') |
|
131 | p = Permission.get_by_key('hg.create.repository') | |
132 | perms = UserGroupToPerm.query()\ |
|
132 | perms = UserGroupToPerm.query() \ | |
133 | .filter(UserGroupToPerm.users_group_id == ugid).all() |
|
133 | .filter(UserGroupToPerm.users_group_id == ugid).all() | |
134 | perms = [[x.users_group_id, |
|
134 | perms = [[x.users_group_id, | |
135 | x.permission_id, ] for x in perms] |
|
135 | x.permission_id, ] for x in perms] | |
@@ -160,7 +160,7 b' class TestAdminUsersGroupsController(Tes' | |||||
160 | p3 = Permission.get_by_key('hg.fork.repository') |
|
160 | p3 = Permission.get_by_key('hg.fork.repository') | |
161 | # check if user has this perms, they should be here since |
|
161 | # check if user has this perms, they should be here since | |
162 | # defaults are on |
|
162 | # defaults are on | |
163 | perms = UserGroupToPerm.query()\ |
|
163 | perms = UserGroupToPerm.query() \ | |
164 | .filter(UserGroupToPerm.users_group == ug).all() |
|
164 | .filter(UserGroupToPerm.users_group == ug).all() | |
165 |
|
165 | |||
166 | self.assertEqual( |
|
166 | self.assertEqual( | |
@@ -180,7 +180,7 b' class TestAdminUsersGroupsController(Tes' | |||||
180 | p3 = Permission.get_by_key('hg.fork.none') |
|
180 | p3 = Permission.get_by_key('hg.fork.none') | |
181 | # check if user has this perms, they should be here since |
|
181 | # check if user has this perms, they should be here since | |
182 | # defaults are on |
|
182 | # defaults are on | |
183 | perms = UserGroupToPerm.query()\ |
|
183 | perms = UserGroupToPerm.query() \ | |
184 | .filter(UserGroupToPerm.users_group == ug).all() |
|
184 | .filter(UserGroupToPerm.users_group == ug).all() | |
185 |
|
185 | |||
186 | self.assertEqual( |
|
186 | self.assertEqual( | |
@@ -195,13 +195,13 b' class TestAdminUsersGroupsController(Tes' | |||||
195 | response = self.app.post(url('users_group', id=ug.users_group_id), |
|
195 | response = self.app.post(url('users_group', id=ug.users_group_id), | |
196 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) |
|
196 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) | |
197 | response = response.follow() |
|
197 | response = response.follow() | |
198 | gr = Session().query(UserGroup)\ |
|
198 | gr = Session().query(UserGroup) \ | |
199 | .filter(UserGroup.users_group_name == |
|
199 | .filter(UserGroup.users_group_name == | |
200 | users_group_name).scalar() |
|
200 | users_group_name).scalar() | |
201 |
|
201 | |||
202 | self.assertEqual(gr, None) |
|
202 | self.assertEqual(gr, None) | |
203 | p = Permission.get_by_key('hg.fork.repository') |
|
203 | p = Permission.get_by_key('hg.fork.repository') | |
204 | perms = UserGroupToPerm.query()\ |
|
204 | perms = UserGroupToPerm.query() \ | |
205 | .filter(UserGroupToPerm.users_group_id == ugid).all() |
|
205 | .filter(UserGroupToPerm.users_group_id == ugid).all() | |
206 | perms = [[x.users_group_id, |
|
206 | perms = [[x.users_group_id, | |
207 | x.permission_id, ] for x in perms] |
|
207 | x.permission_id, ] for x in perms] |
@@ -64,7 +64,7 b' class TestAdminUsersController(TestContr' | |||||
64 | self.checkSessionFlash(response, '''Created user <a href="/_admin/users/''') |
|
64 | self.checkSessionFlash(response, '''Created user <a href="/_admin/users/''') | |
65 | self.checkSessionFlash(response, '''/edit">%s</a>''' % (username)) |
|
65 | self.checkSessionFlash(response, '''/edit">%s</a>''' % (username)) | |
66 |
|
66 | |||
67 | new_user = Session().query(User).\ |
|
67 | new_user = Session().query(User). \ | |
68 | filter(User.username == username).one() |
|
68 | filter(User.username == username).one() | |
69 |
|
69 | |||
70 | self.assertEqual(new_user.username, username) |
|
70 | self.assertEqual(new_user.username, username) | |
@@ -165,7 +165,7 b' class TestAdminUsersController(TestContr' | |||||
165 |
|
165 | |||
166 | fixture.create_user(name=username) |
|
166 | fixture.create_user(name=username) | |
167 |
|
167 | |||
168 | new_user = Session().query(User)\ |
|
168 | new_user = Session().query(User) \ | |
169 | .filter(User.username == username).one() |
|
169 | .filter(User.username == username).one() | |
170 | response = self.app.post(url('user', id=new_user.user_id), |
|
170 | response = self.app.post(url('user', id=new_user.user_id), | |
171 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) |
|
171 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) | |
@@ -180,7 +180,7 b' class TestAdminUsersController(TestContr' | |||||
180 | fixture.create_user(name=username) |
|
180 | fixture.create_user(name=username) | |
181 | fixture.create_repo(name=reponame, cur_user=username) |
|
181 | fixture.create_repo(name=reponame, cur_user=username) | |
182 |
|
182 | |||
183 | new_user = Session().query(User)\ |
|
183 | new_user = Session().query(User) \ | |
184 | .filter(User.username == username).one() |
|
184 | .filter(User.username == username).one() | |
185 | response = self.app.post(url('user', id=new_user.user_id), |
|
185 | response = self.app.post(url('user', id=new_user.user_id), | |
186 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) |
|
186 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) | |
@@ -205,7 +205,7 b' class TestAdminUsersController(TestContr' | |||||
205 | fixture.create_user(name=username) |
|
205 | fixture.create_user(name=username) | |
206 | fixture.create_repo_group(name=groupname, cur_user=username) |
|
206 | fixture.create_repo_group(name=groupname, cur_user=username) | |
207 |
|
207 | |||
208 | new_user = Session().query(User)\ |
|
208 | new_user = Session().query(User) \ | |
209 | .filter(User.username == username).one() |
|
209 | .filter(User.username == username).one() | |
210 | response = self.app.post(url('user', id=new_user.user_id), |
|
210 | response = self.app.post(url('user', id=new_user.user_id), | |
211 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) |
|
211 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) | |
@@ -234,7 +234,7 b' class TestAdminUsersController(TestContr' | |||||
234 | fixture.create_user(name=username) |
|
234 | fixture.create_user(name=username) | |
235 | ug = fixture.create_user_group(name=groupname, cur_user=username) |
|
235 | ug = fixture.create_user_group(name=groupname, cur_user=username) | |
236 |
|
236 | |||
237 | new_user = Session().query(User)\ |
|
237 | new_user = Session().query(User) \ | |
238 | .filter(User.username == username).one() |
|
238 | .filter(User.username == username).one() | |
239 | response = self.app.post(url('user', id=new_user.user_id), |
|
239 | response = self.app.post(url('user', id=new_user.user_id), | |
240 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) |
|
240 | params={'_method': 'delete', '_authentication_token': self.authentication_token()}) |
@@ -130,7 +130,7 b' class _BaseTestCase(object):' | |||||
130 | % (repo_name, fork_name_full, fork_name_full)) |
|
130 | % (repo_name, fork_name_full, fork_name_full)) | |
131 |
|
131 | |||
132 | #test if the fork was created in the database |
|
132 | #test if the fork was created in the database | |
133 | fork_repo = Session().query(Repository)\ |
|
133 | fork_repo = Session().query(Repository) \ | |
134 | .filter(Repository.repo_name == fork_name_full).one() |
|
134 | .filter(Repository.repo_name == fork_name_full).one() | |
135 |
|
135 | |||
136 | self.assertEqual(fork_repo.repo_name, fork_name_full) |
|
136 | self.assertEqual(fork_repo.repo_name, fork_name_full) | |
@@ -173,7 +173,7 b' class _BaseTestCase(object):' | |||||
173 | % (repo_name, fork_name, fork_name)) |
|
173 | % (repo_name, fork_name, fork_name)) | |
174 |
|
174 | |||
175 | #test if the fork was created in the database |
|
175 | #test if the fork was created in the database | |
176 | fork_repo = Session().query(Repository)\ |
|
176 | fork_repo = Session().query(Repository) \ | |
177 | .filter(Repository.repo_name == fork_name).one() |
|
177 | .filter(Repository.repo_name == fork_name).one() | |
178 |
|
178 | |||
179 | self.assertEqual(fork_repo.repo_name, fork_name) |
|
179 | self.assertEqual(fork_repo.repo_name, fork_name) | |
@@ -189,8 +189,8 b' class _BaseTestCase(object):' | |||||
189 | usr = self.log_user(self.username, self.password)['user_id'] |
|
189 | usr = self.log_user(self.username, self.password)['user_id'] | |
190 | repo_name = self.REPO |
|
190 | repo_name = self.REPO | |
191 |
|
191 | |||
192 | forks = Repository.query()\ |
|
192 | forks = Repository.query() \ | |
193 | .filter(Repository.repo_type == self.REPO_TYPE)\ |
|
193 | .filter(Repository.repo_type == self.REPO_TYPE) \ | |
194 | .filter(Repository.fork_id != None).all() |
|
194 | .filter(Repository.fork_id != None).all() | |
195 | self.assertEqual(1, len(forks)) |
|
195 | self.assertEqual(1, len(forks)) | |
196 |
|
196 | |||
@@ -209,8 +209,8 b' class _BaseTestCase(object):' | |||||
209 | usr = self.log_user(self.username, self.password)['user_id'] |
|
209 | usr = self.log_user(self.username, self.password)['user_id'] | |
210 | repo_name = self.REPO |
|
210 | repo_name = self.REPO | |
211 |
|
211 | |||
212 | forks = Repository.query()\ |
|
212 | forks = Repository.query() \ | |
213 | .filter(Repository.repo_type == self.REPO_TYPE)\ |
|
213 | .filter(Repository.repo_type == self.REPO_TYPE) \ | |
214 | .filter(Repository.fork_id != None).all() |
|
214 | .filter(Repository.fork_id != None).all() | |
215 | self.assertEqual(1, len(forks)) |
|
215 | self.assertEqual(1, len(forks)) | |
216 |
|
216 |
@@ -15,8 +15,8 b' class TestJournalController(TestControll' | |||||
15 | # usr = Session().query(User).filter(User.username == TEST_USER_ADMIN_LOGIN).one() |
|
15 | # usr = Session().query(User).filter(User.username == TEST_USER_ADMIN_LOGIN).one() | |
16 | # repo = Session().query(Repository).filter(Repository.repo_name == HG_REPO).one() |
|
16 | # repo = Session().query(Repository).filter(Repository.repo_name == HG_REPO).one() | |
17 | # |
|
17 | # | |
18 | # followings = Session().query(UserFollowing)\ |
|
18 | # followings = Session().query(UserFollowing) \ | |
19 | # .filter(UserFollowing.user == usr)\ |
|
19 | # .filter(UserFollowing.user == usr) \ | |
20 | # .filter(UserFollowing.follows_repository == repo).all() |
|
20 | # .filter(UserFollowing.follows_repository == repo).all() | |
21 | # |
|
21 | # | |
22 | # assert len(followings) == 1, 'Not following any repository' |
|
22 | # assert len(followings) == 1, 'Not following any repository' |
@@ -72,8 +72,8 b' class TestMyAccountController(TestContro' | |||||
72 | response = self.app.get(url('my_account_emails')) |
|
72 | response = self.app.get(url('my_account_emails')) | |
73 |
|
73 | |||
74 | from kallithea.model.db import UserEmailMap |
|
74 | from kallithea.model.db import UserEmailMap | |
75 | email_id = UserEmailMap.query()\ |
|
75 | email_id = UserEmailMap.query() \ | |
76 | .filter(UserEmailMap.user == User.get_by_username(TEST_USER_ADMIN_LOGIN))\ |
|
76 | .filter(UserEmailMap.user == User.get_by_username(TEST_USER_ADMIN_LOGIN)) \ | |
77 | .filter(UserEmailMap.email == 'barz@example.com').one().email_id |
|
77 | .filter(UserEmailMap.email == 'barz@example.com').one().email_id | |
78 |
|
78 | |||
79 | response.mustcontain('barz@example.com') |
|
79 | response.mustcontain('barz@example.com') | |
@@ -180,7 +180,7 b' class TestMyAccountController(TestContro' | |||||
180 |
|
180 | |||
181 | response.mustcontain('An email address must contain a single @') |
|
181 | response.mustcontain('An email address must contain a single @') | |
182 | from kallithea.model import validators |
|
182 | from kallithea.model import validators | |
183 | msg = validators.ValidUsername(edit=False, old_data={})\ |
|
183 | msg = validators.ValidUsername(edit=False, old_data={}) \ | |
184 | ._messages['username_exists'] |
|
184 | ._messages['username_exists'] | |
185 | msg = h.html_escape(msg % {'username': TEST_USER_ADMIN_LOGIN}) |
|
185 | msg = h.html_escape(msg % {'username': TEST_USER_ADMIN_LOGIN}) | |
186 | response.mustcontain(msg) |
|
186 | response.mustcontain(msg) |
@@ -55,7 +55,7 b' class TestNotifications(BaseTestCase):' | |||||
55 | self.assertEqual(notification.notification_id, |
|
55 | self.assertEqual(notification.notification_id, | |
56 | notifications[0].notification_id) |
|
56 | notifications[0].notification_id) | |
57 |
|
57 | |||
58 | unotification = UserNotification.query()\ |
|
58 | unotification = UserNotification.query() \ | |
59 | .filter(UserNotification.notification == notification).all() |
|
59 | .filter(UserNotification.notification == notification).all() | |
60 |
|
60 | |||
61 | self.assertEqual(len(unotification), len(usrs)) |
|
61 | self.assertEqual(len(unotification), len(usrs)) | |
@@ -100,10 +100,10 b' class TestNotifications(BaseTestCase):' | |||||
100 | recipients=[self.u3, self.u1, self.u2]) |
|
100 | recipients=[self.u3, self.u1, self.u2]) | |
101 | Session().commit() |
|
101 | Session().commit() | |
102 |
|
102 | |||
103 | unotification = UserNotification.query()\ |
|
103 | unotification = UserNotification.query() \ | |
104 | .filter(UserNotification.notification == |
|
104 | .filter(UserNotification.notification == | |
105 | notification)\ |
|
105 | notification) \ | |
106 | .filter(UserNotification.user_id == self.u3)\ |
|
106 | .filter(UserNotification.user_id == self.u3) \ | |
107 | .scalar() |
|
107 | .scalar() | |
108 |
|
108 | |||
109 | self.assertEqual(unotification.user_id, self.u3) |
|
109 | self.assertEqual(unotification.user_id, self.u3) | |
@@ -112,10 +112,10 b' class TestNotifications(BaseTestCase):' | |||||
112 | notification.notification_id) |
|
112 | notification.notification_id) | |
113 | Session().commit() |
|
113 | Session().commit() | |
114 |
|
114 | |||
115 | u3notification = UserNotification.query()\ |
|
115 | u3notification = UserNotification.query() \ | |
116 | .filter(UserNotification.notification == |
|
116 | .filter(UserNotification.notification == | |
117 | notification)\ |
|
117 | notification) \ | |
118 | .filter(UserNotification.user_id == self.u3)\ |
|
118 | .filter(UserNotification.user_id == self.u3) \ | |
119 | .scalar() |
|
119 | .scalar() | |
120 |
|
120 | |||
121 | self.assertEqual(u3notification, None) |
|
121 | self.assertEqual(u3notification, None) | |
@@ -124,16 +124,16 b' class TestNotifications(BaseTestCase):' | |||||
124 | self.assertEqual(Notification.query().all(), [notification]) |
|
124 | self.assertEqual(Notification.query().all(), [notification]) | |
125 |
|
125 | |||
126 | #u1 and u2 still have assignments |
|
126 | #u1 and u2 still have assignments | |
127 | u1notification = UserNotification.query()\ |
|
127 | u1notification = UserNotification.query() \ | |
128 | .filter(UserNotification.notification == |
|
128 | .filter(UserNotification.notification == | |
129 | notification)\ |
|
129 | notification) \ | |
130 | .filter(UserNotification.user_id == self.u1)\ |
|
130 | .filter(UserNotification.user_id == self.u1) \ | |
131 | .scalar() |
|
131 | .scalar() | |
132 | self.assertNotEqual(u1notification, None) |
|
132 | self.assertNotEqual(u1notification, None) | |
133 | u2notification = UserNotification.query()\ |
|
133 | u2notification = UserNotification.query() \ | |
134 | .filter(UserNotification.notification == |
|
134 | .filter(UserNotification.notification == | |
135 | notification)\ |
|
135 | notification) \ | |
136 | .filter(UserNotification.user_id == self.u2)\ |
|
136 | .filter(UserNotification.user_id == self.u2) \ | |
137 | .scalar() |
|
137 | .scalar() | |
138 | self.assertNotEqual(u2notification, None) |
|
138 | self.assertNotEqual(u2notification, None) | |
139 |
|
139 |
@@ -2,7 +2,7 b' from kallithea.tests import *' | |||||
2 | from kallithea.tests.fixture import Fixture |
|
2 | from kallithea.tests.fixture import Fixture | |
3 | from kallithea.model.repo_group import RepoGroupModel |
|
3 | from kallithea.model.repo_group import RepoGroupModel | |
4 | from kallithea.model.repo import RepoModel |
|
4 | from kallithea.model.repo import RepoModel | |
5 | from kallithea.model.db import RepoGroup, User, UserGroupRepoGroupToPerm,\ |
|
5 | from kallithea.model.db import RepoGroup, User, UserGroupRepoGroupToPerm, \ | |
6 | Permission, UserToPerm |
|
6 | Permission, UserToPerm | |
7 | from kallithea.model.user import UserModel |
|
7 | from kallithea.model.user import UserModel | |
8 |
|
8 | |||
@@ -325,9 +325,9 b' class TestPermissions(BaseTestCase):' | |||||
325 | perm='group.read') |
|
325 | perm='group.read') | |
326 | Session().commit() |
|
326 | Session().commit() | |
327 | # check if the |
|
327 | # check if the | |
328 | obj = Session().query(UserGroupRepoGroupToPerm)\ |
|
328 | obj = Session().query(UserGroupRepoGroupToPerm) \ | |
329 | .filter(UserGroupRepoGroupToPerm.group == self.g1)\ |
|
329 | .filter(UserGroupRepoGroupToPerm.group == self.g1) \ | |
330 | .filter(UserGroupRepoGroupToPerm.users_group == self.ug1)\ |
|
330 | .filter(UserGroupRepoGroupToPerm.users_group == self.ug1) \ | |
331 | .scalar() |
|
331 | .scalar() | |
332 | self.assertEqual(obj.permission.permission_name, 'group.read') |
|
332 | self.assertEqual(obj.permission.permission_name, 'group.read') | |
333 |
|
333 | |||
@@ -689,8 +689,8 b' class TestPermissions(BaseTestCase):' | |||||
689 | 'repository.admin') |
|
689 | 'repository.admin') | |
690 |
|
690 | |||
691 | def _test_def_perm_equal(self, user, change_factor=0): |
|
691 | def _test_def_perm_equal(self, user, change_factor=0): | |
692 | perms = UserToPerm.query()\ |
|
692 | perms = UserToPerm.query() \ | |
693 | .filter(UserToPerm.user == user)\ |
|
693 | .filter(UserToPerm.user == user) \ | |
694 | .all() |
|
694 | .all() | |
695 | self.assertEqual(len(perms), |
|
695 | self.assertEqual(len(perms), | |
696 | len(Permission.DEFAULT_USER_PERMISSIONS,)+change_factor, |
|
696 | len(Permission.DEFAULT_USER_PERMISSIONS,)+change_factor, | |
@@ -704,8 +704,8 b' class TestPermissions(BaseTestCase):' | |||||
704 | PermissionModel().create_default_permissions(user=self.u1) |
|
704 | PermissionModel().create_default_permissions(user=self.u1) | |
705 | self._test_def_perm_equal(user=self.u1) |
|
705 | self._test_def_perm_equal(user=self.u1) | |
706 | #now we delete one, it should be re-created after another call |
|
706 | #now we delete one, it should be re-created after another call | |
707 | perms = UserToPerm.query()\ |
|
707 | perms = UserToPerm.query() \ | |
708 | .filter(UserToPerm.user == self.u1)\ |
|
708 | .filter(UserToPerm.user == self.u1) \ | |
709 | .all() |
|
709 | .all() | |
710 | Session().delete(perms[0]) |
|
710 | Session().delete(perms[0]) | |
711 | Session().commit() |
|
711 | Session().commit() | |
@@ -734,9 +734,9 b' class TestPermissions(BaseTestCase):' | |||||
734 | self.assertNotEqual(new, None) |
|
734 | self.assertNotEqual(new, None) | |
735 |
|
735 | |||
736 | #now modify permissions |
|
736 | #now modify permissions | |
737 | p = UserToPerm.query()\ |
|
737 | p = UserToPerm.query() \ | |
738 | .filter(UserToPerm.user == self.u1)\ |
|
738 | .filter(UserToPerm.user == self.u1) \ | |
739 | .filter(UserToPerm.permission == old)\ |
|
739 | .filter(UserToPerm.permission == old) \ | |
740 | .one() |
|
740 | .one() | |
741 | p.permission = new |
|
741 | p.permission = new | |
742 | Session().add(p) |
|
742 | Session().add(p) |
@@ -1,6 +1,6 b'' | |||||
1 | from kallithea.tests import * |
|
1 | from kallithea.tests import * | |
2 |
|
2 | |||
3 | from kallithea.model.db import User, UserGroup, UserGroupMember, UserEmailMap,\ |
|
3 | from kallithea.model.db import User, UserGroup, UserGroupMember, UserEmailMap, \ | |
4 | Permission |
|
4 | Permission | |
5 | from kallithea.model.user import UserModel |
|
5 | from kallithea.model.user import UserModel | |
6 |
|
6 |
@@ -303,8 +303,8 b' class GitChangesetTest(unittest.TestCase' | |||||
303 | self.assertTrue(api is chset.get_node('docs/api')) |
|
303 | self.assertTrue(api is chset.get_node('docs/api')) | |
304 | index = api.get_node('index.rst') |
|
304 | index = api.get_node('index.rst') | |
305 | self.assertTrue(index is chset.get_node('docs/api/index.rst')) |
|
305 | self.assertTrue(index is chset.get_node('docs/api/index.rst')) | |
306 | self.assertTrue(index is chset.get_node('docs')\ |
|
306 | self.assertTrue(index is chset.get_node('docs') \ | |
307 | .get_node('api')\ |
|
307 | .get_node('api') \ | |
308 | .get_node('index.rst')) |
|
308 | .get_node('index.rst')) | |
309 |
|
309 | |||
310 | def test_branch_and_tags(self): |
|
310 | def test_branch_and_tags(self): | |
@@ -535,8 +535,8 b' class GitChangesetTest(unittest.TestCase' | |||||
535 | """ |
|
535 | """ | |
536 | Tests state of FileNodes. |
|
536 | Tests state of FileNodes. | |
537 | """ |
|
537 | """ | |
538 | node = self.repo\ |
|
538 | node = self.repo \ | |
539 | .get_changeset('e6ea6d16e2f26250124a1f4b4fe37a912f9d86a0')\ |
|
539 | .get_changeset('e6ea6d16e2f26250124a1f4b4fe37a912f9d86a0') \ | |
540 | .get_node('vcs/utils/diffs.py') |
|
540 | .get_node('vcs/utils/diffs.py') | |
541 | self.assertTrue(node.state, NodeState.ADDED) |
|
541 | self.assertTrue(node.state, NodeState.ADDED) | |
542 | self.assertTrue(node.added) |
|
542 | self.assertTrue(node.added) | |
@@ -544,8 +544,8 b' class GitChangesetTest(unittest.TestCase' | |||||
544 | self.assertFalse(node.not_changed) |
|
544 | self.assertFalse(node.not_changed) | |
545 | self.assertFalse(node.removed) |
|
545 | self.assertFalse(node.removed) | |
546 |
|
546 | |||
547 | node = self.repo\ |
|
547 | node = self.repo \ | |
548 | .get_changeset('33fa3223355104431402a888fa77a4e9956feb3e')\ |
|
548 | .get_changeset('33fa3223355104431402a888fa77a4e9956feb3e') \ | |
549 | .get_node('.hgignore') |
|
549 | .get_node('.hgignore') | |
550 | self.assertTrue(node.state, NodeState.CHANGED) |
|
550 | self.assertTrue(node.state, NodeState.CHANGED) | |
551 | self.assertFalse(node.added) |
|
551 | self.assertFalse(node.added) | |
@@ -553,8 +553,8 b' class GitChangesetTest(unittest.TestCase' | |||||
553 | self.assertFalse(node.not_changed) |
|
553 | self.assertFalse(node.not_changed) | |
554 | self.assertFalse(node.removed) |
|
554 | self.assertFalse(node.removed) | |
555 |
|
555 | |||
556 | node = self.repo\ |
|
556 | node = self.repo \ | |
557 | .get_changeset('e29b67bd158580fc90fc5e9111240b90e6e86064')\ |
|
557 | .get_changeset('e29b67bd158580fc90fc5e9111240b90e6e86064') \ | |
558 | .get_node('setup.py') |
|
558 | .get_node('setup.py') | |
559 | self.assertTrue(node.state, NodeState.NOT_CHANGED) |
|
559 | self.assertTrue(node.state, NodeState.NOT_CHANGED) | |
560 | self.assertFalse(node.added) |
|
560 | self.assertFalse(node.added) | |
@@ -599,24 +599,24 b' class GitChangesetTest(unittest.TestCase' | |||||
599 |
|
599 | |||
600 | def test_author_email(self): |
|
600 | def test_author_email(self): | |
601 | self.assertEqual('marcin@python-blog.com', |
|
601 | self.assertEqual('marcin@python-blog.com', | |
602 | self.repo.get_changeset('c1214f7e79e02fc37156ff215cd71275450cffc3')\ |
|
602 | self.repo.get_changeset('c1214f7e79e02fc37156ff215cd71275450cffc3') \ | |
603 | .author_email) |
|
603 | .author_email) | |
604 | self.assertEqual('lukasz.balcerzak@python-center.pl', |
|
604 | self.assertEqual('lukasz.balcerzak@python-center.pl', | |
605 | self.repo.get_changeset('ff7ca51e58c505fec0dd2491de52c622bb7a806b')\ |
|
605 | self.repo.get_changeset('ff7ca51e58c505fec0dd2491de52c622bb7a806b') \ | |
606 | .author_email) |
|
606 | .author_email) | |
607 | self.assertEqual('none@none', |
|
607 | self.assertEqual('none@none', | |
608 | self.repo.get_changeset('8430a588b43b5d6da365400117c89400326e7992')\ |
|
608 | self.repo.get_changeset('8430a588b43b5d6da365400117c89400326e7992') \ | |
609 | .author_email) |
|
609 | .author_email) | |
610 |
|
610 | |||
611 | def test_author_username(self): |
|
611 | def test_author_username(self): | |
612 | self.assertEqual('Marcin Kuzminski', |
|
612 | self.assertEqual('Marcin Kuzminski', | |
613 | self.repo.get_changeset('c1214f7e79e02fc37156ff215cd71275450cffc3')\ |
|
613 | self.repo.get_changeset('c1214f7e79e02fc37156ff215cd71275450cffc3') \ | |
614 | .author_name) |
|
614 | .author_name) | |
615 | self.assertEqual('Lukasz Balcerzak', |
|
615 | self.assertEqual('Lukasz Balcerzak', | |
616 | self.repo.get_changeset('ff7ca51e58c505fec0dd2491de52c622bb7a806b')\ |
|
616 | self.repo.get_changeset('ff7ca51e58c505fec0dd2491de52c622bb7a806b') \ | |
617 | .author_name) |
|
617 | .author_name) | |
618 | self.assertEqual('marcink', |
|
618 | self.assertEqual('marcink', | |
619 | self.repo.get_changeset('8430a588b43b5d6da365400117c89400326e7992')\ |
|
619 | self.repo.get_changeset('8430a588b43b5d6da365400117c89400326e7992') \ | |
620 | .author_name) |
|
620 | .author_name) | |
621 |
|
621 | |||
622 |
|
622 |
@@ -302,8 +302,8 b' class MercurialChangesetTest(unittest.Te' | |||||
302 | self.assertTrue(api is chset.get_node('docs/api')) |
|
302 | self.assertTrue(api is chset.get_node('docs/api')) | |
303 | index = api.get_node('index.rst') |
|
303 | index = api.get_node('index.rst') | |
304 | self.assertTrue(index is chset.get_node('docs/api/index.rst')) |
|
304 | self.assertTrue(index is chset.get_node('docs/api/index.rst')) | |
305 | self.assertTrue(index is chset.get_node('docs')\ |
|
305 | self.assertTrue(index is chset.get_node('docs') \ | |
306 | .get_node('api')\ |
|
306 | .get_node('api') \ | |
307 | .get_node('index.rst')) |
|
307 | .get_node('index.rst')) | |
308 |
|
308 | |||
309 | def test_branch_and_tags(self): |
|
309 | def test_branch_and_tags(self): |
@@ -6,6 +6,7 b" files=`hg loc '*.py' '*.html' '*.css' '*" | |||||
6 |
|
6 | |||
7 | sed -i -e "s,`printf '\t'`, ,g" $files |
|
7 | sed -i -e "s,`printf '\t'`, ,g" $files | |
8 | sed -i -e "s, *$,,g" $files |
|
8 | sed -i -e "s, *$,,g" $files | |
|
9 | sed -i -e 's,\([^ ]\)\\$,\1 \\,g' -e 's,\(["'"'"']["'"'"']["'"'"']\) \\$,\1\\,g' $files | |||
9 | # ensure one trailing newline - remove empty last line and make last line include trailing newline: |
|
10 | # ensure one trailing newline - remove empty last line and make last line include trailing newline: | |
10 | sed -i -e '$,${/^$/d}' -e '$a\' $files |
|
11 | sed -i -e '$,${/^$/d}' -e '$a\' $files | |
11 |
|
12 |
General Comments 0
You need to be logged in to leave comments.
Login now