Skip to content

Commit bc5718d

Browse files
committed
fine tune "view as"
1 parent 95312c7 commit bc5718d

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

routers/web/org/home.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,12 @@ func home(ctx *context.Context, viewRepositories bool) {
116116
}
117117

118118
// if no profile readme, it still means "view repositories"
119-
ctx.Data["PageIsViewRepositories"] = viewRepositories || !prepareOrgProfileReadme(ctx, prepareResult)
119+
isViewOverview := !viewRepositories && prepareOrgProfileReadme(ctx, prepareResult)
120+
ctx.Data["PageIsViewRepositories"] = !isViewOverview
121+
ctx.Data["PageIsViewOverview"] = isViewOverview
122+
ctx.Data["ShowOrgProfileReadmeSelector"] = isViewOverview && prepareResult.ProfilePublicReadmeBlob != nil && prepareResult.ProfilePrivateReadmeBlob != nil
120123

121-
var (
122-
repos []*repo_model.Repository
123-
count int64
124-
)
125-
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
124+
repos, count, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
126125
ListOptions: db.ListOptions{
127126
PageSize: setting.UI.User.RepoPagingNum,
128127
Page: page,
@@ -156,7 +155,7 @@ func home(ctx *context.Context, viewRepositories bool) {
156155
}
157156

158157
func prepareOrgProfileReadme(ctx *context.Context, prepareResult *shared_user.PrepareOrgHeaderResult) bool {
159-
viewAs := ctx.FormString("view_as")
158+
viewAs := ctx.FormString("view_as", util.Iif(ctx.Org.IsMember, "member", "public"))
160159
viewAsMember := viewAs == "member"
161160

162161
var profileRepo *repo_model.Repository

routers/web/shared/user/header.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,5 @@ func PrepareOrgHeader(ctx *context.Context) (result *PrepareOrgHeaderResult, err
202202
result.ProfilePrivateRepo, result.ProfilePrivateReadmeBlob = FindOwnerProfileReadme(ctx, ctx.Doer, RepoNameProfilePrivate)
203203
result.HasOrgProfileReadme = result.ProfilePublicReadmeBlob != nil || result.ProfilePrivateReadmeBlob != nil
204204
ctx.Data["HasOrgProfileReadme"] = result.HasOrgProfileReadme // many pages need it to show the "overview" tab
205-
ctx.Data["ShowOrgProfileReadmeSelector"] = result.ProfilePublicReadmeBlob != nil && result.ProfilePrivateReadmeBlob != nil
206205
return result, nil
207206
}

services/context/base_form.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ import (
88
"strings"
99

1010
"code.gitea.io/gitea/modules/optional"
11+
"code.gitea.io/gitea/modules/util"
1112
)
1213

1314
// FormString returns the first value matching the provided key in the form as a string
14-
func (b *Base) FormString(key string) string {
15-
return b.Req.FormValue(key)
15+
func (b *Base) FormString(key string, def ...string) string {
16+
s := b.Req.FormValue(key)
17+
if s == "" {
18+
s = util.OptionalArg(def)
19+
}
20+
return s
1621
}
1722

1823
// FormStrings returns a string slice for the provided key from the form

templates/org/home.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
3434
<div class="menu">
3535
{{/* TODO: does it really need to use CurrentURL with query parameters? Why not construct a new link with clear parameters */}}
36-
<a href="{{QueryBuild $.CurrentURL "view_as" "public"}}" class="item {{if not .IsViewingOrgAsMember}}selected{{end}}">
36+
<a href="?view_as=public" class="item {{if not .IsViewingOrgAsMember}}selected{{end}}">
3737
{{svg "octicon-check" 14 (Iif (not .IsViewingOrgAsMember) "" "tw-invisible")}} {{ctx.Locale.Tr "settings.visibility.public"}}
3838
</a>
39-
<a href="{{QueryBuild $.CurrentURL "view_as" "member"}}" class="item {{if .IsViewingOrgAsMember}}selected{{end}}">
39+
<a href="?view_as=member" class="item {{if .IsViewingOrgAsMember}}selected{{end}}">
4040
{{svg "octicon-check" 14 (Iif .IsViewingOrgAsMember "" "tw-invisible")}} {{ctx.Locale.Tr "org.members.member"}}
4141
</a>
4242
</div>

tests/integration/org_profile_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ func testOrgProfile(t *testing.T, u *url.URL) {
8282

8383
// Site Admin
8484
session = loginUser(t, "user1")
85-
req = NewRequest(t, "GET", "org3")
85+
req = NewRequest(t, "GET", "/org3")
8686
resp = session.MakeRequest(t, req, http.StatusOK)
8787
bodyString = util.UnsafeBytesToString(resp.Body.Bytes())
88-
assert.Contains(t, bodyString, contentPublicReadme)
88+
assert.Contains(t, bodyString, contentPrivateReadme) // as an org member, default to show the private profile
8989
assert.Contains(t, bodyString, `id="org-home-view-as-dropdown"`)
9090

9191
req = NewRequest(t, "GET", "/org3?view_as=member")

0 commit comments

Comments
 (0)