diff --git a/files/assets/js/admin/alts.js b/files/assets/js/admin/alts.js index 7477d0753..d3c403306 100644 --- a/files/assets/js/admin/alts.js +++ b/files/assets/js/admin/alts.js @@ -1,13 +1,7 @@ function submitAddAlt(element, username) { - const isLinking = element.id == 'add-alt-form-link'; - const otherElement = isLinking ? document.getElementById('add-alt-form-delink') : document.getElementById('add-alt-form-link'); - if (!otherElement) return; element.disabled = true; - otherElement.disabled = true; element.classList.add('disabled'); - otherElement.classList.add('disabled'); const form = new FormData(); - if (!isLinking) form.append('deleted', 'true'); form.append('other_username', document.getElementById('link-input-other').value); const xhr = createXhrWithFormKey(`/@${username}/alts/`, 'POST', form); xhr[0].onload = function() { @@ -24,10 +18,17 @@ function submitAddAlt(element, username) { } else { showToast(false, getMessageFromJsonData(false, data)); element.disabled = false; - otherElement.disabled = false; element.classList.remove('disabled'); - otherElement.classList.remove('disabled'); } } xhr[0].send(xhr[1]); } + +function delink(t, url) { + postToast(t, url, + {}, + () => { + t.parentElement.parentElement.remove() + } + ); +} diff --git a/files/routes/admin.py b/files/routes/admin.py index f9880e18a..d1c3a7280 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -641,35 +641,27 @@ def admin_add_alt(v:User, username): g.db.add(ma) return {"message": f"{word} @{user1.username} and @{user2.username} successfully!"} -@app.route('/@/alts//deleted', methods=["PUT", "DELETE"]) +@app.post('/@/alts//deleted') @limiter.limit(DEFAULT_RATELIMIT_SLOWER) @limiter.limit(DEFAULT_RATELIMIT_SLOWER, key_func=get_ID) @admin_level_required(PERMS['USER_LINK']) def admin_delink_relink_alt(v:User, username, other): - is_delinking = request.method == 'PUT' # we're adding the 'deleted' state if a PUT request user1 = get_user(username) user2 = get_account(other) ids = [user1.id, user2.id] a = g.db.query(Alt).filter(Alt.user1.in_(ids), Alt.user2.in_(ids)).one_or_none() if not a: abort(404) - a.deleted = is_delinking - g.db.add(a) - g.db.flush() - check_for_alts(user1) - check_for_alts(user2) - word = 'Delinked' if is_delinking else 'Relinked' - ma_word = 'delink' if is_delinking else 'link' - note = f'from @{user2.username}' if is_delinking else f'with @{user2.username} (relinked)' + g.db.delete(a) ma = ModAction( - kind=f"{ma_word}_accounts", + kind=f"delink_accounts", user_id=v.id, target_user_id=user1.id, - _note=note + _note=f'from @{user2.username}' ) g.db.add(ma) - return {"message": f"{word} @{user1.username} and @{user2.username} successfully!"} + return {"message": f"Delinked @{user1.username} and @{user2.username} successfully!"} @app.get("/admin/removed/posts") diff --git a/files/templates/admin/alts.html b/files/templates/admin/alts.html index a6c277005..91f6e4114 100644 --- a/files/templates/admin/alts.html +++ b/files/templates/admin/alts.html @@ -26,9 +26,7 @@ # Name Account Created - Alt Link Created Manual - Delinked Actions @@ -37,11 +35,9 @@ {{loop.index}} {% include "user_in_table.html" %} {{user.created_utc|timestamp}} - {{user._alt_created_utc|timestamp}} {{user._is_manual}} - - + Alts {% if v.admin_level >= PERMS['VIEW_ALT_VOTES'] %} Alt Votes @@ -53,14 +49,10 @@
Add Alt
-

This tool allows you to add an alt either linked or delinked.
- Adding linked will link the two alts together manually, while adding delinked will attempt to delink alts whereever possible.
- You're on your own for reversing any propagation though. -

+

This tool allows you to link an alt.

- - +
{% endif %}