mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-01 14:56:30 +00:00
api: implement logic and endpoint for moving issues between projects in repos
This commit is contained in:
parent
49a1961b03
commit
7bfa54672f
@ -417,6 +417,18 @@ func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reqRepoWriterOr returns a middleware for requiring repository write to one of the unit permission
|
||||||
|
func reqRepoWriterOr(unitTypes ...unit.Type) func(ctx *context.APIContext) {
|
||||||
|
return func(ctx *context.APIContext) {
|
||||||
|
for _, unitType := range unitTypes {
|
||||||
|
if ctx.Repo.CanWrite(unitType) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// reqRepoBranchWriter user should have a permission to write to a branch, or be a site admin
|
// reqRepoBranchWriter user should have a permission to write to a branch, or be a site admin
|
||||||
func reqRepoBranchWriter(ctx *context.APIContext) {
|
func reqRepoBranchWriter(ctx *context.APIContext) {
|
||||||
options, ok := web.GetForm(ctx).(api.FileOptionInterface)
|
options, ok := web.GetForm(ctx).(api.FileOptionInterface)
|
||||||
@ -1060,6 +1072,10 @@ func Routes() *web.Router {
|
|||||||
})
|
})
|
||||||
}, reqRepoWriter(unit.TypeProjects), mustNotBeArchived)
|
}, reqRepoWriter(unit.TypeProjects), mustNotBeArchived)
|
||||||
}, individualPermsChecker)
|
}, individualPermsChecker)
|
||||||
|
|
||||||
|
m.Group("/{type:issues|pulls}", func() {
|
||||||
|
m.Post("/projects", reqRepoWriterOr(unit.TypeIssues, unit.TypePullRequests), reqRepoWriter(unit.TypeProjects), repo.UpdateIssueProject)
|
||||||
|
}, individualPermsChecker)
|
||||||
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryUser, auth_model.AccessTokenScopeCategoryRepository), reqToken(), repoAssignment(), reqRepoReader(unit.TypeProjects), mustEnableRepoProjects)
|
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryUser, auth_model.AccessTokenScopeCategoryRepository), reqToken(), repoAssignment(), reqRepoReader(unit.TypeProjects), mustEnableRepoProjects)
|
||||||
|
|
||||||
// Organizations (requires orgs scope)
|
// Organizations (requires orgs scope)
|
||||||
@ -1116,6 +1132,10 @@ func Routes() *web.Router {
|
|||||||
})
|
})
|
||||||
}, reqRepoWriter(unit.TypeProjects), mustNotBeArchived)
|
}, reqRepoWriter(unit.TypeProjects), mustNotBeArchived)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
m.Group("/{type:issues|pulls}", func() {
|
||||||
|
m.Post("/projects", reqRepoWriterOr(unit.TypeIssues, unit.TypePullRequests), reqRepoWriter(unit.TypeProjects), repo.UpdateIssueProject)
|
||||||
|
}, reqRepoWriter(unit.TypeProjects), mustNotBeArchived)
|
||||||
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryOrganization, auth_model.AccessTokenScopeCategoryRepository), reqToken(), repoAssignment(), reqRepoReader(unit.TypeProjects), mustEnableRepoProjects)
|
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryOrganization, auth_model.AccessTokenScopeCategoryRepository), reqToken(), repoAssignment(), reqRepoReader(unit.TypeProjects), mustEnableRepoProjects)
|
||||||
|
|
||||||
// Users (requires user scope)
|
// Users (requires user scope)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -460,24 +461,13 @@ func MoveIssues(ctx *context.APIContext) {
|
|||||||
ctx.JSON(http.StatusOK, map[string]string{"message": "issues moved successfully"})
|
ctx.JSON(http.StatusOK, map[string]string{"message": "issues moved successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getActionIssues(ctx *context.APIContext) issues_model.IssueList {
|
func getActionIssues(ctx *context.APIContext, issuesIDs []int64) issues_model.IssueList {
|
||||||
type updateIssuesForm struct {
|
|
||||||
Issues []int64 `json:"issues"`
|
|
||||||
}
|
|
||||||
|
|
||||||
form := &updateIssuesForm{}
|
if len(issuesIDs) == 0 {
|
||||||
|
|
||||||
if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
|
|
||||||
ctx.ServerError("DecodeMovedIssuesForm", err)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(form.Issues) == 0 {
|
issues, err := issues_model.GetIssuesByIDs(ctx, issuesIDs)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
issueIDs := form.Issues
|
|
||||||
issues, err := issues_model.GetIssuesByIDs(ctx, issueIDs)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetIssuesByIDs", err)
|
ctx.ServerError("GetIssuesByIDs", err)
|
||||||
return nil
|
return nil
|
||||||
@ -504,7 +494,21 @@ func getActionIssues(ctx *context.APIContext) issues_model.IssueList {
|
|||||||
|
|
||||||
// UpdateIssueProject change an issue's project
|
// UpdateIssueProject change an issue's project
|
||||||
func UpdateIssueProject(ctx *context.APIContext) {
|
func UpdateIssueProject(ctx *context.APIContext) {
|
||||||
issues := getActionIssues(ctx)
|
type updateIssuesForm struct {
|
||||||
|
ProjectID int64 `json:"project_id"`
|
||||||
|
Issues []int64 `json:"issues"`
|
||||||
|
}
|
||||||
|
|
||||||
|
form := &updateIssuesForm{}
|
||||||
|
|
||||||
|
if err := json.NewDecoder(ctx.Req.Body).Decode(&form); err != nil {
|
||||||
|
ctx.ServerError("DecodeMovedIssuesForm", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("form", form)
|
||||||
|
log.Println(ctx.Repo.Repository.ID)
|
||||||
|
issues := getActionIssues(ctx, form.Issues)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -518,7 +522,7 @@ func UpdateIssueProject(ctx *context.APIContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
projectID := ctx.FormInt64("project_id")
|
projectID := form.ProjectID
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
if issue.Project != nil && issue.Project.ID == projectID {
|
if issue.Project != nil && issue.Project.ID == projectID {
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user