Skip to content

Commit cbf794c

Browse files
committed
Hide activity contributors, recent commits and code frequrency left tabs if there is no code permission
1 parent bf9500b commit cbf794c

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

routers/web/repo/activity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func Activity(ctx *context.Context) {
5151
ctx.Data["DateFrom"] = timeFrom
5252
ctx.Data["DateUntil"] = timeUntil
5353
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
54+
ctx.Data["CanReadCode"] = ctx.Repo.CanRead(unit.TypeCode)
5455

5556
var err error
5657
if ctx.Data["Activity"], err = activities_model.GetActivityStats(ctx, ctx.Repo.Repository, timeFrom,

routers/web/repo/code_frequency.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"net/http"
99

10+
"code.gitea.io/gitea/models/unit"
1011
"code.gitea.io/gitea/modules/templates"
1112
"code.gitea.io/gitea/services/context"
1213
contributors_service "code.gitea.io/gitea/services/repository"
@@ -23,6 +24,7 @@ func CodeFrequency(ctx *context.Context) {
2324
ctx.Data["PageIsActivity"] = true
2425
ctx.Data["PageIsCodeFrequency"] = true
2526
ctx.PageData["repoLink"] = ctx.Repo.RepoLink
27+
ctx.Data["CanReadCode"] = ctx.Repo.CanRead(unit.TypeCode)
2628

2729
ctx.HTML(http.StatusOK, tplCodeFrequency)
2830
}

routers/web/repo/contributors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"net/http"
99

10+
"code.gitea.io/gitea/models/unit"
1011
"code.gitea.io/gitea/modules/templates"
1112
"code.gitea.io/gitea/services/context"
1213
contributors_service "code.gitea.io/gitea/services/repository"
@@ -21,6 +22,8 @@ func Contributors(ctx *context.Context) {
2122
ctx.Data["Title"] = ctx.Tr("repo.activity.navbar.contributors")
2223
ctx.Data["PageIsActivity"] = true
2324
ctx.Data["PageIsContributors"] = true
25+
ctx.Data["CanReadCode"] = ctx.Repo.CanRead(unit.TypeCode)
26+
2427
ctx.HTML(http.StatusOK, tplContributors)
2528
}
2629

routers/web/repo/recent_commits.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"net/http"
99

10+
"code.gitea.io/gitea/models/unit"
1011
"code.gitea.io/gitea/modules/templates"
1112
"code.gitea.io/gitea/services/context"
1213
contributors_service "code.gitea.io/gitea/services/repository"
@@ -23,6 +24,7 @@ func RecentCommits(ctx *context.Context) {
2324
ctx.Data["PageIsActivity"] = true
2425
ctx.Data["PageIsRecentCommits"] = true
2526
ctx.PageData["repoLink"] = ctx.Repo.RepoLink
27+
ctx.Data["CanReadCode"] = ctx.Repo.CanRead(unit.TypeCode)
2628

2729
ctx.HTML(http.StatusOK, tplRecentCommits)
2830
}

templates/repo/navbar.tmpl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
<a class="{{if .PageIsPulse}}active {{end}}item" href="{{.RepoLink}}/activity">
33
{{ctx.Locale.Tr "repo.activity.navbar.pulse"}}
44
</a>
5-
<a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
6-
{{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
7-
</a>
8-
<a class="{{if .PageIsCodeFrequency}}active{{end}} item" href="{{.RepoLink}}/activity/code-frequency">
9-
{{ctx.Locale.Tr "repo.activity.navbar.code_frequency"}}
10-
</a>
11-
<a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
12-
{{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
13-
</a>
5+
{{if .CanReadCode}}
6+
<a class="{{if .PageIsContributors}}active {{end}}item" href="{{.RepoLink}}/activity/contributors">
7+
{{ctx.Locale.Tr "repo.activity.navbar.contributors"}}
8+
</a>
9+
<a class="{{if .PageIsCodeFrequency}}active{{end}} item" href="{{.RepoLink}}/activity/code-frequency">
10+
{{ctx.Locale.Tr "repo.activity.navbar.code_frequency"}}
11+
</a>
12+
<a class="{{if .PageIsRecentCommits}}active{{end}} item" href="{{.RepoLink}}/activity/recent-commits">
13+
{{ctx.Locale.Tr "repo.activity.navbar.recent_commits"}}
14+
</a>
15+
{{end}}
1416
</div>

0 commit comments

Comments
 (0)