From c77934e481b30f56e001266306bbd19c08c00602 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 11 2018 10:58:28 +0000 Subject: [PATCH 1/2] Properly retrieve the number of projects and forks users have On the user's public page we are using the limit and offset restriction on the query that is retrieving the list of projects and forks. So we would retrieve X projects and make the list of the user's project be of length X completely by-passing the pagination we added... Fixes https://pagure.io/pagure/issue/2881 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/app.py b/pagure/ui/app.py index 4ebb5ae..986260b 100644 --- a/pagure/ui/app.py +++ b/pagure/ui/app.py @@ -384,7 +384,13 @@ def view_user(username): if repos and acl: repos = _filter_acls(repos, acl, user) - repos_length = len(repos) + repos_length = pagure.lib.search_projects( + flask.g.session, + username=username, + fork=False, + exclude_groups=pagure_config.get('EXCLUDE_GROUP_INDEX'), + private=private, + count=True) forks = pagure.lib.search_projects( flask.g.session, @@ -393,7 +399,13 @@ def view_user(username): start=fork_start, limit=limit, private=private) - forks_length = len(forks) + + forks_length = pagure.lib.search_projects( + flask.g.session, + username=username, + fork=True, + private=private, + count=True) total_page_repos = int(ceil(repos_length / float(limit))) total_page_forks = int(ceil(forks_length / float(limit))) From ef2ad5c2894c20824f6d8c363665b3b9be64a398 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 11 2018 11:22:16 +0000 Subject: [PATCH 2/2] Add tests to check the pagination works as expected Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index f58335d..21a7fcc 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -86,6 +86,24 @@ class PagureFlaskApptests(tests.Modeltests): '', output.data) + @patch.dict('pagure.config.config', {'ITEM_PER_PAGE': 2}) + def test_view_user_repo_cnt(self): + """ Test the repo counts on the view_user endpoint. """ + tests.create_projects(self.session) + self.gitrepos = tests.create_projects_git( + pagure.config.config['GIT_FOLDER']) + + output = self.app.get('/user/pingou') + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Projects 3', + output.data) + self.assertIn( + '
  • page 1 of 2
  • ', output.data) + self.assertEqual(output.data.count('class="repo_desc"'), 2) + self.assertIn( + 'Forks 0', output.data) + def test_view_user(self): """ Test the view_user endpoint. """ @@ -109,6 +127,9 @@ class PagureFlaskApptests(tests.Modeltests): output.data) self.assertIn( 'Forks 0', output.data) + self.assertNotIn( + '
  • page 1 of 2
  • ', output.data) + self.assertEqual(output.data.count('class="repo_desc"'), 3) @patch.dict('pagure.config.config', {'ENABLE_UI_NEW_PROJECTS': False}) def test_new_project_when_turned_off_in_the_ui(self):