0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

modules/m_command: Add conf whitelist for user access for now.

This commit is contained in:
Jason Volk 2020-11-19 11:57:04 -08:00
parent a80c6f9c1c
commit 92666a5d09

View file

@ -858,6 +858,26 @@ edit_path
{ "default", string_view{} },
};
conf::item<std::string>
edit_whitelist
{
{ "name", "ircd.m.cmd.edit.whitelist" },
{ "default", string_view{} },
};
static bool
edit_whitelisted(const m::user::id &user_id)
{
bool ret(false);
ircd::tokens(edit_whitelist, ' ', [&user_id, &ret]
(const string_view &whitelisted_user_id)
{
ret |= whitelisted_user_id == user_id;
});
return ret;
}
command_result
command__edit(const mutable_buffer &buf_,
const m::user &user,
@ -878,6 +898,13 @@ command__edit(const mutable_buffer &buf_,
"Configure the 'ircd.m.cmd.edit.path' to use this feature.",
};
if(!edit_whitelisted(user))
throw m::ACCESS_DENIED
{
"'%s' is not listed in the 'ircd.m.cmd.edit.whitelist'.",
string_view{user.user_id},
};
const string_view parts[2]
{
edit_path, param["path"]
@ -927,6 +954,9 @@ try
if(!edit_path)
return;
if(!edit_whitelisted(json::get<"sender"_>(event)))
return;
const json::object &content
{
json::get<"content"_>(event)