Allow editors to restore packages

This commit is contained in:
rubenwardy 2021-12-20 23:52:51 +00:00
parent 5932ac3c7c
commit 2e7d4277e1
3 changed files with 69 additions and 6 deletions

@ -95,3 +95,31 @@ def send_bulk_notification():
return redirect(url_for("admin.admin_page")) return redirect(url_for("admin.admin_page"))
return render_template("admin/send_bulk_notification.html", form=form) return render_template("admin/send_bulk_notification.html", form=form)
@bp.route("/admin/restore/", methods=["GET", "POST"])
@rank_required(UserRank.EDITOR)
def restore():
if request.method == "POST":
target = request.form["submit"]
if "Review" in target:
target = PackageState.READY_FOR_REVIEW
elif "Changes" in target:
target = PackageState.CHANGES_NEEDED
else:
target = PackageState.WIP
package = Package.query.get(request.form["package"])
if package is None:
flash("Unknown package", "danger")
else:
package.state = target
addAuditLog(AuditSeverity.EDITOR, current_user, f"Restored package to state {target.value}",
package.getURL("packages.view"), package)
db.session.commit()
return redirect(package.getURL("packages.view"))
deleted_packages = Package.query.filter(Package.state==PackageState.DELETED).join(Package.author).order_by(db.asc(User.username), db.asc(Package.name)).all()
return render_template("admin/restore.html", deleted_packages=deleted_packages)

@ -0,0 +1,30 @@
{% extends "base.html" %}
{% block title %}
Restore
{% endblock %}
{% block content %}
<div class="card w-50">
<h2 class="card-header">Restore Package</h2>
<form method="post" action="" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<div class="">
<select name="package" class="custom-select px-3" required>
<option disabled selected>-- please select --</option>
{% for p in deleted_packages %}
<option value="{{ p.id }}">
{{ p.author.username }} / {{ p.name }}&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;id={{ p.id }}
</option>
{% endfor %}
</select>
<div class="mt-3">
<input type="submit" name="submit" value="To Draft" class="col-sm-auto btn btn-warning" />
<input type="submit" name="submit" value="To Changes Needed" class="col-sm-auto btn btn-danger ml-2" />
<input type="submit" name="submit" value="To Ready for Review" class="col-sm-auto btn btn-success ml-2" />
</div>
</div>
</form>
</div>
{% endblock %}

@ -123,22 +123,27 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ url_for('todo.view_user', username=current_user.username) }}">To do list</a> <a class="nav-link" href="{{ url_for('todo.view_user', username=current_user.username) }}">To do list</a>
</li> </li>
{% if current_user.rank.atLeast(current_user.rank.MODERATOR) %} {% if current_user.rank.atLeast(current_user.rank.EDITOR) or check_global_perm(current_user, "CREATE_TAG") %}
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
{% endif %}
{% if current_user.rank.atLeast(current_user.rank.MODERATOR) %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.audit') }}">{{ _("Audit Log") }}</a></li> <li class="nav-item"><a class="nav-link" href="{{ url_for('admin.audit') }}">{{ _("Audit Log") }}</a></li>
{% if current_user.rank == current_user.rank.ADMIN %} {% if current_user.rank == current_user.rank.ADMIN %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.admin_page') }}">{{ _("Admin") }}</a></li> <li class="nav-item"><a class="nav-link" href="{{ url_for('admin.admin_page') }}">{{ _("Admin") }}</a></li>
{% else %} {% else %}
{% if check_global_perm(current_user, "EDIT_TAGS") %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.tag_list') }}">{{ _("Tag Editor") }}</a></li>
{% elif check_global_perm(current_user, "CREATE_TAG") %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.create_edit_tag') }}">{{ _("Create Tag") }}</a></li>
{% endif %}
{% if current_user.rank == current_user.rank.MODERATOR %} {% if current_user.rank == current_user.rank.MODERATOR %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.license_list') }}">{{ _("License Editor") }}</a></li> <li class="nav-item"><a class="nav-link" href="{{ url_for('admin.license_list') }}">{{ _("License Editor") }}</a></li>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if current_user.rank.atLeast(current_user.rank.EDITOR) %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.restore') }}">{{ _("Restore Package") }}</a></li>
{% endif %}
{% if check_global_perm(current_user, "EDIT_TAGS") %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.tag_list') }}">{{ _("Tag Editor") }}</a></li>
{% elif check_global_perm(current_user, "CREATE_TAG") %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin.create_edit_tag') }}">{{ _("Create Tag") }}</a></li>
{% endif %}
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ url_for('users.profile_edit', username=current_user.username) }}">Settings</a> <a class="nav-link" href="{{ url_for('users.profile_edit', username=current_user.username) }}">Settings</a>