mirror of https://github.com/go-gitea/gitea.git
Add the delete function and remove formatting error.
Signed-off-by: Alex Lau(AvengerMoJo) <avengermojo@gmail.com>
This commit is contained in:
parent
1fc998984f
commit
d4fd5b553d
|
@ -9,21 +9,18 @@ import (
|
|||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
//"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
type RequireAction struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OrgID int64 `xorm:"index"`
|
||||
RepoName string `xorm:"VARCHAR(255)"`
|
||||
WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"`
|
||||
// Description string `xorm:"LONGTEXT NOT NULL"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
|
||||
// RepoRange string // glob match which repositories could use this runner
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OrgID int64 `xorm:"index"`
|
||||
RepoName string `xorm:"VARCHAR(255)"`
|
||||
WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
|
||||
}
|
||||
|
||||
type GlobalWorkflow struct {
|
||||
|
@ -76,3 +73,10 @@ func AddRequireAction(ctx context.Context, orgID int64, repoName, workflowName s
|
|||
}
|
||||
return ra, db.Insert(ctx, ra)
|
||||
}
|
||||
|
||||
func DeleteRequireAction(ctx context.Context, requireActionID int64) error {
|
||||
if _, err := db.DeleteByID[RequireAction](ctx, requireActionID); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package v1_23 //nolint
|
|||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
|
|
|
@ -3648,6 +3648,7 @@ require_action.add = Add Global Workflow
|
|||
require_action.add_require_action = Enable selected Workflow
|
||||
require_action.new = Create New
|
||||
require_action.status = Status
|
||||
require_action.search = Search...
|
||||
require_action.version = Version
|
||||
require_action.repo = Repo Name
|
||||
require_action.workflow = Workflow Filename
|
||||
|
@ -3656,6 +3657,12 @@ require_action.remove = Remove
|
|||
require_action.none = No Require Actions Available.
|
||||
require_action.creation.failed = Create Global Require Action %s Failed.
|
||||
require_action.creation.success = Create Global Require Action %s successfully.
|
||||
require_action.deletion = Delete
|
||||
require_action.deletion.description = Removing the Global Require Action is permanent and cannot be undone. Continue?
|
||||
require_action.deletion.success = The Global Require Action has been removed.
|
||||
|
||||
|
||||
|
||||
|
||||
workflow.disable = Disable Workflow
|
||||
workflow.disable_success = Workflow '%s' disabled successfully.
|
||||
|
|
|
@ -9,15 +9,11 @@ import (
|
|||
"errors"
|
||||
"net/http"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
// "code.gitea.io/gitea/modules/log"
|
||||
|
||||
"code.gitea.io/gitea/services/context"
|
||||
|
||||
//"code.gitea.io/gitea/modules/setting"
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
shared "code.gitea.io/gitea/routers/web/shared/actions"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -80,3 +76,12 @@ func RequireActionCreate(ctx *context.Context) {
|
|||
}
|
||||
shared.CreateRequireAction(ctx, vCtx.OrgID, vCtx.RedirectLink)
|
||||
}
|
||||
|
||||
func RequireActionDelete(ctx *context.Context) {
|
||||
vCtx, err := getRequireActionCtx(ctx)
|
||||
if err != nil {
|
||||
ctx.ServerError("getRequireActionCtx", err)
|
||||
return
|
||||
}
|
||||
shared.DeleteRequireAction(ctx, vCtx.RedirectLink)
|
||||
}
|
||||
|
|
|
@ -13,9 +13,8 @@ import (
|
|||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
actions_service "code.gitea.io/gitea/services/actions"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
)
|
||||
|
||||
// SetRequireActionDeletePost response for deleting a require action workflow
|
||||
|
@ -62,8 +61,6 @@ func GlobalEnableWorkflow(ctx *context.Context, orgID int64) {
|
|||
func CreateRequireAction(ctx *context.Context, orgID int64, redirectURL string) {
|
||||
ctx.Data["OrgID"] = ctx.Org.Organization.ID
|
||||
form := web.GetForm(ctx).(*forms.RequireActionForm)
|
||||
// log.Error("org %d, repo_name: %s, workflow_name %s", orgID, form.RepoName, form.WorkflowName)
|
||||
log.Error("org %d, repo_name: %+v", orgID, form)
|
||||
v, err := actions_service.CreateRequireAction(ctx, orgID, form.RepoName, form.WorkflowName)
|
||||
if err != nil {
|
||||
log.Error("CreateRequireAction: %v", err)
|
||||
|
@ -73,3 +70,15 @@ func CreateRequireAction(ctx *context.Context, orgID int64, redirectURL string)
|
|||
ctx.Flash.Success(ctx.Tr("actions.require_action.creation.success", v.WorkflowName))
|
||||
ctx.JSONRedirect(redirectURL)
|
||||
}
|
||||
|
||||
func DeleteRequireAction(ctx *context.Context, redirectURL string) {
|
||||
id := ctx.ParamsInt64(":require_action_id")
|
||||
|
||||
if err := actions_service.DeleteRequireActionByID(ctx, id); err != nil {
|
||||
log.Error("Delete RequireAction [%d] failed: %v", id, err)
|
||||
ctx.JSONError(ctx.Tr("actions.require_action.deletion.failed"))
|
||||
return
|
||||
}
|
||||
ctx.Flash.Success(ctx.Tr("actions.require_action.deletion.success"))
|
||||
ctx.JSONRedirect(redirectURL)
|
||||
}
|
||||
|
|
|
@ -463,6 +463,7 @@ func registerRoutes(m *web.Route) {
|
|||
m.Group("/require_action", func() {
|
||||
m.Get("", repo_setting.RequireAction)
|
||||
m.Post("/add", web.Bind(forms.RequireActionForm{}), repo_setting.RequireActionCreate)
|
||||
m.Post("/{require_action_id}/delete", repo_setting.RequireActionDelete)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -16,3 +16,7 @@ func CreateRequireAction(ctx context.Context, orgID int64, repoName, workflowNam
|
|||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func DeleteRequireActionByID(ctx context.Context, requireActionID int64) error {
|
||||
return actions_model.DeleteRequireAction(ctx, requireActionID)
|
||||
}
|
||||
|
|
|
@ -15,10 +15,8 @@
|
|||
<div class="ui attached segment">
|
||||
<form class="ui form ignore-dirty" id="require-action-list-search-form" action="{{$.Link}}">
|
||||
<!-- Search Text -->
|
||||
<div class="ui fluid action input">
|
||||
{{template "shared/search/combo" dict "Value" .Keyword}}
|
||||
<button class="ui primary button">{{ctx.Locale.Tr "actions.require_action.search"}}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="ui attached table segment">
|
||||
|
@ -45,8 +43,15 @@
|
|||
<td>{{.RepoName}}</td>
|
||||
<td><a href="/{{$.OrgName}}/{{.RepoName}}">Workflow Link</a></td>
|
||||
<td class="require_action-ops">
|
||||
{{if .Removable $.OrgID }}
|
||||
<a href="{{$.Link}}/{{.ID}}">{{svg "octicon-x-circle-fill"}}</a>
|
||||
{{if .Removable $.OrgID}}
|
||||
<button class="btn interact-bg tw-p-2 link-action"
|
||||
data-tooltip-content="{{ctx.Locale.Tr "actions.require_action.deletion"}}"
|
||||
data-url="{{$.Link}}/{{.ID}}/delete"
|
||||
data-modal-confirm="{{ctx.Locale.Tr "actions.require_action.deletion.description"}}"
|
||||
>
|
||||
{{svg "octicon-trash"}}
|
||||
</button>
|
||||
<!-- <a href="{{$.Link}}/{{.ID}}/delete">{{svg "octicon-x-circle-fill"}}</a>-->
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -103,12 +108,12 @@
|
|||
</a>
|
||||
</div></td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{end}}
|
||||
{{else}}
|
||||
<tr>
|
||||
<td class="center aligned" colspan="8">{{ctx.Locale.Tr "actions.require_action.none"}}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="divider"></div>
|
||||
|
|
Loading…
Reference in New Issue