authd/src/requests/list.cr

24 lines
672 B
Crystal

class AuthD::Request
IPC::JSON.message ListUsers, 8 do
# Since the list could be long, here is a way to get it at a reasonable pace.
property offset : Int32 = 0
# By default, authd will send 10 users at a time.
def initialize()
end
def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd
return Response::Error.new "you must be logged" if logged_user.nil?
# Test if the user is a moderator.
logged_user.assert_permission("authd", "*", User::PermissionLevel::Read)
list = authd.users.to_h.map &.[1].to_public
Response::UsersList.new list[offset..offset+10]
end
end
AuthD.requests << ListUsers
end