loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Disable issue subscribe button for guest users (#4095)

* disabled the button itself, but added the tooltip to the form, because it didn't work for the button and likely has something to do with JS
* added an integration test to verify the new logic

## Preview

|Signed in|Guest|
|-|-|
|![](/attachments/b1441565-6aec-4a72-a28f-6383914c8918)|![](/attachments/839cc58e-18cf-4a5d-a9d7-f0e3e2556c98)|

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4095
Reviewed-by: Mai-Lapyst <mai-lapyst@noreply.codeberg.org>

0ko 367317af 187860bd

+59 -4
+5 -2
options/locale/locale_en-US.ini
··· 1211 1211 fork_guest_user = Sign in to fork this repository. 1212 1212 watch_guest_user = Sign in to watch this repository. 1213 1213 star_guest_user = Sign in to star this repository. 1214 + subscribe.issue.guest.tooltip = Sign in to subscribe to this issue. 1215 + subscribe.pull.guest.tooltip = Sign in to subscribe to this pull request. 1216 + 1217 + watch = Watch 1214 1218 unwatch = Unwatch 1215 - watch = Watch 1219 + star = Star 1216 1220 unstar = Unstar 1217 - star = Star 1218 1221 fork = Fork 1219 1222 download_archive = Download repository 1220 1223 more_operations = More operations
+1
release-notes/8.0.0/4095.md
··· 1 + Disable Subscribe button for guest users.
+9 -2
templates/repo/issue/view_content/sidebar/watching.tmpl
··· 1 - <form hx-boost="true" hx-sync="this:replace" hx-target="this" method="post" action="{{.Issue.Link}}/watch"> 1 + <form hx-boost="true" hx-sync="this:replace" hx-target="this" method="post" action="{{.Issue.Link}}/watch" 2 + {{if not $.IsSigned}} 3 + {{if $.Issue.IsPull}} 4 + data-tooltip-content="{{ctx.Locale.Tr "repo.subscribe.pull.guest.tooltip"}}" 5 + {{else}} 6 + data-tooltip-content="{{ctx.Locale.Tr "repo.subscribe.issue.guest.tooltip"}}" 7 + {{end}} 8 + {{end}}> 2 9 <input type="hidden" name="watch" value="{{if $.IssueWatch.IsWatching}}0{{else}}1{{end}}"> 3 - <button class="fluid ui button"> 10 + <button class="fluid ui button {{if not $.IsSigned}}disabled{{end}}"> 4 11 {{if $.IssueWatch.IsWatching}} 5 12 {{svg "octicon-mute" 16 "tw-mr-2"}} 6 13 {{ctx.Locale.Tr "repo.issues.unsubscribe"}}
+44
tests/integration/issue_subscribe_test.go
··· 1 + // Copyright 2024 The Forgejo Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package integration 5 + 6 + import ( 7 + "net/http" 8 + "net/url" 9 + "path" 10 + "testing" 11 + 12 + "github.com/stretchr/testify/assert" 13 + ) 14 + 15 + func TestIssueSubscribe(t *testing.T) { 16 + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { 17 + session := emptyTestSession(t) 18 + testIssueSubscribe(t, *session, true) 19 + }) 20 + } 21 + 22 + func testIssueSubscribe(t *testing.T, session TestSession, unavailable bool) { 23 + t.Helper() 24 + 25 + testIssue := "/user2/repo1/issues/1" 26 + testPull := "/user2/repo1/pulls/2" 27 + selector := ".issue-content-right .watching form" 28 + 29 + resp := session.MakeRequest(t, NewRequest(t, "GET", path.Join(testIssue)), http.StatusOK) 30 + area := NewHTMLParser(t, resp.Body).Find(selector) 31 + tooltip, exists := area.Attr("data-tooltip-content") 32 + assert.EqualValues(t, unavailable, exists) 33 + if unavailable { 34 + assert.EqualValues(t, "Sign in to subscribe to this issue.", tooltip) 35 + } 36 + 37 + resp = session.MakeRequest(t, NewRequest(t, "GET", path.Join(testPull)), http.StatusOK) 38 + area = NewHTMLParser(t, resp.Body).Find(selector) 39 + tooltip, exists = area.Attr("data-tooltip-content") 40 + assert.EqualValues(t, unavailable, exists) 41 + if unavailable { 42 + assert.EqualValues(t, "Sign in to subscribe to this pull request.", tooltip) 43 + } 44 + }