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

Fix duplicate entry error when add team member #19702

Merged
merged 1 commit into from
May 14, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions models/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ func AddTeamMember(team *organization.Team, userID int64) error {
}
defer committer.Close()

// check in transaction
isAlreadyMember, err = organization.IsTeamMember(ctx, team.OrgID, team.ID, userID)
if err != nil || isAlreadyMember {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But err is nil when isAlreadyMember is true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will return nil than, this should be fine

return err
}

sess := db.GetEngine(ctx)

if err := db.Insert(ctx, &organization.TeamUser{
Expand Down
6 changes: 6 additions & 0 deletions models/organization/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ func AddOrgUser(orgID, uid int64) error {
}
defer committer.Close()

// check in transaction
isAlreadyMember, err = IsOrganizationMember(ctx, orgID, uid)
if err != nil || isAlreadyMember {
return err
}

ou := &OrgUser{
UID: uid,
OrgID: orgID,
Expand Down