From 77e9346342ccea20157412820b08204f122f262f Mon Sep 17 00:00:00 2001 From: zuzuviewer <750938164@qq.com> Date: Sat, 14 May 2022 21:30:19 +0800 Subject: [PATCH] Fix duplicate entry error when add team member (#19702) --- models/org_team.go | 6 ++++++ models/organization/org.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/models/org_team.go b/models/org_team.go index 40eb037452..0aba0cbb23 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -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 { + return err + } + sess := db.GetEngine(ctx) if err := db.Insert(ctx, &organization.TeamUser{ diff --git a/models/organization/org.go b/models/organization/org.go index 3761335922..43d96793b1 100644 --- a/models/organization/org.go +++ b/models/organization/org.go @@ -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,