-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Custom domains: don't allow adding a custom domain on subprojects #8953
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4d14403
Custom domains: warn users about adding a custom domain to a subproject
stsewd 7901c51
Merge branch 'master' into warn-users-domains-on-subprojects
stsewd 73d1f3d
Lint
stsewd 74c69cd
Lint
stsewd 85ea9a8
Lint
stsewd 60ca4cd
Don't allow adding/editing domains on subprojects
stsewd 5e1f5fb
Merge branch 'main' into warn-users-domains-on-subprojects
stsewd 403d1e6
Update docs
stsewd 5a8b926
Tests
stsewd 7fb3fb1
Fix tests
stsewd 3a70a80
Fix tests
stsewd 044bd0e
Merge branch 'main' into warn-users-domains-on-subprojects
stsewd c0dba16
Update readthedocs/templates/projects/domain_list.html
stsewd 45f5c88
Merge branch 'main' into warn-users-domains-on-subprojects
stsewd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
from django_dynamic_fixture import get | ||
|
||
from readthedocs.organizations.models import Organization | ||
from readthedocs.projects.models import Domain, Project | ||
|
||
|
||
@override_settings(RTD_ALLOW_ORGANIZATIONS=False) | ||
class TestDomainViews(TestCase): | ||
def setUp(self): | ||
self.user = get(User, username="user") | ||
self.project = get(Project, users=[self.user], slug="project") | ||
self.subproject = get(Project, users=[self.user], slug="subproject") | ||
self.project.add_subproject(self.subproject) | ||
self.client.force_login(self.user) | ||
|
||
def test_domain_creation(self): | ||
self.assertEqual(self.project.domains.count(), 0) | ||
|
||
resp = self.client.post( | ||
reverse("projects_domains_create", args=[self.project.slug]), | ||
data={"domain": "test.example.com"}, | ||
) | ||
self.assertEqual(resp.status_code, 302) | ||
self.assertEqual(self.project.domains.count(), 1) | ||
|
||
domain = self.project.domains.first() | ||
self.assertEqual(domain.domain, "test.example.com") | ||
|
||
def test_domain_deletion(self): | ||
domain = get(Domain, project=self.project, domain="test.example.com") | ||
self.assertEqual(self.project.domains.count(), 1) | ||
|
||
resp = self.client.post( | ||
reverse("projects_domains_delete", args=[self.project.slug, domain.pk]), | ||
) | ||
self.assertEqual(resp.status_code, 302) | ||
self.assertEqual(self.project.domains.count(), 0) | ||
|
||
def test_domain_edit(self): | ||
domain = get( | ||
Domain, project=self.project, domain="test.example.com", canonical=False | ||
) | ||
|
||
self.assertEqual(domain.canonical, False) | ||
resp = self.client.post( | ||
reverse("projects_domains_edit", args=[self.project.slug, domain.pk]), | ||
data={"canonical": True}, | ||
) | ||
self.assertEqual(resp.status_code, 302) | ||
self.assertEqual(self.project.domains.count(), 1) | ||
|
||
domain = self.project.domains.first() | ||
self.assertEqual(domain.domain, "test.example.com") | ||
self.assertEqual(domain.canonical, True) | ||
|
||
def test_adding_domain_on_subproject(self): | ||
self.assertEqual(self.subproject.domains.count(), 0) | ||
|
||
resp = self.client.post( | ||
reverse("projects_domains_create", args=[self.subproject.slug]), | ||
data={"domain": "test.example.com"}, | ||
) | ||
self.assertEqual(resp.status_code, 401) | ||
self.assertEqual(self.subproject.domains.count(), 0) | ||
|
||
def test_delete_domain_on_subproject(self): | ||
domain = get(Domain, project=self.subproject, domain="test.example.com") | ||
self.assertEqual(self.subproject.domains.count(), 1) | ||
|
||
resp = self.client.post( | ||
reverse("projects_domains_delete", args=[self.subproject.slug, domain.pk]), | ||
) | ||
self.assertEqual(resp.status_code, 302) | ||
self.assertEqual(self.subproject.domains.count(), 0) | ||
|
||
def test_edit_domain_on_subproject(self): | ||
domain = get( | ||
Domain, project=self.subproject, domain="test.example.com", canonical=False | ||
) | ||
|
||
self.assertEqual(domain.canonical, False) | ||
resp = self.client.post( | ||
reverse("projects_domains_edit", args=[self.subproject.slug, domain.pk]), | ||
data={"canonical": True}, | ||
) | ||
self.assertEqual(resp.status_code, 401) | ||
self.assertEqual(self.subproject.domains.count(), 1) | ||
|
||
domain = self.subproject.domains.first() | ||
self.assertEqual(domain.domain, "test.example.com") | ||
self.assertEqual(domain.canonical, False) | ||
|
||
|
||
@override_settings(RTD_ALLOW_ORGANIZATIONS=True) | ||
class TestDomainViewsWithOrganizations(TestDomainViews): | ||
def setUp(self): | ||
super().setUp() | ||
self.org = get( | ||
Organization, owners=[self.user], projects=[self.project, self.subproject] | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
so, not sure if we should show both messages when this is a subproject.
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.
I think it makes sense to just show one block. We have discussed on another issue that a better UX would be to show the form as disabled, but we can come back to this as well. There are maybe a few patterns to figure out there.