Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-24 10:46:10 +01:00

Prevent NPE if trying to restore an already restored deleted branch (#21940) (#21944)

Backport #21940

If a deleted-branch has already been restored, a request to restore it
again will cause a NPE. This PR adds detection for this case, but also
disables buttons when they're clicked in order to help prevent
accidental repeat requests.

Fix #21930

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath 2022-11-25 23:28:03 +00:00 committed by GitHub
parent ff4e292b3f
commit b56d269cf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -126,6 +126,10 @@ func RestoreBranchPost(ctx *context.Context) {
log.Error("GetDeletedBranchByID: %v", err) log.Error("GetDeletedBranchByID: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName)) ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName))
return return
} else if deletedBranch == nil {
log.Debug("RestoreBranch: Can't restore branch[%d] '%s', as it does not exist", branchID, branchName)
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName))
return
} }
if err := git.Push(ctx, ctx.Repo.Repository.RepoPath(), git.PushOptions{ if err := git.Push(ctx, ctx.Repo.Repository.RepoPath(), git.PushOptions{

View file

@ -260,6 +260,7 @@ export function initGlobalLinkActions() {
e.preventDefault(); e.preventDefault();
const $this = $(this); const $this = $(this);
const redirect = $this.data('redirect'); const redirect = $this.data('redirect');
$this.prop('disabled', true);
$.post($this.data('url'), { $.post($this.data('url'), {
_csrf: csrfToken _csrf: csrfToken
}).done((data) => { }).done((data) => {
@ -270,6 +271,8 @@ export function initGlobalLinkActions() {
} else { } else {
window.location.reload(); window.location.reload();
} }
}).always(() => {
$this.prop('disabled', false);
}); });
} }
@ -283,11 +286,14 @@ export function initGlobalLinkActions() {
// FIXME: this is only used once, and should be replace with `link-action` instead // FIXME: this is only used once, and should be replace with `link-action` instead
$('.undo-button').on('click', function () { $('.undo-button').on('click', function () {
const $this = $(this); const $this = $(this);
$this.prop('disabled', true);
$.post($this.data('url'), { $.post($this.data('url'), {
_csrf: csrfToken, _csrf: csrfToken,
id: $this.data('id') id: $this.data('id')
}).done((data) => { }).done((data) => {
window.location.href = data.redirect; window.location.href = data.redirect;
}).always(() => {
$this.prop('disabled', false);
}); });
}); });
} }