add: ability to ip block users from their profile
This commit is contained in:
parent
a799c777ea
commit
0163391380
12 changed files with 241 additions and 20 deletions
|
@ -2,7 +2,7 @@ use oiseau::cache::Cache;
|
|||
use crate::model::{Error, Result, auth::User, auth::IpBlock, permissions::FinePermission};
|
||||
use crate::{auto_method, DataManager};
|
||||
|
||||
use oiseau::PostgresRow;
|
||||
use oiseau::{query_rows, PostgresRow};
|
||||
|
||||
use oiseau::{execute, get, query_row, params};
|
||||
|
||||
|
@ -19,7 +19,7 @@ impl DataManager {
|
|||
|
||||
auto_method!(get_ipblock_by_id()@get_ipblock_from_row -> "SELECT * FROM ipblocks WHERE id = $1" --name="ip block" --returns=IpBlock --cache-key-tmpl="atto.ipblock:{}");
|
||||
|
||||
/// Get a user block by `initiator` and `receiver` (in that order).
|
||||
/// Get a ip block by `initiator` and `receiver` (in that order).
|
||||
pub async fn get_ipblock_by_initiator_receiver(
|
||||
&self,
|
||||
initiator: usize,
|
||||
|
@ -38,13 +38,13 @@ impl DataManager {
|
|||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("user block".to_string()));
|
||||
return Err(Error::GeneralNotFound("ip block".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get a user block by `receiver` and `initiator` (in that order).
|
||||
/// Get a ip block by `receiver` and `initiator` (in that order).
|
||||
pub async fn get_ipblock_by_receiver_initiator(
|
||||
&self,
|
||||
receiver: &str,
|
||||
|
@ -63,13 +63,34 @@ impl DataManager {
|
|||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("user block".to_string()));
|
||||
return Err(Error::GeneralNotFound("ip block".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Create a new user block in the database.
|
||||
/// Get all ip blocks by `initiator`.
|
||||
pub async fn get_ipblocks_by_initiator(&self, initiator: usize) -> Result<Vec<IpBlock>> {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM ipblocks WHERE initiator = $1",
|
||||
params![&(initiator as i64)],
|
||||
|x| { Self::get_ipblock_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("ip block".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Create a new ip block in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `data` - a mock [`IpBlock`] object to insert
|
||||
|
@ -102,7 +123,7 @@ impl DataManager {
|
|||
let block = self.get_ipblock_by_id(id).await?;
|
||||
|
||||
if user.id != block.initiator {
|
||||
// only the initiator (or moderators) can delete user blocks!
|
||||
// only the initiator (or moderators) can delete ip blocks!
|
||||
if !user.permissions.check(FinePermission::MANAGE_FOLLOWS) {
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
|
|
@ -192,6 +192,15 @@ pub struct UserSettings {
|
|||
/// Custom CSS input.
|
||||
#[serde(default)]
|
||||
pub theme_custom_css: String,
|
||||
/// The color of an online online indicator.
|
||||
#[serde(default)]
|
||||
pub theme_color_online: String,
|
||||
/// The color of an idle online indicator.
|
||||
#[serde(default)]
|
||||
pub theme_color_idle: String,
|
||||
/// The color of an offline online indicator.
|
||||
#[serde(default)]
|
||||
pub theme_color_offline: String,
|
||||
#[serde(default)]
|
||||
pub disable_other_themes: bool,
|
||||
#[serde(default)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue