Skip to content

Commit

Permalink
Allow externalID to be UUID (go-gitea#8551)
Browse files Browse the repository at this point in the history
Signed-off-by: Wenxuan Zhao <viz@linux.com>
  • Loading branch information
vizv authored and guillep2k committed Oct 21, 2019
1 parent afeab94 commit 6dc1567
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion models/external_login_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func FindExternalUsersByProvider(opts FindExternalUserOptions) ([]ExternalLoginU
}

// UpdateMigrationsByType updates all migrated repositories' posterid from gitServiceType to replace originalAuthorID to posterID
func UpdateMigrationsByType(tp structs.GitServiceType, externalUserID, userID int64) error {
func UpdateMigrationsByType(tp structs.GitServiceType, externalUserID string, userID int64) error {
if err := UpdateIssuesMigrationsByType(tp, externalUserID, userID); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, menti
}

// UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
func UpdateIssuesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID, posterID int64) error {
func UpdateIssuesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := x.Table("issue").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID).
Expand Down
2 changes: 1 addition & 1 deletion models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ func FetchCodeComments(issue *Issue, currentUser *User) (CodeComments, error) {
}

// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID, posterID int64) error {
func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := x.Table("comment").
Where(builder.In("issue_id",
builder.Select("issue.id").
Expand Down
2 changes: 1 addition & 1 deletion models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func SyncReleasesWithTags(repo *Repository, gitRepo *git.Repository) error {
}

// UpdateReleasesMigrationsByType updates all migrated repositories' releases from gitServiceType to replace originalAuthorID to posterID
func UpdateReleasesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID, posterID int64) error {
func UpdateReleasesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID string, posterID int64) error {
_, err := x.Table("release").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID).
Expand Down
8 changes: 1 addition & 7 deletions modules/migrations/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package migrations

import (
"strconv"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs"
Expand Down Expand Up @@ -40,11 +38,7 @@ func updateMigrationPosterIDByGitService(tp structs.GitServiceType) error {
}

for _, user := range users {
externalUserID, err := strconv.ParseInt(user.ExternalID, 10, 64)
if err != nil {
log.Warn("Parse externalUser %#v 's userID failed: %v", user, err)
continue
}
externalUserID := user.ExternalID
if err := models.UpdateMigrationsByType(tp, externalUserID, user.UserID); err != nil {
log.Error("UpdateMigrationsByType type %s external user id %v to local user id %v failed: %v", tp.Name(), user.ExternalID, user.UserID, err)
}
Expand Down
6 changes: 1 addition & 5 deletions services/externalaccount/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package externalaccount

import (
"strconv"
"strings"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -45,10 +44,7 @@ func LinkAccountToUser(user *models.User, gothUser goth.User) error {
return err
}

externalID, err := strconv.ParseInt(externalLoginUser.ExternalID, 10, 64)
if err != nil {
return err
}
externalID := externalLoginUser.ExternalID

var tp structs.GitServiceType
for _, s := range structs.SupportedFullGitService {
Expand Down

0 comments on commit 6dc1567

Please sign in to comment.