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(
|
if add_user_account(
|
||||||
base_url, session["auth_credentials"], username, password, stream
|
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
|
# Run the NPM config update in a background thread
|
||||||
thread = threading.Thread(target=_update_npm_config_in_background)
|
thread = threading.Thread(target=_update_npm_config_in_background)
|
||||||
thread.start()
|
thread.start()
|
||||||
@ -267,11 +269,12 @@ def add_account() -> Union[Response, str]:
|
|||||||
@app.route("/accounts/delete", methods=["POST"])
|
@app.route("/accounts/delete", methods=["POST"])
|
||||||
def delete_account() -> Response:
|
def delete_account() -> Response:
|
||||||
"""Handles deleting a user account."""
|
"""Handles deleting a user account."""
|
||||||
stream = request.form.get("stream")
|
account_id = request.form.get("id")
|
||||||
username = request.form.get("username")
|
|
||||||
base_url = app.config["BACKEND_URL"]
|
base_url = app.config["BACKEND_URL"]
|
||||||
delete_user_account(base_url, session["auth_credentials"], stream, username)
|
delete_user_account(base_url, session["auth_credentials"], account_id)
|
||||||
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)
|
||||||
return redirect(url_for("user_accounts"))
|
return redirect(url_for("user_accounts"))
|
||||||
|
|
||||||
@app.route("/validateAccount", methods=["POST"])
|
@app.route("/validateAccount", methods=["POST"])
|
||||||
|
@ -58,9 +58,9 @@ def get_user_accounts(base_url: str, auth: str) -> List[Dict[str, Any]]:
|
|||||||
return accounts
|
return accounts
|
||||||
|
|
||||||
|
|
||||||
def delete_user_account(base_url: str, auth: str, stream: str, username: str) -> bool:
|
def delete_user_account(base_url: str, auth: str, account_id: str) -> bool:
|
||||||
"""Deletes a user account via the API."""
|
"""Deletes a user account via the API using its ID."""
|
||||||
payload = {"stream": stream, "user": username}
|
payload = {"id": account_id}
|
||||||
response = _make_api_request(
|
response = _make_api_request(
|
||||||
"POST", base_url, auth, "deleteAccount", payload=payload
|
"POST", base_url, auth, "deleteAccount", payload=payload
|
||||||
)
|
)
|
||||||
|
@ -53,8 +53,7 @@
|
|||||||
<span class="button-text">Validate</span>
|
<span class="button-text">Validate</span>
|
||||||
</button>
|
</button>
|
||||||
<form action="/accounts/delete" method="POST" style="display:inline;">
|
<form action="/accounts/delete" method="POST" style="display:inline;">
|
||||||
<input type="hidden" name="stream" value="{{ account.stream }}">
|
<input type="hidden" name="id" value="{{ account.id }}">
|
||||||
<input type="hidden" name="username" value="{{ account.username }}">
|
|
||||||
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this account?');">
|
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this account?');">
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
@ -124,14 +123,38 @@
|
|||||||
success: function(response) {
|
success: function(response) {
|
||||||
spinner.hide();
|
spinner.hide();
|
||||||
buttonText.show();
|
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.prop('disabled', false);
|
||||||
button.removeClass('btn-info').addClass('btn-success');
|
button.removeClass('btn-info').addClass('btn-success');
|
||||||
buttonText.text('Valid & Updated');
|
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() {
|
setTimeout(function() {
|
||||||
button.removeClass('btn-success').addClass('btn-info');
|
button.removeClass('btn-success').addClass('btn-info');
|
||||||
buttonText.text('Validate');
|
buttonText.text('Validate');
|
||||||
}, 3000);
|
button.tooltip('dispose');
|
||||||
|
button.removeAttr('title');
|
||||||
|
}, 5000);
|
||||||
} else {
|
} else {
|
||||||
button.prop('disabled', false);
|
button.prop('disabled', false);
|
||||||
button.removeClass('btn-info').addClass('btn-success');
|
button.removeClass('btn-info').addClass('btn-success');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user