mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-22 01:44:24 +01:00
Compare commits
4 commits
0b2750714c
...
a7d3c04cb1
Author | SHA1 | Date | |
---|---|---|---|
a7d3c04cb1 | |||
f5c0570533 | |||
298863c701 | |||
c3653e0eaa |
|
@ -6,6 +6,8 @@
|
||||||
package templates
|
package templates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
@ -29,6 +31,23 @@ func NewFuncMap() template.FuncMap {
|
||||||
return map[string]any{
|
return map[string]any{
|
||||||
"ctx": func() any { return nil }, // template context function
|
"ctx": func() any { return nil }, // template context function
|
||||||
|
|
||||||
|
"ExecuteTemplate": func(ctx context.Context, tmplName string, args any) template.HTML {
|
||||||
|
h := HTMLRenderer()
|
||||||
|
tmpl, err := h.TemplateLookup(tmplName, ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic("Template not found: " + tmplName)
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
if err := tmpl.Execute(&buf, args); err != nil {
|
||||||
|
panic("Error while executing template")
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can safely return this as `template.HTML` as html/template will
|
||||||
|
// already make sure it's sanitized.
|
||||||
|
return template.HTML(buf.String())
|
||||||
|
},
|
||||||
|
|
||||||
"DumpVar": dumpVar,
|
"DumpVar": dumpVar,
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
|
|
|
@ -1746,8 +1746,8 @@ issues.add_time_sum_to_small = No time was entered.
|
||||||
issues.time_spent_total = Total time spent
|
issues.time_spent_total = Total time spent
|
||||||
issues.time_spent_from_all_authors = `Total time spent: %s`
|
issues.time_spent_from_all_authors = `Total time spent: %s`
|
||||||
issues.due_date = Due date
|
issues.due_date = Due date
|
||||||
issues.push_commit_1 = added %d commit %s
|
discussion.added_commits_one = %[1]s added %[2]d commit %[3]s
|
||||||
issues.push_commits_n = added %d commits %s
|
discussion.added_commits_few = %[1]s added %[2]d commits %[3]s
|
||||||
issues.force_push_codes = `force-pushed %[1]s from <a class="%[7]s" href="%[3]s"><code>%[2]s</code></a> to <a class="%[7]s" href="%[5]s"><code>%[4]s</code></a> %[6]s`
|
issues.force_push_codes = `force-pushed %[1]s from <a class="%[7]s" href="%[3]s"><code>%[2]s</code></a> to <a class="%[7]s" href="%[5]s"><code>%[4]s</code></a> %[6]s`
|
||||||
issues.force_push_compare = Compare
|
issues.force_push_compare = Compare
|
||||||
issues.due_date_form = yyyy-mm-dd
|
issues.due_date_form = yyyy-mm-dd
|
||||||
|
@ -2622,9 +2622,9 @@ diff.browse_source = Browse source
|
||||||
diff.parent = parent
|
diff.parent = parent
|
||||||
diff.commit = commit
|
diff.commit = commit
|
||||||
diff.git-notes = Notes
|
diff.git-notes = Notes
|
||||||
diff.git-notes.add = Add Note
|
diff.git-notes.add = Add note
|
||||||
diff.git-notes.remove-header = Remove Note
|
diff.git-notes.remove-header = Remove note
|
||||||
diff.git-notes.remove-body = This will remove this Note
|
diff.git-notes.remove-body = This note will be removed.
|
||||||
diff.data_not_available = Diff content is not available
|
diff.data_not_available = Diff content is not available
|
||||||
diff.options_button = Diff options
|
diff.options_button = Diff options
|
||||||
diff.show_diff_stats = Show stats
|
diff.show_diff_stats = Show stats
|
||||||
|
|
|
@ -128,6 +128,9 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="commit-notes-add-button" class="item">
|
||||||
|
{{ctx.Locale.Tr "repo.diff.git-notes.add"}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -277,20 +280,20 @@
|
||||||
<span class="text grey" id="note-authored-time">{{DateUtils.TimeSince .NoteCommit.Author.When}}</span>
|
<span class="text grey" id="note-authored-time">{{DateUtils.TimeSince .NoteCommit.Author.When}}</span>
|
||||||
{{if or ($.Permission.CanWrite $.UnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}
|
{{if or ($.Permission.CanWrite $.UnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}
|
||||||
<div class="ui right">
|
<div class="ui right">
|
||||||
<button id="commit-notes-edit-button" class="ui tiny button yellow" data-modal="#delete-note-modal">{{ctx.Locale.Tr "edit"}}</button>
|
<button id="commit-notes-edit-button" class="ui tiny primary button" data-modal="#delete-note-modal">{{ctx.Locale.Tr "edit"}}</button>
|
||||||
<button class="ui tiny button red show-modal" data-modal="#delete-note-modal">{{ctx.Locale.Tr "remove"}}</button>
|
<button class="ui tiny button red show-modal" data-modal="#delete-note-modal">{{ctx.Locale.Tr "remove"}}</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui small modal" id="delete-note-modal">
|
<div class="ui small modal" id="delete-note-modal">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{{ctx.Locale.Tr "repo.diff.git-notes.remove-header"}}
|
{{ctx.Locale.Tr "repo.diff.git-notes.remove-header"}}
|
||||||
</div>
|
</div>
|
||||||
<p>{{ctx.Locale.Tr "repo.diff.git-notes.remove-body"}}</p>
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
<p>{{ctx.Locale.Tr "repo.diff.git-notes.remove-body"}}</p>
|
||||||
<div class="text right actions">
|
<div class="text right actions">
|
||||||
<form action="{{.Link}}/notes/remove" method="post">
|
<form action="{{.Link}}/notes/remove" method="post">
|
||||||
{{.CsrfTokenHtml}}
|
{{.CsrfTokenHtml}}
|
||||||
<button type="button" class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
|
<button type="button" class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
|
||||||
<button type="submit" class="ui primary button red" href="{{.Link}}/notes/remove">{{ctx.Locale.Tr "remove"}}</button>
|
<button type="submit" class="ui red button" href="{{.Link}}/notes/remove">{{ctx.Locale.Tr "remove"}}</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -316,7 +319,6 @@
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else if and ($.Permission.CanWrite $.UnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}
|
{{else if and ($.Permission.CanWrite $.UnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}
|
||||||
<button id="commit-notes-add-button" class="ui primary button green tw-mt-3">{{ctx.Locale.Tr "repo.diff.git-notes.add"}}</button>
|
|
||||||
<div id="commit-notes-add-area" class="ui tw-mt-3 segment tw-hidden">
|
<div id="commit-notes-add-area" class="ui tw-mt-3 segment tw-hidden">
|
||||||
<form class="ui form" action="{{.Link}}/notes" method="post">
|
<form class="ui form" action="{{.Link}}/notes" method="post">
|
||||||
{{.CsrfTokenHtml}}
|
{{.CsrfTokenHtml}}
|
||||||
|
|
|
@ -549,11 +549,10 @@
|
||||||
<div class="timeline-item event" id="{{.HashTag}}">
|
<div class="timeline-item event" id="{{.HashTag}}">
|
||||||
<span class="badge">{{svg "octicon-repo-push"}}</span>
|
<span class="badge">{{svg "octicon-repo-push"}}</span>
|
||||||
<span class="text grey muted-links">
|
<span class="text grey muted-links">
|
||||||
{{template "shared/user/authorlink" .Poster}}
|
|
||||||
{{if .IsForcePush}}
|
{{if .IsForcePush}}
|
||||||
{{ctx.Locale.Tr "repo.issues.force_push_codes" $.Issue.PullRequest.HeadBranch (ShortSha .OldCommit) ($.Issue.Repo.CommitLink .OldCommit) (ShortSha .NewCommit) ($.Issue.Repo.CommitLink .NewCommit) $createdStr "ui sha"}}
|
{{template "shared/user/authorlink" .Poster}} {{ctx.Locale.Tr "repo.issues.force_push_codes" $.Issue.PullRequest.HeadBranch (ShortSha .OldCommit) ($.Issue.Repo.CommitLink .OldCommit) (ShortSha .NewCommit) ($.Issue.Repo.CommitLink .NewCommit) $createdStr "ui sha"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{ctx.Locale.TrN (len .Commits) "repo.issues.push_commit_1" "repo.issues.push_commits_n" (len .Commits) $createdStr}}
|
{{ctx.Locale.TrN (len .Commits) "repo.discussion.added_commits_one" "repo.discussion.added_commits_few" (ExecuteTemplate ctx "shared/user/authorlink" .Poster) (len .Commits) $createdStr}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</span>
|
</span>
|
||||||
{{if and .IsForcePush $.Issue.PullRequest.BaseRepo.Name}}
|
{{if and .IsForcePush $.Issue.PullRequest.BaseRepo.Name}}
|
||||||
|
|
|
@ -51,10 +51,12 @@
|
||||||
</div>
|
</div>
|
||||||
<input id="pronouns-custom" name="pronouns" value="{{.SignedUser.Pronouns}}" maxlength="50">
|
<input id="pronouns-custom" name="pronouns" value="{{.SignedUser.Pronouns}}" maxlength="50">
|
||||||
</div>
|
</div>
|
||||||
<div class="field {{if .Err_Email}}error{{end}}">
|
{{if not .SignedUser.KeepEmailPrivate}}
|
||||||
<label>{{ctx.Locale.Tr "email"}}</label>
|
<div class="field">
|
||||||
<p id="signed-user-email">{{.SignedUser.Email}}</p>
|
<label>{{ctx.Locale.Tr "email"}}</label>
|
||||||
</div>
|
<p id="signed-user-email">{{.SignedUser.Email}}</p>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
<div class="field {{if .Err_Biography}}error{{end}}">
|
<div class="field {{if .Err_Biography}}error{{end}}">
|
||||||
<label for="biography">{{ctx.Locale.Tr "user.user_bio"}}</label>
|
<label for="biography">{{ctx.Locale.Tr "user.user_bio"}}</label>
|
||||||
<textarea id="biography" name="biography" rows="2" placeholder="{{ctx.Locale.Tr "settings.biography_placeholder"}}" maxlength="255">{{.SignedUser.Description}}</textarea>
|
<textarea id="biography" name="biography" rows="2" placeholder="{{ctx.Locale.Tr "settings.biography_placeholder"}}" maxlength="255">{{.SignedUser.Description}}</textarea>
|
||||||
|
|
72
tests/integration/discussion_events_test.go
Normal file
72
tests/integration/discussion_events_test.go
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
package integration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestDiscussionEvents is a test for various events displayed in the timelines of pulls and issues
|
||||||
|
func TestDiscussionEvents(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
|
repoName := "discussion-timeline-tests"
|
||||||
|
user1 := "user1"
|
||||||
|
description := "This PR will be used for testing events in discussions"
|
||||||
|
// Expected branch name when initializing repo automatically
|
||||||
|
defaultBranch := "master"
|
||||||
|
htmlCleaner := regexp.MustCompile(`[\t\n]`)
|
||||||
|
|
||||||
|
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||||
|
sessionUser1 := loginUser(t, user1)
|
||||||
|
tokenUser1 := getTokenForLoggedInUser(t, sessionUser1, auth_model.AccessTokenScopeAll)
|
||||||
|
|
||||||
|
// Create test repo
|
||||||
|
var repo api.Repository
|
||||||
|
resp := sessionUser1.MakeRequest(t, NewRequestWithJSON(t, "POST", "/api/v1/user/repos", &api.CreateRepoOption{
|
||||||
|
Name: repoName,
|
||||||
|
AutoInit: true,
|
||||||
|
}).AddTokenAuth(tokenUser1), http.StatusCreated)
|
||||||
|
DecodeJSON(t, resp, &repo)
|
||||||
|
|
||||||
|
// == Test pulls ==
|
||||||
|
|
||||||
|
// Open a new PR as user1
|
||||||
|
testEditFileToNewBranch(t, sessionUser1, user1, repo.Name, defaultBranch, "comment-labels", "README.md", description)
|
||||||
|
sessionUser1.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(repo.FullName, "compare", fmt.Sprintf("%s...comment-labels", defaultBranch)),
|
||||||
|
map[string]string{
|
||||||
|
"_csrf": GetCSRF(t, sessionUser1, path.Join(repo.FullName, "compare", fmt.Sprintf("%s...comment-labels", defaultBranch))),
|
||||||
|
"title": description,
|
||||||
|
},
|
||||||
|
), http.StatusOK)
|
||||||
|
|
||||||
|
// Pull number, expected to be 1 in a fresh repo
|
||||||
|
testPullID := "1"
|
||||||
|
|
||||||
|
// Get the PR page and find all events
|
||||||
|
response := sessionUser1.MakeRequest(t, NewRequest(t, "GET", path.Join(repo.FullName, "pulls", testPullID)), http.StatusOK)
|
||||||
|
page := NewHTMLParser(t, response.Body)
|
||||||
|
events := page.Find(".timeline .timeline-item.event .text")
|
||||||
|
|
||||||
|
// Check the event. Should contain: "<username> added 1 commit <relative-time>"
|
||||||
|
event := events.Eq(0)
|
||||||
|
eventHTML, _ := event.Html()
|
||||||
|
eventText := htmlCleaner.ReplaceAllString(strings.TrimSpace(event.Text()), "")
|
||||||
|
assert.Contains(t, eventHTML, `href="/user1">user1</a>`)
|
||||||
|
assert.Contains(t, eventHTML, `<relative-time`)
|
||||||
|
assert.Contains(t, eventText, `user1 added 1 commit`)
|
||||||
|
})
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||||
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package integration
|
package integration
|
||||||
|
@ -156,3 +157,23 @@ func TestSettingSecurityAuthSource(t *testing.T) {
|
||||||
assert.Contains(t, resp.Body.String(), `gitlab-active`)
|
assert.Contains(t, resp.Body.String(), `gitlab-active`)
|
||||||
assert.Contains(t, resp.Body.String(), `gitlab-inactive`)
|
assert.Contains(t, resp.Body.String(), `gitlab-inactive`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSettingShowUserEmailSettings(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
|
// user1: keep_email_private = false, user2: keep_email_private = true
|
||||||
|
|
||||||
|
// user1 can see own visible email
|
||||||
|
session := loginUser(t, "user1")
|
||||||
|
req := NewRequest(t, "GET", "/user/settings")
|
||||||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
assert.Contains(t, htmlDoc.doc.Find("#signed-user-email").Text(), "user1@example.com")
|
||||||
|
|
||||||
|
// user2 cannot see own hidden email
|
||||||
|
session = loginUser(t, "user2")
|
||||||
|
req = NewRequest(t, "GET", "/user/settings")
|
||||||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||||
|
assert.NotContains(t, htmlDoc.doc.Find("#signed-user-email").Text(), "user2@example.com")
|
||||||
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ export function initCommitNotes() {
|
||||||
const notesAddButton = document.getElementById('commit-notes-add-button');
|
const notesAddButton = document.getElementById('commit-notes-add-button');
|
||||||
if (notesAddButton !== null) {
|
if (notesAddButton !== null) {
|
||||||
notesAddButton.addEventListener('click', () => {
|
notesAddButton.addEventListener('click', () => {
|
||||||
notesAddButton.classList.add('tw-hidden');
|
|
||||||
document.getElementById('commit-notes-add-area').classList.remove('tw-hidden');
|
document.getElementById('commit-notes-add-area').classList.remove('tw-hidden');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue