mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-16 21:47:34 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce178d86d5 | ||
|
|
02f4f9d88d | ||
|
|
1deaf99409 | ||
|
|
1e34bd2ed9 |
No files matched your search
@@ -659,6 +659,9 @@ default-features = false
|
||||
[workspace.dependencies.ruminuwuity]
|
||||
package = "ruminuwuity"
|
||||
path = "src/ruminuwuity"
|
||||
features = [
|
||||
"unstable-msc4484"
|
||||
]
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod rooms;
|
||||
pub mod users;
|
||||
@@ -6,7 +6,7 @@ use ruminuwuity::admin::continuwuity::rooms;
|
||||
|
||||
use crate::{Ruma, client::leave_room};
|
||||
|
||||
/// # `PUT /_continuwuity/admin/rooms/{roomID}/ban`
|
||||
/// # `PUT /_continuwuity/admin/v1/rooms/{roomID}/ban`
|
||||
///
|
||||
/// Bans or unbans a room.
|
||||
pub(crate) async fn ban_room(
|
||||
|
||||
@@ -6,7 +6,7 @@ use ruminuwuity::admin::continuwuity::rooms;
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
/// # `GET /_continuwuity/admin/rooms/list`
|
||||
/// # `GET /_continuwuity/admin/v1/rooms/list`
|
||||
///
|
||||
/// Lists all rooms known to this server, excluding banned ones.
|
||||
pub(crate) async fn list_rooms(
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Err, error};
|
||||
use ruma::{api::client::profile::PropagateTo, profile::ProfileFieldValue};
|
||||
use ruminuwuity::admin::continuwuity::users::create::v1::{Request, Response};
|
||||
use service::users::{HashedPassword, ProfileFieldChange};
|
||||
|
||||
use crate::router::Ruma;
|
||||
|
||||
/// # `POST /_continuwuity/admin/v1/users`
|
||||
///
|
||||
/// Creates a new user on the homeserver.
|
||||
pub(crate) async fn create_user(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<Request>,
|
||||
) -> conduwuit::Result<Response> {
|
||||
let sender_user = body.identity.expect_sender_user()?;
|
||||
if !services.users.is_admin(sender_user).await {
|
||||
return Err!(Request(Forbidden("Only server administrators can use this endpoint")));
|
||||
}
|
||||
|
||||
if !services.globals.user_is_local(&body.user_id) {
|
||||
return Err!(Request(InvalidParam("User ID does not belong to this server.")));
|
||||
}
|
||||
if services.users.status(&body.user_id).await.is_found() {
|
||||
return Err!(Request(UserInUse("An account with this user ID already exists.")));
|
||||
}
|
||||
|
||||
services
|
||||
.users
|
||||
.create_local_account(
|
||||
&body.user_id,
|
||||
body.password
|
||||
.as_ref()
|
||||
.and_then(|raw| HashedPassword::new(raw).ok()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
if body.locked {
|
||||
services
|
||||
.users
|
||||
.lock_account(&body.user_id, sender_user)
|
||||
.await;
|
||||
}
|
||||
if body.suspended {
|
||||
services
|
||||
.users
|
||||
.suspend_account(&body.user_id, sender_user)
|
||||
.await;
|
||||
}
|
||||
for (key, value) in body.profile.clone().unwrap_or_default() {
|
||||
services
|
||||
.users
|
||||
.set_profile_field(
|
||||
&body.user_id,
|
||||
ProfileFieldChange::Set(ProfileFieldValue::new(&key, value)?),
|
||||
PropagateTo::All,
|
||||
)
|
||||
.await
|
||||
.inspect_err(|e| error!(error=?e, %key, "Failed to set profile field"))
|
||||
.ok();
|
||||
}
|
||||
if body.admin {
|
||||
services.admin.make_user_admin(&body.user_id).await?;
|
||||
}
|
||||
|
||||
Ok(Response::default())
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err,
|
||||
utils::{TryFutureExtExt, stream::WidebandExt},
|
||||
};
|
||||
use futures::StreamExt;
|
||||
use ruminuwuity::admin::continuwuity::users::list::v1::{QueryFilter, Request, Response, User};
|
||||
use service::users::AccountStatus;
|
||||
|
||||
use crate::router::Ruma;
|
||||
|
||||
/// # `GET /_continuwuity/admin/v1/users`
|
||||
///
|
||||
/// Lists users on this homeserver
|
||||
pub(crate) async fn list_users(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<Request>,
|
||||
) -> conduwuit::Result<Response> {
|
||||
if !services
|
||||
.users
|
||||
.is_admin(body.identity.expect_sender_user()?)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(Forbidden("Only server administrators can use this endpoint")));
|
||||
}
|
||||
|
||||
let limit = body.limit.unwrap_or(100);
|
||||
let offset = limit.saturating_mul(body.page.unwrap_or_default());
|
||||
let users = services
|
||||
.users
|
||||
.stream_local_users()
|
||||
.wide_filter_map(|user_id| {
|
||||
let body = &body;
|
||||
async move {
|
||||
let status = services.users.status(&user_id).await;
|
||||
assert_ne!(
|
||||
status,
|
||||
AccountStatus::NotFound,
|
||||
"Not found users should not appear in stream_local_users"
|
||||
);
|
||||
let (deactivated, locked, suspended, admin) = tokio::join!(
|
||||
std::future::ready(status == AccountStatus::Deactivated),
|
||||
services.users.is_locked(&user_id).unwrap_or_default(),
|
||||
services.users.is_suspended(&user_id).unwrap_or_default(),
|
||||
services.users.is_admin(&user_id),
|
||||
);
|
||||
// Exclude deactivated accounts by default
|
||||
if !deactivated && body.active == Some(QueryFilter::Exclude) {
|
||||
return None;
|
||||
}
|
||||
if deactivated
|
||||
&& body
|
||||
.deactivated
|
||||
.as_ref()
|
||||
.is_none_or(|d| *d == QueryFilter::Include)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
// Exclude locked accounts by default
|
||||
if locked && body.locked != Some(QueryFilter::Include) {
|
||||
return None;
|
||||
}
|
||||
// Include suspended accounts by default
|
||||
if suspended && body.suspended == Some(QueryFilter::Exclude) {
|
||||
return None;
|
||||
}
|
||||
// Include admins by default
|
||||
if admin && body.admin == Some(QueryFilter::Exclude) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((user_id, deactivated, suspended, locked, admin))
|
||||
}
|
||||
})
|
||||
.skip(offset)
|
||||
.wide_then(|(user_id, deactivated, suspended, locked, admin)| async move {
|
||||
let (displayname, avatar_url) = tokio::join!(
|
||||
services.users.displayname(&user_id).ok(),
|
||||
services.users.avatar_url(&user_id).ok(),
|
||||
);
|
||||
let user = User {
|
||||
displayname,
|
||||
avatar_url,
|
||||
suspended,
|
||||
locked,
|
||||
deactivated,
|
||||
admin,
|
||||
};
|
||||
|
||||
(user_id, user)
|
||||
})
|
||||
.take(limit)
|
||||
.collect::<BTreeMap<_, _>>()
|
||||
.await;
|
||||
|
||||
Ok(Response::new(users))
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod create;
|
||||
pub mod list;
|
||||
pub mod rooms;
|
||||
@@ -0,0 +1,134 @@
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Event, at,
|
||||
utils::{IterStream, ReadyExt, TryFutureExtExt, stream::WidebandExt},
|
||||
};
|
||||
use futures::StreamExt;
|
||||
use ruma::events::room::member::MembershipState;
|
||||
use ruminuwuity::admin::continuwuity::users::rooms::v1::{Request, Response, RoomInfo};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::router::Ruma;
|
||||
|
||||
/// # `GET /_continuwuity/admin/v1/users/{user_id}/rooms`
|
||||
///
|
||||
/// Lists the memberships of a user on this server.
|
||||
pub(crate) async fn list_user_rooms(
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<Request>,
|
||||
) -> conduwuit::Result<Response> {
|
||||
if !services
|
||||
.users
|
||||
.is_admin(body.identity.expect_sender_user()?)
|
||||
.await
|
||||
{
|
||||
return Err!(Request(Forbidden("Only server administrators can use this endpoint")));
|
||||
}
|
||||
|
||||
let limit = body.limit.unwrap_or(100).try_into()?;
|
||||
let offset = body
|
||||
.limit
|
||||
.unwrap_or(100)
|
||||
.saturating_mul(body.page.unwrap_or_default())
|
||||
.try_into()?;
|
||||
|
||||
let room_ids: Vec<_> = match body.state {
|
||||
| MembershipState::Join =>
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_joined(&body.user_id)
|
||||
.skip(offset)
|
||||
.take(limit)
|
||||
.collect()
|
||||
.await,
|
||||
| MembershipState::Invite =>
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_invited(&body.user_id)
|
||||
.skip(offset)
|
||||
.take(limit)
|
||||
.map(at!(0))
|
||||
.collect()
|
||||
.await,
|
||||
| MembershipState::Knock =>
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_knocked(&body.user_id)
|
||||
.skip(offset)
|
||||
.take(limit)
|
||||
.map(at!(0))
|
||||
.collect()
|
||||
.await,
|
||||
| MembershipState::Leave =>
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_left(&body.user_id)
|
||||
.skip(offset)
|
||||
.take(limit)
|
||||
.ready_filter_map(|(room_id, pdu)| {
|
||||
pdu.is_some_and(|pdu| {
|
||||
pdu.get_content::<ExtractMembership>()
|
||||
.expect("membership PDU must have a membership field")
|
||||
.membership
|
||||
== MembershipState::Leave
|
||||
})
|
||||
.then_some(room_id)
|
||||
})
|
||||
.collect()
|
||||
.await,
|
||||
| MembershipState::Ban =>
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_left(&body.user_id)
|
||||
.skip(offset)
|
||||
.take(limit)
|
||||
.ready_filter_map(|(room_id, pdu)| {
|
||||
pdu.is_some_and(|pdu| {
|
||||
pdu.get_content::<ExtractMembership>()
|
||||
.expect("membership PDU must have a membership field")
|
||||
.membership
|
||||
== MembershipState::Ban
|
||||
})
|
||||
.then_some(room_id)
|
||||
})
|
||||
.collect()
|
||||
.await,
|
||||
| _ => return Err!(Request(InvalidParam("Unknown membership kind: {:?}", body.state))),
|
||||
};
|
||||
|
||||
let resp = room_ids
|
||||
.into_iter()
|
||||
.stream()
|
||||
.wide_then(|room_id| async move {
|
||||
let (name, avatar, alias, members) = tokio::join!(
|
||||
services.rooms.state_accessor.get_name(&room_id).ok(),
|
||||
services.rooms.state_accessor.get_avatar(&room_id),
|
||||
services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.get_canonical_alias(&room_id)
|
||||
.ok(),
|
||||
services.rooms.state_cache.room_members(&room_id).count(),
|
||||
);
|
||||
(room_id, RoomInfo {
|
||||
name,
|
||||
avatar_url: avatar.into_option().and_then(|a| a.url),
|
||||
canonical_alias: alias,
|
||||
member_count: members.try_into().unwrap_or(0),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
Ok(Response::new(resp))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ExtractMembership {
|
||||
pub membership: MembershipState,
|
||||
}
|
||||
@@ -267,11 +267,19 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
||||
summary.into()
|
||||
})
|
||||
.ready_filter_map(|chunk: PublicRoomsChunk| {
|
||||
if !filter.room_types.is_empty() && !filter.room_types.contains(&RoomTypeFilter::from(chunk.room_type.clone())) {
|
||||
if !filter.room_types.is_empty()
|
||||
&& !filter
|
||||
.room_types
|
||||
.contains(&RoomTypeFilter::from(chunk.room_type.clone()))
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(query) = filter.generic_search_term.as_ref().map(|q| q.to_lowercase()) {
|
||||
if let Some(query) = filter
|
||||
.generic_search_term
|
||||
.as_ref()
|
||||
.map(|q| q.to_lowercase())
|
||||
{
|
||||
if let Some(name) = &chunk.name {
|
||||
if name.to_lowercase().contains(&query) {
|
||||
return Some(chunk);
|
||||
|
||||
@@ -55,5 +55,8 @@ fn oauth_router() -> Router<crate::State> {
|
||||
.route(concat!("/", JWKS_URI_PATH), get(async || Json(json!({"keys": []}))))
|
||||
.route(concat!("/", TOKEN_PATH), post(token::token_route))
|
||||
.route(concat!("/", TOKEN_REVOKE_PATH), post(token::revoke_token_route))
|
||||
.route(concat!("/", DEVICE_AUTHORIZATION_PATH), post(device::device_authorization_route))
|
||||
.route(
|
||||
concat!("/", DEVICE_AUTHORIZATION_PATH),
|
||||
post(device::device_authorization_route),
|
||||
)
|
||||
}
|
||||
+17
-12
@@ -1563,20 +1563,25 @@ where
|
||||
// joined users
|
||||
device_list_changes.extend(
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
// Don't send key updates from the sender to the sender
|
||||
.ready_filter(|user_id| sender_user != *user_id)
|
||||
// Only send keys if the sender doesn't share an encrypted room with the target
|
||||
// already
|
||||
.filter_map(async |user_id| {
|
||||
share_encrypted_room(services, sender_user, &user_id, Some(room_id))
|
||||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
// Don't send key updates from the sender to the sender
|
||||
.ready_filter(|user_id| sender_user != *user_id)
|
||||
// Only send keys if the sender doesn't share an encrypted room with
|
||||
// the target already
|
||||
.filter_map(async |user_id| {
|
||||
share_encrypted_room(
|
||||
services,
|
||||
sender_user,
|
||||
&user_id,
|
||||
Some(room_id),
|
||||
)
|
||||
.map(|res| res.or_some(user_id.clone()))
|
||||
.await
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.await,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.await,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-8
@@ -21,7 +21,7 @@ use crate::{admin, client, server};
|
||||
pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
let config = &state.server.config;
|
||||
let mut router = router
|
||||
.ruma_route(&client::appservice_ping)
|
||||
.ruma_route(&client::appservice_ping)
|
||||
.ruma_route(&client::get_supported_versions_route)
|
||||
.ruma_route(&client::get_register_available_route)
|
||||
.ruma_route(&client::register::register_route)
|
||||
@@ -61,8 +61,8 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.ruma_route(&client::get_global_account_data_route)
|
||||
.ruma_route(&client::get_room_account_data_route)
|
||||
.ruma_route(&client::get_profile_field_route)
|
||||
.ruma_route(&client::set_profile_field_route)
|
||||
.ruma_route(&client::delete_profile_field_route)
|
||||
.ruma_route(&client::set_profile_field_route)
|
||||
.ruma_route(&client::delete_profile_field_route)
|
||||
.ruma_route(&client::get_profile_route)
|
||||
.ruma_route(&client::set_presence_route)
|
||||
.ruma_route(&client::get_presence_route)
|
||||
@@ -112,14 +112,17 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.ruma_route(&client::search_users_route)
|
||||
.ruma_route(&client::get_member_events_route)
|
||||
.ruma_route(&client::get_protocols_route)
|
||||
.route("/_matrix/client/unstable/thirdparty/protocols",
|
||||
get(client::get_protocols_route_unstable))
|
||||
.route(
|
||||
"/_matrix/client/unstable/thirdparty/protocols",
|
||||
get(client::get_protocols_route_unstable),
|
||||
)
|
||||
.ruma_route(&client::send_message_event_route)
|
||||
.ruma_route(&client::send_state_event_for_key_route)
|
||||
.ruma_route(&client::get_state_events_route)
|
||||
.ruma_route(&client::get_state_event_for_key_route)
|
||||
// Ruma doesn't have support for multiple paths for a single endpoint yet, and these routes
|
||||
// share one Ruma request / response type pair with {get,send}_state_event_for_key_route
|
||||
// Ruma doesn't have support for multiple paths for a single endpoint yet, and these
|
||||
// routes share one Ruma request / response type pair with
|
||||
// {get,send}_state_event_for_key_route
|
||||
.route(
|
||||
"/_matrix/client/r0/rooms/{room_id}/state/{event_type}",
|
||||
get(client::get_state_events_for_empty_key_route)
|
||||
@@ -194,7 +197,10 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
||||
.merge(client::oauth::router(state))
|
||||
.route("/_continuwuity/server_version", get(client::continuwuity_server_version))
|
||||
.ruma_route(&admin::rooms::ban::ban_room)
|
||||
.ruma_route(&admin::rooms::list::list_rooms);
|
||||
.ruma_route(&admin::rooms::list::list_rooms)
|
||||
.ruma_route(&admin::users::list::list_users)
|
||||
.ruma_route(&admin::users::create::create_user)
|
||||
.ruma_route(&admin::users::rooms::list_user_rooms);
|
||||
|
||||
if config.allow_federation {
|
||||
router = router
|
||||
|
||||
@@ -11,13 +11,14 @@ version.workspace = true
|
||||
path = "mod.rs"
|
||||
|
||||
[features]
|
||||
default = ["client", "server"]
|
||||
default = ["client", "server", "unstable-msc4484"]
|
||||
client = []
|
||||
server = []
|
||||
|
||||
unstable-exhaustive-types = []
|
||||
unstable-msc3202 = []
|
||||
unstable-msc4203 = []
|
||||
unstable-msc4484 = ["ruma/unstable-msc4484"]
|
||||
|
||||
[dependencies]
|
||||
assign.workspace = true
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod rooms;
|
||||
pub mod users;
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod v1 {
|
||||
use ruma::{
|
||||
OwnedRoomAliasId, OwnedRoomId, OwnedUserId,
|
||||
api::{auth_scheme::AccessToken, request, response},
|
||||
api::{OAuthClientScope, auth_scheme::AccessToken, request, response},
|
||||
metadata,
|
||||
};
|
||||
|
||||
@@ -10,8 +10,9 @@ pub mod v1 {
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
history: {
|
||||
1.0 => "/_continuwuity/admin/rooms/{room_id}/ban",
|
||||
}
|
||||
1.0 => "/_continuwuity/admin/v1/rooms/{room_id}/ban",
|
||||
},
|
||||
required_client_scopes: [OAuthClientScope::ServerAdministration]
|
||||
}
|
||||
|
||||
#[request]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod v1 {
|
||||
use ruma::{
|
||||
OwnedRoomId,
|
||||
api::{auth_scheme::AccessToken, request, response},
|
||||
api::{OAuthClientScope, auth_scheme::AccessToken, request, response},
|
||||
metadata,
|
||||
};
|
||||
|
||||
@@ -10,8 +10,9 @@ pub mod v1 {
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
history: {
|
||||
1.0 => "/_continuwuity/admin/rooms/list",
|
||||
}
|
||||
1.0 => "/_continuwuity/admin/v1/rooms/list",
|
||||
},
|
||||
required_client_scopes: [OAuthClientScope::ServerAdministration]
|
||||
}
|
||||
|
||||
#[request]
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
pub mod v1 {
|
||||
|
||||
use ruma::{
|
||||
OwnedUserId,
|
||||
api::{OAuthClientScope, auth_scheme::AccessToken, request, response},
|
||||
metadata,
|
||||
profile::UserProfile,
|
||||
};
|
||||
|
||||
metadata! {
|
||||
method: POST,
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
history: {
|
||||
1.0 => "/_continuwuity/admin/v1/users",
|
||||
},
|
||||
required_client_scopes: [OAuthClientScope::ServerAdministration]
|
||||
}
|
||||
|
||||
#[request]
|
||||
pub struct Request {
|
||||
/// The full user ID to create. Must belong to the server.
|
||||
pub user_id: OwnedUserId,
|
||||
/// The password to set for the new user.
|
||||
///
|
||||
/// If `None`, the user will not be able to log in.
|
||||
#[serde(default, skip_serializing_if = "ruma::serde::is_default")]
|
||||
pub password: Option<String>,
|
||||
/// The profile fields to set for the user. This can be used to set the
|
||||
/// new user's display name and profile picture.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub profile: Option<UserProfile>,
|
||||
#[serde(default, skip_serializing_if = "ruma::serde::is_default")]
|
||||
pub admin: bool,
|
||||
#[serde(default, skip_serializing_if = "ruma::serde::is_default")]
|
||||
pub suspended: bool,
|
||||
#[serde(default, skip_serializing_if = "ruma::serde::is_default")]
|
||||
pub locked: bool,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[response]
|
||||
pub struct Response;
|
||||
|
||||
impl Request {
|
||||
#[must_use]
|
||||
pub fn new(user_id: OwnedUserId) -> Self {
|
||||
Self {
|
||||
user_id,
|
||||
password: None,
|
||||
profile: None,
|
||||
admin: false,
|
||||
suspended: false,
|
||||
locked: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
pub mod v1 {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma::{
|
||||
OwnedMxcUri, OwnedUserId,
|
||||
api::{OAuthClientScope, auth_scheme::AccessToken, request, response},
|
||||
metadata,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
metadata! {
|
||||
method: GET,
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
history: {
|
||||
1.0 => "/_continuwuity/admin/v1/users",
|
||||
},
|
||||
required_client_scopes: [OAuthClientScope::ServerAdministration]
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Copy)]
|
||||
pub enum QueryFilter {
|
||||
/// Always include entities matching this criteria.
|
||||
#[serde(rename = "include")]
|
||||
Include,
|
||||
/// Never include entities matching this criteria.
|
||||
#[serde(rename = "exclude")]
|
||||
Exclude,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[request]
|
||||
#[serde(default)]
|
||||
pub struct Request {
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub active: Option<QueryFilter>,
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub deactivated: Option<QueryFilter>,
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub suspended: Option<QueryFilter>,
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub locked: Option<QueryFilter>,
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub admin: Option<QueryFilter>,
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub limit: Option<usize>,
|
||||
#[ruma_api(query)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub page: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
|
||||
pub struct User {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub displayname: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub avatar_url: Option<OwnedMxcUri>,
|
||||
#[serde(skip_serializing_if = "ruma::serde::is_default")]
|
||||
pub suspended: bool,
|
||||
#[serde(skip_serializing_if = "ruma::serde::is_default")]
|
||||
pub locked: bool,
|
||||
#[serde(skip_serializing_if = "ruma::serde::is_default")]
|
||||
pub deactivated: bool,
|
||||
#[serde(skip_serializing_if = "ruma::serde::is_default")]
|
||||
pub admin: bool,
|
||||
}
|
||||
|
||||
#[response]
|
||||
pub struct Response {
|
||||
#[ruma_api(body)]
|
||||
pub users: BTreeMap<OwnedUserId, User>,
|
||||
}
|
||||
|
||||
impl Response {
|
||||
#[must_use]
|
||||
pub fn new(users: BTreeMap<OwnedUserId, User>) -> Self { Self { users } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod create;
|
||||
pub mod list;
|
||||
pub mod rooms;
|
||||
@@ -0,0 +1,66 @@
|
||||
pub mod v1 {
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ruma::{
|
||||
OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId,
|
||||
api::{OAuthClientScope, auth_scheme::AccessToken, request, response},
|
||||
events::room::member::MembershipState,
|
||||
metadata,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
metadata! {
|
||||
method: GET,
|
||||
rate_limited: false,
|
||||
authentication: AccessToken,
|
||||
history: {
|
||||
1.0 => "/_continuwuity/admin/v1/users/{user_id}/rooms",
|
||||
},
|
||||
required_client_scopes: [OAuthClientScope::ServerAdministration]
|
||||
}
|
||||
|
||||
#[request]
|
||||
pub struct Request {
|
||||
#[ruma_api(path)]
|
||||
pub user_id: OwnedUserId,
|
||||
|
||||
pub state: MembershipState,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub limit: Option<u32>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub page: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
|
||||
pub struct RoomInfo {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub avatar_url: Option<OwnedMxcUri>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub canonical_alias: Option<OwnedRoomAliasId>,
|
||||
pub member_count: u32,
|
||||
}
|
||||
|
||||
#[response]
|
||||
pub struct Response {
|
||||
pub rooms: BTreeMap<OwnedRoomId, RoomInfo>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
user_id: OwnedUserId,
|
||||
state: MembershipState,
|
||||
limit: Option<u32>,
|
||||
page: Option<u32>,
|
||||
) -> Self {
|
||||
Self { user_id, state, limit, page }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
#[must_use]
|
||||
pub fn new(rooms: BTreeMap<OwnedRoomId, RoomInfo>) -> Self { Self { rooms } }
|
||||
}
|
||||
}
|
||||
@@ -571,7 +571,8 @@ impl Service {
|
||||
));
|
||||
}
|
||||
|
||||
let device_id = self.services
|
||||
let device_id = self
|
||||
.services
|
||||
.users
|
||||
.create_device(
|
||||
&authorizing_user,
|
||||
|
||||
@@ -72,7 +72,10 @@ impl std::fmt::Display for ValidTokenSource {
|
||||
|
||||
impl crate::Service for Service {
|
||||
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
||||
let registration_tokens_from_file = args.server.config.registration_token_file
|
||||
let registration_tokens_from_file = args
|
||||
.server
|
||||
.config
|
||||
.registration_token_file
|
||||
.clone()
|
||||
// If the token file option was set, read the path it points to
|
||||
.map(std::fs::read_to_string)
|
||||
@@ -80,7 +83,8 @@ impl crate::Service for Service {
|
||||
.map_err(|err| err!("Failed to read registration token file: {err}"))
|
||||
.map(|tokens| {
|
||||
if let Some(tokens) = tokens {
|
||||
// If the token file option was set, return the file's lines as tokens
|
||||
// If the token file option was set, return the file's lines
|
||||
// as tokens
|
||||
tokens.lines().map(ToOwned::to_owned).collect()
|
||||
} else {
|
||||
// Otherwise, if the option wasn't set, return no tokens
|
||||
|
||||
@@ -164,12 +164,12 @@ impl Service {
|
||||
}
|
||||
|
||||
let mut children: Vec<_> = summary
|
||||
.children_state
|
||||
.iter()
|
||||
// Ignore deserialization failures
|
||||
.flat_map(Raw::deserialize)
|
||||
// Filter out non-suggested children if suggested_only is set
|
||||
.filter(|child| !suggested_only || child.content.suggested)
|
||||
.children_state
|
||||
.iter()
|
||||
// Ignore deserialization failures
|
||||
.flat_map(Raw::deserialize)
|
||||
// Filter out non-suggested children if suggested_only is set
|
||||
.filter(|child| !suggested_only || child.content.suggested)
|
||||
.collect();
|
||||
children.sort();
|
||||
let children = children
|
||||
@@ -323,43 +323,46 @@ impl Service {
|
||||
};
|
||||
|
||||
let (accessible_children, inaccessible_children) = children_state
|
||||
.iter()
|
||||
// Ignore deserialization failures
|
||||
.flat_map(Raw::deserialize)
|
||||
// Fetch summaries for the children in parallel
|
||||
.stream()
|
||||
.broad_then(async |child| {
|
||||
let summary = {
|
||||
if let Some(summary) = self.build_local_room_summary(&child.state_key).await {
|
||||
if self.server_may_see_summary(querying_server, &summary).await {
|
||||
Accessibility::Accessible(summary)
|
||||
} else {
|
||||
Accessibility::Inaccessible
|
||||
}
|
||||
} else {
|
||||
Accessibility::NotFound
|
||||
}
|
||||
};
|
||||
.iter()
|
||||
// Ignore deserialization failures
|
||||
.flat_map(Raw::deserialize)
|
||||
// Fetch summaries for the children in parallel
|
||||
.stream()
|
||||
.broad_then(async |child| {
|
||||
let summary = {
|
||||
if let Some(summary) = self.build_local_room_summary(&child.state_key).await {
|
||||
if self.server_may_see_summary(querying_server, &summary).await {
|
||||
Accessibility::Accessible(summary)
|
||||
} else {
|
||||
Accessibility::Inaccessible
|
||||
}
|
||||
} else {
|
||||
Accessibility::NotFound
|
||||
}
|
||||
};
|
||||
|
||||
(child.state_key, summary)
|
||||
})
|
||||
// Sort the children into two Vecs by accessibility
|
||||
.ready_fold_default(|(mut accessible_children, mut inaccessible_children): (Vec<_>, Vec<_>), (room_id, summary)| {
|
||||
match summary {
|
||||
Accessibility::Accessible(summary) => {
|
||||
accessible_children.push(summary);
|
||||
},
|
||||
Accessibility::Inaccessible => {
|
||||
inaccessible_children.push(room_id);
|
||||
},
|
||||
Accessibility::NotFound => {
|
||||
// Skip inaccessible children
|
||||
}
|
||||
}
|
||||
(child.state_key, summary)
|
||||
})
|
||||
// Sort the children into two Vecs by accessibility
|
||||
.ready_fold_default(
|
||||
|(mut accessible_children, mut inaccessible_children): (Vec<_>, Vec<_>),
|
||||
(room_id, summary)| {
|
||||
match summary {
|
||||
| Accessibility::Accessible(summary) => {
|
||||
accessible_children.push(summary);
|
||||
},
|
||||
| Accessibility::Inaccessible => {
|
||||
inaccessible_children.push(room_id);
|
||||
},
|
||||
| Accessibility::NotFound => {
|
||||
// Skip inaccessible children
|
||||
},
|
||||
}
|
||||
|
||||
(accessible_children, inaccessible_children)
|
||||
})
|
||||
.await;
|
||||
(accessible_children, inaccessible_children)
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
Accessibility::Accessible(assign!(
|
||||
get_hierarchy::v1::Response::new(SpaceHierarchyParentSummary::new(summary, children_state)),
|
||||
|
||||
@@ -449,7 +449,12 @@ impl super::Service {
|
||||
// Don't notify the sender of their own events, and don't send from ignored users
|
||||
.ready_filter(|user| *user != pdu.sender())
|
||||
.filter_map(|recipient_user| async move {
|
||||
(!self.services.users.user_is_ignored(pdu.sender(), &recipient_user).await).then_some(recipient_user)
|
||||
(!self
|
||||
.services
|
||||
.users
|
||||
.user_is_ignored(pdu.sender(), &recipient_user)
|
||||
.await)
|
||||
.then_some(recipient_user)
|
||||
})
|
||||
.collect()
|
||||
.await;
|
||||
@@ -806,7 +811,7 @@ impl super::Service {
|
||||
.read()
|
||||
.await
|
||||
.values()
|
||||
.map(ToOwned::to_owned) // TODO: is this to_owned expensive?
|
||||
.map(ToOwned::to_owned) // TODO: is this to_owned expensive?
|
||||
.collect::<Vec<_>>();
|
||||
interested_appservices
|
||||
.stream()
|
||||
|
||||
@@ -37,7 +37,7 @@ pub enum AccessTokenStatus {
|
||||
}
|
||||
|
||||
/// The status of a user account.
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Debug, Eq)]
|
||||
pub enum AccountStatus {
|
||||
NotFound,
|
||||
Active,
|
||||
|
||||
@@ -449,7 +449,12 @@ impl super::Service {
|
||||
.rooms_joined(user_id)
|
||||
// Don't send key updates to unencrypted rooms
|
||||
.filter_map(async |room_id| {
|
||||
if self.services.state_accessor.is_encrypted_room(&room_id).await {
|
||||
if self
|
||||
.services
|
||||
.state_accessor
|
||||
.is_encrypted_room(&room_id)
|
||||
.await
|
||||
{
|
||||
Some(room_id)
|
||||
} else {
|
||||
None
|
||||
|
||||
Reference in new issue
Block a user