-
Notifications
You must be signed in to change notification settings - Fork 54
2.4.0 fix multisite not all sites #1488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
9cdc2a2
c17a1e1
8858756
6fbe9de
8427adc
ccc0e0c
a851204
ec58221
de9b360
f79a7f1
dd38f6d
02755ca
5b33ed7
ff8ff63
cd37b53
98d5c1e
f197bfb
d1e4e3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
|
|
||
| from django.db.models import QuerySet | ||
|
|
||
| from rdmo.core.managers import ( | ||
| AvailabilityQuerySetMixin, | ||
| ForCatalogQuerySetMixin, | ||
| ForGroupsQuerySetMixin, | ||
| ForSiteQuerySetMixin, | ||
| ) | ||
|
|
||
|
|
||
| class ForProjectQuerySet(ForSiteQuerySetMixin, ForGroupsQuerySetMixin, ForCatalogQuerySetMixin, | ||
|
||
| AvailabilityQuerySetMixin, QuerySet): | ||
|
|
||
| def filter_for_project(self, project, user=None): | ||
| qs = ( | ||
| self.filter_for_site(project.site) | ||
| .filter_for_catalog(project.catalog) | ||
| .filter_for_groups(project.groups) | ||
| ) | ||
| if user is not None: | ||
| return qs.filter_availability(user) | ||
| else: | ||
| return qs.filter(available=True) | ||
|
|
||
| class ForProjectManagerMixin: | ||
|
|
||
| def get_queryset(self): | ||
| return ForProjectQuerySet(self.model, using=self._db) | ||
|
|
||
| def filter_for_project(self, project, user=None): | ||
| return self.get_queryset().filter_for_project(project, user=user) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import pytest | ||
|
|
||
| from rdmo.questions.models import Catalog | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def clear_sites_from_other_catalogs(settings): | ||
| # arrange, remove sites from the other catalogs | ||
| # for 'list': 'v1-projects:catalog-list' | ||
| # in non-multisite, they should appear | ||
| # however, in a multisite they should not appear | ||
| other_catalogs = Catalog.objects.exclude(sites=settings.SITE_ID) | ||
| assert set(other_catalogs.values_list('id',flat=True)) == {3,4} | ||
| for catalog in other_catalogs: | ||
| catalog.sites.clear() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import pytest | ||
|
|
||
| from django.urls import reverse | ||
|
|
||
| users = ( | ||
| ('owner', 'owner'), | ||
| ('manager', 'manager'), | ||
| ('author', 'author'), | ||
| ('guest', 'guest'), | ||
| ('api', 'api'), | ||
| ('user', 'user'), | ||
| ('site', 'site'), | ||
| ('anonymous', None), | ||
| ('foo-user','foo-user'), | ||
| ('foo-editor', 'foo-editor'), | ||
| ('bar-user','bar-user'), | ||
| ('bar-editor', 'bar-editor'), | ||
| ) | ||
|
|
||
| view_project_catalog_permission_map = { # id, available | ||
| 'owner': [(1, True)], | ||
| 'manager': [(1, True)], | ||
| 'author': [(1, True)], | ||
| 'guest': [(1, True)], | ||
| 'user': [(1, True)], | ||
| 'editor': [(1, True)], | ||
| 'reviewer': [(1, True)], | ||
| 'api': [(1, True),(2, False)], | ||
| 'site': [(1, True)], | ||
| 'foo-user': [(1, True)], | ||
| 'foo-editor': [(1, True)], | ||
| 'bar-user': [(1, True)], | ||
| 'bar-editor': [(1, True)], | ||
| } | ||
|
|
||
| urlnames = { | ||
| 'list': 'v1-projects:catalog-list', | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('username,password', users) | ||
| def test_list(db, settings, enable_multisite, client, username, password): | ||
| client.login(username=username, password=password) | ||
|
|
||
| url = reverse(urlnames['list']) | ||
| response = client.get(url) | ||
|
|
||
| if password: | ||
| assert response.status_code == 200 | ||
| data = response.json() | ||
| assert isinstance(data, list) | ||
| assert view_project_catalog_permission_map[username] == [(i['id'],i['available']) for i in data] | ||
| else: | ||
| assert response.status_code == 401 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('username,password', users) | ||
| def test_list_with_cleared_sites(db, settings, enable_multisite, clear_sites_from_other_catalogs, | ||
| client, username, password): | ||
| client.login(username=username, password=password) | ||
|
|
||
| url = reverse(urlnames['list']) | ||
| response = client.get(url) | ||
|
|
||
| if password: | ||
| assert response.status_code == 200 | ||
| data = response.json() | ||
| assert isinstance(data, list) | ||
| assert view_project_catalog_permission_map[username] == [(i['id'],i['available']) for i in data] | ||
| else: | ||
| assert response.status_code == 401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the fix for the issue #1481