mirror of
https://github.com/go-gitea/gitea
synced 2025-01-06 07:54:25 +00:00
Backport #33058 by lunny Fix #32992 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
68736ec292
commit
bc83fb26ef
@ -126,6 +126,14 @@ func (p *Project) LoadRepo(ctx context.Context) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ProjectLinkForOrg(org *user_model.User, projectID int64) string { //nolint
|
||||||
|
return fmt.Sprintf("%s/-/projects/%d", org.HomeLink(), projectID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProjectLinkForRepo(repo *repo_model.Repository, projectID int64) string { //nolint
|
||||||
|
return fmt.Sprintf("%s/projects/%d", repo.Link(), projectID)
|
||||||
|
}
|
||||||
|
|
||||||
// Link returns the project's relative URL.
|
// Link returns the project's relative URL.
|
||||||
func (p *Project) Link(ctx context.Context) string {
|
func (p *Project) Link(ctx context.Context) string {
|
||||||
if p.OwnerID > 0 {
|
if p.OwnerID > 0 {
|
||||||
@ -134,7 +142,7 @@ func (p *Project) Link(ctx context.Context) string {
|
|||||||
log.Error("LoadOwner: %v", err)
|
log.Error("LoadOwner: %v", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s/-/projects/%d", p.Owner.HomeLink(), p.ID)
|
return ProjectLinkForOrg(p.Owner, p.ID)
|
||||||
}
|
}
|
||||||
if p.RepoID > 0 {
|
if p.RepoID > 0 {
|
||||||
err := p.LoadRepo(ctx)
|
err := p.LoadRepo(ctx)
|
||||||
@ -142,7 +150,7 @@ func (p *Project) Link(ctx context.Context) string {
|
|||||||
log.Error("LoadRepo: %v", err)
|
log.Error("LoadRepo: %v", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s/projects/%d", p.Repo.Link(), p.ID)
|
return ProjectLinkForRepo(p.Repo, p.ID)
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ func ChangeProjectStatus(ctx *context.Context) {
|
|||||||
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
|
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSONRedirect(fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), id))
|
ctx.JSONRedirect(project_model.ProjectLinkForOrg(ctx.ContextUser, id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteProject delete a project
|
// DeleteProject delete a project
|
||||||
@ -262,7 +262,7 @@ func RenderEditProject(ctx *context.Context) {
|
|||||||
ctx.Data["redirect"] = ctx.FormString("redirect")
|
ctx.Data["redirect"] = ctx.FormString("redirect")
|
||||||
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
|
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
|
||||||
ctx.Data["card_type"] = p.CardType
|
ctx.Data["card_type"] = p.CardType
|
||||||
ctx.Data["CancelLink"] = fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), p.ID)
|
ctx.Data["CancelLink"] = project_model.ProjectLinkForOrg(ctx.ContextUser, p.ID)
|
||||||
|
|
||||||
ctx.HTML(http.StatusOK, tplProjectsNew)
|
ctx.HTML(http.StatusOK, tplProjectsNew)
|
||||||
}
|
}
|
||||||
@ -276,7 +276,7 @@ func EditProjectPost(ctx *context.Context) {
|
|||||||
ctx.Data["PageIsViewProjects"] = true
|
ctx.Data["PageIsViewProjects"] = true
|
||||||
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
|
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
|
||||||
ctx.Data["CardTypes"] = project_model.GetCardConfig()
|
ctx.Data["CardTypes"] = project_model.GetCardConfig()
|
||||||
ctx.Data["CancelLink"] = fmt.Sprintf("%s/-/projects/%d", ctx.ContextUser.HomeLink(), projectID)
|
ctx.Data["CancelLink"] = project_model.ProjectLinkForOrg(ctx.ContextUser, projectID)
|
||||||
|
|
||||||
shared_user.RenderUserHeader(ctx)
|
shared_user.RenderUserHeader(ctx)
|
||||||
|
|
||||||
|
@ -396,8 +396,15 @@ func NewIssuePost(ctx *context.Context) {
|
|||||||
|
|
||||||
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
|
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
|
||||||
if ctx.FormString("redirect_after_creation") == "project" && projectID > 0 {
|
if ctx.FormString("redirect_after_creation") == "project" && projectID > 0 {
|
||||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects/" + strconv.FormatInt(projectID, 10))
|
project, err := project_model.GetProjectByID(ctx, projectID)
|
||||||
} else {
|
if err == nil {
|
||||||
ctx.JSONRedirect(issue.Link())
|
if project.Type == project_model.TypeOrganization {
|
||||||
|
ctx.JSONRedirect(project_model.ProjectLinkForOrg(ctx.Repo.Owner, project.ID))
|
||||||
|
} else {
|
||||||
|
ctx.JSONRedirect(project_model.ProjectLinkForRepo(repo, project.ID))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ctx.JSONRedirect(issue.Link())
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ func ChangeProjectStatus(ctx *context.Context) {
|
|||||||
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
|
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.JSONRedirect(fmt.Sprintf("%s/projects/%d", ctx.Repo.RepoLink, id))
|
ctx.JSONRedirect(project_model.ProjectLinkForRepo(ctx.Repo.Repository, id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteProject delete a project
|
// DeleteProject delete a project
|
||||||
@ -235,7 +235,7 @@ func RenderEditProject(ctx *context.Context) {
|
|||||||
ctx.Data["content"] = p.Description
|
ctx.Data["content"] = p.Description
|
||||||
ctx.Data["card_type"] = p.CardType
|
ctx.Data["card_type"] = p.CardType
|
||||||
ctx.Data["redirect"] = ctx.FormString("redirect")
|
ctx.Data["redirect"] = ctx.FormString("redirect")
|
||||||
ctx.Data["CancelLink"] = fmt.Sprintf("%s/projects/%d", ctx.Repo.Repository.Link(), p.ID)
|
ctx.Data["CancelLink"] = project_model.ProjectLinkForRepo(ctx.Repo.Repository, p.ID)
|
||||||
|
|
||||||
ctx.HTML(http.StatusOK, tplProjectsNew)
|
ctx.HTML(http.StatusOK, tplProjectsNew)
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ func EditProjectPost(ctx *context.Context) {
|
|||||||
ctx.Data["PageIsEditProjects"] = true
|
ctx.Data["PageIsEditProjects"] = true
|
||||||
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
||||||
ctx.Data["CardTypes"] = project_model.GetCardConfig()
|
ctx.Data["CardTypes"] = project_model.GetCardConfig()
|
||||||
ctx.Data["CancelLink"] = fmt.Sprintf("%s/projects/%d", ctx.Repo.Repository.Link(), projectID)
|
ctx.Data["CancelLink"] = project_model.ProjectLinkForRepo(ctx.Repo.Repository, projectID)
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(http.StatusOK, tplProjectsNew)
|
ctx.HTML(http.StatusOK, tplProjectsNew)
|
||||||
|
Loading…
Reference in New Issue
Block a user