mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Changing preferred to display name. Fixes #1211
This commit is contained in:
parent
fac024b90c
commit
bf7558830f
15 changed files with 56 additions and 45 deletions
|
@ -16,7 +16,7 @@
|
||||||
"eslint": "^7.18.0",
|
"eslint": "^7.18.0",
|
||||||
"eslint-plugin-jane": "^9.0.3",
|
"eslint-plugin-jane": "^9.0.3",
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"lemmy-js-client": "0.10.0-rc.13",
|
"lemmy-js-client": "0.11.0-rc.1",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"prettier": "^2.1.2",
|
"prettier": "^2.1.2",
|
||||||
"ts-jest": "^26.4.4",
|
"ts-jest": "^26.4.4",
|
||||||
|
|
|
@ -19,7 +19,7 @@ let apShortname: string;
|
||||||
|
|
||||||
function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe) {
|
function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe) {
|
||||||
expect(userOne.person.name).toBe(userTwo.person.name);
|
expect(userOne.person.name).toBe(userTwo.person.name);
|
||||||
expect(userOne.person.preferred_username).toBe(userTwo.person.preferred_username);
|
expect(userOne.person.display_name).toBe(userTwo.person.display_name);
|
||||||
expect(userOne.person.bio).toBe(userTwo.person.bio);
|
expect(userOne.person.bio).toBe(userTwo.person.bio);
|
||||||
expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
|
expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
|
||||||
expect(userOne.person.avatar).toBe(userTwo.person.avatar);
|
expect(userOne.person.avatar).toBe(userTwo.person.avatar);
|
||||||
|
@ -49,7 +49,7 @@ test('Set some user settings, check that they are federated', async () => {
|
||||||
lang: '',
|
lang: '',
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
preferred_username: 'user321',
|
display_name: 'user321',
|
||||||
show_avatars: false,
|
show_avatars: false,
|
||||||
send_notifications_to_email: false,
|
send_notifications_to_email: false,
|
||||||
bio,
|
bio,
|
||||||
|
|
|
@ -3233,10 +3233,10 @@ language-tags@^1.0.5:
|
||||||
dependencies:
|
dependencies:
|
||||||
language-subtag-registry "~0.3.2"
|
language-subtag-registry "~0.3.2"
|
||||||
|
|
||||||
lemmy-js-client@0.10.0-rc.13:
|
lemmy-js-client@0.11.0-rc.1:
|
||||||
version "0.10.0-rc.13"
|
version "0.11.0-rc.1"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.10.0-rc.13.tgz#ea2e88857243374d7fbd49ee6b4bb94c34359d85"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.0-rc.1.tgz#0031676be9fc787157a21dd3f5095dd1ee9e6a57"
|
||||||
integrity sha512-zodvYkwBYR7iP27ah6L/QPUphUUdq38kCH7QF2CUYBrsSAEkGmq2kdz+iusnQ1Ht7Ad80GtYycFprsZBveV5eQ==
|
integrity sha512-dtpxe/hHTbYEv2WnfGkAieOB9jyKUVED+y4DosUp/FcaatjPcMTiKOvCdMNjlvvG/9GyclWEoyNitPEsvJwjmg==
|
||||||
|
|
||||||
leven@^3.1.0:
|
leven@^3.1.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
|
|
|
@ -60,7 +60,7 @@ use lemmy_utils::{
|
||||||
email::send_email,
|
email::send_email,
|
||||||
location_info,
|
location_info,
|
||||||
settings::structs::Settings,
|
settings::structs::Settings,
|
||||||
utils::{generate_random_string, is_valid_preferred_username, naive_from_unix},
|
utils::{generate_random_string, is_valid_display_name, naive_from_unix},
|
||||||
ApiError,
|
ApiError,
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
|
@ -174,7 +174,7 @@ impl Perform for SaveUserSettings {
|
||||||
let banner = diesel_option_overwrite_to_url(&data.banner)?;
|
let banner = diesel_option_overwrite_to_url(&data.banner)?;
|
||||||
let email = diesel_option_overwrite(&data.email);
|
let email = diesel_option_overwrite(&data.email);
|
||||||
let bio = diesel_option_overwrite(&data.bio);
|
let bio = diesel_option_overwrite(&data.bio);
|
||||||
let preferred_username = diesel_option_overwrite(&data.preferred_username);
|
let display_name = diesel_option_overwrite(&data.display_name);
|
||||||
let matrix_user_id = diesel_option_overwrite(&data.matrix_user_id);
|
let matrix_user_id = diesel_option_overwrite(&data.matrix_user_id);
|
||||||
|
|
||||||
if let Some(Some(bio)) = &bio {
|
if let Some(Some(bio)) = &bio {
|
||||||
|
@ -183,8 +183,8 @@ impl Perform for SaveUserSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(Some(preferred_username)) = &preferred_username {
|
if let Some(Some(display_name)) = &display_name {
|
||||||
if !is_valid_preferred_username(preferred_username.trim()) {
|
if !is_valid_display_name(display_name.trim()) {
|
||||||
return Err(ApiError::err("invalid_username").into());
|
return Err(ApiError::err("invalid_username").into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ impl Perform for SaveUserSettings {
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
inbox_url: None,
|
inbox_url: None,
|
||||||
preferred_username,
|
display_name,
|
||||||
published: None,
|
published: None,
|
||||||
updated: Some(naive_now()),
|
updated: Some(naive_now()),
|
||||||
banned: None,
|
banned: None,
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub struct SaveUserSettings {
|
||||||
pub lang: Option<String>,
|
pub lang: Option<String>,
|
||||||
pub avatar: Option<String>,
|
pub avatar: Option<String>,
|
||||||
pub banner: Option<String>,
|
pub banner: Option<String>,
|
||||||
pub preferred_username: Option<String>,
|
pub display_name: Option<String>,
|
||||||
pub email: Option<String>,
|
pub email: Option<String>,
|
||||||
pub bio: Option<String>,
|
pub bio: Option<String>,
|
||||||
pub matrix_user_id: Option<String>,
|
pub matrix_user_id: Option<String>,
|
||||||
|
|
|
@ -64,7 +64,8 @@ impl ToApub for DbPerson {
|
||||||
set_content_and_source(&mut person, bio)?;
|
set_content_and_source(&mut person, bio)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(i) = self.preferred_username.to_owned() {
|
// In apub, the "name" is a display name
|
||||||
|
if let Some(i) = self.display_name.to_owned() {
|
||||||
person.set_name(i);
|
person.set_name(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +162,7 @@ impl FromApubToForm<PersonExt> for PersonForm {
|
||||||
.preferred_username()
|
.preferred_username()
|
||||||
.context(location_info!())?
|
.context(location_info!())?
|
||||||
.to_string();
|
.to_string();
|
||||||
let preferred_username: Option<String> = person
|
let display_name: Option<String> = person
|
||||||
.name()
|
.name()
|
||||||
.map(|n| n.one())
|
.map(|n| n.one())
|
||||||
.flatten()
|
.flatten()
|
||||||
|
@ -176,12 +177,12 @@ impl FromApubToForm<PersonExt> for PersonForm {
|
||||||
.map(|s| s.to_owned().into());
|
.map(|s| s.to_owned().into());
|
||||||
|
|
||||||
check_slurs(&name)?;
|
check_slurs(&name)?;
|
||||||
check_slurs_opt(&preferred_username)?;
|
check_slurs_opt(&display_name)?;
|
||||||
check_slurs_opt(&bio)?;
|
check_slurs_opt(&bio)?;
|
||||||
|
|
||||||
Ok(PersonForm {
|
Ok(PersonForm {
|
||||||
name,
|
name,
|
||||||
preferred_username: Some(preferred_username),
|
display_name: Some(display_name),
|
||||||
banned: None,
|
banned: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
avatar: avatar.map(|o| o.map(|i| i.into())),
|
avatar: avatar.map(|o| o.map(|i| i.into())),
|
||||||
|
|
|
@ -15,7 +15,7 @@ mod safe_type {
|
||||||
type Columns = (
|
type Columns = (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
preferred_username,
|
display_name,
|
||||||
avatar,
|
avatar,
|
||||||
banned,
|
banned,
|
||||||
published,
|
published,
|
||||||
|
@ -37,7 +37,7 @@ mod safe_type {
|
||||||
(
|
(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
preferred_username,
|
display_name,
|
||||||
avatar,
|
avatar,
|
||||||
banned,
|
banned,
|
||||||
published,
|
published,
|
||||||
|
@ -63,7 +63,7 @@ mod safe_type_alias_1 {
|
||||||
type Columns = (
|
type Columns = (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
preferred_username,
|
display_name,
|
||||||
avatar,
|
avatar,
|
||||||
banned,
|
banned,
|
||||||
published,
|
published,
|
||||||
|
@ -85,7 +85,7 @@ mod safe_type_alias_1 {
|
||||||
(
|
(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
preferred_username,
|
display_name,
|
||||||
avatar,
|
avatar,
|
||||||
banned,
|
banned,
|
||||||
published,
|
published,
|
||||||
|
@ -111,7 +111,7 @@ mod safe_type_alias_2 {
|
||||||
type Columns = (
|
type Columns = (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
preferred_username,
|
display_name,
|
||||||
avatar,
|
avatar,
|
||||||
banned,
|
banned,
|
||||||
published,
|
published,
|
||||||
|
@ -133,7 +133,7 @@ mod safe_type_alias_2 {
|
||||||
(
|
(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
preferred_username,
|
display_name,
|
||||||
avatar,
|
avatar,
|
||||||
banned,
|
banned,
|
||||||
published,
|
published,
|
||||||
|
@ -236,7 +236,7 @@ impl Person_ for Person {
|
||||||
|
|
||||||
diesel::update(person.find(person_id))
|
diesel::update(person.find(person_id))
|
||||||
.set((
|
.set((
|
||||||
preferred_username.eq::<Option<String>>(None),
|
display_name.eq::<Option<String>>(None),
|
||||||
bio.eq::<Option<String>>(None),
|
bio.eq::<Option<String>>(None),
|
||||||
matrix_user_id.eq::<Option<String>>(None),
|
matrix_user_id.eq::<Option<String>>(None),
|
||||||
deleted.eq(true),
|
deleted.eq(true),
|
||||||
|
@ -264,7 +264,7 @@ mod tests {
|
||||||
let expected_person = Person {
|
let expected_person = Person {
|
||||||
id: inserted_person.id,
|
id: inserted_person.id,
|
||||||
name: "holly".into(),
|
name: "holly".into(),
|
||||||
preferred_username: None,
|
display_name: None,
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
banned: false,
|
banned: false,
|
||||||
|
|
|
@ -270,7 +270,7 @@ table! {
|
||||||
person (id) {
|
person (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
name -> Varchar,
|
name -> Varchar,
|
||||||
preferred_username -> Nullable<Varchar>,
|
display_name -> Nullable<Varchar>,
|
||||||
avatar -> Nullable<Varchar>,
|
avatar -> Nullable<Varchar>,
|
||||||
banned -> Bool,
|
banned -> Bool,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
|
@ -470,7 +470,7 @@ table! {
|
||||||
person_alias_1 (id) {
|
person_alias_1 (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
name -> Varchar,
|
name -> Varchar,
|
||||||
preferred_username -> Nullable<Varchar>,
|
display_name -> Nullable<Varchar>,
|
||||||
avatar -> Nullable<Varchar>,
|
avatar -> Nullable<Varchar>,
|
||||||
banned -> Bool,
|
banned -> Bool,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
|
@ -494,7 +494,7 @@ table! {
|
||||||
person_alias_2 (id) {
|
person_alias_2 (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
name -> Varchar,
|
name -> Varchar,
|
||||||
preferred_username -> Nullable<Varchar>,
|
display_name -> Nullable<Varchar>,
|
||||||
avatar -> Nullable<Varchar>,
|
avatar -> Nullable<Varchar>,
|
||||||
banned -> Bool,
|
banned -> Bool,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
|
|
|
@ -10,7 +10,7 @@ use serde::Serialize;
|
||||||
pub struct Person {
|
pub struct Person {
|
||||||
pub id: PersonId,
|
pub id: PersonId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub preferred_username: Option<String>,
|
pub display_name: Option<String>,
|
||||||
pub avatar: Option<DbUrl>,
|
pub avatar: Option<DbUrl>,
|
||||||
pub banned: bool,
|
pub banned: bool,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
|
@ -35,7 +35,7 @@ pub struct Person {
|
||||||
pub struct PersonSafe {
|
pub struct PersonSafe {
|
||||||
pub id: PersonId,
|
pub id: PersonId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub preferred_username: Option<String>,
|
pub display_name: Option<String>,
|
||||||
pub avatar: Option<DbUrl>,
|
pub avatar: Option<DbUrl>,
|
||||||
pub banned: bool,
|
pub banned: bool,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
|
@ -56,7 +56,7 @@ pub struct PersonSafe {
|
||||||
pub struct PersonAlias1 {
|
pub struct PersonAlias1 {
|
||||||
pub id: PersonId,
|
pub id: PersonId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub preferred_username: Option<String>,
|
pub display_name: Option<String>,
|
||||||
pub avatar: Option<DbUrl>,
|
pub avatar: Option<DbUrl>,
|
||||||
pub banned: bool,
|
pub banned: bool,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
|
@ -80,7 +80,7 @@ pub struct PersonAlias1 {
|
||||||
pub struct PersonSafeAlias1 {
|
pub struct PersonSafeAlias1 {
|
||||||
pub id: PersonId,
|
pub id: PersonId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub preferred_username: Option<String>,
|
pub display_name: Option<String>,
|
||||||
pub avatar: Option<DbUrl>,
|
pub avatar: Option<DbUrl>,
|
||||||
pub banned: bool,
|
pub banned: bool,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
|
@ -101,7 +101,7 @@ pub struct PersonSafeAlias1 {
|
||||||
pub struct PersonAlias2 {
|
pub struct PersonAlias2 {
|
||||||
pub id: PersonId,
|
pub id: PersonId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub preferred_username: Option<String>,
|
pub display_name: Option<String>,
|
||||||
pub avatar: Option<DbUrl>,
|
pub avatar: Option<DbUrl>,
|
||||||
pub banned: bool,
|
pub banned: bool,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
|
@ -125,7 +125,7 @@ pub struct PersonAlias2 {
|
||||||
pub struct PersonSafeAlias2 {
|
pub struct PersonSafeAlias2 {
|
||||||
pub id: PersonId,
|
pub id: PersonId,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub preferred_username: Option<String>,
|
pub display_name: Option<String>,
|
||||||
pub avatar: Option<DbUrl>,
|
pub avatar: Option<DbUrl>,
|
||||||
pub banned: bool,
|
pub banned: bool,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
|
@ -145,7 +145,7 @@ pub struct PersonSafeAlias2 {
|
||||||
#[table_name = "person"]
|
#[table_name = "person"]
|
||||||
pub struct PersonForm {
|
pub struct PersonForm {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub preferred_username: Option<Option<String>>,
|
pub display_name: Option<Option<String>>,
|
||||||
pub avatar: Option<Option<DbUrl>>,
|
pub avatar: Option<Option<DbUrl>>,
|
||||||
pub banned: Option<bool>,
|
pub banned: Option<bool>,
|
||||||
pub published: Option<chrono::NaiveDateTime>,
|
pub published: Option<chrono::NaiveDateTime>,
|
||||||
|
|
|
@ -519,7 +519,7 @@ mod tests {
|
||||||
creator: PersonSafe {
|
creator: PersonSafe {
|
||||||
id: inserted_person.id,
|
id: inserted_person.id,
|
||||||
name: "timmy".into(),
|
name: "timmy".into(),
|
||||||
preferred_username: None,
|
display_name: None,
|
||||||
published: inserted_person.published,
|
published: inserted_person.published,
|
||||||
avatar: None,
|
avatar: None,
|
||||||
actor_id: inserted_person.actor_id.to_owned(),
|
actor_id: inserted_person.actor_id.to_owned(),
|
||||||
|
|
|
@ -541,7 +541,7 @@ mod tests {
|
||||||
creator: PersonSafe {
|
creator: PersonSafe {
|
||||||
id: inserted_person.id,
|
id: inserted_person.id,
|
||||||
name: person_name,
|
name: person_name,
|
||||||
preferred_username: None,
|
display_name: None,
|
||||||
published: inserted_person.published,
|
published: inserted_person.published,
|
||||||
avatar: None,
|
avatar: None,
|
||||||
actor_id: inserted_person.actor_id.to_owned(),
|
actor_id: inserted_person.actor_id.to_owned(),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
is_valid_community_name,
|
is_valid_community_name,
|
||||||
|
is_valid_display_name,
|
||||||
is_valid_post_title,
|
is_valid_post_title,
|
||||||
is_valid_preferred_username,
|
|
||||||
is_valid_username,
|
is_valid_username,
|
||||||
remove_slurs,
|
remove_slurs,
|
||||||
scrape_text_for_mentions,
|
scrape_text_for_mentions,
|
||||||
|
@ -29,9 +29,9 @@ fn test_valid_register_username() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_valid_preferred_username() {
|
fn test_valid_display_name() {
|
||||||
assert!(is_valid_preferred_username("hello @there"));
|
assert!(is_valid_display_name("hello @there"));
|
||||||
assert!(!is_valid_preferred_username("@hello there"));
|
assert!(!is_valid_display_name("@hello there"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -108,10 +108,8 @@ pub fn is_valid_username(name: &str) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't do a regex here, reverse lookarounds not supported
|
// Can't do a regex here, reverse lookarounds not supported
|
||||||
pub fn is_valid_preferred_username(preferred_username: &str) -> bool {
|
pub fn is_valid_display_name(name: &str) -> bool {
|
||||||
!preferred_username.starts_with('@')
|
!name.starts_with('@') && name.chars().count() >= 3 && name.chars().count() <= 20
|
||||||
&& preferred_username.chars().count() >= 3
|
|
||||||
&& preferred_username.chars().count() <= 20
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid_community_name(name: &str) -> bool {
|
pub fn is_valid_community_name(name: &str) -> bool {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
alter table person rename display_name to preferred_username;
|
||||||
|
|
||||||
|
-- Regenerate the person_alias views
|
||||||
|
drop view person_alias_1, person_alias_2;
|
||||||
|
create view person_alias_1 as select * from person;
|
||||||
|
create view person_alias_2 as select * from person;
|
|
@ -0,0 +1,6 @@
|
||||||
|
alter table person rename preferred_username to display_name;
|
||||||
|
|
||||||
|
-- Regenerate the person_alias views
|
||||||
|
drop view person_alias_1, person_alias_2;
|
||||||
|
create view person_alias_1 as select * from person;
|
||||||
|
create view person_alias_2 as select * from person;
|
Loading…
Reference in a new issue