mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-21 07:57:34 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce178d86d5 | ||
|
|
02f4f9d88d | ||
|
|
1deaf99409 |
No files matched your search
@@ -659,6 +659,9 @@ default-features = false
|
|||||||
[workspace.dependencies.ruminuwuity]
|
[workspace.dependencies.ruminuwuity]
|
||||||
package = "ruminuwuity"
|
package = "ruminuwuity"
|
||||||
path = "src/ruminuwuity"
|
path = "src/ruminuwuity"
|
||||||
|
features = [
|
||||||
|
"unstable-msc4484"
|
||||||
|
]
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
pub mod rooms;
|
pub mod rooms;
|
||||||
|
pub mod users;
|
||||||
@@ -6,7 +6,7 @@ use ruminuwuity::admin::continuwuity::rooms;
|
|||||||
|
|
||||||
use crate::{Ruma, client::leave_room};
|
use crate::{Ruma, client::leave_room};
|
||||||
|
|
||||||
/// # `PUT /_continuwuity/admin/rooms/{roomID}/ban`
|
/// # `PUT /_continuwuity/admin/v1/rooms/{roomID}/ban`
|
||||||
///
|
///
|
||||||
/// Bans or unbans a room.
|
/// Bans or unbans a room.
|
||||||
pub(crate) async fn ban_room(
|
pub(crate) async fn ban_room(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use ruminuwuity::admin::continuwuity::rooms;
|
|||||||
|
|
||||||
use crate::Ruma;
|
use crate::Ruma;
|
||||||
|
|
||||||
/// # `GET /_continuwuity/admin/rooms/list`
|
/// # `GET /_continuwuity/admin/v1/rooms/list`
|
||||||
///
|
///
|
||||||
/// Lists all rooms known to this server, excluding banned ones.
|
/// Lists all rooms known to this server, excluding banned ones.
|
||||||
pub(crate) async fn list_rooms(
|
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,
|
||||||
|
}
|
||||||
+4
-1
@@ -197,7 +197,10 @@ pub fn build(router: Router<State>, state: State) -> Router<State> {
|
|||||||
.merge(client::oauth::router(state))
|
.merge(client::oauth::router(state))
|
||||||
.route("/_continuwuity/server_version", get(client::continuwuity_server_version))
|
.route("/_continuwuity/server_version", get(client::continuwuity_server_version))
|
||||||
.ruma_route(&admin::rooms::ban::ban_room)
|
.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 {
|
if config.allow_federation {
|
||||||
router = router
|
router = router
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ version.workspace = true
|
|||||||
path = "mod.rs"
|
path = "mod.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["client", "server"]
|
default = ["client", "server", "unstable-msc4484"]
|
||||||
client = []
|
client = []
|
||||||
server = []
|
server = []
|
||||||
|
|
||||||
unstable-exhaustive-types = []
|
unstable-exhaustive-types = []
|
||||||
unstable-msc3202 = []
|
unstable-msc3202 = []
|
||||||
unstable-msc4203 = []
|
unstable-msc4203 = []
|
||||||
|
unstable-msc4484 = ["ruma/unstable-msc4484"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
assign.workspace = true
|
assign.workspace = true
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
pub mod rooms;
|
pub mod rooms;
|
||||||
|
pub mod users;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
pub mod v1 {
|
pub mod v1 {
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedRoomAliasId, OwnedRoomId, OwnedUserId,
|
OwnedRoomAliasId, OwnedRoomId, OwnedUserId,
|
||||||
api::{auth_scheme::AccessToken, request, response},
|
api::{OAuthClientScope, auth_scheme::AccessToken, request, response},
|
||||||
metadata,
|
metadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -10,8 +10,9 @@ pub mod v1 {
|
|||||||
rate_limited: false,
|
rate_limited: false,
|
||||||
authentication: AccessToken,
|
authentication: AccessToken,
|
||||||
history: {
|
history: {
|
||||||
1.0 => "/_continuwuity/admin/rooms/{room_id}/ban",
|
1.0 => "/_continuwuity/admin/v1/rooms/{room_id}/ban",
|
||||||
}
|
},
|
||||||
|
required_client_scopes: [OAuthClientScope::ServerAdministration]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[request]
|
#[request]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pub mod v1 {
|
pub mod v1 {
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedRoomId,
|
OwnedRoomId,
|
||||||
api::{auth_scheme::AccessToken, request, response},
|
api::{OAuthClientScope, auth_scheme::AccessToken, request, response},
|
||||||
metadata,
|
metadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -10,8 +10,9 @@ pub mod v1 {
|
|||||||
rate_limited: false,
|
rate_limited: false,
|
||||||
authentication: AccessToken,
|
authentication: AccessToken,
|
||||||
history: {
|
history: {
|
||||||
1.0 => "/_continuwuity/admin/rooms/list",
|
1.0 => "/_continuwuity/admin/v1/rooms/list",
|
||||||
}
|
},
|
||||||
|
required_client_scopes: [OAuthClientScope::ServerAdministration]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[request]
|
#[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 } }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ pub enum AccessTokenStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The status of a user account.
|
/// The status of a user account.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, PartialEq, Debug, Eq)]
|
||||||
pub enum AccountStatus {
|
pub enum AccountStatus {
|
||||||
NotFound,
|
NotFound,
|
||||||
Active,
|
Active,
|
||||||
|
|||||||
Reference in new issue
Block a user