Skip to content

Commit d4fd5b5

Browse files
committed
Add the delete function and remove formatting error.
Signed-off-by: Alex Lau(AvengerMoJo) <[email protected]>
1 parent 1fc9989 commit d4fd5b5

File tree

8 files changed

+61
-25
lines changed

8 files changed

+61
-25
lines changed

models/actions/require_action.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@ import (
99
"context"
1010

1111
"code.gitea.io/gitea/models/db"
12-
//"code.gitea.io/gitea/models/unit"
1312
"code.gitea.io/gitea/modules/timeutil"
1413

1514
"xorm.io/builder"
1615
)
1716

1817
type RequireAction struct {
19-
ID int64 `xorm:"pk autoincr"`
20-
OrgID int64 `xorm:"index"`
21-
RepoName string `xorm:"VARCHAR(255)"`
22-
WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"`
23-
// Description string `xorm:"LONGTEXT NOT NULL"`
24-
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
25-
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
26-
// RepoRange string // glob match which repositories could use this runner
18+
ID int64 `xorm:"pk autoincr"`
19+
OrgID int64 `xorm:"index"`
20+
RepoName string `xorm:"VARCHAR(255)"`
21+
WorkflowName string `xorm:"VARCHAR(255) UNIQUE(require_action) NOT NULL"`
22+
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
23+
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
2724
}
2825

2926
type GlobalWorkflow struct {
@@ -76,3 +73,10 @@ func AddRequireAction(ctx context.Context, orgID int64, repoName, workflowName s
7673
}
7774
return ra, db.Insert(ctx, ra)
7875
}
76+
77+
func DeleteRequireAction(ctx context.Context, requireActionID int64) error {
78+
if _, err := db.DeleteByID[RequireAction](ctx, requireActionID); err != nil {
79+
return err
80+
}
81+
return nil
82+
}

models/migrations/v1_23/v295.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package v1_23 //nolint
55

66
import (
77
"code.gitea.io/gitea/modules/timeutil"
8+
89
"xorm.io/xorm"
910
)
1011

options/locale/locale_en-US.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3648,6 +3648,7 @@ require_action.add = Add Global Workflow
36483648
require_action.add_require_action = Enable selected Workflow
36493649
require_action.new = Create New
36503650
require_action.status = Status
3651+
require_action.search = Search...
36513652
require_action.version = Version
36523653
require_action.repo = Repo Name
36533654
require_action.workflow = Workflow Filename
@@ -3656,6 +3657,12 @@ require_action.remove = Remove
36563657
require_action.none = No Require Actions Available.
36573658
require_action.creation.failed = Create Global Require Action %s Failed.
36583659
require_action.creation.success = Create Global Require Action %s successfully.
3660+
require_action.deletion = Delete
3661+
require_action.deletion.description = Removing the Global Require Action is permanent and cannot be undone. Continue?
3662+
require_action.deletion.success = The Global Require Action has been removed.
3663+
3664+
3665+
36593666
36603667
workflow.disable = Disable Workflow
36613668
workflow.disable_success = Workflow '%s' disabled successfully.

routers/web/repo/setting/require_action.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ import (
99
"errors"
1010
"net/http"
1111

12+
actions_model "code.gitea.io/gitea/models/actions"
1213
"code.gitea.io/gitea/models/db"
1314
"code.gitea.io/gitea/modules/base"
14-
// "code.gitea.io/gitea/modules/log"
15-
16-
"code.gitea.io/gitea/services/context"
17-
18-
//"code.gitea.io/gitea/modules/setting"
19-
actions_model "code.gitea.io/gitea/models/actions"
2015
shared "code.gitea.io/gitea/routers/web/shared/actions"
16+
"code.gitea.io/gitea/services/context"
2117
)
2218

2319
const (
@@ -80,3 +76,12 @@ func RequireActionCreate(ctx *context.Context) {
8076
}
8177
shared.CreateRequireAction(ctx, vCtx.OrgID, vCtx.RedirectLink)
8278
}
79+
80+
func RequireActionDelete(ctx *context.Context) {
81+
vCtx, err := getRequireActionCtx(ctx)
82+
if err != nil {
83+
ctx.ServerError("getRequireActionCtx", err)
84+
return
85+
}
86+
shared.DeleteRequireAction(ctx, vCtx.RedirectLink)
87+
}

routers/web/shared/actions/require_action.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import (
1313
"code.gitea.io/gitea/modules/log"
1414
"code.gitea.io/gitea/modules/web"
1515
actions_service "code.gitea.io/gitea/services/actions"
16-
"code.gitea.io/gitea/services/forms"
17-
1816
"code.gitea.io/gitea/services/context"
17+
"code.gitea.io/gitea/services/forms"
1918
)
2019

2120
// SetRequireActionDeletePost response for deleting a require action workflow
@@ -62,8 +61,6 @@ func GlobalEnableWorkflow(ctx *context.Context, orgID int64) {
6261
func CreateRequireAction(ctx *context.Context, orgID int64, redirectURL string) {
6362
ctx.Data["OrgID"] = ctx.Org.Organization.ID
6463
form := web.GetForm(ctx).(*forms.RequireActionForm)
65-
// log.Error("org %d, repo_name: %s, workflow_name %s", orgID, form.RepoName, form.WorkflowName)
66-
log.Error("org %d, repo_name: %+v", orgID, form)
6764
v, err := actions_service.CreateRequireAction(ctx, orgID, form.RepoName, form.WorkflowName)
6865
if err != nil {
6966
log.Error("CreateRequireAction: %v", err)
@@ -73,3 +70,15 @@ func CreateRequireAction(ctx *context.Context, orgID int64, redirectURL string)
7370
ctx.Flash.Success(ctx.Tr("actions.require_action.creation.success", v.WorkflowName))
7471
ctx.JSONRedirect(redirectURL)
7572
}
73+
74+
func DeleteRequireAction(ctx *context.Context, redirectURL string) {
75+
id := ctx.ParamsInt64(":require_action_id")
76+
77+
if err := actions_service.DeleteRequireActionByID(ctx, id); err != nil {
78+
log.Error("Delete RequireAction [%d] failed: %v", id, err)
79+
ctx.JSONError(ctx.Tr("actions.require_action.deletion.failed"))
80+
return
81+
}
82+
ctx.Flash.Success(ctx.Tr("actions.require_action.deletion.success"))
83+
ctx.JSONRedirect(redirectURL)
84+
}

routers/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ func registerRoutes(m *web.Route) {
463463
m.Group("/require_action", func() {
464464
m.Get("", repo_setting.RequireAction)
465465
m.Post("/add", web.Bind(forms.RequireActionForm{}), repo_setting.RequireActionCreate)
466+
m.Post("/{require_action_id}/delete", repo_setting.RequireActionDelete)
466467
})
467468
}
468469

services/actions/require_action.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ func CreateRequireAction(ctx context.Context, orgID int64, repoName, workflowNam
1616
}
1717
return v, nil
1818
}
19+
20+
func DeleteRequireActionByID(ctx context.Context, requireActionID int64) error {
21+
return actions_model.DeleteRequireAction(ctx, requireActionID)
22+
}

templates/shared/actions/require_action_list.tmpl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
<div class="ui attached segment">
1616
<form class="ui form ignore-dirty" id="require-action-list-search-form" action="{{$.Link}}">
1717
<!-- Search Text -->
18-
<div class="ui fluid action input">
1918
{{template "shared/search/combo" dict "Value" .Keyword}}
2019
<button class="ui primary button">{{ctx.Locale.Tr "actions.require_action.search"}}</button>
21-
</div>
2220
</form>
2321
</div>
2422
<div class="ui attached table segment">
@@ -45,8 +43,15 @@
4543
<td>{{.RepoName}}</td>
4644
<td><a href="/{{$.OrgName}}/{{.RepoName}}">Workflow Link</a></td>
4745
<td class="require_action-ops">
48-
{{if .Removable $.OrgID }}
49-
<a href="{{$.Link}}/{{.ID}}">{{svg "octicon-x-circle-fill"}}</a>
46+
{{if .Removable $.OrgID}}
47+
<button class="btn interact-bg tw-p-2 link-action"
48+
data-tooltip-content="{{ctx.Locale.Tr "actions.require_action.deletion"}}"
49+
data-url="{{$.Link}}/{{.ID}}/delete"
50+
data-modal-confirm="{{ctx.Locale.Tr "actions.require_action.deletion.description"}}"
51+
>
52+
{{svg "octicon-trash"}}
53+
</button>
54+
<!-- <a href="{{$.Link}}/{{.ID}}/delete">{{svg "octicon-x-circle-fill"}}</a>-->
5055
{{end}}
5156
</td>
5257
</tr>
@@ -103,12 +108,12 @@
103108
</a>
104109
</div></td>
105110
</tr>
106-
{{ end }}
111+
{{end}}
107112
{{else}}
108113
<tr>
109114
<td class="center aligned" colspan="8">{{ctx.Locale.Tr "actions.require_action.none"}}</td>
110115
</tr>
111-
{{ end }}
116+
{{end}}
112117
</tbody>
113118
</table>
114119
<div class="divider"></div>

0 commit comments

Comments
 (0)