mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-08 11:11:37 +00:00
use single config value, fix migrations, increase displayname length
This commit is contained in:
parent
e812ba10d3
commit
f9a5375393
10 changed files with 46 additions and 45 deletions
|
@ -39,10 +39,8 @@
|
||||||
pictrs_url: "http://pictrs:8080"
|
pictrs_url: "http://pictrs:8080"
|
||||||
# address where iframely is available
|
# address where iframely is available
|
||||||
iframely_url: "http://iframely"
|
iframely_url: "http://iframely"
|
||||||
# maximum length of local community names (between 3 and 255)
|
# maximum length of local community and user names
|
||||||
community_name_max_length: 20
|
actor_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 limits for various user actions, by user ip
|
||||||
rate_limit: {
|
rate_limit: {
|
||||||
# maximum number of messages created in interval
|
# maximum number of messages created in interval
|
||||||
|
|
|
@ -28,7 +28,7 @@ use lemmy_db_schema::source::{
|
||||||
use lemmy_db_views_actor::community_view::CommunityView;
|
use lemmy_db_views_actor::community_view::CommunityView;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
apub::generate_actor_keypair,
|
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,
|
ApiError,
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
|
@ -56,7 +56,7 @@ impl PerformCrud for CreateCommunity {
|
||||||
check_slurs(&data.title)?;
|
check_slurs(&data.title)?;
|
||||||
check_slurs_opt(&data.description)?;
|
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());
|
return Err(ApiError::err("invalid_community_name").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ use lemmy_utils::{
|
||||||
apub::generate_actor_keypair,
|
apub::generate_actor_keypair,
|
||||||
claims::Claims,
|
claims::Claims,
|
||||||
settings::structs::Settings,
|
settings::structs::Settings,
|
||||||
utils::{check_slurs, is_valid_username},
|
utils::{check_slurs, is_valid_actor_name},
|
||||||
ApiError,
|
ApiError,
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
|
@ -91,7 +91,7 @@ impl PerformCrud for Register {
|
||||||
check_slurs(&data.username)?;
|
check_slurs(&data.username)?;
|
||||||
|
|
||||||
let actor_keypair = generate_actor_keypair()?;
|
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());
|
return Err(ApiError::err("invalid_username").into());
|
||||||
}
|
}
|
||||||
let actor_id = generate_apub_endpoint(EndpointType::Person, &data.username)?;
|
let actor_id = generate_apub_endpoint(EndpointType::Person, &data.username)?;
|
||||||
|
|
|
@ -89,12 +89,12 @@ impl actix_web::error::ResponseError for LemmyError {
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
|
pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
|
||||||
"^group:([a-z0-9_]{{3, 20}})@{}$",
|
"^group:([a-z0-9_]{{3,}})@{}$",
|
||||||
Settings::get().hostname()
|
Settings::get().hostname()
|
||||||
))
|
))
|
||||||
.expect("compile webfinger regex");
|
.expect("compile webfinger regex");
|
||||||
pub static ref WEBFINGER_USERNAME_REGEX: Regex = Regex::new(&format!(
|
pub static ref WEBFINGER_USERNAME_REGEX: Regex = Regex::new(&format!(
|
||||||
"^acct:([a-z0-9_]{{3, 20}})@{}$",
|
"^acct:([a-z0-9_]{{3,}})@{}$",
|
||||||
Settings::get().hostname()
|
Settings::get().hostname()
|
||||||
))
|
))
|
||||||
.expect("compile webfinger regex");
|
.expect("compile webfinger regex");
|
||||||
|
|
|
@ -18,8 +18,7 @@ impl Default for Settings {
|
||||||
pictrs_url: Some("http://pictrs:8080".into()),
|
pictrs_url: Some("http://pictrs:8080".into()),
|
||||||
iframely_url: Some("http://iframely".into()),
|
iframely_url: Some("http://iframely".into()),
|
||||||
additional_slurs: None,
|
additional_slurs: None,
|
||||||
community_name_max_length: Some(20),
|
actor_name_max_length: Some(20),
|
||||||
user_name_max_length: Some(20),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ pub struct Settings {
|
||||||
pub(crate) email: Option<EmailConfig>,
|
pub(crate) email: Option<EmailConfig>,
|
||||||
pub(crate) setup: Option<SetupConfig>,
|
pub(crate) setup: Option<SetupConfig>,
|
||||||
pub(crate) additional_slurs: Option<String>,
|
pub(crate) additional_slurs: Option<String>,
|
||||||
pub(crate) community_name_max_length: Option<usize>,
|
pub(crate) actor_name_max_length: Option<usize>,
|
||||||
pub(crate) user_name_max_length: Option<usize>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
is_valid_community_name,
|
is_valid_actor_name,
|
||||||
is_valid_display_name,
|
is_valid_display_name,
|
||||||
is_valid_matrix_id,
|
is_valid_matrix_id,
|
||||||
is_valid_post_title,
|
is_valid_post_title,
|
||||||
is_valid_username,
|
|
||||||
remove_slurs,
|
remove_slurs,
|
||||||
scrape_text_for_mentions,
|
scrape_text_for_mentions,
|
||||||
slur_check,
|
slur_check,
|
||||||
|
@ -21,12 +20,12 @@ fn test_mentions_regex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_valid_register_username() {
|
fn test_valid_actor_name() {
|
||||||
assert!(is_valid_username("Hello_98"));
|
assert!(is_valid_actor_name("Hello_98"));
|
||||||
assert!(is_valid_username("ten"));
|
assert!(is_valid_actor_name("ten"));
|
||||||
assert!(!is_valid_username("Hello-98"));
|
assert!(!is_valid_actor_name("Hello-98"));
|
||||||
assert!(!is_valid_username("a"));
|
assert!(!is_valid_actor_name("a"));
|
||||||
assert!(!is_valid_username(""));
|
assert!(!is_valid_actor_name(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -41,15 +40,6 @@ fn test_valid_display_name() {
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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]
|
#[test]
|
||||||
fn test_valid_post_title() {
|
fn test_valid_post_title() {
|
||||||
assert!(is_valid_post_title("Post Title"));
|
assert!(is_valid_post_title("Post Title"));
|
||||||
|
|
|
@ -22,8 +22,7 @@ lazy_static! {
|
||||||
// TODO keep this old one, it didn't work with port well tho
|
// 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._-]+\.[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 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,}$").expect("compile regex");
|
static ref VALID_ACTOR_NAME_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_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");
|
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
|
// taken from https://en.wikipedia.org/wiki/UTM_parameters
|
||||||
|
@ -116,32 +115,32 @@ pub fn scrape_text_for_mentions(text: &str) -> Vec<MentionData> {
|
||||||
out.into_iter().unique().collect()
|
out.into_iter().unique().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid_username(name: &str) -> bool {
|
pub fn is_valid_actor_name(name: &str) -> bool {
|
||||||
let max_length = Settings::get()
|
let max_length = Settings::get()
|
||||||
.user_name_max_length
|
.actor_name_max_length
|
||||||
.unwrap_or_else(|| Settings::default().user_name_max_length.unwrap());
|
.unwrap_or_else(|| Settings::default().actor_name_max_length.unwrap());
|
||||||
name.chars().count() <= max_length && VALID_USERNAME_REGEX.is_match(name)
|
dbg!(&max_length);
|
||||||
|
dbg!(&name);
|
||||||
|
dbg!(name.chars().count() <= max_length);
|
||||||
|
dbg!(VALID_ACTOR_NAME_REGEX.is_match(name));
|
||||||
|
name.chars().count() <= max_length && VALID_ACTOR_NAME_REGEX.is_match(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't do a regex here, reverse lookarounds not supported
|
// Can't do a regex here, reverse lookarounds not supported
|
||||||
pub fn is_valid_display_name(name: &str) -> bool {
|
pub fn is_valid_display_name(name: &str) -> bool {
|
||||||
|
let max_length = Settings::get()
|
||||||
|
.actor_name_max_length
|
||||||
|
.unwrap_or_else(|| Settings::default().actor_name_max_length.unwrap());
|
||||||
!name.starts_with('@')
|
!name.starts_with('@')
|
||||||
&& !name.starts_with('\u{200b}')
|
&& !name.starts_with('\u{200b}')
|
||||||
&& name.chars().count() >= 3
|
&& name.chars().count() >= 3
|
||||||
&& name.chars().count() <= 20
|
&& name.chars().count() <= max_length
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid_matrix_id(matrix_id: &str) -> bool {
|
pub fn is_valid_matrix_id(matrix_id: &str) -> bool {
|
||||||
VALID_MATRIX_ID_REGEX.is_match(matrix_id)
|
VALID_MATRIX_ID_REGEX.is_match(matrix_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid_community_name(name: &str) -> bool {
|
|
||||||
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 {
|
pub fn is_valid_post_title(title: &str) -> bool {
|
||||||
VALID_POST_TITLE_REGEX.is_match(title)
|
VALID_POST_TITLE_REGEX.is_match(title)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,10 @@
|
||||||
|
DROP VIEW person_alias_1;
|
||||||
|
DROP VIEW person_alias_2;
|
||||||
|
|
||||||
ALTER TABLE community ALTER COLUMN name TYPE varchar(20);
|
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 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;
|
||||||
|
|
|
@ -1,2 +1,10 @@
|
||||||
|
DROP VIEW person_alias_1;
|
||||||
|
DROP VIEW person_alias_2;
|
||||||
|
|
||||||
ALTER TABLE community ALTER COLUMN name TYPE varchar(255);
|
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 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;
|
||||||
|
|
Loading…
Reference in a new issue