aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2024-01-22 08:19:56 +0100
committerGitHub <noreply@github.com>2024-01-22 07:19:56 +0000
commit8e9b6817bc2032c5af607b63d70ffc7e6599ebbb (patch)
tree4c6215d0dac51478aebacf58ff7a756dd0032efd
parent23efd9d2781c2ac22594a83afa75182d276b1571 (diff)
downloadgitea-8e9b6817bc2032c5af607b63d70ffc7e6599ebbb.tar.gz
gitea-8e9b6817bc2032c5af607b63d70ffc7e6599ebbb.zip
Fix `DeleteCollaboration` transaction behaviour (#28886)
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.
-rw-r--r--services/repository/collaboration.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/services/repository/collaboration.go b/services/repository/collaboration.go
index eff33c71f3..dccc124748 100644
--- a/services/repository/collaboration.go
+++ b/services/repository/collaboration.go
@@ -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
}