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

modules/admin: Implement (undocumented) users/deactivate.

This commit is contained in:
Jason Volk 2020-05-02 12:30:14 -07:00
parent ff96eb803d
commit e4cfe61551
3 changed files with 100 additions and 0 deletions

View file

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

View file

@ -517,9 +517,11 @@ client_module_LTLIBRARIES += \
admin_moduledir = @moduledir@
admin_admin_users_la_SOURCES = admin/users.cc
admin_admin_deactivate_la_SOURCES = admin/deactivate.cc
admin_module_LTLIBRARIES = \
admin/admin_users.la \
admin/admin_deactivate.la \
###
###############################################################################

View file

@ -0,0 +1,97 @@
// 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_post(client &, const resource::request &);
extern resource::method post_method;
extern resource deactivate_resource;
};
ircd::mapi::header
IRCD_MODULE
{
"Admin (undocumented) :Deactivate"
};
decltype(ircd::m::admin::deactivate_resource)
ircd::m::admin::deactivate_resource
{
"/_synapse/admin/v1/deactivate/",
{
"(undocumented) Admin deactivate",
resource::DIRECTORY
}
};
decltype(ircd::m::admin::post_method)
ircd::m::admin::post_method
{
deactivate_resource, "POST", handle_post,
{
post_method.REQUIRES_AUTH
}
};
ircd::m::resource::response
ircd::m::admin::handle_post(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(!is_oper(request.user_id))
throw m::ACCESS_DENIED
{
"You are not an operator."
};
m::user user
{
user_id
};
if(!exists(user))
throw m::NOT_FOUND
{
"%s is not a known user",
string_view{user_id}
};
const event::id::buf event_id
{
active(user)?
user.deactivate():
event::id::buf{}
};
static const string_view id_server_unbind_result
{
"no-support"
};
return m::resource::response
{
client, json::members
{
{ "event_id", event_id },
{ "id_server_unbind_result", id_server_unbind_result },
}
};
}