Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
404bdd1d
Commit
404bdd1d
authored
11 months ago
by
🥺
Committed by
🥺
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
allow ban-list-of-rooms to take room aliases
Signed-off-by:
strawberry
<
strawberry@puppygock.gay
>
parent
59be0b3d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/service/admin/room_moderation.rs
+100
-18
100 additions, 18 deletions
src/service/admin/room_moderation.rs
with
100 additions
and
18 deletions
src/service/admin/room_moderation.rs
+
100
−
18
View file @
404bdd1d
use
std
::
fmt
::
Write
as
_
;
use
std
::
fmt
::
Write
as
_
;
use
clap
::
Subcommand
;
use
clap
::
Subcommand
;
use
ruma
::{
events
::
room
::
message
::
RoomMessageEventContent
,
OwnedUserId
,
RoomAliasId
,
RoomId
,
RoomOrAliasId
};
use
ruma
::{
events
::
room
::
message
::
RoomMessageEventContent
,
OwnedRoomId
,
OwnedUserId
,
RoomAliasId
,
RoomId
,
RoomOrAliasId
,
};
use
tracing
::{
debug
,
error
,
info
};
use
tracing
::{
debug
,
error
,
info
};
use
crate
::{
use
crate
::{
...
@@ -37,8 +39,8 @@ pub(crate) enum RoomModerationCommand {
...
@@ -37,8 +39,8 @@ pub(crate) enum RoomModerationCommand {
room
:
Box
<
RoomOrAliasId
>
,
room
:
Box
<
RoomOrAliasId
>
,
},
},
/// - Bans a list of rooms
f
rom
a newline delimited codeblock similar to
/// - Bans a list of rooms
(
ro
o
m
IDs and room aliases) from a newline
/// `user deactivate-all`
///
delimited codeblock similar to
`user deactivate-all`
BanListOfRooms
{
BanListOfRooms
{
#[arg(short,
long)]
#[arg(short,
long)]
/// Evicts admins out of the room and ignores any potential errors when
/// Evicts admins out of the room and ignores any potential errors when
...
@@ -236,41 +238,121 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
...
@@ -236,41 +238,121 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
if
body
.len
()
>
2
&&
body
[
0
]
.trim
()
.starts_with
(
"```"
)
&&
body
.last
()
.unwrap
()
.trim
()
==
"```"
{
if
body
.len
()
>
2
&&
body
[
0
]
.trim
()
.starts_with
(
"```"
)
&&
body
.last
()
.unwrap
()
.trim
()
==
"```"
{
let
rooms_s
=
body
.clone
()
.drain
(
1
..
body
.len
()
-
1
)
.collect
::
<
Vec
<
_
>>
();
let
rooms_s
=
body
.clone
()
.drain
(
1
..
body
.len
()
-
1
)
.collect
::
<
Vec
<
_
>>
();
let
admin_room_alias
:
Box
<
RoomAliasId
>
=
format!
(
"#admins:{}"
,
services
()
.globals
.server_name
())
.try_into
()
.expect
(
"#admins:server_name is a valid alias name"
);
let
mut
room_ban_count
=
0
;
let
mut
room_ban_count
=
0
;
let
mut
room_ids
:
Vec
<
&
RoomId
>
=
Vec
::
new
();
let
mut
room_ids
:
Vec
<
Owned
RoomId
>
=
Vec
::
new
();
for
&
room_id
in
&
rooms_s
{
for
&
room
in
&
rooms_s
{
match
<&
RoomId
>
::
try_from
(
room_id
)
{
match
<&
RoomOrAliasId
>
::
try_from
(
room
)
{
Ok
(
owned_room_id
)
=>
{
Ok
(
room_alias_or_id
)
=>
{
// silently ignore deleting admin room
if
let
Some
(
admin_room_id
)
=
Service
::
get_admin_room
()
?
{
if
let
Some
(
admin_room_id
)
=
Service
::
get_admin_room
()
?
{
if
owned_room_id
.eq
(
&
admin_room_
id
)
{
if
room
.to_owned
()
.eq
(
&
admin_room_id
)
||
room
.to_owned
()
.eq
(
&
admin_room_
alias
)
{
info!
(
"User specified admin room in bulk ban list, ignoring"
);
info!
(
"User specified admin room in bulk ban list, ignoring"
);
continue
;
continue
;
}
}
}
}
room_ids
.push
(
owned_room_id
);
if
room_alias_or_id
.is_room_id
()
{
let
room_id
=
match
RoomId
::
parse
(
room_alias_or_id
)
{
Ok
(
room_id
)
=>
room_id
,
Err
(
e
)
=>
{
if
force
{
// ignore rooms we failed to parse if we're force banning
error!
(
"Error parsing room
\"
{room}
\"
during bulk room banning, ignoring
\
error and logging here: {e}"
);
continue
;
}
return
Ok
(
RoomMessageEventContent
::
text_plain
(
format!
(
"{room} is not a valid room ID or room alias, please fix the list and try
\
again: {e}"
)));
},
};
room_ids
.push
(
room_id
);
}
if
room_alias_or_id
.is_room_alias_id
()
{
match
RoomAliasId
::
parse
(
room_alias_or_id
)
{
Ok
(
room_alias
)
=>
{
let
room_id
=
if
let
Some
(
room_id
)
=
services
()
.rooms.alias
.resolve_local_alias
(
&
room_alias
)
?
{
room_id
}
else
{
debug!
(
"We don't have this room alias to a room ID locally, attempting to
\
fetch room ID over federation"
);
match
get_alias_helper
(
room_alias
)
.await
{
Ok
(
response
)
=>
{
debug!
(
"Got federation response fetching room ID for room {room}:
\
{:?}"
,
response
);
response
.room_id
},
Err
(
e
)
=>
{
if
force
{
format!
(
"Failed to resolve room alias {room} to a room ID: {e}"
);
}
return
Ok
(
RoomMessageEventContent
::
text_plain
(
format!
(
"Failed to resolve room alias {room} to a room ID: {e}"
)));
},
}
};
room_ids
.push
(
room_id
);
},
Err
(
e
)
=>
{
if
force
{
// ignore rooms we failed to parse if we're force deleting
error!
(
"Error parsing room
\"
{room}
\"
during bulk room banning, ignoring
\
error and logging here: {e}"
);
continue
;
}
return
Ok
(
RoomMessageEventContent
::
text_plain
(
format!
(
"{room} is not a valid room ID or room alias, please fix the list and try
\
again: {e}"
)));
},
}
}
},
},
Err
(
e
)
=>
{
Err
(
e
)
=>
{
if
force
{
if
force
{
// ignore rooms we failed to parse if we're force deleting
// ignore rooms we failed to parse if we're force deleting
error!
(
error!
(
"Error parsing room
ID
{room
_id}
during bulk room banning, ignoring error and
\
"Error parsing room
\"
{room
}
\"
during bulk room banning, ignoring error and
\
logging here: {e}"
logging here: {e}"
);
);
continue
;
continue
;
}
}
return
Ok
(
RoomMessageEventContent
::
text_plain
(
format!
(
return
Ok
(
RoomMessageEventContent
::
text_plain
(
format!
(
"{room
_id
} is not a valid room ID, please fix the list and try again: {e}"
"{room} is not a valid room ID
or room alias
, please fix the list and try again: {e}"
)));
)));
},
},
}
}
}
}
for
room_id
in
room_ids
{
for
room_id
in
room_ids
{
if
services
()
.rooms.metadata
.ban_room
(
room_id
,
true
)
.is_ok
()
{
if
services
()
.rooms.metadata
.ban_room
(
&
room_id
,
true
)
.is_ok
()
{
debug!
(
"Banned {room_id} successfully"
);
debug!
(
"Banned {room_id} successfully"
);
room_ban_count
+=
1
;
room_ban_count
+=
1
;
}
}
...
@@ -280,7 +362,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
...
@@ -280,7 +362,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
for
local_user
in
services
()
for
local_user
in
services
()
.rooms
.rooms
.state_cache
.state_cache
.room_members
(
room_id
)
.room_members
(
&
room_id
)
.filter_map
(|
user
|
{
.filter_map
(|
user
|
{
user
.ok
()
.filter
(|
local_user
|
{
user
.ok
()
.filter
(|
local_user
|
{
local_user
.server_name
()
==
services
()
.globals
.server_name
()
local_user
.server_name
()
==
services
()
.globals
.server_name
()
...
@@ -306,13 +388,13 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
...
@@ -306,13 +388,13 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
admins too)"
,
admins too)"
,
&
local_user
,
room_id
&
local_user
,
room_id
);
);
_
=
leave_room
(
&
local_user
,
room_id
,
None
)
.await
;
_
=
leave_room
(
&
local_user
,
&
room_id
,
None
)
.await
;
}
}
}
else
{
}
else
{
for
local_user
in
services
()
for
local_user
in
services
()
.rooms
.rooms
.state_cache
.state_cache
.room_members
(
room_id
)
.room_members
(
&
room_id
)
.filter_map
(|
user
|
{
.filter_map
(|
user
|
{
user
.ok
()
.filter
(|
local_user
|
{
user
.ok
()
.filter
(|
local_user
|
{
local_user
.server_name
()
==
services
()
.globals
.server_name
()
local_user
.server_name
()
==
services
()
.globals
.server_name
()
...
@@ -329,7 +411,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
...
@@ -329,7 +411,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
.collect
::
<
Vec
<
OwnedUserId
>>
()
.collect
::
<
Vec
<
OwnedUserId
>>
()
{
{
debug!
(
"Attempting leave for user {} in room {}"
,
&
local_user
,
&
room_id
);
debug!
(
"Attempting leave for user {} in room {}"
,
&
local_user
,
&
room_id
);
if
let
Err
(
e
)
=
leave_room
(
&
local_user
,
room_id
,
None
)
.await
{
if
let
Err
(
e
)
=
leave_room
(
&
local_user
,
&
room_id
,
None
)
.await
{
error!
(
error!
(
"Error attempting to make local user {} leave room {} during bulk room banning: {}"
,
"Error attempting to make local user {} leave room {} during bulk room banning: {}"
,
&
local_user
,
&
room_id
,
e
&
local_user
,
&
room_id
,
e
...
@@ -345,7 +427,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
...
@@ -345,7 +427,7 @@ pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) ->
}
}
if
disable_federation
{
if
disable_federation
{
services
()
.rooms.metadata
.disable_room
(
room_id
,
true
)
?
;
services
()
.rooms.metadata
.disable_room
(
&
room_id
,
true
)
?
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment