Skip to content

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 14 commits into from
May 12, 2022
7 changes: 7 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,13 @@ def is_subproject(self):
"""Return whether or not this project is a subproject."""
return self.superprojects.exists()

@property
def superproject(self):
relationship = self.get_parent_relationship()
if relationship:
return relationship.parent
return None

@property
def alias(self):
"""Return the alias (as subproject) if it's a subproject.""" # noqa
Expand Down
4 changes: 3 additions & 1 deletion readthedocs/projects/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def get_project(self):
def get_context_data(self, **kwargs):
"""Add project to context data."""
context = super().get_context_data(**kwargs)
context['project'] = self.get_project()
project = self.get_project()
context['project'] = project
context['superproject'] = project and project.superproject
return context

def get_form(self, data=None, files=None, **kwargs):
Expand Down
5 changes: 1 addition & 4 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,7 @@ def get_success_url(self):

class ProjectRelationshipList(ProjectRelationListMixin, ProjectRelationshipMixin, ListView):

def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx['superproject'] = self.project.superprojects.first()
return ctx
pass


class ProjectRelationshipCreate(ProjectRelationshipMixin, CreateView):
Expand Down
21 changes: 16 additions & 5 deletions readthedocs/templates/projects/domain_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@
{% block project_edit_content_header %}{% trans "Domains" %}{% endblock %}

{% block project_edit_content %}
<p class="help_text">
{% blocktrans trimmed with docs_url='https://docs.readthedocs.io/page/custom_domains.html' %}
Configuring a custom domain allows you to serve your documentation from a domain other than "{{ default_domain }}". <a href="{{ docs_url }}">Learn more</a>.
{% endblocktrans %}
</p>
{% if superproject %}
{% url "projects_detail" superproject.slug as superproject_url %}
<p class="help_text">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think we have something like a class for a "warning" banner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not, not yet at least!

{% blocktrans trimmed with superproject=superproject.name superproject_url=superproject_url domain=project.subdomain %}
This project is a subproject of <a href="{{ superproject_url }}">{{ superproject }}</a>,
its documentation will always be served from the <code>{{ domain }}</code> domain.
<a href="https://docs.readthedocs.io/page/subprojects.html#custom-domain-on-subprojects">Learn more</a>.
{% endblocktrans %}
</p>
{% else %}
<p class="help_text">
{% blocktrans trimmed with docs_url='https://docs.readthedocs.io/page/custom_domains.html' %}
Configuring a custom domain allows you to serve your documentation from a domain other than "{{ default_domain }}". <a href="{{ docs_url }}">Learn more</a>.
{% endblocktrans %}
Comment on lines +25 to +28
Copy link
Member Author

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.

Copy link
Contributor

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.

</p>
{% endif %}

{% if object_list %}
<h3> {% trans "Existing Domains" %} </h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

{% if superproject %}
<p>
{% blocktrans trimmed with project=superproject.parent.name %}
{% blocktrans trimmed with project=superproject.name %}
This project is already configured as a subproject of {{ project }}.
Nested subprojects are not currently supported.
{% endblocktrans %}
</p>

<a href="{% url 'projects_subprojects' project_slug=superproject.parent.slug %}">
{% blocktrans trimmed with project=superproject.parent.name %}
<a href="{% url 'projects_subprojects' project_slug=superproject.slug %}">
{% blocktrans trimmed with project=superproject.name %}
View subprojects of {{ project }}
{% endblocktrans %}
</a>
Expand Down