admin/users: force delete paper key
This commit is contained in:
parent
f8afea4e70
commit
2418c8e124
3 changed files with 82 additions and 0 deletions
|
|
@ -27,6 +27,7 @@ pub fn routes() -> Vec<Route> {
|
|||
admin_users_view,
|
||||
admin_users_archive,
|
||||
admin_users_password_reset,
|
||||
admin_users_paper_key_reset,
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -329,3 +329,40 @@ pub async fn admin_users_password_reset(
|
|||
flash_message,
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Debug, FromForm)]
|
||||
pub struct PaperKeyResetForm {
|
||||
pub delete: Option<bool>,
|
||||
}
|
||||
|
||||
#[post("/admin/users/<id>/paper_key", data = "<form>")]
|
||||
pub async fn admin_users_paper_key_reset(
|
||||
_admin_not_current: JwtAdminNotCurrent,
|
||||
mut db: Connection<Database>,
|
||||
id: RocketUserID,
|
||||
form: Form<PaperKeyResetForm>,
|
||||
) -> Result<Flash<Redirect>> {
|
||||
let (flash_kind, flash_message) = match form.delete {
|
||||
Some(true) => {
|
||||
let mut transaction = db.begin().await?;
|
||||
|
||||
// Get user
|
||||
let user = User::get_by_id(&mut transaction, &id.0)
|
||||
.await?
|
||||
.ok_or_else(|| Error::not_found("Could not find user"))?;
|
||||
|
||||
user.set_paper_key(&mut transaction, None).await?;
|
||||
|
||||
transaction.commit().await?;
|
||||
|
||||
(FlashKind::Success, "Paper key has been deleted.")
|
||||
}
|
||||
_ => (FlashKind::Warning, "Nothing to do."),
|
||||
};
|
||||
|
||||
Ok(Flash::new(
|
||||
Redirect::to(uri!(admin_users_view(id))),
|
||||
flash_kind,
|
||||
flash_message,
|
||||
))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -385,6 +385,50 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Paper key reset -->
|
||||
<div class="modal modal-blur" tabindex="-1" id="modal-paper-key">
|
||||
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-status bg-danger"></div>
|
||||
|
||||
<form action="{{ local.id }}/paper_key" method="post">
|
||||
|
||||
<div class="modal-body text-center py-4">
|
||||
|
||||
<div class="text-danger mb-2">
|
||||
{% include "icons/alert-triangle-large" %}
|
||||
</div>
|
||||
|
||||
<h3>Do you want to delete the paper key for this user?</h3>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<div class="w-100">
|
||||
<div class="row">
|
||||
|
||||
<div class="col">
|
||||
<a href="#" class="btn w-100" data-bs-dismiss="modal">Cancel</a>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<button type="submit" name="delete" value="true"
|
||||
class="btn btn-danger w-100">
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
{% block libs_js %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue