Skip to content
Merged
2 changes: 1 addition & 1 deletion modules/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ParseJSONError(buf []byte) (ret struct {
}

func ParseJSONRedirect(buf []byte) (ret struct {
Redirect string `json:"redirect"`
Redirect *string `json:"redirect"`
},
) {
_ = json.Unmarshal(buf, &ret)
Expand Down
48 changes: 24 additions & 24 deletions routers/web/repo/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,16 @@ func handleSettingsPostConvert(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RepoSettingForm)
repo := ctx.Repo.Repository
if !ctx.Repo.IsOwner() {
ctx.HTTPError(http.StatusNotFound)
ctx.JSONErrorNotFound()
return
}
if repo.Name != form.RepoName {
ctx.RenderWithErrDeprecated(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("form.enterred_invalid_repo_name"))
return
}

if !repo.IsMirror {
ctx.HTTPError(http.StatusNotFound)
ctx.JSONErrorNotFound()
return
}
repo.IsMirror = false
Expand All @@ -748,35 +748,35 @@ func handleSettingsPostConvert(ctx *context.Context) {
}
log.Trace("Repository converted from mirror to regular: %s", repo.FullName())
ctx.Flash.Success(ctx.Tr("repo.settings.convert_succeed"))
ctx.Redirect(repo.Link())
ctx.JSONRedirect(repo.Link())
}

func handleSettingsPostConvertFork(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RepoSettingForm)
repo := ctx.Repo.Repository
if !ctx.Repo.IsOwner() {
ctx.HTTPError(http.StatusNotFound)
ctx.JSONErrorNotFound()
return
}
if err := repo.LoadOwner(ctx); err != nil {
ctx.ServerError("Convert Fork", err)
return
}
if repo.Name != form.RepoName {
ctx.RenderWithErrDeprecated(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("form.enterred_invalid_repo_name"))
return
}

if !repo.IsFork {
ctx.HTTPError(http.StatusNotFound)
ctx.JSONErrorNotFound()
return
}

if !ctx.Doer.CanForkRepoIn(ctx.Repo.Owner) {
maxCreationLimit := ctx.Repo.Owner.MaxCreationLimit()
msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
ctx.Flash.Error(msg)
ctx.Redirect(repo.Link() + "/settings")
ctx.JSONRedirect(repo.Link() + "/settings")
return
}

Expand All @@ -788,25 +788,25 @@ func handleSettingsPostConvertFork(ctx *context.Context) {

log.Trace("Repository converted from fork to regular: %s", repo.FullName())
ctx.Flash.Success(ctx.Tr("repo.settings.convert_fork_succeed"))
ctx.Redirect(repo.Link())
ctx.JSONRedirect(repo.Link())
}

func handleSettingsPostTransfer(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RepoSettingForm)
repo := ctx.Repo.Repository
if !ctx.Repo.IsOwner() {
ctx.HTTPError(http.StatusNotFound)
ctx.JSONErrorNotFound()
return
}
if repo.Name != form.RepoName {
ctx.RenderWithErrDeprecated(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("form.enterred_invalid_repo_name"))
return
}

newOwner, err := user_model.GetUserByName(ctx, ctx.FormString("new_owner_name"))
if err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.RenderWithErrDeprecated(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("form.enterred_invalid_owner_name"))
return
}
ctx.ServerError("IsUserExist", err)
Expand All @@ -816,7 +816,7 @@ func handleSettingsPostTransfer(ctx *context.Context) {
if newOwner.Type == user_model.UserTypeOrganization {
if !ctx.Doer.IsAdmin && newOwner.Visibility == structs.VisibleTypePrivate && !organization.OrgFromUser(newOwner).HasMemberWithUserID(ctx, ctx.Doer.ID) {
// The user shouldn't know about this organization
ctx.RenderWithErrDeprecated(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("form.enterred_invalid_owner_name"))
return
}
}
Expand All @@ -830,14 +830,14 @@ func handleSettingsPostTransfer(ctx *context.Context) {
oldFullname := repo.FullName()
if err := repo_service.StartRepositoryTransfer(ctx, ctx.Doer, newOwner, repo, nil); err != nil {
if repo_model.IsErrRepoAlreadyExist(err) {
ctx.RenderWithErrDeprecated(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("repo.settings.new_owner_has_same_repo"))
} else if repo_model.IsErrRepoTransferInProgress(err) {
ctx.RenderWithErrDeprecated(ctx.Tr("repo.settings.transfer_in_progress"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("repo.settings.transfer_in_progress"))
} else if repo_service.IsRepositoryLimitReached(err) {
limit := err.(repo_service.LimitReachedError).Limit
ctx.RenderWithErrDeprecated(ctx.TrN(limit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", limit), tplSettingsOptions, nil)
ctx.JSONError(ctx.TrN(limit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", limit))
} else if errors.Is(err, user_model.ErrBlockedUser) {
ctx.RenderWithErrDeprecated(ctx.Tr("repo.settings.transfer.blocked_user"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("repo.settings.transfer.blocked_user"))
} else {
ctx.ServerError("TransferOwnership", err)
}
Expand All @@ -852,7 +852,7 @@ func handleSettingsPostTransfer(ctx *context.Context) {
log.Trace("Repository transferred: %s -> %s", oldFullname, ctx.Repo.Repository.FullName())
ctx.Flash.Success(ctx.Tr("repo.settings.transfer_succeed"))
}
ctx.Redirect(repo.Link() + "/settings")
ctx.JSONRedirect(repo.Link() + "/settings")
}

func handleSettingsPostCancelTransfer(ctx *context.Context) {
Expand Down Expand Up @@ -887,11 +887,11 @@ func handleSettingsPostDelete(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RepoSettingForm)
repo := ctx.Repo.Repository
if !ctx.Repo.IsOwner() {
ctx.HTTPError(http.StatusNotFound)
ctx.JSONErrorNotFound()
return
}
if repo.Name != form.RepoName {
ctx.RenderWithErrDeprecated(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("form.enterred_invalid_repo_name"))
return
}

Expand All @@ -907,18 +907,18 @@ func handleSettingsPostDelete(ctx *context.Context) {
log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name)

ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
ctx.Redirect(ctx.Repo.Owner.DashboardLink())
ctx.JSONRedirect(ctx.Repo.Owner.DashboardLink())
}

func handleSettingsPostDeleteWiki(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RepoSettingForm)
repo := ctx.Repo.Repository
if !ctx.Repo.IsOwner() {
ctx.HTTPError(http.StatusNotFound)
ctx.JSONErrorNotFound()
return
}
if repo.Name != form.RepoName {
ctx.RenderWithErrDeprecated(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil)
ctx.JSONError(ctx.Tr("form.enterred_invalid_repo_name"))
return
}

Expand All @@ -929,7 +929,7 @@ func handleSettingsPostDeleteWiki(ctx *context.Context) {
log.Trace("Repository wiki deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name)

ctx.Flash.Success(ctx.Tr("repo.settings.wiki_deletion_success"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings")
}

func handleSettingsPostArchive(ctx *context.Context) {
Expand Down
10 changes: 5 additions & 5 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@
<div class="ui warning message">
{{ctx.Locale.Tr "repo.settings.convert_notices_1"}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form form-fetch-action" action="{{.Link}}" method="post">
<input type="hidden" name="action" value="convert">
{{template "repo/settings/repo_name_confirm_fields" (dict "RepoName" .Repository.Name)}}
{{template "base/modal_actions_confirm" (dict "ModalButtonDangerText" (ctx.Locale.Tr "repo.settings.convert_confirm"))}}
Expand All @@ -902,7 +902,7 @@
<div class="ui warning message">
{{ctx.Locale.Tr "repo.settings.convert_fork_notices_1"}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form form-fetch-action" action="{{.Link}}" method="post">
<input type="hidden" name="action" value="convert_fork">
{{template "repo/settings/repo_name_confirm_fields" (dict "RepoName" .Repository.Name)}}
{{template "base/modal_actions_confirm" (dict "ModalButtonDangerText" (ctx.Locale.Tr "repo.settings.convert_fork_confirm"))}}
Expand All @@ -921,7 +921,7 @@
{{ctx.Locale.Tr "repo.settings.transfer_notices_3"}} <br>
{{ctx.Locale.Tr "repo.settings.transfer_notices_4"}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form form-fetch-action" action="{{.Link}}" method="post">
<input type="hidden" name="action" value="transfer">
{{template "repo/settings/repo_name_confirm_fields" (dict "RepoName" .Repository.Name)}}
<div class="required field">
Expand All @@ -946,7 +946,7 @@
{{ctx.Locale.Tr "repo.settings.delete_notices_fork_1"}}
{{end}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form form-fetch-action" action="{{.Link}}" method="post">
<input type="hidden" name="action" value="delete">
Comment thread
wxiaoguang marked this conversation as resolved.
{{template "repo/settings/repo_name_confirm_fields" (dict "RepoName" .Repository.Name)}}
{{template "base/modal_actions_confirm" (dict "ModalButtonDangerText" (ctx.Locale.Tr "repo.settings.confirm_delete"))}}
Expand Down Expand Up @@ -1012,7 +1012,7 @@
{{ctx.Locale.Tr "repo.settings.delete_notices_1"}}<br>
{{ctx.Locale.Tr "repo.settings.wiki_delete_notices_1" .Repository.Name}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
<form class="ui form form-fetch-action" action="{{.Link}}" method="post">
<input type="hidden" name="action" value="delete-wiki">
{{template "repo/settings/repo_name_confirm_fields" (dict "RepoName" .Repository.Name)}}
{{template "base/modal_actions_confirm" (dict "ModalButtonDangerText" (ctx.Locale.Tr "repo.settings.confirm_wiki_delete"))}}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/editor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ func testForkToEditFile(t *testing.T, session *TestSession, user, owner, repo, b
"action": "convert_fork",
},
)
session.MakeRequest(t, req, http.StatusSeeOther)
resp = session.MakeRequest(t, req, http.StatusOK)
assert.NotNil(t, test.ParseJSONRedirect(resp.Body.Bytes()).Redirect)
Comment thread
wxiaoguang marked this conversation as resolved.
})

// Fork repository again, and check the existence of the forked repo with unique name
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/pull_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ func testDeleteRepository(t *testing.T, session *TestSession, ownerName, repoNam
req := NewRequestWithValues(t, "POST", relURL+"?action=delete", map[string]string{
"repo_name": repoName,
})
session.MakeRequest(t, req, http.StatusSeeOther)
resp := session.MakeRequest(t, req, http.StatusOK)
assert.NotNil(t, test.ParseJSONRedirect(resp.Body.Bytes()).Redirect)
Comment thread
wxiaoguang marked this conversation as resolved.
}

func TestPullBranchDelete(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/repo_visibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestRepositoryVisibilityChange(t *testing.T) {
"confirm_repo_name": "user2/repo1",
})
resp = session.MakeRequest(t, req, http.StatusOK)
assert.NotEmpty(t, test.ParseJSONRedirect(resp.Body.Bytes()).Redirect)
assert.NotNil(t, test.ParseJSONRedirect(resp.Body.Bytes()).Redirect)
Comment thread
wxiaoguang marked this conversation as resolved.

repo1 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
assert.True(t, repo1.IsPrivate)
Expand All @@ -51,7 +51,7 @@ func TestRepositoryVisibilityChange(t *testing.T) {
"private": "false",
})
resp := session.MakeRequest(t, req, http.StatusOK)
assert.NotEmpty(t, test.ParseJSONRedirect(resp.Body.Bytes()).Redirect)
assert.NotNil(t, test.ParseJSONRedirect(resp.Body.Bytes()).Redirect)
Comment thread
wxiaoguang marked this conversation as resolved.

repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
assert.False(t, repo2.IsPrivate)
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/common-fetch-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function handleFetchActionSuccess(el: HTMLElement, opt: FetchActionOpts, r
async function handleFetchActionError(resp: Response) {
const isRespJson = resp.headers.get('content-type')?.includes('application/json');
const respText = await resp.text();
const respJson = isRespJson ? JSON.parse(await resp.text()) : null;
const respJson = isRespJson ? JSON.parse(respText) : null;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:

Image

Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good catch, it is a bug (my bug ...)

if (respJson?.errorMessage) {
// the code was quite messy, sometimes the backend uses "err", sometimes it uses "error", and even "user_error"
// but at the moment, as a new approach, we only use "errorMessage" here, backend can use JSONError() to respond.
Expand Down