Skip to content

Commit 1df6c57

Browse files
committed
use ctx.JSON
1 parent 9c33b96 commit 1df6c57

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

routers/web/repo/setting/actions.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,13 @@ func ActionsUnitPost(ctx *context.Context) {
6969
}
7070

7171
func AddCollaborativeOwner(ctx *context.Context) {
72-
redirectURL := ctx.Repo.RepoLink + "/settings/actions/general"
7372
name := strings.ToLower(ctx.FormString("collaborative_owner"))
7473

7574
ownerID, err := user_model.GetUserOrOrgIDByName(ctx, name)
7675
if err != nil {
7776
if errors.Is(err, util.ErrNotExist) {
7877
ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
79-
ctx.Redirect(redirectURL)
78+
ctx.JSONErrorNotFound()
8079
} else {
8180
ctx.ServerError("GetUserOrOrgIDByName", err)
8281
}
@@ -95,11 +94,10 @@ func AddCollaborativeOwner(ctx *context.Context) {
9594
return
9695
}
9796

98-
ctx.Redirect(redirectURL)
97+
ctx.JSONOK()
9998
}
10099

101100
func DeleteCollaborativeOwner(ctx *context.Context) {
102-
redirectURL := ctx.Repo.RepoLink + "/settings/actions/general"
103101
ownerID := ctx.FormInt64("id")
104102

105103
actionsUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeActions)
@@ -110,7 +108,7 @@ func DeleteCollaborativeOwner(ctx *context.Context) {
110108
actionsCfg := actionsUnit.ActionsConfig()
111109
if !actionsCfg.IsCollaborativeOwner(ownerID) {
112110
ctx.Flash.Error(ctx.Tr("actions.general.collaborative_owner_not_exist"))
113-
ctx.Redirect(redirectURL)
111+
ctx.JSONErrorNotFound()
114112
return
115113
}
116114
actionsCfg.RemoveCollaborativeOwner(ownerID)
@@ -119,5 +117,5 @@ func DeleteCollaborativeOwner(ctx *context.Context) {
119117
return
120118
}
121119

122-
ctx.JSONRedirect(redirectURL)
120+
ctx.JSONOK()
123121
}

templates/repo/settings/actions_general.tmpl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,19 @@
4242
</div>
4343
</div>
4444
<div class="flex-item-trailing">
45-
<button class="ui red tiny button inline delete-button" data-url="{{$.Link}}/collaborative_owner/delete" data-id="{{.ID}}">
46-
{{ctx.Locale.Tr "remove"}}
47-
</button>
45+
<button class="ui red tiny button inline link-action"
46+
data-url="{{$.Link}}/collaborative_owner/delete?id={{.ID}}"
47+
data-modal-confirm-header="{{ctx.Locale.Tr "actions.general.remove_collaborative_owner"}}"
48+
data-modal-confirm-content="{{ctx.Locale.Tr "actions.general.remove_collaborative_owner_desc"}}"
49+
>{{ctx.Locale.Tr "remove"}}</button>
4850
</div>
4951
</div>
5052
{{end}}
5153
</div>
5254
</div>
5355
{{end}}
5456
<div class="ui bottom attached segment">
55-
<form class="ui form" action="{{.Link}}/collaborative_owner/add" method="post">
57+
<form class="ui form form-fetch-action" action="{{.Link}}/collaborative_owner/add" method="post">
5658
{{.CsrfTokenHtml}}
5759
<div id="search-user-box" class="ui search input tw-align-middle" data-include-orgs="true">
5860
<input class="prompt" name="collaborative_owner" placeholder="{{ctx.Locale.Tr "search.user_kind"}}" autocomplete="off" autofocus required>
@@ -65,14 +67,3 @@
6567
{{end}}
6668
{{end}}
6769
</div>
68-
69-
<div class="ui g-modal-confirm delete modal">
70-
<div class="header">
71-
{{svg "octicon-trash"}}
72-
{{ctx.Locale.Tr "actions.general.remove_collaborative_owner"}}
73-
</div>
74-
<div class="content">
75-
<p>{{ctx.Locale.Tr "actions.general.remove_collaborative_owner_desc"}}</p>
76-
</div>
77-
{{template "base/modal_actions_confirm" .}}
78-
</div>

tests/integration/actions_settings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestActionsCollaborativeOwner(t *testing.T) {
4040
"_csrf": GetUserCSRFToken(t, user2Session),
4141
"collaborative_owner": user10.Name,
4242
})
43-
user2Session.MakeRequest(t, req, http.StatusSeeOther)
43+
user2Session.MakeRequest(t, req, http.StatusOK)
4444

4545
// the git clone will be successful
4646
doGitClone(dstPath, u)(t)

0 commit comments

Comments
 (0)