mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Allow non-admin users to delete review requests (#29057)
Fix #14459 The following users can add/remove review requests of a PR - the poster of the PR - the owner or collaborators of the repository - members with read permission on the pull requests unit
This commit is contained in:
@@ -217,7 +217,7 @@ func TestAPISearchIssues(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
// as this API was used in the frontend, it uses UI page size
|
||||
expectedIssueCount := 18 // from the fixtures
|
||||
expectedIssueCount := 20 // from the fixtures
|
||||
if expectedIssueCount > setting.UI.IssuePagingNum {
|
||||
expectedIssueCount = setting.UI.IssuePagingNum
|
||||
}
|
||||
@@ -257,7 +257,7 @@ func TestAPISearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String()).AddTokenAuth(token)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "20", resp.Header().Get("X-Total-Count"))
|
||||
assert.EqualValues(t, "22", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 20)
|
||||
|
||||
query.Add("limit", "10")
|
||||
@@ -265,7 +265,7 @@ func TestAPISearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String()).AddTokenAuth(token)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "20", resp.Header().Get("X-Total-Count"))
|
||||
assert.EqualValues(t, "22", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 10)
|
||||
|
||||
query = url.Values{"assigned": {"true"}, "state": {"all"}}
|
||||
@@ -315,7 +315,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
// as this API was used in the frontend, it uses UI page size
|
||||
expectedIssueCount := 18 // from the fixtures
|
||||
expectedIssueCount := 20 // from the fixtures
|
||||
if expectedIssueCount > setting.UI.IssuePagingNum {
|
||||
expectedIssueCount = setting.UI.IssuePagingNum
|
||||
}
|
||||
|
@@ -32,8 +32,8 @@ func TestNodeinfo(t *testing.T) {
|
||||
DecodeJSON(t, resp, &nodeinfo)
|
||||
assert.True(t, nodeinfo.OpenRegistrations)
|
||||
assert.Equal(t, "gitea", nodeinfo.Software.Name)
|
||||
assert.Equal(t, 26, nodeinfo.Usage.Users.Total)
|
||||
assert.Equal(t, 20, nodeinfo.Usage.LocalPosts)
|
||||
assert.Equal(t, 29, nodeinfo.Usage.Users.Total)
|
||||
assert.Equal(t, 22, nodeinfo.Usage.LocalPosts)
|
||||
assert.Equal(t, 3, nodeinfo.Usage.LocalComments)
|
||||
})
|
||||
}
|
||||
|
@@ -177,7 +177,7 @@ func TestAPIGetAll(t *testing.T) {
|
||||
var apiOrgList []*api.Organization
|
||||
|
||||
DecodeJSON(t, resp, &apiOrgList)
|
||||
assert.Len(t, apiOrgList, 11)
|
||||
assert.Len(t, apiOrgList, 12)
|
||||
assert.Equal(t, "Limited Org 36", apiOrgList[1].FullName)
|
||||
assert.Equal(t, "limited", apiOrgList[1].Visibility)
|
||||
|
||||
@@ -186,7 +186,7 @@ func TestAPIGetAll(t *testing.T) {
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
DecodeJSON(t, resp, &apiOrgList)
|
||||
assert.Len(t, apiOrgList, 7)
|
||||
assert.Len(t, apiOrgList, 8)
|
||||
assert.Equal(t, "org 17", apiOrgList[0].FullName)
|
||||
assert.Equal(t, "public", apiOrgList[0].Visibility)
|
||||
}
|
||||
|
@@ -279,6 +279,49 @@ func TestAPIPullReviewRequest(t *testing.T) {
|
||||
}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// a collaborator can add/remove a review request
|
||||
pullIssue21 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 21})
|
||||
assert.NoError(t, pullIssue21.LoadAttributes(db.DefaultContext))
|
||||
pull21Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue21.RepoID}) // repo60
|
||||
user38Session := loginUser(t, "user38")
|
||||
user38Token := getTokenForLoggedInUser(t, user38Session, auth_model.AccessTokenScopeWriteRepository)
|
||||
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{
|
||||
Reviewers: []string{"user4@example.com"},
|
||||
}).AddTokenAuth(user38Token)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{
|
||||
Reviewers: []string{"user4@example.com"},
|
||||
}).AddTokenAuth(user38Token)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// the poster of the PR can add/remove a review request
|
||||
user39Session := loginUser(t, "user39")
|
||||
user39Token := getTokenForLoggedInUser(t, user39Session, auth_model.AccessTokenScopeWriteRepository)
|
||||
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{
|
||||
Reviewers: []string{"user8"},
|
||||
}).AddTokenAuth(user39Token)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{
|
||||
Reviewers: []string{"user8"},
|
||||
}).AddTokenAuth(user39Token)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// user with read permission on pull requests unit can add/remove a review request
|
||||
pullIssue22 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 22})
|
||||
assert.NoError(t, pullIssue22.LoadAttributes(db.DefaultContext))
|
||||
pull22Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue22.RepoID}) // repo61
|
||||
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{
|
||||
Reviewers: []string{"user38"},
|
||||
}).AddTokenAuth(user39Token) // user39 is from a team with read permission on pull requests unit
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{
|
||||
Reviewers: []string{"user38"},
|
||||
}).AddTokenAuth(user39Token) // user39 is from a team with read permission on pull requests unit
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
// Test team review request
|
||||
pullIssue12 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 12})
|
||||
assert.NoError(t, pullIssue12.LoadAttributes(db.DefaultContext))
|
||||
|
@@ -93,9 +93,9 @@ func TestAPISearchRepo(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
|
||||
nil: {count: 33},
|
||||
user: {count: 33},
|
||||
user2: {count: 33},
|
||||
nil: {count: 35},
|
||||
user: {count: 35},
|
||||
user2: {count: 35},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@@ -407,7 +407,7 @@ func TestSearchIssues(t *testing.T) {
|
||||
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
expectedIssueCount := 18 // from the fixtures
|
||||
expectedIssueCount := 20 // from the fixtures
|
||||
if expectedIssueCount > setting.UI.IssuePagingNum {
|
||||
expectedIssueCount = setting.UI.IssuePagingNum
|
||||
}
|
||||
@@ -444,7 +444,7 @@ func TestSearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "20", resp.Header().Get("X-Total-Count"))
|
||||
assert.EqualValues(t, "22", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 20)
|
||||
|
||||
query.Add("limit", "5")
|
||||
@@ -452,7 +452,7 @@ func TestSearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "20", resp.Header().Get("X-Total-Count"))
|
||||
assert.EqualValues(t, "22", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 5)
|
||||
|
||||
query = url.Values{"assigned": {"true"}, "state": {"all"}}
|
||||
@@ -501,7 +501,7 @@ func TestSearchIssues(t *testing.T) {
|
||||
func TestSearchIssuesWithLabels(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
expectedIssueCount := 18 // from the fixtures
|
||||
expectedIssueCount := 20 // from the fixtures
|
||||
if expectedIssueCount > setting.UI.IssuePagingNum {
|
||||
expectedIssueCount = setting.UI.IssuePagingNum
|
||||
}
|
||||
|
Reference in New Issue
Block a user