Skip to content

Commit dbae193

Browse files
authored
fix(admin): confirm malware observations have URLs (#18725)
Fixes #18724 Fixes WAREHOUSE-PRODUCTION-287 Signed-off-by: Mike Fiedler <[email protected]>
1 parent ab60539 commit dbae193

File tree

2 files changed

+81
-38
lines changed

2 files changed

+81
-38
lines changed

warehouse/admin/templates/admin/malware_reports/detail.html

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,29 +211,53 @@ <h4 class="modal-title">Remove Malware</h4>
211211
</button>
212212
</div>
213213
<div class="modal-body">
214-
<p>
215-
You are confirming that this Malware Observation for <code>{{ report.related.name }}</code>
216-
is valid and malware.
217-
</p>
218-
<p>This will remove the Project, freeze the Owner's account, prohibit the Project name from being reused.</p>
219-
<div class="form-group col-sm-12">
220-
<label for="confirm_project_name">
221-
Are you sure you want to confirm
222-
<strong><code>{{ report.related.name }}</code></strong>
223-
<button type="button"
224-
class="copy-text"
225-
data-copy-text="{{ report.related.name }}">
226-
<i class="fa fa-copy" aria-hidden="true"></i>
227-
</button>
228-
as malware?
229-
</label>
230-
<input name="project" type="hidden" value="{{ report.related.name }}">
231-
<input name="confirm_project_name" id="confirm_project_name" class="form-control" type="text" placeholder="Enter project name to confirm" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsDelete) }} autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
232-
</div>
214+
{% set project_malware_reports = report.related.observations | selectattr("kind", "equalto", "is_malware") | list %}
215+
{% set missing_urls = project_malware_reports | selectattr("additional.helpscout_conversation_url", "undefined") | list %}
216+
{% if missing_urls %}
217+
<div class="alert alert-warning">
218+
<i class="fa fa-exclamation-triangle"></i>
219+
<strong>Action Blocked:</strong> {{ missing_urls | length }} observation(s) for this project are missing HelpScout conversation URLs.
220+
Please add HelpScout conversation URLs to all observations before removing as malware.
221+
</div>
222+
<p>Missing URLs for observations:</p>
223+
<ul>
224+
{% for missing_report in missing_urls %}
225+
<li>
226+
{% if missing_report.id == report.id %}
227+
<strong>Observation {{ missing_report.id | string | truncate(8, False, '...') }} - {{ missing_report.created }} (current)</strong>
228+
{% else %}
229+
<a href="{{ request.route_path('admin.malware_reports.detail', observation_id=missing_report.id) }}">
230+
Observation {{ missing_report.id | string | truncate(8, False, '...') }} - {{ missing_report.created }}
231+
</a>
232+
{% endif %}
233+
</li>
234+
{% endfor %}
235+
</ul>
236+
{% else %}
237+
<p>
238+
You are confirming that this Malware Observation for <code>{{ report.related.name }}</code>
239+
is valid and malware.
240+
</p>
241+
<p>This will remove the Project, freeze the Owner's account, prohibit the Project name from being reused.</p>
242+
<div class="form-group col-sm-12">
243+
<label for="confirm_project_name">
244+
Are you sure you want to confirm
245+
<strong><code>{{ report.related.name }}</code></strong>
246+
<button type="button"
247+
class="copy-text"
248+
data-copy-text="{{ report.related.name }}">
249+
<i class="fa fa-copy" aria-hidden="true"></i>
250+
</button>
251+
as malware?
252+
</label>
253+
<input name="project" type="hidden" value="{{ report.related.name }}">
254+
<input name="confirm_project_name" id="confirm_project_name" class="form-control" type="text" placeholder="Enter project name to confirm" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsDelete) }} autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
255+
</div>
256+
{% endif %}
233257
</div>
234258
<div class="modal-footer justify-content-between">
235259
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
236-
<button type="submit" class="btn btn-danger">Verdict: Remove Malware</button>
260+
<button type="submit" class="btn btn-danger" {% if missing_urls %}disabled{% endif %}>Verdict: Remove Malware</button>
237261
</div>
238262
</div>
239263
</form>

warehouse/admin/templates/admin/malware_reports/project_list.html

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,27 +246,46 @@ <h4 class="modal-title">Remove Malware</h4>
246246
</button>
247247
</div>
248248
<div class="modal-body">
249-
<p>
250-
You are confirming that any Malware Observations for <code>{{ project.name }}</code>
251-
are valid and malware.
252-
</p>
253-
<p>This will remove the Project, freeze the Owner's account, prohibit the Project name from being reused.</p>
254-
<div class="form-group col-sm-12">
255-
<label for="confirm_project_name">
256-
Are you sure you want to confirm
257-
<strong><code>{{ project.name }}</code></strong>
258-
<button type="button" class="copy-text" data-copy-text="{{ project.name }}">
259-
<i class="fa fa-copy" aria-hidden="true"></i>
260-
</button>
261-
as malware?
262-
</label>
263-
<input name="project" type="hidden" value="{{ project.name }}">
264-
<input name="confirm_project_name" id="confirm_project_name" class="form-control" type="text" placeholder="Enter project name to confirm" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsDelete) }} autocomplete="off" autocorrect="off" autocapitalize="off">
265-
</div>
249+
{% set missing_urls = malware_reports | selectattr("additional.helpscout_conversation_url", "undefined") | list %}
250+
{% if missing_urls %}
251+
<div class="alert alert-warning">
252+
<i class="fa fa-exclamation-triangle"></i>
253+
<strong>Action Blocked:</strong> {{ missing_urls | length }} observation(s) are missing HelpScout conversation URLs.
254+
Please add HelpScout conversation URLs to all observations before removing as malware.
255+
</div>
256+
<p>Missing URLs for observations:</p>
257+
<ul>
258+
{% for report in missing_urls %}
259+
<li>
260+
<a href="{{ request.route_path('admin.malware_reports.detail', observation_id=report.id) }}">
261+
Observation {{ report.id | string | truncate(8, False, '...') }} - {{ report.created }}
262+
</a>
263+
</li>
264+
{% endfor %}
265+
</ul>
266+
{% else %}
267+
<p>
268+
You are confirming that any Malware Observations for <code>{{ project.name }}</code>
269+
are valid and malware.
270+
</p>
271+
<p>This will remove the Project, freeze the Owner's account, prohibit the Project name from being reused.</p>
272+
<div class="form-group col-sm-12">
273+
<label for="confirm_project_name">
274+
Are you sure you want to confirm
275+
<strong><code>{{ project.name }}</code></strong>
276+
<button type="button" class="copy-text" data-copy-text="{{ project.name }}">
277+
<i class="fa fa-copy" aria-hidden="true"></i>
278+
</button>
279+
as malware?
280+
</label>
281+
<input name="project" type="hidden" value="{{ project.name }}">
282+
<input name="confirm_project_name" id="confirm_project_name" class="form-control" type="text" placeholder="Enter project name to confirm" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsDelete) }} autocomplete="off" autocorrect="off" autocapitalize="off">
283+
</div>
284+
{% endif %}
266285
</div>
267286
<div class="modal-footer justify-content-between">
268287
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
269-
<button type="submit" class="btn btn-danger">Verdict: Remove Malware</button>
288+
<button type="submit" class="btn btn-danger" {% if missing_urls %}disabled{% endif %}>Verdict: Remove Malware</button>
270289
</div>
271290
</div>
272291
</form>

0 commit comments

Comments
 (0)