Skip to content

Commit

Permalink
Fix DeleteCollaboration transaction behaviour (#28886) (#28889)
Browse files Browse the repository at this point in the history
Backport #28886 by @KN4CK3R

The method can't be called with an outer transaction because if the user
is not a collaborator the outer transaction will be rolled back even if
the inner transaction uses the no-error path.

`has == 0` leads to `return nil` which cancels the transaction. A
standalone call of this method does nothing but if used with an outer
transaction, that will be canceled.

Co-authored-by: KN4CK3R <[email protected]>
  • Loading branch information
GiteaBot and KN4CK3R authored Jan 22, 2024
1 parent 633996d commit fd1edb9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions services/repository/collaboration.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ func DeleteCollaboration(ctx context.Context, repo *repo_model.Repository, uid i
}
defer committer.Close()

if has, err := db.GetEngine(ctx).Delete(collaboration); err != nil || has == 0 {
if has, err := db.GetEngine(ctx).Delete(collaboration); err != nil {
return err
} else if err = access_model.RecalculateAccesses(ctx, repo); err != nil {
} else if has == 0 {
return committer.Commit()
}
if err = access_model.RecalculateAccesses(ctx, repo); err != nil {
return err
}

Expand Down

0 comments on commit fd1edb9

Please sign in to comment.