mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-01 07:09:21 +01:00
894d9b2836
Since `modules/context` has to depend on `models` and many other packages, it should be moved from `modules/context` to `services/context` according to design principles. There is no logic code change on this PR, only move packages. - Move `code.gitea.io/gitea/modules/context` to `code.gitea.io/gitea/services/context` - Move `code.gitea.io/gitea/modules/contexttest` to `code.gitea.io/gitea/services/contexttest` because of depending on context - Move `code.gitea.io/gitea/modules/upload` to `code.gitea.io/gitea/services/context/upload` because of depending on context (cherry picked from commit 29f149bd9f517225a3c9f1ca3fb0a7b5325af696) Conflicts: routers/api/packages/alpine/alpine.go routers/api/v1/repo/issue_reaction.go routers/install/install.go routers/web/admin/config.go routers/web/passkey.go routers/web/repo/search.go routers/web/repo/setting/default_branch.go routers/web/user/home.go routers/web/user/profile.go tests/integration/editor_test.go tests/integration/integration_test.go tests/integration/mirror_push_test.go trivial context conflicts also modified all other occurrences in Forgejo specific files
116 lines
3.3 KiB
Go
116 lines
3.3 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package org
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
|
"code.gitea.io/gitea/modules/label"
|
|
repo_module "code.gitea.io/gitea/modules/repository"
|
|
"code.gitea.io/gitea/modules/web"
|
|
"code.gitea.io/gitea/services/context"
|
|
"code.gitea.io/gitea/services/forms"
|
|
)
|
|
|
|
// RetrieveLabels find all the labels of an organization
|
|
func RetrieveLabels(ctx *context.Context) {
|
|
labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), db.ListOptions{})
|
|
if err != nil {
|
|
ctx.ServerError("RetrieveLabels.GetLabels", err)
|
|
return
|
|
}
|
|
for _, l := range labels {
|
|
l.CalOpenIssues()
|
|
}
|
|
ctx.Data["Labels"] = labels
|
|
ctx.Data["NumLabels"] = len(labels)
|
|
ctx.Data["SortType"] = ctx.FormString("sort")
|
|
}
|
|
|
|
// NewLabel create new label for organization
|
|
func NewLabel(ctx *context.Context) {
|
|
form := web.GetForm(ctx).(*forms.CreateLabelForm)
|
|
ctx.Data["Title"] = ctx.Tr("repo.labels")
|
|
ctx.Data["PageIsLabels"] = true
|
|
ctx.Data["PageIsOrgSettings"] = true
|
|
|
|
if ctx.HasError() {
|
|
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
|
|
return
|
|
}
|
|
|
|
l := &issues_model.Label{
|
|
OrgID: ctx.Org.Organization.ID,
|
|
Name: form.Title,
|
|
Exclusive: form.Exclusive,
|
|
Description: form.Description,
|
|
Color: form.Color,
|
|
}
|
|
if err := issues_model.NewLabel(ctx, l); err != nil {
|
|
ctx.ServerError("NewLabel", err)
|
|
return
|
|
}
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
|
|
}
|
|
|
|
// UpdateLabel update a label's name and color
|
|
func UpdateLabel(ctx *context.Context) {
|
|
form := web.GetForm(ctx).(*forms.CreateLabelForm)
|
|
l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, form.ID)
|
|
if err != nil {
|
|
switch {
|
|
case issues_model.IsErrOrgLabelNotExist(err):
|
|
ctx.Error(http.StatusNotFound)
|
|
default:
|
|
ctx.ServerError("UpdateLabel", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
l.Name = form.Title
|
|
l.Exclusive = form.Exclusive
|
|
l.Description = form.Description
|
|
l.Color = form.Color
|
|
l.SetArchived(form.IsArchived)
|
|
if err := issues_model.UpdateLabel(ctx, l); err != nil {
|
|
ctx.ServerError("UpdateLabel", err)
|
|
return
|
|
}
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
|
|
}
|
|
|
|
// DeleteLabel delete a label
|
|
func DeleteLabel(ctx *context.Context) {
|
|
if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.FormInt64("id")); err != nil {
|
|
ctx.Flash.Error("DeleteLabel: " + err.Error())
|
|
} else {
|
|
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
|
|
}
|
|
|
|
ctx.JSONRedirect(ctx.Org.OrgLink + "/settings/labels")
|
|
}
|
|
|
|
// InitializeLabels init labels for an organization
|
|
func InitializeLabels(ctx *context.Context) {
|
|
form := web.GetForm(ctx).(*forms.InitializeLabelsForm)
|
|
if ctx.HasError() {
|
|
ctx.Redirect(ctx.Org.OrgLink + "/labels")
|
|
return
|
|
}
|
|
|
|
if err := repo_module.InitializeLabels(ctx, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
|
|
if label.IsErrTemplateLoad(err) {
|
|
originalErr := err.(label.ErrTemplateLoad).OriginalError
|
|
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
|
|
return
|
|
}
|
|
ctx.ServerError("InitializeLabels", err)
|
|
return
|
|
}
|
|
ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
|
|
}
|