##// END OF EJS Templates
my-account: owner/watched repos are now loaded only using DB queries....
marcink -
r4153:4c7da78c default
parent child Browse files
Show More
@@ -33,22 +33,21 b' from rhodecode import forms'
33 from rhodecode.lib import helpers as h
33 from rhodecode.lib import helpers as h
34 from rhodecode.lib import audit_logger
34 from rhodecode.lib import audit_logger
35 from rhodecode.lib.ext_json import json
35 from rhodecode.lib.ext_json import json
36 from rhodecode.lib.auth import LoginRequired, NotAnonymous, CSRFRequired, \
36 from rhodecode.lib.auth import (
37 HasRepoPermissionAny, HasRepoGroupPermissionAny
37 LoginRequired, NotAnonymous, CSRFRequired,
38 HasRepoPermissionAny, HasRepoGroupPermissionAny, AuthUser)
38 from rhodecode.lib.channelstream import (
39 from rhodecode.lib.channelstream import (
39 channelstream_request, ChannelstreamException)
40 channelstream_request, ChannelstreamException)
40 from rhodecode.lib.utils2 import safe_int, md5, str2bool
41 from rhodecode.lib.utils2 import safe_int, md5, str2bool
41 from rhodecode.model.auth_token import AuthTokenModel
42 from rhodecode.model.auth_token import AuthTokenModel
42 from rhodecode.model.comment import CommentsModel
43 from rhodecode.model.comment import CommentsModel
43 from rhodecode.model.db import (
44 from rhodecode.model.db import (
44 IntegrityError, joinedload,
45 IntegrityError, or_, in_filter_generator,
45 Repository, UserEmailMap, UserApiKeys, UserFollowing,
46 Repository, UserEmailMap, UserApiKeys, UserFollowing,
46 PullRequest, UserBookmark, RepoGroup)
47 PullRequest, UserBookmark, RepoGroup)
47 from rhodecode.model.meta import Session
48 from rhodecode.model.meta import Session
48 from rhodecode.model.pull_request import PullRequestModel
49 from rhodecode.model.pull_request import PullRequestModel
49 from rhodecode.model.scm import RepoList
50 from rhodecode.model.user import UserModel
50 from rhodecode.model.user import UserModel
51 from rhodecode.model.repo import RepoModel
52 from rhodecode.model.user_group import UserGroupModel
51 from rhodecode.model.user_group import UserGroupModel
53 from rhodecode.model.validation_schema.schemas import user_schema
52 from rhodecode.model.validation_schema.schemas import user_schema
54
53
@@ -345,23 +344,59 b' class MyAccountView(BaseAppView, DataGri'
345 'You should see a new live message now.'}
344 'You should see a new live message now.'}
346
345
347 def _load_my_repos_data(self, watched=False):
346 def _load_my_repos_data(self, watched=False):
347
348 allowed_ids = [-1] + self._rhodecode_user.repo_acl_ids_from_stack(AuthUser.repo_read_perms)
349
348 if watched:
350 if watched:
349 admin = False
351 # repos user watch
350 follows_repos = Session().query(UserFollowing)\
352 repo_list = Session().query(
351 .filter(UserFollowing.user_id == self._rhodecode_user.user_id)\
353 Repository
352 .options(joinedload(UserFollowing.follows_repository))\
354 ) \
355 .join(
356 (UserFollowing, UserFollowing.follows_repo_id == Repository.repo_id)
357 ) \
358 .filter(
359 UserFollowing.user_id == self._rhodecode_user.user_id
360 ) \
361 .filter(or_(
362 # generate multiple IN to fix limitation problems
363 *in_filter_generator(Repository.repo_id, allowed_ids))
364 ) \
365 .order_by(Repository.repo_name) \
353 .all()
366 .all()
354 repo_list = [x.follows_repository for x in follows_repos]
367
355 else:
368 else:
356 admin = True
369 # repos user is owner of
357 repo_list = Repository.get_all_repos(
370 repo_list = Session().query(
358 user_id=self._rhodecode_user.user_id)
371 Repository
359 repo_list = RepoList(repo_list, perm_set=[
372 ) \
360 'repository.read', 'repository.write', 'repository.admin'],
373 .filter(
361 extra_kwargs=dict(user=self._rhodecode_user))
374 Repository.user_id == self._rhodecode_user.user_id
375 ) \
376 .filter(or_(
377 # generate multiple IN to fix limitation problems
378 *in_filter_generator(Repository.repo_id, allowed_ids))
379 ) \
380 .order_by(Repository.repo_name) \
381 .all()
362
382
363 repos_data = RepoModel().get_repos_as_dict(
383 _render = self.request.get_partial_renderer(
364 repo_list=repo_list, admin=admin, short_name=False)
384 'rhodecode:templates/data_table/_dt_elements.mako')
385
386 def repo_lnk(name, rtype, rstate, private, archived, fork_of):
387 return _render('repo_name', name, rtype, rstate, private, archived, fork_of,
388 short_name=False, admin=False)
389
390 repos_data = []
391 for repo in repo_list:
392 row = {
393 "name": repo_lnk(repo.repo_name, repo.repo_type, repo.repo_state,
394 repo.private, repo.archived, repo.fork),
395 "name_raw": repo.repo_name.lower(),
396 }
397
398 repos_data.append(row)
399
365 # json used to render the grid
400 # json used to render the grid
366 return json.dumps(repos_data)
401 return json.dumps(repos_data)
367
402
@@ -1051,6 +1051,8 b' class AuthUser(object):'
1051 anonymous access is enabled and if so, it returns default user as logged in
1051 anonymous access is enabled and if so, it returns default user as logged in
1052 """
1052 """
1053 GLOBAL_PERMS = [x[0] for x in Permission.PERMS]
1053 GLOBAL_PERMS = [x[0] for x in Permission.PERMS]
1054 repo_read_perms = ['repository.read', 'repository.admin', 'repository.write']
1055 repo_group_read_perms = ['group.read', 'group.write', 'group.admin']
1054
1056
1055 def __init__(self, user_id=None, api_key=None, username=None, ip_addr=None):
1057 def __init__(self, user_id=None, api_key=None, username=None, ip_addr=None):
1056
1058
@@ -40,8 +40,8 b''
40 <li class="${h.is_active('external_identity', c.active)}"><a href="${my_account_external_url}">${_('External Identities')}</a></li>
40 <li class="${h.is_active('external_identity', c.active)}"><a href="${my_account_external_url}">${_('External Identities')}</a></li>
41 % endif
41 % endif
42
42
43 <li class="${h.is_active('repos', c.active)}"><a href="${h.route_path('my_account_repos')}">${_('Repositories')}</a></li>
43 <li class="${h.is_active('repos', c.active)}"><a href="${h.route_path('my_account_repos')}">${_('Owned Repositories')}</a></li>
44 <li class="${h.is_active('watched', c.active)}"><a href="${h.route_path('my_account_watched')}">${_('Watched')}</a></li>
44 <li class="${h.is_active('watched', c.active)}"><a href="${h.route_path('my_account_watched')}">${_('Watched Repositories')}</a></li>
45 <li class="${h.is_active('pullrequests', c.active)}"><a href="${h.route_path('my_account_pullrequests')}">${_('Pull Requests')}</a></li>
45 <li class="${h.is_active('pullrequests', c.active)}"><a href="${h.route_path('my_account_pullrequests')}">${_('Pull Requests')}</a></li>
46 <li class="${h.is_active('perms', c.active)}"><a href="${h.route_path('my_account_perms')}">${_('Permissions')}</a></li>
46 <li class="${h.is_active('perms', c.active)}"><a href="${h.route_path('my_account_perms')}">${_('Permissions')}</a></li>
47 <li class="${h.is_active('my_notifications', c.active)}"><a href="${h.route_path('my_account_notifications')}">${_('Live Notifications')}</a></li>
47 <li class="${h.is_active('my_notifications', c.active)}"><a href="${h.route_path('my_account_notifications')}">${_('Live Notifications')}</a></li>
@@ -15,13 +15,10 b''
15 <script>
15 <script>
16 $(document).ready(function() {
16 $(document).ready(function() {
17
17
18 var get_datatable_count = function(){
18 // repo list
19 var api = $('#repo_list_table').dataTable().api();
19 $repoListTable = $('#repo_list_table');
20 $('#repo_count').text(api.page.info().recordsDisplay);
21 };
22
20
23 // repo list
21 $repoListTable.DataTable({
24 $('#repo_list_table').DataTable({
25 data: ${c.data|n},
22 data: ${c.data|n},
26 dom: 'rtp',
23 dom: 'rtp',
27 pageLength: ${c.visual.admin_grid_items},
24 pageLength: ${c.visual.admin_grid_items},
@@ -29,39 +26,23 b''
29 columns: [
26 columns: [
30 { data: {"_": "name",
27 { data: {"_": "name",
31 "sort": "name_raw"}, title: "${_('Name')}", className: "td-componentname" },
28 "sort": "name_raw"}, title: "${_('Name')}", className: "td-componentname" },
32 { data: 'menu', className: "quick_repo_menu" },
33 { data: {"_": "last_changeset",
34 "sort": "last_changeset_raw",
35 "type": Number}, title: "${_('Commit')}", className: "td-hash" },
36 { data: {"_": "action",
37 "sort": "action"}, title: "${_('Action')}", className: "td-action" }
38 ],
29 ],
39 language: {
30 language: {
40 paginate: DEFAULT_GRID_PAGINATION,
31 paginate: DEFAULT_GRID_PAGINATION,
41 emptyTable: _gettext("No repositories available yet.")
32 emptyTable: _gettext("No repositories available yet.")
42 },
33 },
43 "initComplete": function( settings, json ) {
44 get_datatable_count();
45 quick_repo_menu();
46 }
47 });
48
34
49 // update the counter when doing search
50 $('#repo_list_table').on( 'search.dt', function (e,settings) {
51 get_datatable_count();
52 });
35 });
53
36
54 // filter, filter both grids
37 // filter
55 $('#q_filter').on( 'keyup', function () {
38 $('#q_filter').on('keyup',
56 var repo_api = $('#repo_list_table').dataTable().api();
39 $.debounce(250, function() {
57 repo_api
40 $repoListTable.DataTable().search(
58 .columns(0)
41 $('#q_filter').val()
59 .search(this.value)
42 ).draw();
60 .draw();
43 })
61 });
44 );
62
45
63 // refilter table if page load via back button
64 $("#q_filter").trigger('keyup');
65
46
66 });
47 });
67
48
@@ -15,13 +15,10 b''
15 <script>
15 <script>
16 $(document).ready(function() {
16 $(document).ready(function() {
17
17
18 var get_datatable_count = function(){
18 // repo list
19 var api = $('#repo_list_table').dataTable().api();
19 $repoListTable = $('#repo_list_table');
20 $('#repo_count').text(api.page.info().recordsDisplay);
21 };
22
20
23 // repo list
21 $repoListTable.DataTable({
24 $('#repo_list_table').DataTable({
25 data: ${c.data|n},
22 data: ${c.data|n},
26 dom: 'rtp',
23 dom: 'rtp',
27 pageLength: ${c.visual.admin_grid_items},
24 pageLength: ${c.visual.admin_grid_items},
@@ -29,37 +26,23 b''
29 columns: [
26 columns: [
30 { data: {"_": "name",
27 { data: {"_": "name",
31 "sort": "name_raw"}, title: "${_('Name')}", className: "td-componentname" },
28 "sort": "name_raw"}, title: "${_('Name')}", className: "td-componentname" },
32 { data: 'menu', className: "quick_repo_menu" },
33 { data: {"_": "last_changeset",
34 "sort": "last_changeset_raw",
35 "type": Number}, title: "${_('Commit')}", className: "td-hash" }
36 ],
29 ],
37 language: {
30 language: {
38 paginate: DEFAULT_GRID_PAGINATION,
31 paginate: DEFAULT_GRID_PAGINATION,
39 emptyTable: _gettext("No repositories available yet.")
32 emptyTable: _gettext("No repositories available yet.")
40 },
33 },
41 "initComplete": function( settings, json ) {
42 get_datatable_count();
43 quick_repo_menu();
44 }
45 });
46
34
47 // update the counter when doing search
48 $('#repo_list_table').on( 'search.dt', function (e,settings) {
49 get_datatable_count();
50 });
35 });
51
36
52 // filter, filter both grids
37 // filter
53 $('#q_filter').on( 'keyup', function () {
38 $('#q_filter').on('keyup',
54 var repo_api = $('#repo_list_table').dataTable().api();
39 $.debounce(250, function() {
55 repo_api
40 $repoListTable.DataTable().search(
56 .columns(0)
41 $('#q_filter').val()
57 .search(this.value)
42 ).draw();
58 .draw();
43 })
59 });
44 );
60
45
61 // refilter table if page load via back button
62 $("#q_filter").trigger('keyup');
63
46
64 });
47 });
65
48
General Comments 0
You need to be logged in to leave comments. Login now