Skip to content

Commit

Permalink
Integrations: always show secret and show warning if secret is not set (
Browse files Browse the repository at this point in the history
#10908)

* Integrations: always show secret and show warning if secret is not set

This is a backport of
readthedocs/ext-theme#231.

Closes #10906.

* Updates from review

* Format
  • Loading branch information
stsewd authored Nov 22, 2023
1 parent 6723e59 commit 12305ba
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 86 deletions.
19 changes: 1 addition & 18 deletions readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,24 +863,7 @@ def get_success_url(self):


class IntegrationDetail(IntegrationMixin, DetailView):

# Some of the templates can be combined, we'll avoid duplicating templates
SUFFIX_MAP = {
Integration.GITHUB_WEBHOOK: 'webhook',
Integration.GITLAB_WEBHOOK: 'webhook',
Integration.BITBUCKET_WEBHOOK: 'webhook',
Integration.API_WEBHOOK: 'generic_webhook',
}

def get_template_names(self):
if self.template_name:
return self.template_name
integration_type = self.get_integration().integration_type
suffix = self.SUFFIX_MAP.get(integration_type, integration_type)
return (
'projects/integration_{}{}.html'
.format(suffix, self.template_name_suffix)
)
template_name = "projects/integration_webhook_detail.html"


class IntegrationDelete(IntegrationMixin, DeleteView):
Expand Down

This file was deleted.

107 changes: 57 additions & 50 deletions readthedocs/templates/projects/integration_webhook_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,75 +16,82 @@
{% endblock %}

{% block project_edit_content %}
{% if integration.has_sync and integration.can_sync %}
<p>
{% blocktrans trimmed %}
This integration is being managed automatically by Read the Docs. If
it isn't functioning correctly, try re-syncing the webhook:
{% endblocktrans %}
</p>
<p>
{% url 'api_webhook' project_slug=project.slug integration_pk=integration.pk as webhook_url %}
<a href="//{{ PRODUCTION_DOMAIN }}{{ webhook_url }}">{{ PRODUCTION_DOMAIN }}{{ webhook_url }}</a>
</p>
{% else %}
{% comment %}
Display information for manual webhook set up if either case is true:

* Integration doesn't have the ability to sync
* Integration has ability to sync, but we don't have the data returned
from the provider API on webhook creation (or webhook was automatically
created on new data from an old webhook)
{% endcomment %}
{% if integration.has_sync and not integration.can_sync %}
{% if integration.has_sync %}
{% if integration.can_sync %}
<p>
{% blocktrans trimmed %}
This integration is not managed by Read the Docs currently.
If this integration is not functioning correctly,
you can try re-syncing it. Otherwise you'll need to update
the configuration on your repository.
You can use the following address to manually configure this webhook.
This integration is being managed automatically by Read the Docs. If
it isn't functioning correctly, try re-syncing the webhook:
{% endblocktrans %}
</p>
{% else %}
{% comment %}
Display information for manual webhook set up if either case is true:

* Integration doesn't have the ability to sync
* Integration has ability to sync, but we don't have the data returned
from the provider API on webhook creation (or webhook was automatically
created on new data from an old webhook)
{% endcomment %}
<p>
{% blocktrans trimmed %}
To manually configure this webhook with your provider, use the
following address:
This integration is not managed by Read the Docs currently.
If this integration is not functioning correctly,
you can try re-syncing it. Otherwise you'll need to update
the configuration on your repository.
You can use the following address to manually configure this webhook.
{% endblocktrans %}
</p>
{% endif %}
{% endif %}

<p>
{% blocktrans trimmed %}
To manually configure this webhook with your provider, use the
following information:
{% endblocktrans %}
</p>

<div class="integration-details">
<p>
{% url 'api_webhook' project_slug=project.slug integration_pk=integration.pk as webhook_url %}
<a href="//{{ PRODUCTION_DOMAIN }}{{ webhook_url }}">{{ PRODUCTION_DOMAIN }}{{ webhook_url }}</a>
<p>
<label for="id_webhook_url">{% trans "Webhook URL:" %}</label>
{% url 'api_webhook' project_slug=project.slug integration_pk=integration.pk as webhook_url %}
<input type="text" id="id_webhook_url" value="https://{{ PRODUCTION_DOMAIN }}{{ webhook_url }}">
</p>
</p>

{% block integration_details %}
<div class="integration-details">
{% if integration.secret %}
<p>
<label for="id_secret">Secret:</label>
<input type="text" id="id_secret" value="{{ integration.secret }}">
</p>
{% else %}
<p class="empty">
{% blocktrans trimmed %}
This integration does not have a secret,
the authenticity of the incoming webhook cannot be verified.
<strong>Click on "Resync webhook" to generate a secret.</strong>
Read more in our <a href="https://blog.readthedocs.com/security-update-on-incoming-webhooks/">blog post</a>.
{% endblocktrans %}
</p>
{% endif %}
</div>
{% endblock %}
{% if not integration.has_sync %}
{# For generic webhooks #}
<p>
<label for="id_secret">{% trans "Secret:" %}</label>
<input type="text" id="id_secret" value="{{ integration.token }}">
</p>
{% elif integration.secret %}
<p>
<label for="id_secret">{% trans "Secret:" %}</label>
<input type="text" id="id_secret" value="{{ integration.secret }}">
</p>
{% endif %}
</div>

{% if integration.has_sync and not integration.secret %}
<p class="empty">
{% blocktrans trimmed %}
This integration does not have a secret,
the authenticity of the incoming webhook cannot be verified.
<strong>Click on "Resync webhook" to generate a secret.</strong>
Read more in our <a href="https://blog.readthedocs.com/security-update-on-incoming-webhooks/">blog post</a>.
{% endblocktrans %}
</p>
{% endif %}

{% if not integration.can_sync %}
<p>
{% blocktrans trimmed %}
For more information on manually configuring a webhook, refer to
<a href="https://docs.readthedocs.io/page/guides/setup/git-repo-automatic.html">
our webhook documentation
our webhook documentation.
</a>
{% endblocktrans %}
</p>
Expand Down

0 comments on commit 12305ba

Please sign in to comment.