Merge pull request 'Fix repo unarchivation button' (#2550) from 0ko/forgejo:unarchive_btn into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2550
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-03-10 06:31:47 +00:00
commit 79f8339c74
3 changed files with 85 additions and 3 deletions

View file

@ -2465,7 +2465,7 @@ settings.matrix.homeserver_url = Homeserver URL
settings.matrix.room_id = Room ID settings.matrix.room_id = Room ID
settings.matrix.message_type = Message Type settings.matrix.message_type = Message Type
settings.archive.button = Archive Repo settings.archive.button = Archive Repo
settings.archive.header = Archive This Repo settings.archive.header = Archive this repo
settings.archive.text = Archiving the repo will make it entirely read-only. It will be hidden from the dashboard. Nobody (not even you!) will be able to make new commits, or open any issues or pull requests. settings.archive.text = Archiving the repo will make it entirely read-only. It will be hidden from the dashboard. Nobody (not even you!) will be able to make new commits, or open any issues or pull requests.
settings.archive.success = The repo was successfully archived. settings.archive.success = The repo was successfully archived.
settings.archive.error = An error occurred while trying to archive the repo. See the log for more details. settings.archive.error = An error occurred while trying to archive the repo. See the log for more details.
@ -2473,7 +2473,7 @@ settings.archive.error_ismirror = You cannot archive a mirrored repo.
settings.archive.branchsettings_unavailable = Branch settings are not available if the repo is archived. settings.archive.branchsettings_unavailable = Branch settings are not available if the repo is archived.
settings.archive.tagsettings_unavailable = Tag settings are not available if the repo is archived. settings.archive.tagsettings_unavailable = Tag settings are not available if the repo is archived.
settings.archive.mirrors_unavailable = Mirrors are not available if the repo is archived. settings.archive.mirrors_unavailable = Mirrors are not available if the repo is archived.
settings.unarchive.button = Unarchive repo settings.unarchive.button = Unarchive Repo
settings.unarchive.header = Unarchive this repo settings.unarchive.header = Unarchive this repo
settings.unarchive.text = Unarchiving the repo will restore its ability to receive commits and pushes, as well as new issues and pull-requests. settings.unarchive.text = Unarchiving the repo will restore its ability to receive commits and pushes, as well as new issues and pull-requests.
settings.unarchive.success = The repo was successfully unarchived. settings.unarchive.success = The repo was successfully unarchived.

View file

@ -742,7 +742,13 @@
<input type="hidden" name="repo_id" value="{{.Repository.ID}}"> <input type="hidden" name="repo_id" value="{{.Repository.ID}}">
<div class="text right actions"> <div class="text right actions">
<button class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button> <button class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
<button class="ui red button">{{ctx.Locale.Tr "repo.settings.archive.button"}}</button> <button class="ui red button">
{{if .Repository.IsArchived}}
{{ctx.Locale.Tr "repo.settings.unarchive.button"}}
{{else}}
{{ctx.Locale.Tr "repo.settings.archive.button"}}
{{end}}
</button>
</div> </div>
</form> </form>
</div> </div>

View file

@ -0,0 +1,76 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"net/url"
"path"
"strings"
"testing"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/translation"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
)
func TestArchiveText(t *testing.T) {
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
testUser := "user2"
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: testUser})
session := loginUser(t, testUser)
testRepoName := "archived_repo"
tr := translation.NewLocale("en-US")
link := path.Join(testUser, testRepoName, "settings")
// Create test repo
_, _, f := CreateDeclarativeRepo(t, user2, testRepoName, nil, nil, nil)
defer f()
// Test settings page
req := NewRequest(t, "GET", link)
resp := session.MakeRequest(t, req, http.StatusOK)
archivation := NewHTMLParser(t, resp.Body)
testRepoArchiveElements(t, tr, archivation, "archive")
// Archive repo
req = NewRequestWithValues(t, "POST", link, map[string]string{
"action": "archive",
"_csrf": GetCSRF(t, session, link),
})
_ = session.MakeRequest(t, req, http.StatusSeeOther)
// Test settings page again
req = NewRequest(t, "GET", link)
resp = session.MakeRequest(t, req, http.StatusOK)
unarchivation := NewHTMLParser(t, resp.Body)
testRepoArchiveElements(t, tr, unarchivation, "unarchive")
})
}
func testRepoArchiveElements(t *testing.T, tr translation.Locale, doc *HTMLDoc, opType string) {
t.Helper()
// Test danger section
section := doc.Find(".danger.segment .flex-list .flex-item:has(.button[data-modal='#archive-repo-modal'])")
testRepoArchiveElement(t, tr, section, ".flex-item-title", opType+".header")
testRepoArchiveElement(t, tr, section, ".flex-item-body", opType+".text")
testRepoArchiveElement(t, tr, section, ".button", opType+".button")
// Test modal
modal := doc.Find("#archive-repo-modal")
testRepoArchiveElement(t, tr, modal, ".header", opType+".header")
testRepoArchiveElement(t, tr, modal, ".message", opType+".text")
testRepoArchiveElement(t, tr, modal, ".button.red", opType+".button")
}
func testRepoArchiveElement(t *testing.T, tr translation.Locale, doc *goquery.Selection, selector, op string) {
t.Helper()
element := doc.Find(selector).Text()
element = strings.TrimSpace(element)
assert.Equal(t, tr.TrString("repo.settings."+op), element)
}