Skip to content
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

Handles user data username case formatting #359

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Handles user data username formatting
  - While running the api, config.yaml has some entries of username
    with some scopes added, which are stored in db, so there can be a
    scenario where user's username case is different than what it is
    actually on the Git application. This might loss the user's existing
    data i.e. the rating of resources which user has already given
    because it would create a new entry if username won't be found.

  - Hence this patch checks for the case of username while inserting
    the user data when user authenticates to Hub.

Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
  • Loading branch information
PuneetPunamiya committed Jan 31, 2022
commit ad861897d28b4a8ea693ef61f901d51b5305689a
5 changes: 3 additions & 2 deletions api/pkg/auth/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package auth
import (
"crypto/sha256"
"encoding/hex"
"strings"

"github.com/markbates/goth"
"github.com/tektoncd/hub/api/pkg/auth/app"
Expand Down Expand Up @@ -121,7 +122,7 @@ func (r *request) insertData(gitUser goth.User, code, provider string) error {
// If email doesn't exists in users table
if err != nil {
// Check whether username and provider are matching
accountQuery := r.db.Model(&model.Account{}).Where("user_name = ?", gitUser.NickName).Where("provider = ?", provider)
accountQuery := r.db.Model(&model.Account{}).Where("LOWER(user_name) = ?", strings.ToLower(gitUser.NickName)).Where("provider = ?", provider)
err = accountQuery.First(&acc).Error

// If user doesn't exist, create a new record
Expand All @@ -145,7 +146,7 @@ func (r *request) insertData(gitUser goth.User, code, provider string) error {

// Update the AvatarUrl and Name in Accounts table
if err := updateAccountDetails(accountQuery, acc,
model.Account{AvatarURL: gitUser.AvatarURL, Name: gitUser.Name}); err != nil {
model.Account{AvatarURL: gitUser.AvatarURL, Name: gitUser.Name, UserName: gitUser.NickName}); err != nil {
r.log.Error(err)
return err
}
Expand Down