Add warning when removing a package will break mods

This commit is contained in:
rubenwardy 2023-12-03 13:47:52 +00:00
parent 54a4eb2ac8
commit b80ce88bc0
2 changed files with 23 additions and 1 deletions

@ -460,7 +460,15 @@ def move_to_state(package):
@is_package_page @is_package_page
def remove(package): def remove(package):
if request.method == "GET": if request.method == "GET":
return render_template("packages/remove.html", package=package, # Find packages that will having missing hard deps after this action
broken_meta = MetaPackage.query.filter(MetaPackage.packages.contains(package),
~MetaPackage.packages.any(and_(Package.id != package.id, Package.state == PackageState.APPROVED)))
hard_deps = Package.query.filter(
Package.state == PackageState.APPROVED,
Package.dependencies.any(
and_(Dependency.meta_package_id.in_([x.id for x in broken_meta]), Dependency.optional == False)))
return render_template("packages/remove.html", package=package, hard_deps=hard_deps,
tabs=get_package_tabs(current_user, package), current_tab="remove") tabs=get_package_tabs(current_user, package), current_tab="remove")
reason = request.form.get("reason") or "?" reason = request.form.get("reason") or "?"

@ -21,6 +21,20 @@ Remove {{ package.title }}
</p> </p>
{% endif %} {% endif %}
{% if hard_deps %}
{% set hard_deps_links -%}
{%- for dep in hard_deps -%}
{%- if not loop.first and loop.length > 2 %}, {% endif -%}
{%- if loop.last and loop.length > 1 %} and {% endif -%}
<a href="{{ dep.get_url('packages.view') }}">{{ dep.title }}</a>
{%- endfor -%}
{%- endset %}
<p class="text-danger">
<i class="fas fa-exclamation-triangle me-2"></i>
{{ _("Removing this package will break the following mods: %(names)s", names=hard_deps_links) }}
</p>
{% endif %}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" /> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<div class="form-group mb-3"> <div class="form-group mb-3">