mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
use admin_bot_user_id more
Also change some terminology to be less weird.
This commit is contained in:
parent
d4b5f62bfe
commit
b0d85bb575
2 changed files with 21 additions and 42 deletions
|
|
@ -529,21 +529,12 @@ impl KeyValueDatabase {
|
||||||
// Matrix resource ownership is based on the server name; changing it
|
// Matrix resource ownership is based on the server name; changing it
|
||||||
// requires recreating the database from scratch.
|
// requires recreating the database from scratch.
|
||||||
if services().users.count()? > 0 {
|
if services().users.count()? > 0 {
|
||||||
let grapevine_user = UserId::parse_with_server_name(
|
let admin_bot = services().globals.admin_bot_user_id.as_ref();
|
||||||
if services().globals.config.conduit_compat {
|
if !services().users.exists(admin_bot)? {
|
||||||
"conduit"
|
|
||||||
} else {
|
|
||||||
"grapevine"
|
|
||||||
},
|
|
||||||
services().globals.server_name(),
|
|
||||||
)
|
|
||||||
.expect("admin bot username should be valid");
|
|
||||||
|
|
||||||
if !services().users.exists(&grapevine_user)? {
|
|
||||||
error!(
|
error!(
|
||||||
"The {} server user does not exist, and the database is \
|
"The {} admin bot does not exist, and the database is not \
|
||||||
not new.",
|
new.",
|
||||||
grapevine_user
|
admin_bot
|
||||||
);
|
);
|
||||||
return Err(Error::bad_database(
|
return Err(Error::bad_database(
|
||||||
"Cannot reuse an existing database after changing the \
|
"Cannot reuse an existing database after changing the \
|
||||||
|
|
@ -1221,25 +1212,21 @@ impl KeyValueDatabase {
|
||||||
/// Sets the emergency password and push rules for the @grapevine account in
|
/// Sets the emergency password and push rules for the @grapevine account in
|
||||||
/// case emergency password is set
|
/// case emergency password is set
|
||||||
fn set_emergency_access() -> Result<bool> {
|
fn set_emergency_access() -> Result<bool> {
|
||||||
let grapevine_user = UserId::parse_with_server_name(
|
let admin_bot = services().globals.admin_bot_user_id.as_ref();
|
||||||
"grapevine",
|
|
||||||
services().globals.server_name(),
|
|
||||||
)
|
|
||||||
.expect("@grapevine:server_name is a valid UserId");
|
|
||||||
|
|
||||||
services().users.set_password(
|
services().users.set_password(
|
||||||
&grapevine_user,
|
admin_bot,
|
||||||
services().globals.emergency_password().as_deref(),
|
services().globals.emergency_password().as_deref(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (ruleset, res) = match services().globals.emergency_password() {
|
let (ruleset, res) = match services().globals.emergency_password() {
|
||||||
Some(_) => (Ruleset::server_default(&grapevine_user), Ok(true)),
|
Some(_) => (Ruleset::server_default(admin_bot), Ok(true)),
|
||||||
None => (Ruleset::new(), Ok(false)),
|
None => (Ruleset::new(), Ok(false)),
|
||||||
};
|
};
|
||||||
|
|
||||||
services().account_data.update(
|
services().account_data.update(
|
||||||
None,
|
None,
|
||||||
&grapevine_user,
|
admin_bot,
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||||
&serde_json::to_value(&GlobalAccountDataEvent {
|
&serde_json::to_value(&GlobalAccountDataEvent {
|
||||||
content: PushRulesEventContent {
|
content: PushRulesEventContent {
|
||||||
|
|
|
||||||
|
|
@ -516,33 +516,25 @@ impl Service {
|
||||||
&body,
|
&body,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let server_user = format!(
|
let admin_bot = &services().globals.admin_bot_user_id;
|
||||||
"@{}:{}",
|
|
||||||
if services().globals.config.conduit_compat {
|
|
||||||
"conduit"
|
|
||||||
} else {
|
|
||||||
"grapevine"
|
|
||||||
},
|
|
||||||
services().globals.server_name()
|
|
||||||
);
|
|
||||||
|
|
||||||
let to_grapevine = body
|
let to_admin_bot = body
|
||||||
.starts_with(&format!("{server_user}: "))
|
.starts_with(&format!("{admin_bot}: "))
|
||||||
|| body.starts_with(&format!("{server_user} "))
|
|| body.starts_with(&format!("{admin_bot} "))
|
||||||
|| body == format!("{server_user}:")
|
|| body == format!("{admin_bot}:")
|
||||||
|| body == server_user;
|
|| body == admin_bot.as_str();
|
||||||
|
|
||||||
// This will evaluate to false if the emergency password is
|
// This will evaluate to false if the emergency password
|
||||||
// set up so that the administrator can
|
// is set up so that the administrator can execute commands
|
||||||
// execute commands as grapevine
|
// as the admin bot
|
||||||
let from_grapevine = pdu.sender == server_user
|
let from_admin_bot = &pdu.sender == admin_bot
|
||||||
&& services().globals.emergency_password().is_none();
|
&& services().globals.emergency_password().is_none();
|
||||||
|
|
||||||
if let Some(admin_room) =
|
if let Some(admin_room) =
|
||||||
services().admin.get_admin_room()?
|
services().admin.get_admin_room()?
|
||||||
{
|
{
|
||||||
if to_grapevine
|
if to_admin_bot
|
||||||
&& !from_grapevine
|
&& !from_admin_bot
|
||||||
&& admin_room == pdu.room_id
|
&& admin_room == pdu.room_id
|
||||||
{
|
{
|
||||||
services().admin.process_message(body);
|
services().admin.process_message(body);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue