mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-27 06:41:18 +00:00
Make length of user/community name configurable (fixes #1306)
This commit is contained in:
parent
5fe7de2bff
commit
e812ba10d3
6 changed files with 22 additions and 4 deletions
|
@ -39,6 +39,10 @@
|
|||
pictrs_url: "http://pictrs:8080"
|
||||
# address where iframely is available
|
||||
iframely_url: "http://iframely"
|
||||
# maximum length of local community names (between 3 and 255)
|
||||
community_name_max_length: 20
|
||||
# maximum length of local user names (between 3 and 255)
|
||||
user_name_max_length: 20
|
||||
# rate limits for various user actions, by user ip
|
||||
rate_limit: {
|
||||
# maximum number of messages created in interval
|
||||
|
|
|
@ -18,6 +18,8 @@ impl Default for Settings {
|
|||
pictrs_url: Some("http://pictrs:8080".into()),
|
||||
iframely_url: Some("http://iframely".into()),
|
||||
additional_slurs: None,
|
||||
community_name_max_length: Some(20),
|
||||
user_name_max_length: Some(20),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ pub struct Settings {
|
|||
pub(crate) email: Option<EmailConfig>,
|
||||
pub(crate) setup: Option<SetupConfig>,
|
||||
pub(crate) additional_slurs: Option<String>,
|
||||
pub(crate) community_name_max_length: Option<usize>,
|
||||
pub(crate) user_name_max_length: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
|
|
|
@ -22,8 +22,8 @@ lazy_static! {
|
|||
// 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_USERNAME_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex");
|
||||
static ref VALID_COMMUNITY_NAME_REGEX: Regex = Regex::new(r"^[a-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
|
||||
|
@ -117,7 +117,10 @@ pub fn scrape_text_for_mentions(text: &str) -> Vec<MentionData> {
|
|||
}
|
||||
|
||||
pub fn is_valid_username(name: &str) -> bool {
|
||||
VALID_USERNAME_REGEX.is_match(name)
|
||||
let max_length = Settings::get()
|
||||
.user_name_max_length
|
||||
.unwrap_or_else(|| Settings::default().user_name_max_length.unwrap());
|
||||
name.chars().count() <= max_length && VALID_USERNAME_REGEX.is_match(name)
|
||||
}
|
||||
|
||||
// Can't do a regex here, reverse lookarounds not supported
|
||||
|
@ -133,7 +136,10 @@ pub fn is_valid_matrix_id(matrix_id: &str) -> bool {
|
|||
}
|
||||
|
||||
pub fn is_valid_community_name(name: &str) -> bool {
|
||||
VALID_COMMUNITY_NAME_REGEX.is_match(name)
|
||||
let max_length = Settings::get()
|
||||
.community_name_max_length
|
||||
.unwrap_or_else(|| Settings::default().community_name_max_length.unwrap());
|
||||
name.chars().count() <= max_length && VALID_COMMUNITY_NAME_REGEX.is_match(name)
|
||||
}
|
||||
|
||||
pub fn is_valid_post_title(title: &str) -> bool {
|
||||
|
|
2
migrations/2021-07-20-102033_actor_name_length/down.sql
Normal file
2
migrations/2021-07-20-102033_actor_name_length/down.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE community ALTER COLUMN name TYPE varchar(20);
|
||||
ALTER TABLE person ALTER COLUMN name TYPE varchar(20);
|
2
migrations/2021-07-20-102033_actor_name_length/up.sql
Normal file
2
migrations/2021-07-20-102033_actor_name_length/up.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE community ALTER COLUMN name TYPE varchar(255);
|
||||
ALTER TABLE person ALTER COLUMN name TYPE varchar(255);
|
Loading…
Reference in a new issue