Skip to content

add a helper to project admin include for ultranormalization collisions #17124

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 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/unit/admin/views/test_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_administer_project_include_returns_project(db_request):
"project": project,
"prohibited": None,
"project_name": project.name,
"collisions": [],
}


Expand Down
20 changes: 18 additions & 2 deletions warehouse/admin/views/includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# limitations under the License.

from pyramid.view import view_config
from sqlalchemy import func
from sqlalchemy import func, select

from warehouse.accounts.models import User
from warehouse.packaging.models import ProhibitedProjectName, Project
Expand All @@ -34,8 +34,24 @@
.filter(ProhibitedProjectName.name == func.normalize_pep426_name(project_name))
.one_or_none()
)
collisions = request.db.scalars(
select(Project.name)
.filter(
func.ultranormalize_name(Project.name)
== func.ultranormalize_name(project_name)
)
.filter(
func.normalize_pep426_name(Project.name)
!= func.normalize_pep426_name(project_name)
)
).all()

return {"project": project, "project_name": project_name, "prohibited": prohibited}
return {
"project": project,
"project_name": project_name,
"prohibited": prohibited,
"collisions": collisions,
}


@view_config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@
-#}

{% if request.has_permission(Permissions.AdminProjectsRead) %}
<div class="admin-include split-layout split-layout--middle">
<span><b>Admin tools for project: <code>{{ project_name }}</code></b></span>
<div class="admin-include">
<div class="split-layout split-layout--middle">
<span><b>Admin tools for project: <code>{{ project_name }}</code></b></span>
<div>
<a href="{{ request.route_path('admin.project.detail', project_name=project_name) }}" class="button button--small button--primary package-description__edit-button" {{ "" if project else "disabled" }}>View project in admin</a>
{% if prohibited %}
<a href="{{ request.route_path('admin.prohibited_project_names.list', _query={'q': project_name}) }}" class="button button--small button--secondary package-description__edit-button">🚫 Prohibited</a>
{% else %}
<form class="form-inline" method="get" action="{{ request.route_path('admin.prohibited_project_names.add') }}">
<input name="project" type="hidden" value="{{ project_name }}">
<input name="comment" type="hidden" value="dependency confusion" id="prohibitedComment">
<button type="submit" class="button button--small button--warning" title="{{ "Submitting requires superuser privileges" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) or prohibited }}>Remove project as dep confusion</button>
</form>
<form class="form-inline" method="GET" action="{{ request.route_path('admin.prohibited_project_names.add') }}">
<input name="project" type="hidden" value="{{ project_name }}">
<input name="comment" type="hidden" value="malware" id="prohibitedComment">
<button type="submit" class="button button--small button--danger" title="{{ "Submitting requires superuser privileges" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) or prohibited }}>Remove project as malware</button>
</form>
{% endif %}
<a href="https://inspector.pypi.io/project/{{ project_name }}/" class="button button--small button--tertiary package-description__edit-button">🕵️ Inspect</a>
</div>
</div>
<div>
<a href="{{ request.route_path('admin.project.detail', project_name=project_name) }}" class="button button--small button--primary package-description__edit-button" {{ "" if project else "disabled" }}>View project in admin</a>
{% if prohibited %}
<a href="{{ request.route_path('admin.prohibited_project_names.list', _query={'q': project_name}) }}" class="button button--small button--secondary package-description__edit-button">🚫 Prohibited</a>
{% else %}
<form class="form-inline" method="get" action="{{ request.route_path('admin.prohibited_project_names.add') }}">
<input name="project" type="hidden" value="{{ project_name }}">
<input name="comment" type="hidden" value="dependency confusion" id="prohibitedComment">
<button type="submit" class="button button--small button--warning" title="{{ "Submitting requires superuser privileges" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) or prohibited }}>Remove project as dep confusion</button>
</form>
<form class="form-inline" method="GET" action="{{ request.route_path('admin.prohibited_project_names.add') }}">
<input name="project" type="hidden" value="{{ project_name }}">
<input name="comment" type="hidden" value="malware" id="prohibitedComment">
<button type="submit" class="button button--small button--danger" title="{{ "Submitting requires superuser privileges" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) or prohibited }}>Remove project as malware</button>
</form>
{% if collisions %}
<b>Ultranormalization collisions:
{% for collision in collisions %}
<code><a href="{{ request.route_path('admin.project.detail', project_name=collision) }}">{{ collision }}</a></code>{% if not loop.last %}, {% endif %}
{% endfor %}
</b>
{% endif %}
<a href="https://inspector.pypi.io/project/{{ project_name }}/" class="button button--small button--tertiary package-description__edit-button">🕵️ Inspect</a>
</div>
</div>
{% endif %}