laravel.io icon indicating copy to clipboard operation
laravel.io copied to clipboard

GitHub usernames should be unique

Open driesvints opened this issue 4 years ago • 4 comments

Filter out any duplicates with:

SELECT
    github_username,
    COUNT(github_username)
FROM
    users
GROUP BY
    github_username
HAVING
    COUNT(github_username) > 1;

SELECT
    *
FROM
    users
WHERE
    github_username = 'duplicate';

These can actually be synced from their GitHub ID. We should run a queued job that goes over all accounts and syncs them. Maybe also a scheduled job or a GitHub webhook.

driesvints avatar Jul 31 '21 18:07 driesvints

Once duplicates are identified, what should be done with them?

rorymcdaniel avatar Nov 14 '21 14:11 rorymcdaniel

So, the GitHub ID of a user is already unique. We can retrieve the GitHub user from the public rest api to determine its username and then update it in the Laravel.io DB.

driesvints avatar Nov 14 '21 17:11 driesvints

@driesvints I have another proposal for this which may be suitable.

We have an immediate issue where some duplicates exist in the database so we need to clear those up which I think we could do with a one-time command.

The only way I can see duplicates arising after this is when people signup or when they login (we update the GitHub username at this point) and they had previously been using the same GitHub username with a different GitHub account.

If this is the case, can we do a little more work at the point a user signs up or logs in to check for duplicates. We already do this:

private function userFound(User $user, SocialiteUser $socialiteUser): RedirectResponse
{
    $this->dispatchSync(new UpdateProfile($user, ['github_username' => $socialiteUser->getNickname()]));

    Auth::login($user, true);

    return redirect()->route('profile');
}

When we update the profile, we could do something like fire an event with the username and then have a listener that handles the updating of duplicates.

I might be missing something, so let me know what you think.

joedixon avatar Apr 13 '22 07:04 joedixon

We have an immediate issue where some duplicates exist in the database so we need to clear those up which I think we could do with a one-time command.

Yep indeed.

When we update the profile, we could do something like fire an event with the username and then have a listener that handles the updating of duplicates.

Yeah we can do that. I guess there's still a possibility that we can have outdated github usernames. But I guess without listening to GitHub webhooks we can't solve that. So yeah let's go with this to at least solve the duplicate usernames. Maybe only listen for the register event so it doesn't always fires when updating your profile.

driesvints avatar Apr 13 '22 15:04 driesvints

@driesvints @joedixon is this issue resolved? I would like to give it a go.

digitlimit avatar Dec 07 '23 21:12 digitlimit

@digitlimit not yet no

driesvints avatar Dec 08 '23 08:12 driesvints

@driesvints @joedixon Duplicates will not occur during registration since the RegisterRequest is designed to prevent them. We have implemented the following rules in the RegisterRequest:

public function rules(): array
{
    return [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'username' => 'required|alpha_dash|max:40|unique:users',
        'rules' => 'accepted',
        'terms' => 'accepted',
        'github_id' => ['required', new UniqueGitHubUser],
    ];
}

This could also be included in the rules.

    'github_username' => 'nullable|alpha_dash|max:40|unique:users',

Therefore, a one-time command is all that is needed to clean up the duplicates. I have created one here, but I am unsure what we want to do to the duplicates.

digitlimit avatar Jan 09 '24 08:01 digitlimit

Thanks @digitlimit. I'll have a look at all this once I find some time.

driesvints avatar Jan 09 '24 08:01 driesvints