0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 08:13:46 +02:00

modules/admin: Implement GET (undocumented) /admin/users/@user/admin.

This commit is contained in:
Jason Volk 2020-04-30 01:04:35 -07:00
parent cfb9362744
commit b37df3f719
3 changed files with 115 additions and 0 deletions

View file

@ -167,6 +167,8 @@ ircd::m::matrix::module_names
"client_thirdparty_protocols",
"client_versions",
"client_capabilities",
"admin_users",
};
/// This is a list of modules that are considered "optional" and any loading

View file

@ -509,6 +509,21 @@ client_module_LTLIBRARIES += \
client/client_room_keys_keys.la \
###
###############################################################################
#
# /_synapse/admin/
#
# This puts the source in client/ but the installed
# library is client_X.so in the main modules dir.
admin_moduledir = @moduledir@
admin_admin_users_la_SOURCES = admin/users.cc
admin_module_LTLIBRARIES = \
admin/admin_users.la \
###
###############################################################################
#
# JavaScript

98
modules/admin/users.cc Normal file
View file

@ -0,0 +1,98 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
namespace ircd::m::admin
{
static resource::response handle_get_admin(client &, const resource::request &, const user::id &);
static resource::response handle_get(client &, const resource::request &);
extern resource::method get_method;
extern resource users_resource;
};
ircd::mapi::header
IRCD_MODULE
{
"Admin (undocumented) :Users"
};
decltype(ircd::m::admin::users_resource)
ircd::m::admin::users_resource
{
"/_synapse/admin/v1/users/",
{
"(undocumented) Admin Users",
resource::DIRECTORY
}
};
decltype(ircd::m::admin::get_method)
ircd::m::admin::get_method
{
users_resource, "GET", handle_get,
{
get_method.REQUIRES_AUTH
}
};
ircd::m::resource::response
ircd::m::admin::handle_get(client &client,
const resource::request &request)
{
if(request.parv.size() < 1)
throw m::NEED_MORE_PARAMS
{
"user_id path parameter required"
};
user::id::buf user_id
{
url::decode(user_id, request.parv[0])
};
if(request.parv.size() < 2)
throw m::NEED_MORE_PARAMS
{
"Command path parameter required"
};
const auto &cmd
{
request.parv[1]
};
if(cmd == "admin")
return handle_get_admin(client, request, user_id);
throw m::NOT_FOUND
{
"/admin/users command not found"
};
}
/// Return if a user is an admin
ircd::m::resource::response
ircd::m::admin::handle_get_admin(client &client,
const resource::request &request,
const user::id &user_id)
{
const bool admin
{
m::is_oper(user_id)
};
return m::resource::response
{
client, json::members
{
{ "admin", admin }
}
};
}