mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2025-04-10 20:48:36 +00:00
Send only emails to deactivate_users
This commit is contained in:
parent
15a9c24cf3
commit
0cec81f76f
2 changed files with 13 additions and 8 deletions
advlabdb
|
@ -212,10 +212,9 @@ def users():
|
|||
@app.route("/deactivate_users", methods=["GET"])
|
||||
@roles_required("admin")
|
||||
def deactivate_users():
|
||||
usersJson = json.loads(request.args.get("json"))
|
||||
usersEmails = json.loads(request.args.get("json"))
|
||||
deactivatedUsersEmails = []
|
||||
for userJson in usersJson:
|
||||
email = userJson["email"]
|
||||
for email in usersEmails:
|
||||
user = User.query.filter(User.email == email).first()
|
||||
if user == current_user:
|
||||
flash("You have tried to deactivate yourself as user!", "danger")
|
||||
|
@ -223,10 +222,11 @@ def deactivate_users():
|
|||
if user_datastore.deactivate_user(user):
|
||||
deactivatedUsersEmails.append(email)
|
||||
db.session.commit()
|
||||
if deactivatedUsersEmails == []:
|
||||
deactivatedUsersEmailsLen = len(deactivatedUsersEmails)
|
||||
if deactivatedUsersEmailsLen == 0:
|
||||
flash(f"No users deactivated!", "warning")
|
||||
else:
|
||||
flash(f"Users with emails {deactivatedUsersEmails} deactivated!", "success")
|
||||
flash(f"{deactivatedUsersEmailsLen} Users with emails {deactivatedUsersEmails} deactivated!", "success")
|
||||
return redirect(url_for("users"))
|
||||
|
||||
|
||||
|
|
|
@ -14,12 +14,17 @@
|
|||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
var $table = $('#usersTab')
|
||||
var $button = $('#deactivateUsersButton')
|
||||
let $table = $('#usersTab')
|
||||
let $button = $('#deactivateUsersButton')
|
||||
|
||||
$(function() {
|
||||
$button.click(function () {
|
||||
window.location.href = '{{url_for("deactivate_users")}}?json=' + JSON.stringify($table.bootstrapTable('getSelections'))
|
||||
let users = $table.bootstrapTable('getSelections');
|
||||
let emails = [];
|
||||
for (var i=0; i<users.length; i++) {
|
||||
emails.push(users[i]["email"])
|
||||
}
|
||||
window.location.href = '{{url_for("deactivate_users")}}?json=' + JSON.stringify(emails);
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue