From 8ee98c1c48f69c1a1f0eee07f1a313174ead0935 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 31 May 2018 17:34:17 -0400 Subject: [PATCH] Show starred public repositories in the starred repos list We forgot to check if the repository was public in the filter Fixes https://jira.coreos.com/browse/QUAY-857 --- data/model/repository.py | 2 +- endpoints/api/repository_models_pre_oci.py | 3 +- endpoints/api/test/test_repository.py | 34 +++++++++++++++++++--- test/test_sni.py | 4 +++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 test/test_sni.py diff --git a/data/model/repository.py b/data/model/repository.py index 33a1da6b1..c9b640703 100644 --- a/data/model/repository.py +++ b/data/model/repository.py @@ -13,7 +13,7 @@ from data.database import ( Repository, Namespace, RepositoryTag, Star, Image, ImageStorage, User, Visibility, Tag, RepositoryPermission, RepositoryActionCount, Role, RepositoryAuthorizedEmail, TagManifest, DerivedStorageForImage, Label, TagManifestLabel, db_for_update, get_epoch_timestamp, - db_random_func, db_concat_func, RepositorySearchScore) + db_random_func, db_concat_func, RepositorySearchScore, RepositoryKind) from data.text import prefix_search from util.itertoolrecipes import take diff --git a/endpoints/api/repository_models_pre_oci.py b/endpoints/api/repository_models_pre_oci.py index 4dd7e5524..c42bd7ab7 100644 --- a/endpoints/api/repository_models_pre_oci.py +++ b/endpoints/api/repository_models_pre_oci.py @@ -60,7 +60,8 @@ class PreOCIModel(RepositoryDataInterface): if starred: # Return the full list of repos starred by the current user that are still visible to them. def can_view_repo(repo): - return ReadRepositoryPermission(repo.namespace_user.username, repo.name).can() + can_view = ReadRepositoryPermission(repo.namespace_user.username, repo.name).can() + return can_view or model.repository.is_repository_public(repo) unfiltered_repos = model.repository.get_user_starred_repositories(user, kind_filter=repo_kind) diff --git a/endpoints/api/test/test_repository.py b/endpoints/api/test/test_repository.py index 4addeffb9..d98153a5c 100644 --- a/endpoints/api/test/test_repository.py +++ b/endpoints/api/test/test_repository.py @@ -2,8 +2,9 @@ import pytest from mock import patch, ANY, MagicMock +from data import model from endpoints.api.test.shared import conduct_api_call -from endpoints.api.repository import RepositoryTrust, Repository +from endpoints.api.repository import RepositoryTrust, Repository, RepositoryList from endpoints.test.shared import client_with_identity from features import FeatureNameValue @@ -67,6 +68,31 @@ def test_signing_disabled(client): assert not response['trust_enabled'] -def test_sni_support(): - import ssl - assert ssl.HAS_SNI +def test_list_starred_repos(client): + with client_with_identity('devtable', client) as cl: + params = { + 'starred': 'true', + } + + response = conduct_api_call(cl, RepositoryList, 'GET', params).json + repos = {r['namespace'] + '/' + r['name'] for r in response['repositories']} + assert 'devtable/simple' in repos + assert 'public/publicrepo' not in repos + + # Add a star on publicrepo. + publicrepo = model.repository.get_repository('public', 'publicrepo') + model.repository.star_repository(model.user.get_user('devtable'), publicrepo) + + # Ensure publicrepo shows up. + response = conduct_api_call(cl, RepositoryList, 'GET', params).json + repos = {r['namespace'] + '/' + r['name'] for r in response['repositories']} + assert 'devtable/simple' in repos + assert 'public/publicrepo' in repos + + # Make publicrepo private and ensure it disappears. + model.repository.set_repository_visibility(publicrepo, 'private') + + response = conduct_api_call(cl, RepositoryList, 'GET', params).json + repos = {r['namespace'] + '/' + r['name'] for r in response['repositories']} + assert 'devtable/simple' in repos + assert 'public/publicrepo' not in repos diff --git a/test/test_sni.py b/test/test_sni.py new file mode 100644 index 000000000..c3ec39091 --- /dev/null +++ b/test/test_sni.py @@ -0,0 +1,4 @@ +import ssl + +def test_sni_support(): + assert ssl.HAS_SNI