mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Allow administrator to create repository for any organization (#4368)
This commit is contained in:
		@@ -262,3 +262,26 @@ func TestAPIRepoMigrate(t *testing.T) {
 | 
			
		||||
		session.MakeRequest(t, req, testCase.expectedStatus)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestAPIOrgRepoCreate(t *testing.T) {
 | 
			
		||||
	testCases := []struct {
 | 
			
		||||
		ctxUserID         int64
 | 
			
		||||
		orgName, repoName string
 | 
			
		||||
		expectedStatus    int
 | 
			
		||||
	}{
 | 
			
		||||
		{ctxUserID: 1, orgName: "user3", repoName: "repo-admin", expectedStatus: http.StatusCreated},
 | 
			
		||||
		{ctxUserID: 2, orgName: "user3", repoName: "repo-own", expectedStatus: http.StatusCreated},
 | 
			
		||||
		{ctxUserID: 2, orgName: "user6", repoName: "repo-bad-org", expectedStatus: http.StatusForbidden},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	prepareTestEnv(t)
 | 
			
		||||
	for _, testCase := range testCases {
 | 
			
		||||
		user := models.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
 | 
			
		||||
		session := loginUser(t, user.Name)
 | 
			
		||||
 | 
			
		||||
		req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/org/%s/repos", testCase.orgName), &api.CreateRepoOption{
 | 
			
		||||
			Name: testCase.repoName,
 | 
			
		||||
		})
 | 
			
		||||
		session.MakeRequest(t, req, testCase.expectedStatus)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -257,6 +257,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !ctx.User.IsAdmin {
 | 
			
		||||
		isOwner, err := org.IsOwnedBy(ctx.User.ID)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.ServerError("IsOwnedBy", err)
 | 
			
		||||
@@ -265,6 +266,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
 | 
			
		||||
			ctx.Error(403, "", "Given user is not owner of organization.")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	CreateUserRepo(ctx, org, opt)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user