add filtering for users with balance below threshold

This commit is contained in:
Riley L. 2024-11-20 21:13:26 +01:00
parent a429216639
commit 5ec847be56

View file

@ -530,7 +530,11 @@ local function r_log(filter)
end)
end
local function r_users(show_special)
local function r_users(show_special, filter_negative)
if filter_negative ~= nil then
filter_negative = tonumber(filter_negative) or 0
end
return respond(200, "Abrechenbarkeit", function()
local users = get_active_users()
@ -579,7 +583,8 @@ local function r_users(show_special)
local show_user = function(user)
local is_spu = user.name:sub(1, 1) == "@"
local filter_out = query.prefix ~= nil and user.name:sub(1, 1):lower() ~= query.prefix
if is_spu == show_special and not filter_out then
if (filter_negative ~= nil and user.balance < filter_negative)
or (filter_negative == nil and is_spu == show_special and not filter_out) then
print(format([[<li>
<a href="/{username_url}">
<span class="name">{!username}</span>
@ -793,15 +798,12 @@ if path == "/" then
elseif query.create_user then
return r_create_user()
elseif query.spus then
return r_users(true)
elseif query.users then
if query.export then
return r_export_balances()
else
return r_users(false)
end
return r_users(true, nil)
elseif query.users and query.export then
return r_export_balances()
else
return r_users(false)
return r_users(false, query.negative)
-- tonumber(query.negative or 0) or nil)
end
else
local username = extract_username()