pictrs_url: "http://pictrs:8080"
# address where iframely is available
iframely_url: "http://iframely"
+ # maximum length of local community and user names
+ actor_name_max_length: 20
# rate limits for various user actions, by user ip
rate_limit: {
# maximum number of messages created in interval
use lemmy_db_views_actor::community_view::CommunityView;
use lemmy_utils::{
apub::generate_actor_keypair,
- utils::{check_slurs, check_slurs_opt, is_valid_community_name},
+ utils::{check_slurs, check_slurs_opt, is_valid_actor_name},
ApiError,
ConnectionId,
LemmyError,
check_slurs(&data.title)?;
check_slurs_opt(&data.description)?;
- if !is_valid_community_name(&data.name) {
+ if !is_valid_actor_name(&data.name) {
return Err(ApiError::err("invalid_community_name").into());
}
apub::generate_actor_keypair,
claims::Claims,
settings::structs::Settings,
- utils::{check_slurs, is_valid_username},
+ utils::{check_slurs, is_valid_actor_name},
ApiError,
ConnectionId,
LemmyError,
check_slurs(&data.username)?;
let actor_keypair = generate_actor_keypair()?;
- if !is_valid_username(&data.username) {
+ if !is_valid_actor_name(&data.username) {
return Err(ApiError::err("invalid_username").into());
}
let actor_id = generate_apub_endpoint(EndpointType::Person, &data.username)?;
lazy_static! {
pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
- "^group:([a-z0-9_]{{3, 20}})@{}$",
+ "^group:([a-z0-9_]{{3,}})@{}$",
Settings::get().hostname()
))
.expect("compile webfinger regex");
pub static ref WEBFINGER_USERNAME_REGEX: Regex = Regex::new(&format!(
- "^acct:([a-z0-9_]{{3, 20}})@{}$",
+ "^acct:([a-z0-9_]{{3,}})@{}$",
Settings::get().hostname()
))
.expect("compile webfinger regex");
pictrs_url: Some("http://pictrs:8080".into()),
iframely_url: Some("http://iframely".into()),
additional_slurs: None,
+ actor_name_max_length: Some(20),
}
}
}
Ok(Self::read_config_file()?)
}
- pub fn database(&self) -> DatabaseConfig {
- self.database.to_owned().unwrap_or_default()
- }
pub fn hostname(&self) -> String {
- self.hostname.to_owned().unwrap_or_default()
+ self.hostname.to_owned().expect("No hostname given")
}
pub fn bind(&self) -> IpAddr {
self.bind.expect("return bind address")
}
pub fn port(&self) -> u16 {
- self.port.unwrap_or_default()
+ self
+ .port
+ .unwrap_or_else(|| Settings::default().port.expect("missing port"))
}
pub fn tls_enabled(&self) -> bool {
- self.tls_enabled.unwrap_or_default()
+ self.tls_enabled.unwrap_or_else(|| {
+ Settings::default()
+ .tls_enabled
+ .expect("missing tls_enabled")
+ })
}
pub fn jwt_secret(&self) -> String {
- self.jwt_secret.to_owned().unwrap_or_default()
+ self
+ .jwt_secret
+ .to_owned()
+ .unwrap_or_else(|| Settings::default().jwt_secret.expect("missing jwt_secret"))
}
pub fn pictrs_url(&self) -> String {
- self.pictrs_url.to_owned().unwrap_or_default()
+ self
+ .pictrs_url
+ .to_owned()
+ .unwrap_or_else(|| Settings::default().pictrs_url.expect("missing pictrs_url"))
}
pub fn iframely_url(&self) -> String {
- self.iframely_url.to_owned().unwrap_or_default()
+ self.iframely_url.to_owned().unwrap_or_else(|| {
+ Settings::default()
+ .iframely_url
+ .expect("missing iframely_url")
+ })
+ }
+ pub fn actor_name_max_length(&self) -> usize {
+ self.actor_name_max_length.unwrap_or_else(|| {
+ Settings::default()
+ .actor_name_max_length
+ .expect("missing actor name length")
+ })
+ }
+ pub fn database(&self) -> DatabaseConfig {
+ self.database.to_owned().unwrap_or_default()
}
pub fn rate_limit(&self) -> RateLimitConfig {
self.rate_limit.to_owned().unwrap_or_default()
pub(crate) email: Option<EmailConfig>,
pub(crate) setup: Option<SetupConfig>,
pub(crate) additional_slurs: Option<String>,
+ pub(crate) actor_name_max_length: Option<usize>,
}
#[derive(Debug, Deserialize, Clone)]
use crate::utils::{
- is_valid_community_name,
+ is_valid_actor_name,
is_valid_display_name,
is_valid_matrix_id,
is_valid_post_title,
- is_valid_username,
remove_slurs,
scrape_text_for_mentions,
slur_check,
}
#[test]
-fn test_valid_register_username() {
- assert!(is_valid_username("Hello_98"));
- assert!(is_valid_username("ten"));
- assert!(!is_valid_username("Hello-98"));
- assert!(!is_valid_username("a"));
- assert!(!is_valid_username(""));
+fn test_valid_actor_name() {
+ assert!(is_valid_actor_name("Hello_98"));
+ assert!(is_valid_actor_name("ten"));
+ assert!(!is_valid_actor_name("Hello-98"));
+ assert!(!is_valid_actor_name("a"));
+ assert!(!is_valid_actor_name(""));
}
#[test]
)));
}
-#[test]
-fn test_valid_community_name() {
- assert!(is_valid_community_name("example"));
- assert!(is_valid_community_name("example_community"));
- assert!(!is_valid_community_name("Example"));
- assert!(!is_valid_community_name("Ex"));
- assert!(!is_valid_community_name(""));
-}
-
#[test]
fn test_valid_post_title() {
assert!(is_valid_post_title("Post Title"));
// TODO keep this old one, it didn't work with port well tho
// static ref MENTIONS_REGEX: Regex = Regex::new(r"@(?P<name>[\w.]+)@(?P<domain>[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)").expect("compile regex");
static ref MENTIONS_REGEX: Regex = Regex::new(r"@(?P<name>[\w.]+)@(?P<domain>[a-zA-Z0-9._:-]+)").expect("compile regex");
- static ref VALID_USERNAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_]{3,20}$").expect("compile regex");
- static ref VALID_COMMUNITY_NAME_REGEX: Regex = Regex::new(r"^[a-z0-9_]{3,20}$").expect("compile regex");
+ static ref VALID_ACTOR_NAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex");
static ref VALID_POST_TITLE_REGEX: Regex = Regex::new(r".*\S.*").expect("compile regex");
static ref VALID_MATRIX_ID_REGEX: Regex = Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex");
// taken from https://en.wikipedia.org/wiki/UTM_parameters
out.into_iter().unique().collect()
}
-pub fn is_valid_username(name: &str) -> bool {
- VALID_USERNAME_REGEX.is_match(name)
+pub fn is_valid_actor_name(name: &str) -> bool {
+ name.chars().count() <= Settings::get().actor_name_max_length()
+ && VALID_ACTOR_NAME_REGEX.is_match(name)
}
// Can't do a regex here, reverse lookarounds not supported
!name.starts_with('@')
&& !name.starts_with('\u{200b}')
&& name.chars().count() >= 3
- && name.chars().count() <= 20
+ && name.chars().count() <= Settings::get().actor_name_max_length()
}
pub fn is_valid_matrix_id(matrix_id: &str) -> bool {
VALID_MATRIX_ID_REGEX.is_match(matrix_id)
}
-pub fn is_valid_community_name(name: &str) -> bool {
- VALID_COMMUNITY_NAME_REGEX.is_match(name)
-}
-
pub fn is_valid_post_title(title: &str) -> bool {
VALID_POST_TITLE_REGEX.is_match(title)
}
--- /dev/null
+DROP VIEW person_alias_1;
+DROP VIEW person_alias_2;
+
+ALTER TABLE community ALTER COLUMN name TYPE varchar(20);
+ALTER TABLE community ALTER COLUMN title TYPE varchar(100);
+ALTER TABLE person ALTER COLUMN name TYPE varchar(20);
+ALTER TABLE person ALTER COLUMN display_name TYPE varchar(20);
+
+create view person_alias_1 as select * from person;
+create view person_alias_2 as select * from person;
--- /dev/null
+DROP VIEW person_alias_1;
+DROP VIEW person_alias_2;
+
+ALTER TABLE community ALTER COLUMN name TYPE varchar(255);
+ALTER TABLE community ALTER COLUMN title TYPE varchar(255);
+ALTER TABLE person ALTER COLUMN name TYPE varchar(255);
+ALTER TABLE person ALTER COLUMN display_name TYPE varchar(255);
+
+create view person_alias_1 as select * from person;
+create view person_alias_2 as select * from person;