Skip to content

Commit 0f2f7f7

Browse files
committed
fix: 🐛 fix bug for which a user can accept self invite
1 parent 3aaaab9 commit 0f2f7f7

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

internal/handlers/invitation.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func (i *InvitationHandler) getInvitations(invitation InvitationAcceptBody) (str
2424
ctx := context.Background()
2525

2626
query := client.Collection("invitations").Where("Link", "==", invitation.InviteLink).Limit(1)
27+
2728
docs, err := query.Documents(ctx).GetAll()
2829
if err != nil {
2930
log.Println("Error querying document by ProjectName:", err)
@@ -103,6 +104,27 @@ func (i *InvitationHandler) acceptInvitation(w http.ResponseWriter, r *http.Requ
103104
return
104105
}
105106

107+
docSnap, err := docRef.Get(ctx)
108+
if err != nil {
109+
log.Println(err)
110+
return
111+
}
112+
113+
var projectData struct {
114+
UID string `firestore:"UID"`
115+
}
116+
117+
err = docSnap.DataTo(&projectData)
118+
if err != nil {
119+
log.Println(err)
120+
return
121+
}
122+
123+
if projectData.UID == invitation.UID {
124+
log.Println("Invitation UID equals project UID, cannot add as collaborator.")
125+
return
126+
}
127+
106128
_, err = docRef.Update(ctx, []firestore.Update{
107129
{
108130
Path: "Collaborators",

0 commit comments

Comments
 (0)