Skip to content

Commit 6fefaa1

Browse files
authored
Store observation kind when prohibiting project names (#17731)
* Store observation kind when prohibiting project names * Add migration
1 parent 714bf2c commit 6fefaa1

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed

warehouse/admin/templates/admin/prohibited_project_names/list.html

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<th>Prohibited by</th>
4646
<th>Prohibited on</th>
4747
<th>Comment</th>
48+
<th>Observation kind</th>
4849
<th>Actions</th>
4950
</tr>
5051
</thead>
@@ -62,6 +63,7 @@
6263
</td>
6364
<td>{{ prohibited_project_name.created|format_datetime() }}</td>
6465
<td>{{ prohibited_project_name.comment }}</td>
66+
<td>{{ prohibited_project_name.observation_kind }}</td>
6567
<td>
6668
<form method="POST" action="{{ request.route_path('admin.prohibited_project_names.remove') }}">
6769
<input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">

warehouse/admin/views/malware_reports.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ def malware_reports_project_verdict_remove_malware(project, request):
187187
}
188188

189189
# prohibit the project
190-
prohibit_and_remove_project(project, request, comment="malware")
190+
prohibit_and_remove_project(
191+
project, request, observation_kind=ObservationKind.IsMalware.value[0]
192+
)
191193
# tell helpdesk to add a tag to all related conversations
192194
helpdesk_service = request.find_service(IHelpDeskService)
193195
for observation in observations:
@@ -325,7 +327,9 @@ def remove_malware_for_project(request):
325327
tag="removed_as_malware_via_admin",
326328
)
327329

328-
prohibit_and_remove_project(project, request, comment="malware")
330+
prohibit_and_remove_project(
331+
project, request, observation_kind=ObservationKind.IsMalware.value[0]
332+
)
329333

330334
request.session.flash(
331335
f"Malware Project {project.name} removed and report updated",

warehouse/admin/views/prohibited_project_names.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def add_prohibited_project_names(request):
250250
)
251251
return HTTPSeeOther(request.route_path("admin.prohibited_project_names.list"))
252252

253-
prohibit_and_remove_project(project_name, request, comment)
253+
prohibit_and_remove_project(project_name, request, comment=comment)
254254

255255
request.session.flash(f"Prohibited Project Name {project_name!r}", queue="success")
256256

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
"""
13+
Add observation_kid to prohibited_project_names
14+
15+
Revision ID: db7633e75422
16+
Revises: 635b80625fc9
17+
Create Date: 2025-03-03 20:21:55.738828
18+
"""
19+
20+
import sqlalchemy as sa
21+
22+
from alembic import op
23+
24+
revision = "db7633e75422"
25+
down_revision = "635b80625fc9"
26+
27+
28+
def upgrade():
29+
op.add_column(
30+
"prohibited_project_names",
31+
sa.Column(
32+
"observation_kind",
33+
sa.String(),
34+
nullable=True,
35+
comment="If this was created via an observation, the kind of observation",
36+
),
37+
)
38+
39+
40+
def downgrade():
41+
op.drop_column("prohibited_project_names", "observation_kind")

warehouse/packaging/models.py

+4
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,10 @@ class ProhibitedProjectName(db.Model):
10711071
)
10721072
prohibited_by: Mapped[User] = orm.relationship()
10731073
comment: Mapped[str] = mapped_column(server_default="")
1074+
observation_kind: Mapped[str] = mapped_column(
1075+
nullable=True,
1076+
comment="If this was created via an observation, the kind of observation",
1077+
)
10741078

10751079

10761080
class ProjectMacaroonWarningAssociation(db.Model):

warehouse/utils/project.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def confirm_project(
7474

7575

7676
def prohibit_and_remove_project(
77-
project: Project | str, request, comment: str, flash: bool = True
77+
project: Project | str,
78+
request,
79+
comment: str | None = None,
80+
observation_kind: str | None = None,
81+
flash: bool = True,
7882
):
7983
"""
8084
View helper to prohibit and remove a project.
@@ -84,7 +88,10 @@ def prohibit_and_remove_project(
8488
# Add our requested prohibition.
8589
request.db.add(
8690
ProhibitedProjectName(
87-
name=project_name, comment=comment, prohibited_by=request.user
91+
name=project_name,
92+
comment=comment,
93+
observation_kind=observation_kind,
94+
prohibited_by=request.user,
8895
)
8996
)
9097
# Go through and delete the project and everything related to it so that

0 commit comments

Comments
 (0)