Skip to content

Commit d40fbda

Browse files
committed
people don't have a "first" and "last" name
https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ migrates all profile data
1 parent a227373 commit d40fbda

File tree

7 files changed

+26
-17
lines changed

7 files changed

+26
-17
lines changed

bin/mongodb/real-name-migrate.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const sel = { $or: [{ 'profile.firstName': { $exists: true } }, { 'profile.lastName': { $exists: true } }] };
2+
3+
db.user4
4+
.find(sel, { profile: 1 })
5+
.limit(1000)
6+
.forEach(function (user) {
7+
const fullName = ((user.profile.firstName || '') + ' ' + (user.profile.lastName || ''))
8+
.trim()
9+
.replace(/\s+/g, ' ');
10+
db.user4.updateOne(
11+
{ _id: user._id },
12+
{
13+
$set: { 'profile.realName': fullName },
14+
$unset: { 'profile.firstName': true, 'profile.lastName': true },
15+
},
16+
);
17+
});

modules/core/src/main/user.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ object user:
111111
@Key("country") flag: Option[String] = None,
112112
location: Option[String] = None,
113113
bio: Option[String] = None,
114-
firstName: Option[String] = None,
115-
lastName: Option[String] = None,
114+
realName: Option[String] = None,
116115
fideRating: Option[Int] = None,
117116
uscfRating: Option[Int] = None,
118117
ecfRating: Option[Int] = None,
@@ -121,10 +120,7 @@ object user:
121120
dsbRating: Option[Int] = None,
122121
links: Option[String] = None
123122
):
124-
def nonEmptyRealName =
125-
List(ne(firstName), ne(lastName)).flatten match
126-
case Nil => none
127-
case names => (names.mkString(" ")).some
123+
def nonEmptyRealName = ne(realName)
128124

129125
def nonEmptyLocation = ne(location)
130126

@@ -133,9 +129,10 @@ object user:
133129
def isEmpty = completionPercent == 0
134130

135131
def completionPercent: Int =
136-
100 * List(flag, bio, firstName, lastName).count(_.isDefined) / 4
132+
100 * List(flag, bio, realName).count(_.isDefined) / 4
137133

138134
private def ne(str: Option[String]) = str.filter(_.nonEmpty)
135+
139136
end Profile
140137

141138
object Profile:

modules/coreI18n/src/main/key.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ object I18nKey:
397397
val `ifNoneLeaveEmpty`: I18nKey = "ifNoneLeaveEmpty"
398398
val `profile`: I18nKey = "profile"
399399
val `editProfile`: I18nKey = "editProfile"
400-
val `firstName`: I18nKey = "firstName"
401-
val `lastName`: I18nKey = "lastName"
400+
val `realName`: I18nKey = "realName"
402401
val `setFlair`: I18nKey = "setFlair"
403402
val `flair`: I18nKey = "flair"
404403
val `youCanHideFlair`: I18nKey = "youCanHideFlair"

modules/pref/src/main/ui/AccountPages.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ final class AccountPages(helpers: Helpers, ui: AccountUi, flagApi: lila.core.use
7878
form3.group(form("location"), trans.site.location(), half = true)(form3.input(_))
7979
),
8080
form3.split(
81-
form3.group(form("firstName"), trans.site.firstName(), half = true)(form3.input(_)),
82-
form3.group(form("lastName"), trans.site.lastName(), half = true)(form3.input(_))
81+
form3.group(form("realName"), trans.site.realName(), half = true)(form3.input(_))
8382
),
8483
form3.split(
8584
List("fide", "uscf", "ecf", "rcf", "cfc", "dsb").map: rn =>

modules/user/src/main/Profile.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ object Profile:
2323

2424
def filterTroll(troll: Boolean): Profile = p.copy(
2525
bio = p.bio.ifFalse(troll),
26-
firstName = p.firstName.ifFalse(troll),
27-
lastName = p.lastName.ifFalse(troll),
26+
realName = p.realName.ifFalse(troll),
2827
location = p.location.ifFalse(troll),
2928
links = p.links.ifFalse(troll)
3029
)

modules/user/src/main/UserForm.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ final class UserForm:
4242
"flag" -> optional(text.verifying(Flags.codeSet contains _)),
4343
"location" -> optional(cleanNoSymbolsAndNonEmptyText(maxLength = 80)),
4444
"bio" -> optional(cleanNoSymbolsAndNonEmptyText(maxLength = 400)),
45-
"firstName" -> nameField,
46-
"lastName" -> nameField,
45+
"realName" -> nameField,
4746
"fideRating" -> optional(number(min = 1400, max = 3000)),
4847
"uscfRating" -> optional(number(min = 100, max = 3000)),
4948
"ecfRating" -> optional(number(min = 0, max = 3000)),

translation/source/site.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,7 @@
509509
<string name="ifNoneLeaveEmpty">If none, leave empty</string>
510510
<string name="profile">Profile</string>
511511
<string name="editProfile">Edit profile</string>
512-
<string name="firstName">First name</string>
513-
<string name="lastName">Surname</string>
512+
<string name="realName">Real name</string>
514513
<string name="setFlair">Set your flair</string>
515514
<string name="flair">Flair</string>
516515
<string name="youCanHideFlair">There is a setting to hide all user flairs across the entire site.</string>

0 commit comments

Comments
 (0)