Skip to content

Commit

Permalink
Simplify archive/unarchive UI buttons (#17532)
Browse files Browse the repository at this point in the history
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
  • Loading branch information
facutuesca and di authored Feb 3, 2025
1 parent fa5ff03 commit 07fc14b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 48 deletions.
31 changes: 17 additions & 14 deletions warehouse/admin/templates/admin/projects/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -613,20 +613,23 @@ <h3 class="card-title">Archive project</h3>
</div>

<div class="card-footer">
{% set can_be_archived = not project.lifecycle_status or project.lifecycle_status == "quarantine-exit" %}
{% set can_be_unarchived = project.lifecycle_status == "archived" %}
<form method="POST" action="{{ request.route_path('admin.project.unarchive', project_name=project.name) }}">
<input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
<div class="float-right">
<button type="submit" class="btn btn-primary" title="{{ 'Unarchiving requires superuser privileges' if not request.has_permission(Permissions.AdminProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsWrite) or not can_be_unarchived }}>Unarchive</button>
</div>
</form>
<form method="POST" action="{{ request.route_path('admin.project.archive', project_name=project.name) }}">
<input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
<div class="float-right">
<button type="submit" class="btn btn-primary" title="{{ 'Archiving requires superuser privileges' if not request.has_permission(Permissions.AdminProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsWrite) or not can_be_archived}}>Archive</button>
</div>
</form>
<div class="float-right">
{% if project.lifecycle_status == "archived" %}
<form method="POST" action="{{ request.route_path('admin.project.unarchive', project_name=project.name) }}">
<input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
<button type="submit" class="btn btn-primary" title="{{ 'Unarchiving requires superuser privileges' if not request.has_permission(Permissions.AdminProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsWrite) }}>
Unarchive project
</button>
</form>
{% else %}
<form method="POST" action="{{ request.route_path('admin.project.archive', project_name=project.name) }}">
<input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
<button type="submit" class="btn btn-primary {{ 'btn-disabled' if project.lifecycle_status == 'quarantine' }}" title="{{ 'Archiving requires superuser privileges' if not request.has_permission(Permissions.AdminProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsWrite) }}>
Archive project
</button>
</form>
{% endif %}
</div>
</div>
</div>

Expand Down
32 changes: 16 additions & 16 deletions warehouse/locale/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ msgstr ""
#: warehouse/templates/manage/project/release.html:182
#: warehouse/templates/manage/project/settings.html:87
#: warehouse/templates/manage/project/settings.html:136
#: warehouse/templates/manage/project/settings.html:394
#: warehouse/templates/manage/project/settings.html:393
#: warehouse/templates/manage/team/settings.html:84
msgid "Warning"
msgstr ""
Expand Down Expand Up @@ -6743,7 +6743,7 @@ msgstr ""

#: warehouse/templates/manage/project/settings.html:108
#: warehouse/templates/manage/project/settings.html:179
#: warehouse/templates/manage/project/settings.html:432
#: warehouse/templates/manage/project/settings.html:431
msgid "Project Name"
msgstr ""

Expand Down Expand Up @@ -6889,12 +6889,12 @@ msgid "Description of the purpose or content of the alternate repository."
msgstr ""

#: warehouse/templates/manage/project/settings.html:354
#: warehouse/templates/manage/project/settings.html:371
#: warehouse/templates/manage/project/settings.html:379
#: warehouse/templates/manage/project/settings.html:383
msgid "Archive project"
msgstr ""

#: warehouse/templates/manage/project/settings.html:359
#: warehouse/templates/manage/project/settings.html:357
#, python-format
msgid ""
"Archiving a project will prevent any new uploads. Before doing so, we "
Expand All @@ -6906,29 +6906,29 @@ msgid ""
"update the project's description by editing the README file."
msgstr ""

#: warehouse/templates/manage/project/settings.html:370
#: warehouse/templates/manage/project/settings.html:374
#: warehouse/templates/manage/project/settings.html:385
msgid "Unarchive project"
msgstr ""

#: warehouse/templates/manage/project/settings.html:380
msgid "Archiving a project will block any new file uploads"
#: warehouse/templates/manage/project/settings.html:375
msgid "Unarchiving a project will allow new file uploads."
msgstr ""

#: warehouse/templates/manage/project/settings.html:386
msgid "Unarchiving a project will allow new file uploads"
#: warehouse/templates/manage/project/settings.html:384
msgid "Archiving a project will block any new file uploads."
msgstr ""

#: warehouse/templates/manage/project/settings.html:392
#: warehouse/templates/manage/project/settings.html:432
#: warehouse/templates/manage/project/settings.html:391
#: warehouse/templates/manage/project/settings.html:431
msgid "Delete project"
msgstr ""

#: warehouse/templates/manage/project/settings.html:395
#: warehouse/templates/manage/project/settings.html:394
msgid "Deleting this project will:"
msgstr ""

#: warehouse/templates/manage/project/settings.html:400
#: warehouse/templates/manage/project/settings.html:399
#, python-format
msgid ""
"Irreversibly delete the project along with <a href=\"%(href)s\">%(count)s"
Expand All @@ -6939,15 +6939,15 @@ msgid_plural ""
msgstr[0] ""
msgstr[1] ""

#: warehouse/templates/manage/project/settings.html:406
#: warehouse/templates/manage/project/settings.html:405
msgid "Irreversibly delete the project"
msgstr ""

#: warehouse/templates/manage/project/settings.html:410
#: warehouse/templates/manage/project/settings.html:409
msgid "Make the project name available to <strong>any other PyPI</strong> user"
msgstr ""

#: warehouse/templates/manage/project/settings.html:412
#: warehouse/templates/manage/project/settings.html:411
msgid ""
"This user will be able to make new releases under this project name, so "
"long as the distribution filenames do not match filenames from a "
Expand Down
35 changes: 17 additions & 18 deletions warehouse/templates/manage/project/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ <h3>
<hr>

<h2>{% trans %}Archive project{% endtrans %}</h2>
{% set can_be_archived = not project.lifecycle_status or project.lifecycle_status == "quarantine-exit" %}
{% set can_be_unarchived = project.lifecycle_status == "archived" %}
<div class="callout-block callout-block--danger" data-controller="archive-confirm">
<p>
{% trans readme_description_href='https://packaging.python.org/guides/making-a-pypi-friendly-readme/'%}
Expand All @@ -367,24 +365,25 @@ <h2>{% trans %}Archive project{% endtrans %}</h2>
{% endtrans %}
</p>
</div>
<a href="#archive-project" class="button button--primary {{ 'button--disabled' if not can_be_archived }}">
{% trans %}Archive project{% endtrans %}
</a>
<a href="#unarchive-project" class="button button--primary {{ 'button--disabled' if not can_be_unarchived }}">
{% if project.lifecycle_status == "archived" %}
<a href="#unarchive-project" class="button button--primary">
{% trans %}Unarchive project{% endtrans %}
</a>

{% set action = request.route_path('manage.project.archive', project_name=project.name) %}
{% set slug = "archive-project" %}
{% set title = gettext("Archive project") %}
{% set extra_description = gettext("Archiving a project will block any new file uploads") %}
{{ confirm_modal(title=title, label=project.name, slug=slug, extra_description=extra_description, action=action, warning=False) }}

{% set action = request.route_path('manage.project.unarchive', project_name=project.name) %}
{% set slug = "unarchive-project" %}
{% set title = gettext("Unarchive project") %}
{% set extra_description = gettext("Unarchiving a project will allow new file uploads") %}
{{ confirm_modal(title=title, label=project.name, slug=slug, extra_description=extra_description, action=action, warning=False) }}
{% set action = request.route_path('manage.project.unarchive', project_name=project.name) %}
{% set slug = "unarchive-project" %}
{% set title = gettext("Unarchive project") %}
{% set extra_description = gettext("Unarchiving a project will allow new file uploads.") %}
{{ confirm_modal(title=title, label=project.name, slug=slug, extra_description=extra_description, action=action, warning=False) }}
{% else %}
<a href="#archive-project" class="button button--primary {{ 'button--disabled' if project.lifecycle_status == 'quarantine' }}">
{% trans %}Archive project{% endtrans %}
</a>
{% set action = request.route_path('manage.project.archive', project_name=project.name) %}
{% set slug = "archive-project" %}
{% set title = gettext("Archive project") %}
{% set extra_description = gettext("Archiving a project will block any new file uploads.") %}
{{ confirm_modal(title=title, label=project.name, slug=slug, extra_description=extra_description, action=action, warning=False) }}
{% endif %}

<hr>

Expand Down

0 comments on commit 07fc14b

Please sign in to comment.