Fix branch_protection api shows users/teams who has no readAccess (#30291)

Add some logic in `convert.ToBranchProtection` to return only the names
associated with readAccess instead of returning all names. This will
ensure consistency in behavior between the frontend and backend.
Fixes: #27694

---------

Co-authored-by: techknowlogick <techknowlogick@gitea.com>
Co-authored-by: wenzhuo.zhang <wenzhuo.zhang@geely.com>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
Edward Zhang 2024-04-17 21:24:07 +08:00 committed by GitHub
parent 0798370f25
commit 02e183bf3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 25 deletions

View file

@ -437,7 +437,7 @@ func GetBranchProtection(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusOK, convert.ToBranchProtection(ctx, bp))
ctx.JSON(http.StatusOK, convert.ToBranchProtection(ctx, bp, repo))
}
// ListBranchProtections list branch protections for a repo
@ -470,7 +470,7 @@ func ListBranchProtections(ctx *context.APIContext) {
}
apiBps := make([]*api.BranchProtection, len(bps))
for i := range bps {
apiBps[i] = convert.ToBranchProtection(ctx, bps[i])
apiBps[i] = convert.ToBranchProtection(ctx, bps[i], repo)
}
ctx.JSON(http.StatusOK, apiBps)
@ -681,7 +681,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusCreated, convert.ToBranchProtection(ctx, bp))
ctx.JSON(http.StatusCreated, convert.ToBranchProtection(ctx, bp, repo))
}
// EditBranchProtection edits a branch protection for a repo
@ -959,7 +959,7 @@ func EditBranchProtection(ctx *context.APIContext) {
return
}
ctx.JSON(http.StatusOK, convert.ToBranchProtection(ctx, bp))
ctx.JSON(http.StatusOK, convert.ToBranchProtection(ctx, bp, repo))
}
// DeleteBranchProtection deletes a branch protection for a repo