cache and multiple account fix
This commit is contained in:
parent
8b9c100e87
commit
75cbcacf18
13
app.py
13
app.py
@ -252,7 +252,9 @@ def add_account() -> Union[Response, str]:
|
||||
if add_user_account(
|
||||
base_url, session["auth_credentials"], username, password, stream
|
||||
):
|
||||
cache.delete_memoized(user_accounts, key_prefix=make_cache_key)
|
||||
# Clear cache for user accounts route
|
||||
cache_key = f"view/{session['username']}/accounts"
|
||||
cache.delete(cache_key)
|
||||
# Run the NPM config update in a background thread
|
||||
thread = threading.Thread(target=_update_npm_config_in_background)
|
||||
thread.start()
|
||||
@ -267,11 +269,12 @@ def add_account() -> Union[Response, str]:
|
||||
@app.route("/accounts/delete", methods=["POST"])
|
||||
def delete_account() -> Response:
|
||||
"""Handles deleting a user account."""
|
||||
stream = request.form.get("stream")
|
||||
username = request.form.get("username")
|
||||
account_id = request.form.get("id")
|
||||
base_url = app.config["BACKEND_URL"]
|
||||
delete_user_account(base_url, session["auth_credentials"], stream, username)
|
||||
cache.delete_memoized(user_accounts, key_prefix=make_cache_key)
|
||||
delete_user_account(base_url, session["auth_credentials"], account_id)
|
||||
# Clear cache for user accounts route
|
||||
cache_key = f"view/{session['username']}/accounts"
|
||||
cache.delete(cache_key)
|
||||
return redirect(url_for("user_accounts"))
|
||||
|
||||
@app.route("/validateAccount", methods=["POST"])
|
||||
|
@ -58,9 +58,9 @@ def get_user_accounts(base_url: str, auth: str) -> List[Dict[str, Any]]:
|
||||
return accounts
|
||||
|
||||
|
||||
def delete_user_account(base_url: str, auth: str, stream: str, username: str) -> bool:
|
||||
"""Deletes a user account via the API."""
|
||||
payload = {"stream": stream, "user": username}
|
||||
def delete_user_account(base_url: str, auth: str, account_id: str) -> bool:
|
||||
"""Deletes a user account via the API using its ID."""
|
||||
payload = {"id": account_id}
|
||||
response = _make_api_request(
|
||||
"POST", base_url, auth, "deleteAccount", payload=payload
|
||||
)
|
||||
|
@ -53,8 +53,7 @@
|
||||
<span class="button-text">Validate</span>
|
||||
</button>
|
||||
<form action="/accounts/delete" method="POST" style="display:inline;">
|
||||
<input type="hidden" name="stream" value="{{ account.stream }}">
|
||||
<input type="hidden" name="username" value="{{ account.username }}">
|
||||
<input type="hidden" name="id" value="{{ account.id }}">
|
||||
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this account?');">
|
||||
Delete
|
||||
</button>
|
||||
@ -124,14 +123,38 @@
|
||||
success: function(response) {
|
||||
spinner.hide();
|
||||
buttonText.show();
|
||||
if (response.message === 'Account is valid and updated') {
|
||||
if (response.message === 'Account is expired') {
|
||||
button.prop('disabled', false);
|
||||
button.removeClass('btn-info').addClass('btn-warning');
|
||||
buttonText.text('Expired');
|
||||
setTimeout(function() {
|
||||
button.removeClass('btn-warning').addClass('btn-info');
|
||||
buttonText.text('Validate');
|
||||
}, 3000);
|
||||
} else if (response.message === 'Account is valid and updated') {
|
||||
button.prop('disabled', false);
|
||||
button.removeClass('btn-info').addClass('btn-success');
|
||||
buttonText.text('Valid & Updated');
|
||||
|
||||
// Display what was updated in a tooltip
|
||||
if (response.updates && response.updates.length > 0) {
|
||||
var updateDetails = response.updates.join('\n');
|
||||
button.attr('title', updateDetails);
|
||||
button.tooltip({
|
||||
placement: 'bottom',
|
||||
trigger: 'hover'
|
||||
});
|
||||
|
||||
// Also show an alert with the updates
|
||||
alert('Account updated:\n' + updateDetails);
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
button.removeClass('btn-success').addClass('btn-info');
|
||||
buttonText.text('Validate');
|
||||
}, 3000);
|
||||
button.tooltip('dispose');
|
||||
button.removeAttr('title');
|
||||
}, 5000);
|
||||
} else {
|
||||
button.prop('disabled', false);
|
||||
button.removeClass('btn-info').addClass('btn-success');
|
||||
|
Loading…
x
Reference in New Issue
Block a user