Prompt users to set maintenance state rather than removing

This commit is contained in:
rubenwardy 2024-06-07 22:57:55 +01:00
parent 22b1008593
commit 598c02eeff
3 changed files with 47 additions and 3 deletions

@ -458,6 +458,11 @@ def translation(package):
@login_required
@is_package_page
def remove(package):
if not package.check_perm(current_user, Permission.EDIT_PACKAGE):
abort(403)
states = [PackageDevState.AS_IS, PackageDevState.DEPRECATED, PackageDevState.LOOKING_FOR_MAINTAINER]
if request.method == "GET":
# Find packages that will having missing hard deps after this action
broken_meta = MetaPackage.query.filter(MetaPackage.packages.contains(package),
@ -467,9 +472,19 @@ def remove(package):
Package.dependencies.any(
and_(Dependency.meta_package_id.in_([x.id for x in broken_meta]), Dependency.optional == False))).all()
return render_template("packages/remove.html", package=package, hard_deps=hard_deps,
return render_template("packages/remove.html",
package=package, hard_deps=hard_deps, states=states,
tabs=get_package_tabs(current_user, package), current_tab="remove")
for state in states:
if state.name in request.form:
flash(gettext("Set state to %(state)s", state=state.title), "success")
package.dev_state = state
msg = "Set dev state of {} to {}".format(package.title, state.title)
add_audit_log(AuditSeverity.NORMAL, current_user, msg, package.get_url("packages.view"), package)
db.session.commit()
return redirect(package.get_url("packages.view"))
reason = request.form.get("reason") or "?"
if len(reason) > 500:
abort(400)

@ -112,6 +112,10 @@ class PackageDevState(enum.Enum):
def __str__(self):
return self.name
@property
def title(self):
return self.value
def get_desc(self):
if self == PackageDevState.WIP:
return "Under active development, and may break worlds/things without warning"

@ -1,12 +1,37 @@
{% extends "packages/package_base.html" %}
{% block title %}
Remove {{ package.title }}
{{ _("Remove %(title)s", title=package.title) }}
{% endblock %}
{% block content %}
<h2 class="mt-0">{{ self.title() }}</h2>
<form method="POST" action="">
<h2 class="mt-0">{{ _("Remove %(title)s", title=package.title) }}</h2>
<h3>{{ _("Change maintenance state") }}</h3>
<p>
{{ _("As an alternative to removing your package, you may wish to change the maintenance state.") }}
</p>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<ul>
{% for state in states %}
<li>
<strong>{{ state.title }}</strong>{% if state.get_desc() %}: {{ state.get_desc() }}{% endif %}
</li>
{% endfor %}
</ul>
<p>
{% for state in states %}
<input type="submit"
name="{{ state.name }}" value="{{ state.title }}"
title="{{ state.get_desc() }}" class="btn btn-primary me-2" />
{% endfor %}
</p>
</form>
<form method="POST" action="" class="mt-5">
<h3>{{ _("Remove") }}</h3>
<p>
{{ _("In order to avoid data loss, you cannot permanently delete packages.
You can remove them from ContentDB, which will cause them to not be