Skip to content

Commit

Permalink
Add warning when removing a package will break mods
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Dec 3, 2023
1 parent 54a4eb2 commit b80ce88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/blueprints/packages/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,15 @@ def move_to_state(package):
@is_package_page
def remove(package):
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")

reason = request.form.get("reason") or "?"
Expand Down
14 changes: 14 additions & 0 deletions app/templates/packages/remove.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ <h2 class="mt-0">{{ _("Remove %(title)s", title=package.title) }}</h2>
</p>
{% 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() }}" />

<div class="form-group mb-3">
Expand Down

0 comments on commit b80ce88

Please sign in to comment.