-
Notifications
You must be signed in to change notification settings - Fork 403
Allow username capitalization change #12438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
3rd commit just fixes branch being behind- ignore. |
a3a5979 to
086c3ac
Compare
086c3ac to
7830ba2
Compare
|
public function testUsernameWithDifferentCasingIsSame()
{
$user = $this->createUser();
$errors = $user->validateChangeUsername('iAmUser')->all();
$expected = [osu_trans('model_validation.user.change_username.username_is_same')];
$this->assertArrayHasKey('username', $errors);
$this->assertArraySubset($expected, $errors['username'], true);
}needs to be checked out, tests fails on there. |
|
Would this not increase the cost of the next namechange? I believe that this is not the case at the moment for namechanges done over email. |
it might, depending whether of not the change is logged into db: public function usernameChangeHistory()
{
return $this->hasMany(UsernameChangeHistory::class);
}public function usernameChangeCost()
{
$minTier = $this->usernameChangeHistory()->paid()->exists() ? 1 : 0;
$tier = max(
$this->usernameChangeHistory()
->paid()
->where('timestamp', '>', Carbon::now()->subYearsNoOverflow(3))
->count(),
$minTier,
);
return match ($tier) {
0 => 0,
1 => 8,
2 => 16,
3 => 32,
4 => 64,
default => 100,
};
} |
private function updateUsername(string $newUsername, string $type): UsernameChangeHistory
{
$oldUsername = $type === 'revert' ? null : $this->getOriginal('username');
$this->username_previous = $oldUsername;
$this->username = $newUsername;
return DB::transaction(function () use ($newUsername, $oldUsername, $type) {
Forum\Forum::where('forum_last_poster_id', $this->user_id)->update(['forum_last_poster_name' => $newUsername]);
// DB::table('phpbb_moderator_cache')->where('user_id', $this->user_id)->update(['username' => $newUsername]);
Forum\Post::where('poster_id', $this->user_id)->update(['post_username' => $newUsername]);
Forum\Topic::where('topic_poster', $this->user_id)
->update(['topic_first_poster_name' => $newUsername]);
Forum\Topic::where('topic_last_poster_id', $this->user_id)
->update(['topic_last_poster_name' => $newUsername]);
$history = $this->usernameChangeHistory()->create([
'username' => $newUsername,
'username_last' => $oldUsername,
'timestamp' => Carbon::now(),
'type' => $type,
]);
if (!$history->exists) {
throw new ModelNotSavedException('failed saving model');
}
$skipValidations = in_array($type, ['inactive', 'revert'], true);
$this->saveOrExplode(['skipValidations' => $skipValidations]);
return $history;
});
}i believe this is where we should change it to not add to db. cleanUsername function removes any cases though so a workaround? |
|
|
||
| if (User::cleanUsername($this->username) === $this->user->username_clean) { | ||
| // Block if new username is exactly the same as current (case-sensitive match) | ||
| if (strcasecmp($this->username, $this->user->username) === 0 && $this->username === $this->user->username) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why not just compare them. If It blocks when they are exactly the same, there doesn't seem to be any need to do a case-insensitive comparison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the cleanUsername strips all possibilities of case comparison
This is not a big need, but the only way to change username capitalization so far has been only to message support (i think?) or to change username twice (temporary username and then other capitalization). This needs to be checked further since i'm not the best at Laravel but should work!
reopened