Skip to content

Commit c578412

Browse files
committed
Refactor templates to handle multiple providers
1 parent ad85df6 commit c578412

File tree

3 files changed

+72
-55
lines changed

3 files changed

+72
-55
lines changed

warehouse/templates/manage/account/publishing.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{{ oidc_title() }}
2323
{% endblock %}
2424

25-
{% macro github_form(request, pending_github_pubisher_form) %}
25+
{% macro github_form(request, pending_github_publisher_form) %}
2626
{{ form_error_anchor(pending_github_publisher_form) }}
2727
<form method="POST" action="{{ request.route_path('manage.account.publishing') }}#errors">
2828
<input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
@@ -169,9 +169,7 @@ <h3>Pending publishers</h3>
169169
<tr>
170170
<th scope="col">{% trans %}Pending project name{% endtrans %}</th>
171171
<th scope="col">{% trans %}Publisher{% endtrans %}</th>
172-
<th scope="col">{% trans %}Repository{% endtrans %}</th>
173-
<th scope="col">{% trans %}Workflow{% endtrans %}</th>
174-
<th scope="col">{% trans %}Environment name{% endtrans %}</th>
172+
<th scope="col">{% trans %}Details{% endtrans %}</th>
175173
<th></th>
176174
</tr>
177175
</thead>

warehouse/templates/manage/manage_base.html

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,17 +535,20 @@ <h3 class="modal__title">{{ title }}</h3>
535535
{{ publisher.publisher_name }}
536536
</td>
537537
<td scope="row">
538-
<a href="{{ publisher.publisher_url() }}">{{ publisher.repository }}</a>
539-
</td>
540-
<td scope="row">
541-
{{ publisher.workflow_filename }}
542-
</td>
543-
<td scope="row">
544-
{% if publisher.environment %}
545-
{{ publisher.environment }}
538+
<small>
539+
{% if publisher.publisher_name == "GitHub" %}
540+
<b>Repository:</b> <a href="{{ publisher.publisher_url() }}">{{ publisher.repository }}</a><br>
541+
<b>Workflow:</b> {{ publisher.workflow_filename }}<br>
542+
<b>Environment name:</b>
543+
{% if publisher.environment %}
544+
{{ publisher.environment }}
545+
{% else %}
546+
<i>({% trans %}Any{% endtrans %})</i>
547+
{% endif %}
546548
{% else %}
547-
<i>({% trans %}Any{% endtrans %})</i>
549+
-
548550
{% endif %}
551+
</small>
549552
</td>
550553
<td scope="row">
551554
<input form="delete-publisher-{{ publisher.id }}" type="submit" value="{% trans %}Remove{% endtrans %}" class="button button--danger">

warehouse/templates/manage/project/publishing.html

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,7 @@
2020
{{ oidc_title() }}
2121
{% endblock %}
2222

23-
{% block main %}
24-
{% if testPyPI %}
25-
{% set title = "TestPyPI" %}
26-
{% else %}
27-
{% set title = "PyPI" %}
28-
{% endif %}
29-
30-
<div class="horizontal-section">
31-
<div class="site-container">
32-
<h1 class="page-title">{{ oidc_title() }}</h1>
33-
34-
{{ oidc_desc() }}
35-
36-
<h2>{% trans %}Manage current publishers{% endtrans %}</h2>
37-
{% if project.oidc_publishers %}
38-
<table class="table table--publisher-list">
39-
<caption class="sr-only">
40-
{% trans project_name=project.name %}OpenID Connect publishers associated with {{ project_name }}{% endtrans %}
41-
</caption>
42-
<thead>
43-
<tr>
44-
<th scope="col">{% trans %}Publisher{% endtrans %}</th>
45-
<th scope="col">{% trans %}Repository{% endtrans %}</th>
46-
<th scope="col">{% trans %}Workflow{% endtrans %}</th>
47-
<th scope="col">{% trans %}Environment name{% endtrans %}</th>
48-
<th></th>
49-
</tr>
50-
</thead>
51-
<tbody>
52-
{% for publisher in project.oidc_publishers %}
53-
{{ oidc_publisher_row(publisher) }}
54-
{% endfor %}
55-
</tbody>
56-
</table>
57-
{% else %}
58-
<p class="no-bottom-padding">{% trans %}No publishers are currently configured.{% endtrans %}</p>
59-
{% endif %}
60-
61-
<h2 class="no-bottom-padding">{% trans %}Add a new publisher{% endtrans %}</h2>
62-
{% if request.user.has_two_factor %}
63-
<h3>GitHub</h3>
64-
23+
{% macro github_form(request, github_publisher_form) %}
6524
<p>
6625
{% trans href="https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect" %}
6726
Read more about GitHub Actions's OpenID Connect support <a href="{{ href }}">here</a>.
@@ -146,7 +105,64 @@ <h3>GitHub</h3>
146105
<input type="submit" value="{% trans %}Add{% endtrans %}" class="button button--primary">
147106
</div>
148107
</form>
108+
{% endmacro %}
109+
110+
{% block main %}
111+
{% if testPyPI %}
112+
{% set title = "TestPyPI" %}
113+
{% else %}
114+
{% set title = "PyPI" %}
115+
{% endif %}
149116

117+
<div class="horizontal-section">
118+
<div class="site-container">
119+
<h1 class="page-title">{{ oidc_title() }}</h1>
120+
121+
{{ oidc_desc() }}
122+
123+
<h2>{% trans %}Manage current publishers{% endtrans %}</h2>
124+
{% if project.oidc_publishers %}
125+
<table class="table table--publisher-list">
126+
<caption class="sr-only">
127+
{% trans project_name=project.name %}OpenID Connect publishers associated with {{ project_name }}{% endtrans %}
128+
</caption>
129+
<thead>
130+
<tr>
131+
<th scope="col">{% trans %}Publisher{% endtrans %}</th>
132+
<th scope="col">{% trans %}Details{% endtrans %}</th>
133+
<th></th>
134+
</tr>
135+
</thead>
136+
<tbody>
137+
{% for publisher in project.oidc_publishers %}
138+
{{ oidc_publisher_row(publisher) }}
139+
{% endfor %}
140+
</tbody>
141+
</table>
142+
{% else %}
143+
<p class="no-bottom-padding">{% trans %}No publishers are currently configured.{% endtrans %}</p>
144+
{% endif %}
145+
146+
<h2 class="no-bottom-padding">{% trans %}Add a new publisher{% endtrans %}</h2>
147+
148+
{% if request.user.has_two_factor %}
149+
150+
{% set publishers = [("GitHub", github_form(request, github_publisher_form))] %}
151+
152+
<div class="horizontal-tabs" data-controller="horizontal-tabs" data-horizontal-tabs-index="0">
153+
<div class="horizontal-tabs__tabbar">
154+
{% for publisher_name, _ in publishers %}
155+
<button data-horizontal-tabs-target="tab" data-action="horizontal-tabs#change" class="tab {{ "is-active" if loop.first else "" }}">
156+
{{ publisher_name }}
157+
</button>
158+
{% endfor %}
159+
</div>
160+
{% for _, publisher_form in publishers %}
161+
<div class="horizontal-tabs__tabcontent {{ "is-hidden" if loop.first else "" }}" data-horizontal-tabs-target="tabPanel">
162+
{{ publisher_form }}
163+
</div>
164+
{% endfor %}
165+
</div>
150166
{% else %}{# user has not enabled 2FA #}
151167
<div class="callout-block callout-block--warning">
152168
{% trans href=request.route_path('manage.account.two-factor') %}

0 commit comments

Comments
 (0)