Skip to content

Commit fd1edb9

Browse files
GiteaBotKN4CK3R
andauthored
Fix DeleteCollaboration transaction behaviour (#28886) (#28889)
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 <admin@oldschoolhack.me>
1 parent 633996d commit fd1edb9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

services/repository/collaboration.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ func DeleteCollaboration(ctx context.Context, repo *repo_model.Repository, uid i
2626
}
2727
defer committer.Close()
2828

29-
if has, err := db.GetEngine(ctx).Delete(collaboration); err != nil || has == 0 {
29+
if has, err := db.GetEngine(ctx).Delete(collaboration); err != nil {
3030
return err
31-
} else if err = access_model.RecalculateAccesses(ctx, repo); err != nil {
31+
} else if has == 0 {
32+
return committer.Commit()
33+
}
34+
if err = access_model.RecalculateAccesses(ctx, repo); err != nil {
3235
return err
3336
}
3437

0 commit comments

Comments
 (0)