mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
simplify is_admin
This commit is contained in:
parent
70fa17dde0
commit
d4b5f62bfe
1 changed files with 4 additions and 16 deletions
|
|
@ -9,7 +9,6 @@ pub(crate) use data::Data;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
device::Device,
|
device::Device,
|
||||||
error::ErrorKind,
|
|
||||||
filter::FilterDefinition,
|
filter::FilterDefinition,
|
||||||
sync::sync_events::{
|
sync::sync_events::{
|
||||||
self,
|
self,
|
||||||
|
|
@ -20,7 +19,7 @@ use ruma::{
|
||||||
events::AnyToDeviceEvent,
|
events::AnyToDeviceEvent,
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, OwnedDeviceId, OwnedDeviceKeyId,
|
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, OwnedDeviceId, OwnedDeviceKeyId,
|
||||||
OwnedMxcUri, OwnedRoomId, OwnedUserId, RoomAliasId, UInt, UserId,
|
OwnedMxcUri, OwnedRoomId, OwnedUserId, UInt, UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result};
|
use crate::{services, Error, Result};
|
||||||
|
|
@ -259,20 +258,9 @@ impl Service {
|
||||||
// Allowed because this function uses `services()`
|
// Allowed because this function uses `services()`
|
||||||
#[allow(clippy::unused_self)]
|
#[allow(clippy::unused_self)]
|
||||||
pub(crate) fn is_admin(&self, user_id: &UserId) -> Result<bool> {
|
pub(crate) fn is_admin(&self, user_id: &UserId) -> Result<bool> {
|
||||||
let admin_room_alias_id = RoomAliasId::parse(format!(
|
services().admin.get_admin_room()?.map_or(Ok(false), |admin_room_id| {
|
||||||
"#admins:{}",
|
services().rooms.state_cache.is_joined(user_id, &admin_room_id)
|
||||||
services().globals.server_name()
|
})
|
||||||
))
|
|
||||||
.map_err(|_| {
|
|
||||||
Error::BadRequest(ErrorKind::InvalidParam, "Invalid alias.")
|
|
||||||
})?;
|
|
||||||
let admin_room_id = services()
|
|
||||||
.rooms
|
|
||||||
.alias
|
|
||||||
.resolve_local_alias(&admin_room_alias_id)?
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
services().rooms.state_cache.is_joined(user_id, &admin_room_id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new user account on this homeserver.
|
/// Create a new user account on this homeserver.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue